Skip to content

Commit 8e1d041

Browse files
Add token metadata to distinguish between :nil and nil (#13999)
1 parent 0174d50 commit 8e1d041

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ access_expr -> bin_heredoc : build_bin_heredoc('$1').
283283
access_expr -> list_heredoc : build_list_heredoc('$1').
284284
access_expr -> bitstring : '$1'.
285285
access_expr -> sigil : build_sigil('$1').
286-
access_expr -> atom : handle_literal(?exprs('$1'), '$1').
287-
access_expr -> atom_quoted : handle_literal(?exprs('$1'), '$1', atom_delimiter('$1')).
288-
access_expr -> atom_safe : build_quoted_atom('$1', true, atom_delimiter('$1')).
289-
access_expr -> atom_unsafe : build_quoted_atom('$1', false, atom_delimiter('$1')).
286+
access_expr -> atom : handle_literal(?exprs('$1'), '$1', atom_colon_meta('$1')).
287+
access_expr -> atom_quoted : handle_literal(?exprs('$1'), '$1', atom_delimiter_meta('$1')).
288+
access_expr -> atom_safe : build_quoted_atom('$1', true, atom_delimiter_meta('$1')).
289+
access_expr -> atom_unsafe : build_quoted_atom('$1', false, atom_delimiter_meta('$1')).
290290
access_expr -> dot_alias : '$1'.
291291
access_expr -> parens_call : '$1'.
292292

@@ -1029,7 +1029,12 @@ build_quoted_atom({_, Location, Args}, Safe, ExtraMeta) ->
10291029
binary_to_atom_op(true) -> binary_to_existing_atom;
10301030
binary_to_atom_op(false) -> binary_to_atom.
10311031

1032-
atom_delimiter({_Kind, {_Line, _Column, Delimiter}, _Args}) ->
1032+
atom_colon_meta({atom, _Location, Atom}) when Atom =:= true orelse Atom =:= false orelse Atom =:= nil ->
1033+
[{format, atom}];
1034+
atom_colon_meta(_) ->
1035+
[].
1036+
1037+
atom_delimiter_meta({_Kind, {_Line, _Column, Delimiter}, _Args}) ->
10331038
case ?token_metadata() of
10341039
true -> [{delimiter, <<Delimiter>>}];
10351040
false -> []

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ defmodule Kernel.ParserTest do
795795
assert string_to_quoted.("nil") == {:__block__, [line: 1], [nil]}
796796
assert string_to_quoted.(":one") == {:__block__, [line: 1], [:one]}
797797

798+
assert string_to_quoted.("true") == {:__block__, [line: 1], [true]}
799+
assert string_to_quoted.(":true") == {:__block__, [format: :atom, line: 1], [true]}
800+
798801
assert string_to_quoted.("[one: :two]") == {
799802
:__block__,
800803
[{:closing, [line: 1]}, {:line, 1}],

0 commit comments

Comments
 (0)