Those are not comments, but line number info necessary to generate the debug info. You can just ignore them when you are processing the AST. If you are writing a macro or otherwise transforming the AST before evaluting it or passing it to the compiler, you should keep the line number nodes whenever possible. If you remove them, it’ll be impossible to generate correct line numbers in the code you generate.
julia> function filter_lineno(ex::Expr)
filter!(ex.args) do e
isa(e, LineNumberNode) && return false
if isa(e, Expr)
(e::Expr).head === :line && return false
filter_lineno(e::Expr)
end
return true
end
return ex
end
filter_lineno (generic function with 1 method)
julia> macro m1(ex::Expr)
esc(filter_lineno(ex))
end
@m1 (macro with 1 method)
julia> macro m2(ex::Expr)
esc(ex)
end
@m2 (macro with 1 method)
julia> @m1 function f()
error()
end
f (generic function with 1 method)
julia> @m2 function f2()
error()
end
f2 (generic function with 1 method)
julia> f()
ERROR:
in f() at ./<missing>:0
julia> f2()
ERROR:
in f2() at ./REPL[5]:2