Skip to content

Commit 3b01b2a

Browse files
Add separate metadata entry for every block parens (#13996)
1 parent 9c7604c commit 3b01b2a

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,7 @@ build_block([{Op, ExprMeta, Args}], {Before, After}) ->
791791
case ?token_metadata() of
792792
true ->
793793
ParensEntry = meta_from_token(Before) ++ [{closing, meta_from_token(After)}],
794-
case ExprMeta of
795-
% If there are multiple parens, those will result in subsequent
796-
% build_block/2 calls, so we can assume parens entry is first
797-
[{parens, Parens} | Meta] ->
798-
[{parens, [ParensEntry | Parens]} | Meta];
799-
800-
Meta ->
801-
[{parens, [ParensEntry]} | Meta]
802-
end;
794+
[{parens, ParensEntry} | ExprMeta];
803795
false ->
804796
ExprMeta
805797
end,
@@ -1147,7 +1139,7 @@ parens_meta({Open, Close}) ->
11471139
case ?token_metadata() of
11481140
true ->
11491141
ParensEntry = meta_from_token(Open) ++ [{closing, meta_from_token(Close)}],
1150-
[{parens, [ParensEntry]}];
1142+
[{parens, ParensEntry}];
11511143
false ->
11521144
[]
11531145
end;

lib/elixir/test/elixir/kernel/parser_test.exs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ defmodule Kernel.ParserTest do
657657
1,
658658
{:+,
659659
[
660-
parens: [[line: 1, column: 5, closing: [line: 1, column: 11]]],
660+
parens: [line: 1, column: 5, closing: [line: 1, column: 11]],
661661
line: 1,
662662
column: 8
663663
], [2, 3]}
@@ -671,10 +671,8 @@ defmodule Kernel.ParserTest do
671671
1,
672672
{:+,
673673
[
674-
parens: [
675-
[line: 1, column: 5, closing: [line: 1, column: 13]],
676-
[line: 1, column: 6, closing: [line: 1, column: 12]]
677-
],
674+
parens: [line: 1, column: 5, closing: [line: 1, column: 13]],
675+
parens: [line: 1, column: 6, closing: [line: 1, column: 12]],
678676
line: 1,
679677
column: 9
680678
], [2, 3]}
@@ -688,17 +686,33 @@ defmodule Kernel.ParserTest do
688686
file = "()"
689687

690688
assert string_to_quoted.(file) ==
691-
{:__block__, [parens: [[line: 1, column: 1, closing: [line: 1, column: 2]]]], []}
689+
{:__block__, [parens: [line: 1, column: 1, closing: [line: 1, column: 2]]], []}
692690

693691
file = "(())"
694692

695693
assert string_to_quoted.(file) ==
696694
{:__block__,
697695
[
698-
parens: [
699-
[line: 1, column: 1, closing: [line: 1, column: 4]],
700-
[line: 1, column: 2, closing: [line: 1, column: 3]]
701-
]
696+
parens: [line: 1, column: 1, closing: [line: 1, column: 4]],
697+
parens: [line: 1, column: 2, closing: [line: 1, column: 3]]
698+
], []}
699+
700+
file = """
701+
(
702+
# Foo
703+
(
704+
# Bar
705+
)
706+
)
707+
"""
708+
709+
assert string_to_quoted.(file) ==
710+
{:__block__,
711+
[
712+
end_of_expression: [newlines: 1, line: 6, column: 2],
713+
parens: [line: 1, column: 1, closing: [line: 6, column: 1]],
714+
end_of_expression: [newlines: 1, line: 5, column: 4],
715+
parens: [line: 3, column: 3, closing: [line: 5, column: 3]]
702716
], []}
703717
end
704718

@@ -710,7 +724,7 @@ defmodule Kernel.ParserTest do
710724
[
711725
{:->,
712726
[
713-
parens: [[line: 1, column: 4, closing: [line: 1, column: 5]]],
727+
parens: [line: 1, column: 4, closing: [line: 1, column: 5]],
714728
line: 1,
715729
column: 7
716730
], [[], {:x, [line: 1, column: 10], nil}]}
@@ -725,7 +739,7 @@ defmodule Kernel.ParserTest do
725739
[
726740
{:->,
727741
[
728-
parens: [[line: 1, column: 4, closing: [line: 1, column: 9]]],
742+
parens: [line: 1, column: 4, closing: [line: 1, column: 9]],
729743
line: 1,
730744
column: 11
731745
],
@@ -753,7 +767,7 @@ defmodule Kernel.ParserTest do
753767
do: [
754768
{:->,
755769
[
756-
parens: [[line: 1, column: 12, closing: [line: 1, column: 17]]],
770+
parens: [line: 1, column: 12, closing: [line: 1, column: 17]],
757771
line: 1,
758772
column: 19
759773
],
@@ -807,7 +821,7 @@ defmodule Kernel.ParserTest do
807821
[
808822
{:__block__,
809823
[
810-
parens: [[line: 1, closing: [line: 1]]],
824+
parens: [line: 1, closing: [line: 1]],
811825
token: "1",
812826
line: 1
813827
], [1]}
@@ -817,7 +831,7 @@ defmodule Kernel.ParserTest do
817831
]}
818832

819833
assert string_to_quoted.("(1)") ==
820-
{:__block__, [parens: [[line: 1, closing: [line: 1]]], token: "1", line: 1], [1]}
834+
{:__block__, [parens: [line: 1, closing: [line: 1]], token: "1", line: 1], [1]}
821835
end
822836

823837
test "adds identifier_location for qualified identifiers" do

0 commit comments

Comments
 (0)