Skip to content

Commit b5eb9eb

Browse files
committed
Improve trivia attachment for ) in parse_brackets
The `)` was attached to the `parameters` expression, but should be attached to node along with the opening `(` instead.
1 parent 47ba19b commit b5eb9eb

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/parser.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,6 @@ function parse_unary_call(ps::ParseState)
11861186
parse_brackets(ps, K")") do had_commas, had_splat, num_semis, num_subexprs
11871187
is_call[] = had_commas || had_splat || initial_semi
11881188
is_block[] = !is_call[] && num_semis > 0
1189-
bump_closing_token(ps, K")")
11901189
return (needs_parameters=is_call[],
11911190
eq_is_kw_before_semi=is_call[],
11921191
eq_is_kw_after_semi=is_call[])
@@ -2009,8 +2008,7 @@ function parse_function(ps::ParseState)
20092008
# producing less consistent syntax for anonymous functions.
20102009
is_anon_func_ = Ref(is_anon_func)
20112010
parse_brackets(ps, K")") do _, _, _, _
2012-
bump_closing_token(ps, K")")
2013-
is_anon_func_[] = peek(ps) != K"("
2011+
is_anon_func_[] = peek(ps, 2) != K"("
20142012
return (needs_parameters = is_anon_func_[],
20152013
eq_is_kw_before_semi = is_anon_func_[],
20162014
eq_is_kw_after_semi = is_anon_func_[])
@@ -2491,7 +2489,6 @@ function parse_call_arglist(ps::ParseState, closer, is_macrocall)
24912489
ps = ParseState(ps, for_generator=true)
24922490

24932491
parse_brackets(ps, closer) do _, _, _, _
2494-
bump_closing_token(ps, closer)
24952492
return (needs_parameters=true,
24962493
eq_is_kw_before_semi=!is_macrocall,
24972494
eq_is_kw_after_semi=true)
@@ -2510,7 +2507,6 @@ function parse_vect(ps::ParseState, closer)
25102507
# [x=1, y=2] ==> (vect (= x 1) (= y 2))
25112508
# [x=1, ; y=2] ==> (vect (= x 1) (parameters (= y 2)))
25122509
parse_brackets(ps, closer) do _, _, _, _
2513-
bump_closing_token(ps, closer)
25142510
return (needs_parameters=true,
25152511
eq_is_kw_before_semi=false,
25162512
eq_is_kw_after_semi=false)
@@ -2868,7 +2864,6 @@ function parse_paren(ps::ParseState, check_identifiers=true)
28682864
is_tuple[] = had_commas || (had_splat && num_semis >= 1) ||
28692865
(initial_semi && (num_semis == 1 || num_subexprs > 0))
28702866
is_block[] = num_semis > 0
2871-
bump_closing_token(ps, K")")
28722867
return (needs_parameters=is_tuple[],
28732868
eq_is_kw_before_semi=false,
28742869
eq_is_kw_after_semi=is_tuple[])
@@ -3023,6 +3018,7 @@ function parse_brackets(after_parse::Function,
30233018
end
30243019
release_positions(ps.stream, params_marks)
30253020
release_positions(ps.stream, eq_positions)
3021+
bump_closing_token(ps, closing_kind)
30263022
end
30273023

30283024
is_indentation(b::UInt8) = (b == UInt8(' ') || b == UInt8('\t'))

test/parser.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,20 @@ broken_tests = [
791791
end
792792
end
793793

794+
@testset "Trivia attachment" begin
795+
@test show_green_tree("f(a;b)") == """
796+
1:6 │[toplevel]
797+
1:6 │ [call]
798+
1:1 │ Identifier ✔ "f"
799+
2:2 │ ( "("
800+
3:3 │ Identifier ✔ "a"
801+
4:5 │ [parameters]
802+
4:4 │ ; ";"
803+
5:5 │ Identifier ✔ "b"
804+
6:6 │ ) ")"
805+
"""
806+
end
807+
794808
@testset "Unicode normalization in tree conversion" begin
795809
# ɛµ normalizes to εμ
796810
@test test_parse(JuliaSyntax.parse_eq, "\u025B\u00B5()") == "(call \u03B5\u03BC)"

test/test_utils.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,7 @@ function itest_parse(production, code; version::VersionNumber=v"1.6")
250250
nothing
251251
end
252252

253+
function show_green_tree(code; version::VersionNumber=v"1.6")
254+
t = JuliaSyntax.parseall(GreenNode, code, version=version)
255+
sprint(show, MIME"text/plain"(), t, code)
256+
end

0 commit comments

Comments
 (0)