Skip to content

Commit 8011552

Browse files
committed
Remove ?break handling duplication
1 parent ebb7c73 commit 8011552

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

lib/elixir/src/elixir_interpolation.erl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,8 @@ extract([$\\ | Rest], Buffer, Output, Line, Column, Scope, Interpol, Last) ->
8080

8181
%% Catch all clause
8282

83-
extract([Char | _Rest], _Buffer, _Output, Line, Column, _Scope, _Interpol, _Last)
84-
when ?break(Char) ->
85-
Token = io_lib:format("\\u~4.16.0B", [Char]),
86-
Pos = io_lib:format(". If you want to use such character, use it in its escaped ~ts form instead", [Token]),
87-
{error, {?LOC(Line, Column),
88-
{"invalid line break character in string: ",
89-
Pos},
90-
Token}};
91-
9283
extract([Char1, Char2 | Rest], Buffer, Output, Line, Column, Scope, Interpol, Last)
93-
when Char1 =< 255, Char2 =< 255 ->
84+
when Char1 =< 255, Char2 =< 255, not (?break(Char1)) ->
9485
extract([Char2 | Rest], [Char1 | Buffer], Output, Line, Column + 1, Scope, Interpol, Last);
9586

9687
extract(Rest, Buffer, Output, Line, Column, Scope, Interpol, Last) ->

lib/elixir/src/elixir_tokenizer.hrl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@
2424

2525
%% Bidirectional control
2626
%% Retrieved from https://trojansource.codes/trojan-source.pdf
27-
-define(bidi(C), C =:= 16#202A;
28-
C =:= 16#202B;
29-
C =:= 16#202D;
30-
C =:= 16#202E;
31-
C =:= 16#2066;
32-
C =:= 16#2067;
33-
C =:= 16#2068;
34-
C =:= 16#202C;
27+
-define(bidi(C), C =:= 16#202A orelse
28+
C =:= 16#202B orelse
29+
C =:= 16#202D orelse
30+
C =:= 16#202E orelse
31+
C =:= 16#2066 orelse
32+
C =:= 16#2067 orelse
33+
C =:= 16#2068 orelse
34+
C =:= 16#202C orelse
3535
C =:= 16#2069).
3636

3737
%% Unsupported newlines
3838
%% https://www.unicode.org/reports/tr55/
39-
-define(break(C), C =:= 16#000B;
40-
C =:= 16#000C;
41-
C =:= 16#0085;
42-
C =:= 16#2028;
39+
-define(break(C), C =:= 16#000B orelse
40+
C =:= 16#000C orelse
41+
C =:= 16#0085 orelse
42+
C =:= 16#2028 orelse
4343
C =:= 16#2029).

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,23 +1137,15 @@ defmodule Kernel.ParserTest do
11371137
"nofile:1:12:",
11381138
"invalid line break character in string: \\u000B. If you want to use such character, use it in its escaped \\u000B form instead"
11391139
],
1140-
:erlang.list_to_binary([34] ++ ~c"this is a " ++ [11, 34])
1140+
[34] ++ ~c"this is a " ++ [11, 34]
11411141
)
11421142

11431143
assert_syntax_error(
11441144
[
11451145
"nofile:1:12:",
11461146
"invalid line break character in string: \\u000C. If you want to use such character, use it in its escaped \\u000C form instead"
11471147
],
1148-
:erlang.list_to_binary([34] ++ ~c"this is a " ++ [12, 34])
1149-
)
1150-
1151-
assert_syntax_error(
1152-
[
1153-
"nofile:1:12:",
1154-
"invalid line break character in string: \\u0085. If you want to use such character, use it in its escaped \\u0085 form instead"
1155-
],
1156-
<<34, "this is a ", 194, 133, 34>>
1148+
[34] ++ ~c"this is a " ++ [12, 34]
11571149
)
11581150
end
11591151

0 commit comments

Comments
 (0)