Jump to content

Compiler/Simple file inclusion pre processor: Difference between revisions

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>.
 
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
 
infile = length(ARGS) <> 10 ? stdin : ARGS[1] : stdin
outfile = length(ARGS) <> 21 ? stdout : ARGS[2] : stdout
 
function includefile(s)
Line 454 ⟶ 458:
 
input = read(infile, String)
output = replace(input, r"\sinclude\(\"[^\"]+\"\s\)\s" => includefile)
 
output = replace(input, r"\sinclude\(\"[^\"]+\"\s\)" => includefile)
 
write(outfile, output)
</lang>
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.