Skip to content

Commit

Permalink
Fix incomplete_tag generation with trailing whitespace (#518)
Browse files Browse the repository at this point in the history
Previously we relied on the last SyntaxNode consuming all trailing
whitespace when detecting incomplete syntax. However this assumption was
broken by #397 and is generally fragile with respect to any extra
bump_trivia() calls. Fix this by just comparing to the stream position
before any bumping of remaining trivia.
  • Loading branch information
c42f authored Dec 8, 2024
1 parent 9483de8 commit 2d19c06
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti
end
end
parse!(stream; rule=options)
pos_before_trivia = last_byte(stream)
if options === :statement
bump_trivia(stream; skip_newlines=false)
if peek(stream) == K"NewlineWs"
Expand All @@ -179,7 +180,7 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti

if any_error(stream)
tree = build_tree(SyntaxNode, stream, first_line=lineno, filename=filename)
tag = _incomplete_tag(tree, lastindex(code))
tag = _incomplete_tag(tree, pos_before_trivia)
if _has_v1_10_hooks
exc = ParseError(stream, filename=filename, first_line=lineno,
incomplete_tag=tag)
Expand Down
3 changes: 3 additions & 0 deletions test/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ end
"1, " => :other
"1,\n" => :other
"1, \n" => :other
"f(1, " => :other
"[x " => :other
"( " => :other

# Reference parser fails to detect incomplete exprs in this case
"(x for y" => :other
Expand Down

0 comments on commit 2d19c06

Please sign in to comment.