Skip to content

Commit f6b0855

Browse files
rrreneJosé Valim
authored andcommitted
Fix column in :elixir_tokenizer for sigils with modifiers (#7529)
This fixes cases where :elixir_tokenizer does not account for sigil modifiers when determining the column for the next token. Signed-off-by: José Valim <[email protected]>
1 parent 8e6cc2c commit f6b0855

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ tokenize([$~, S, H, H, H | T] = Original, Line, Column, Scope, Tokens) when ?is_
182182
{ok, NewLine, NewColumn, Parts, Rest} ->
183183
{Final, Modifiers} = collect_modifiers(Rest, []),
184184
Token = {sigil, {Line, Column, nil}, S, Parts, Modifiers, <<H, H, H>>},
185-
tokenize(Final, NewLine, NewColumn, Scope, [Token | Tokens]);
185+
NewColumn2 = NewColumn + length(Modifiers),
186+
tokenize(Final, NewLine, NewColumn2, Scope, [Token | Tokens]);
186187
{error, Reason} ->
187188
{error, Reason, Original, Tokens}
188189
end;
@@ -192,7 +193,8 @@ tokenize([$~, S, H | T] = Original, Line, Column, Scope, Tokens) when ?is_sigil(
192193
{NewLine, NewColumn, Parts, Rest} ->
193194
{Final, Modifiers} = collect_modifiers(Rest, []),
194195
Token = {sigil, {Line, Column, nil}, S, Parts, Modifiers, <<H>>},
195-
tokenize(Final, NewLine, NewColumn, Scope, [Token | Tokens]);
196+
NewColumn2 = NewColumn + length(Modifiers),
197+
tokenize(Final, NewLine, NewColumn2, Scope, [Token | Tokens]);
196198
{error, Reason} ->
197199
Sigil = [$~, S, H],
198200
interpolation_error(Reason, Original, Tokens, " (for sigil ~ts starting at line ~B)", [Sigil, Line])

lib/elixir/test/erlang/tokenizer_test.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ sigil_terminator_test() ->
208208
[{sigil, {1, 1, nil}, 114, [<<"foo">>], [], <<"/">>}] = tokenize("~r/foo/"),
209209
[{sigil, {1, 1, nil}, 114, [<<"foo">>], [], <<"[">>}] = tokenize("~r[foo]"),
210210
[{sigil, {1, 1, nil}, 114, [<<"foo">>], [], <<"\"">>}] = tokenize("~r\"foo\""),
211+
[{sigil, {1, 1, nil}, 114, [<<"foo">>], [], <<"/">>},
212+
{comp_op, {1, 9, nil}, '=='},
213+
{identifier, {1, 12, nil}, bar}] = tokenize("~r/foo/ == bar"),
214+
[{sigil, {1, 1, nil}, 114, [<<"foo">>], "iu", <<"/">>},
215+
{comp_op, {1, 11, nil}, '=='},
216+
{identifier, {1, 14, nil}, bar}] = tokenize("~r/foo/iu == bar"),
211217
[{sigil, {1, 1, nil}, 83, [<<"sigil heredoc\n">>], [], <<"\"\"\"">>}] = tokenize("~S\"\"\"\nsigil heredoc\n\"\"\""),
212218
[{sigil, {1, 1, nil}, 83, [<<"sigil heredoc\n">>], [], <<"'''">>}] = tokenize("~S'''\nsigil heredoc\n'''").
213219

0 commit comments

Comments
 (0)