Skip to content

Commit 40f1453

Browse files
committed
Change representation to support multiple parens
1 parent bc06c34 commit 40f1453

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,16 @@ build_block([{Op, ExprMeta, Args}], {Before, After}) ->
786786
ExprMetaWithExtra =
787787
case ?token_metadata() of
788788
true ->
789-
ExprMeta ++ [{parens_opening, meta_from_token(Before)}, {parens_closing, meta_from_token(After)}];
789+
ParensEntry = meta_from_token(Before) ++ [{closing, meta_from_token(After)}],
790+
case ExprMeta of
791+
% If there are multiple parens, those will result in subsequent
792+
% build_block/2 calls, so we can assume parens entry is first
793+
[{parens, Parens} | Meta] ->
794+
[{parens, [ParensEntry | Parens]} | Meta];
795+
796+
Meta ->
797+
[{parens, [ParensEntry]} | Meta]
798+
end;
790799
false ->
791800
ExprMeta
792801
end,

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,26 @@ defmodule Kernel.ParserTest do
618618
1,
619619
{:+,
620620
[
621+
parens: [[line: 1, column: 5, closing: [line: 1, column: 11]]],
621622
line: 1,
622-
column: 8,
623-
parens_opening: [line: 1, column: 5],
624-
parens_closing: [line: 1, column: 11]
623+
column: 8
624+
], [2, 3]}
625+
]}
626+
627+
file = "1 + ((2 + 3))"
628+
629+
assert Code.string_to_quoted!(file, token_metadata: true, columns: true) ==
630+
{:+, [line: 1, column: 3],
631+
[
632+
1,
633+
{:+,
634+
[
635+
parens: [
636+
[line: 1, column: 5, closing: [line: 1, column: 13]],
637+
[line: 1, column: 6, closing: [line: 1, column: 12]]
638+
],
639+
line: 1,
640+
column: 9
625641
], [2, 3]}
626642
]}
627643
end
@@ -666,19 +682,17 @@ defmodule Kernel.ParserTest do
666682
[
667683
{:__block__,
668684
[
685+
parens: [[line: 1, closing: [line: 1]]],
669686
token: "1",
670-
line: 1,
671-
parens_opening: [line: 1],
672-
parens_closing: [line: 1]
687+
line: 1
673688
], [1]}
674689
],
675690
{:__block__, [delimiter: "\"", line: 1], ["hello"]}
676691
]}
677692
]}
678693

679694
assert string_to_quoted.("(1)") ==
680-
{:__block__,
681-
[token: "1", line: 1, parens_opening: [line: 1], parens_closing: [line: 1]], [1]}
695+
{:__block__, [parens: [[line: 1, closing: [line: 1]]], token: "1", line: 1], [1]}
682696
end
683697

684698
test "adds identifier_location for qualified identifiers" do

0 commit comments

Comments
 (0)