Skip to content

Commit f56139a

Browse files
committed
Add closing token metadata to a.{}, closes #14682
1 parent 8ac8230 commit f56139a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ dot_identifier -> matched_expr dot_op identifier : build_dot('$2', '$1', '$3').
479479

480480
dot_alias -> alias : build_alias('$1').
481481
dot_alias -> matched_expr dot_op alias : build_dot_alias('$2', '$1', '$3').
482-
dot_alias -> matched_expr dot_op open_curly '}' : build_dot_container('$2', '$1', [], []).
482+
dot_alias -> matched_expr dot_op open_curly '}' : build_dot_container('$2', '$1', [], newlines_pair('$3', '$4')).
483483
dot_alias -> matched_expr dot_op open_curly container_args close_curly : build_dot_container('$2', '$1', '$4', newlines_pair('$3', '$5')).
484484

485485
dot_op_identifier -> op_identifier : '$1'.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,24 @@ defmodule Kernel.ParserTest do
702702
]}
703703
end
704704

705+
test "adds opening and closing information for tuples" do
706+
string_to_quoted = &Code.string_to_quoted!(&1, token_metadata: true, columns: true)
707+
708+
assert string_to_quoted.("{}") ==
709+
{:{}, [closing: [line: 1, column: 2], line: 1, column: 1], []}
710+
711+
assert string_to_quoted.("{123}") ==
712+
{:{}, [closing: [line: 1, column: 5], line: 1, column: 1], [123]}
713+
714+
assert string_to_quoted.("x.{}") ==
715+
{{:., [line: 1, column: 2], [{:x, [line: 1, column: 1], nil}, :{}]},
716+
[closing: [line: 1, column: 4], line: 1, column: 2], []}
717+
718+
assert string_to_quoted.("x.{123}") ==
719+
{{:., [line: 1, column: 2], [{:x, [line: 1, column: 1], nil}, :{}]},
720+
[closing: [line: 1, column: 7], line: 1, column: 2], [123]}
721+
end
722+
705723
test "adds opening and closing information for empty block" do
706724
string_to_quoted =
707725
&Code.string_to_quoted!(&1, token_metadata: true, columns: true, emit_warnings: false)

0 commit comments

Comments
 (0)