Skip to content

Commit 6ee313a

Browse files
committed
Only break newlines if original char is a newline
1 parent c5f1c64 commit 6ee313a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ tokenize([$?, $\\, H | T], Line, Column, Scope, Tokens) ->
241241
end,
242242

243243
Token = {char, {Line, Column, [$?, $\\, H]}, Char},
244-
case Char of
244+
case H of
245245
$\n ->
246-
%% If Char is a literal line feed, we already emit a warning,
246+
%% If original char is a literal line feed, we already emit a warning,
247247
%% but we need to bump the line without emitting an EOL token.
248248
tokenize_eol(T, Line, NewScope, [Token | Tokens]);
249249
_ ->
@@ -262,7 +262,7 @@ tokenize([$?, Char | T], Line, Column, Scope, Tokens) ->
262262
Token = {char, {Line, Column, [$?, Char]}, Char},
263263
case Char of
264264
$\n ->
265-
%% If Char is a literal line feed, we already emit a warning,
265+
%% If original char is a literal line feed, we already emit a warning,
266266
%% but we need to bump the line without emitting an EOL token.
267267
tokenize_eol(T, Line, NewScope, [Token | Tokens]);
268268
_ ->

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,9 @@ defmodule Kernel.ParserTest do
14341434
assert parse!("{?\n}\n{123}") ==
14351435
{:__block__, [], [{:{}, [line: 1], ~c"\n"}, {:{}, [line: 3], ~c"{"}]}
14361436

1437+
assert parse!("{?\\n}\n{123}") ==
1438+
{:__block__, [], [{:{}, [line: 1], ~c"\n"}, {:{}, [line: 2], ~c"{"}]}
1439+
14371440
assert parse!("{?\\\n}\n{123}") ==
14381441
{:__block__, [], [{:{}, [line: 1], ~c"\n"}, {:{}, [line: 3], ~c"{"}]}
14391442
end)

0 commit comments

Comments
 (0)