I am trying to come up with a script to check program’s syntax without running it. Ideally this should not rely on external packages as the goal in mind is to use this within online judge system at competitive programming platform codeforces.com. Initial request for this came up here https://github.com/MikeMirzayanov/binary-heap-benchmark/pull/16
I would appreciate your comments on whether something along these lines is reasonable, platform-independent and safe from false-positive. One particular point is whether [:incomplete, :error
is an exhaustive list of the things that need to be caught. Thanks!
function validatesyntax(fname)
inp = read(fname, String)
ast = ccall(:jl_parse_all, Any, (Cstring, Int64, Cstring, Int64), inp, length(inp), fname, length(fname))
if length(ast.args) > 1 && (ast.args[end].head in [:incomplete, :error])
println("syntax error $(ast.args[end])")
end
end
(length(ARGS) == 1) && validatesyntax(ARGS[1])