Skip to content

Commit 2d19c06

Browse files
authored
Fix incomplete_tag generation with trailing whitespace (#518)
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.
1 parent 9483de8 commit 2d19c06

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/hooks.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti
170170
end
171171
end
172172
parse!(stream; rule=options)
173+
pos_before_trivia = last_byte(stream)
173174
if options === :statement
174175
bump_trivia(stream; skip_newlines=false)
175176
if peek(stream) == K"NewlineWs"
@@ -179,7 +180,7 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti
179180

180181
if any_error(stream)
181182
tree = build_tree(SyntaxNode, stream, first_line=lineno, filename=filename)
182-
tag = _incomplete_tag(tree, lastindex(code))
183+
tag = _incomplete_tag(tree, pos_before_trivia)
183184
if _has_v1_10_hooks
184185
exc = ParseError(stream, filename=filename, first_line=lineno,
185186
incomplete_tag=tag)

test/hooks.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ end
181181
"1, " => :other
182182
"1,\n" => :other
183183
"1, \n" => :other
184+
"f(1, " => :other
185+
"[x " => :other
186+
"( " => :other
184187

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

0 commit comments

Comments
 (0)