Skip to content

Commit

Permalink
Add token metadata to distinguish between :nil and nil (#13999)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Nov 18, 2024
1 parent 0174d50 commit 8e1d041
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/elixir/src/elixir_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ access_expr -> bin_heredoc : build_bin_heredoc('$1').
access_expr -> list_heredoc : build_list_heredoc('$1').
access_expr -> bitstring : '$1'.
access_expr -> sigil : build_sigil('$1').
access_expr -> atom : handle_literal(?exprs('$1'), '$1').
access_expr -> atom_quoted : handle_literal(?exprs('$1'), '$1', atom_delimiter('$1')).
access_expr -> atom_safe : build_quoted_atom('$1', true, atom_delimiter('$1')).
access_expr -> atom_unsafe : build_quoted_atom('$1', false, atom_delimiter('$1')).
access_expr -> atom : handle_literal(?exprs('$1'), '$1', atom_colon_meta('$1')).
access_expr -> atom_quoted : handle_literal(?exprs('$1'), '$1', atom_delimiter_meta('$1')).
access_expr -> atom_safe : build_quoted_atom('$1', true, atom_delimiter_meta('$1')).
access_expr -> atom_unsafe : build_quoted_atom('$1', false, atom_delimiter_meta('$1')).
access_expr -> dot_alias : '$1'.
access_expr -> parens_call : '$1'.

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

atom_delimiter({_Kind, {_Line, _Column, Delimiter}, _Args}) ->
atom_colon_meta({atom, _Location, Atom}) when Atom =:= true orelse Atom =:= false orelse Atom =:= nil ->
[{format, atom}];
atom_colon_meta(_) ->
[].

atom_delimiter_meta({_Kind, {_Line, _Column, Delimiter}, _Args}) ->
case ?token_metadata() of
true -> [{delimiter, <<Delimiter>>}];
false -> []
Expand Down
3 changes: 3 additions & 0 deletions lib/elixir/test/elixir/kernel/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ defmodule Kernel.ParserTest do
assert string_to_quoted.("nil") == {:__block__, [line: 1], [nil]}
assert string_to_quoted.(":one") == {:__block__, [line: 1], [:one]}

assert string_to_quoted.("true") == {:__block__, [line: 1], [true]}
assert string_to_quoted.(":true") == {:__block__, [format: :atom, line: 1], [true]}

assert string_to_quoted.("[one: :two]") == {
:__block__,
[{:closing, [line: 1]}, {:line, 1}],
Expand Down

0 comments on commit 8e1d041

Please sign in to comment.