Compiler/Simple file inclusion pre processor: Difference between revisions
Content added Content deleted
Line 438: | Line 438: | ||
Since Julia already has an include function, adding another seems superfluous. However, one can be created for the purpose, and will be shown below. Such a Julia program could be compiled and run as the file <code>preprocess.jl</code>. |
Since Julia already has an include function, adding another seems superfluous. However, one can be created for the purpose, and will be shown below. Such a Julia program could be compiled and run as the file <code>preprocess.jl</code>. |
||
To use the program, run <code>julia preprocess.jl infile.jl outfile.jl</code> and include files using |
|||
the standard Julia syntax. Calls to the <code>include</code> function that contain a single argument which is a string in parentheses will be preproccessed. Other calls to <code>include</code> with different arguments will not be preprocessed by <code>preprocess.jl</code>. |
|||
<lang julia># preprocess.jl convert includes to file contenets |
<lang julia># preprocess.jl convert includes to file contenets |
||
infile = length(ARGS) |
infile = length(ARGS) > 0 ? ARGS[1] : stdin |
||
outfile = length(ARGS) |
outfile = length(ARGS) > 1 ? ARGS[2] : stdout |
||
function includefile(s) |
function includefile(s) |
||
Line 454: | Line 458: | ||
input = read(infile, String) |
input = read(infile, String) |
||
⚫ | |||
⚫ | |||
write(outfile, output) |
write(outfile, output) |
||
</lang> |
</lang> |