Compiler/Simple file inclusion pre processor: Difference between revisions

m
no edit summary
(Added more explanation and notes)
mNo edit summary
Line 433:
END
</pre>
 
=={{header|Julia}}==
Julia implements the <code>include</code> function, which includes a file into the current file for processing. Julia does JIT compiling, so neither the included file nor the file included into are necessarily compiled until their code is due to be run. One exception is the precompiling of modules, which allows preprocessed, precompiled code to be imported with the <code>using</code> or <code>import</code> keyword.
 
Since Julia already has an include function, adding another seems superfluous. However, one can be created for the purpose, and will be shown below. The Julia program could be compiled and run as the file <code>preprocess.jl</code>.
<lang julia># preprocess.jl convert includes to file contenets
 
infile = length(ARGS) < 1 ? stdin : ARGS[1]
outfile = length(ARGS) < 2 ? stdout : ARGS[2]
 
function includefile(s)
try
m = match(r"(\s)include\"([^\"]+)\"(\s)", s)
return m.captures[1] * read(m.captures[2], String) * m.captures[3]
catch y
warn(y)
return s
end
end
 
input = read(infile, String)
 
output = replace(input, r"\sinclude\"[^\"]+\"\s)" => includefile(x))
 
write(outfile, output)
</lang>
 
=={{header|Phix}}==
4,103

edits