Stream: helpdesk (published)

Topic: Find end of expression starting at a certain line


view this post on Zulip Mason Protter (Jul 29 2025 at 20:08):

If I have a file name and line number where I know there's a top-level julia expression, what would be the best way to find the line where that expression ends?

e.g. if I have a file my_file.jl

a = 1
b = 2
function foo()
    bar()
    baz()
end
c = 3
d = 4

I want a function find_expr_end_at(file, line) such that find_expr_end_at("my_file.jl", 3) returns 7 (i.e. the line after the end of the function definition)

view this post on Zulip jar (Jul 29 2025 at 20:40):

I think that info is accessible from JuliaSyntax.parseall(SyntaxNode, s)). I'm not that familiar with querying the structure, but it should be possible.


Last updated: Aug 14 2025 at 04:51 UTC