Skip to content

Commit 96a1628

Browse files
author
José Valim
committed
Unify precedence of ++, --, **, .., <> ops
1 parent d6de097 commit 96a1628

File tree

3 files changed

+9
-37
lines changed

3 files changed

+9
-37
lines changed

lib/elixir/lib/macro.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ defmodule Macro do
4141
o when o in [:==, :!=, :<, :<=, :>=, :>, :=~, :===, :!==] -> {:left, 150}
4242
o when o in [:<-, :|>, :<<<, :>>>] -> {:right, 160}
4343
:in -> {:left, 170}
44-
:.. -> {:left, 200}
44+
o when o in [:++, :--, :**, :.., :<>] -> {:right, 200}
4545
o when o in [:+, :-] -> {:left, 210}
4646
o when o in [:*, :/] -> {:left, 220}
47-
o when o in [:<>] -> {:right, 230}
48-
o when o in [:++, :--, :**] -> {:right, 240}
4947
:^^^ -> {:left, 250}
5048
:. -> {:left, 310}
5149
end

lib/elixir/src/elixir_parser.yrl

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Nonterminals
55
op_expr matched_op_expr no_parens_op_expr
66
comp_op_eol at_op_eol unary_op_eol and_op_eol or_op_eol tail_op_eol
77
add_op_eol mult_op_eol exp_op_eol two_op_eol type_op_eol stab_op_eol
8-
arrow_op_eol range_op_eol than_op_eol default_op_eol match_op_eol
8+
arrow_op_eol default_op_eol match_op_eol
99
when_op_eol in_op_eol inc_op_eol
1010
open_paren close_paren empty_paren
1111
open_bracket close_bracket
@@ -31,7 +31,7 @@ Terminals
3131
number signed_number atom atom_string bin_string list_string sigil
3232
dot_call_op op_identifier
3333
comp_op at_op unary_op and_op or_op arrow_op match_op
34-
range_op in_op inc_op when_op than_op default_op tail_op
34+
in_op inc_op when_op default_op tail_op
3535
dual_op add_op mult_op exp_op two_op type_op stab_op
3636
'true' 'false' 'nil' 'do' eol ',' '.' '&'
3737
'(' ')' '[' ']' '{' '}' '<<' '>>'
@@ -57,11 +57,9 @@ Left 140 and_op_eol. %% &&, &&&, and
5757
Left 150 comp_op_eol. %% <, >, <=, >=, ==, !=, =~, ===, !==
5858
Right 160 arrow_op_eol. %% < (op), (op) > (e.g <-, |>, <<<, >>>)
5959
Left 170 in_op_eol. %% in
60-
Left 200 range_op_eol. %% ..
60+
Right 200 two_op_eol. %% ++, --, **, .., <>
6161
Left 210 add_op_eol. %% + (op), - (op)
6262
Left 220 mult_op_eol. %% * (op), / (op)
63-
Right 230 than_op_eol. %% < (op) > (e.g <>)
64-
Right 240 two_op_eol. %% ++, --, **
6563
Left 250 exp_op_eol. %% ^ (op) (e.g ^^^)
6664
Nonassoc 300 unary_op_eol. %% +, -, !, ^, not, &, ~~~
6765
Left 310 dot_call_op.
@@ -141,11 +139,9 @@ op_expr -> two_op_eol expr : { '$1', '$2' }.
141139
op_expr -> and_op_eol expr : { '$1', '$2' }.
142140
op_expr -> or_op_eol expr : { '$1', '$2' }.
143141
op_expr -> tail_op_eol expr : { '$1', '$2' }.
144-
op_expr -> than_op_eol expr : { '$1', '$2' }.
145142
op_expr -> in_op_eol expr : { '$1', '$2' }.
146143
op_expr -> inc_op_eol expr : { '$1', '$2' }.
147144
op_expr -> when_op_eol expr : { '$1', '$2' }.
148-
op_expr -> range_op_eol expr : { '$1', '$2' }.
149145
op_expr -> default_op_eol expr : { '$1', '$2' }.
150146
op_expr -> type_op_eol expr : { '$1', '$2' }.
151147
op_expr -> comp_op_eol expr : { '$1', '$2' }.
@@ -159,10 +155,8 @@ no_parens_op_expr -> two_op_eol no_parens_expr : { '$1', '$2' }.
159155
no_parens_op_expr -> and_op_eol no_parens_expr : { '$1', '$2' }.
160156
no_parens_op_expr -> or_op_eol no_parens_expr : { '$1', '$2' }.
161157
no_parens_op_expr -> tail_op_eol no_parens_expr : { '$1', '$2' }.
162-
no_parens_op_expr -> than_op_eol no_parens_expr : { '$1', '$2' }.
163158
no_parens_op_expr -> in_op_eol no_parens_expr : { '$1', '$2' }.
164159
no_parens_op_expr -> inc_op_eol no_parens_expr : { '$1', '$2' }.
165-
no_parens_op_expr -> range_op_eol no_parens_expr : { '$1', '$2' }.
166160
no_parens_op_expr -> default_op_eol no_parens_expr : { '$1', '$2' }.
167161
no_parens_op_expr -> type_op_eol no_parens_expr : { '$1', '$2' }.
168162
no_parens_op_expr -> comp_op_eol no_parens_expr : { '$1', '$2' }.
@@ -180,11 +174,9 @@ matched_op_expr -> two_op_eol matched_expr : { '$1', '$2' }.
180174
matched_op_expr -> and_op_eol matched_expr : { '$1', '$2' }.
181175
matched_op_expr -> or_op_eol matched_expr : { '$1', '$2' }.
182176
matched_op_expr -> tail_op_eol matched_expr : { '$1', '$2' }.
183-
matched_op_expr -> than_op_eol matched_expr : { '$1', '$2' }.
184177
matched_op_expr -> in_op_eol matched_expr : { '$1', '$2' }.
185178
matched_op_expr -> inc_op_eol matched_expr : { '$1', '$2' }.
186179
matched_op_expr -> when_op_eol matched_expr : { '$1', '$2' }.
187-
matched_op_expr -> range_op_eol matched_expr : { '$1', '$2' }.
188180
matched_op_expr -> default_op_eol matched_expr : { '$1', '$2' }.
189181
matched_op_expr -> type_op_eol matched_expr : { '$1', '$2' }.
190182
matched_op_expr -> comp_op_eol matched_expr : { '$1', '$2' }.
@@ -338,9 +330,6 @@ or_op_eol -> or_op eol : '$1'.
338330
tail_op_eol -> tail_op : '$1'.
339331
tail_op_eol -> tail_op eol : '$1'.
340332

341-
than_op_eol -> than_op : '$1'.
342-
than_op_eol -> than_op eol : '$1'.
343-
344333
in_op_eol -> in_op : '$1'.
345334
in_op_eol -> in_op eol : '$1'.
346335

@@ -353,9 +342,6 @@ when_op_eol -> when_op eol : '$1'.
353342
stab_op_eol -> stab_op : '$1'.
354343
stab_op_eol -> stab_op eol : '$1'.
355344

356-
range_op_eol -> range_op : '$1'.
357-
range_op_eol -> range_op eol : '$1'.
358-
359345
at_op_eol -> at_op : '$1'.
360346
at_op_eol -> at_op eol : '$1'.
361347

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@
2525
-define(two_op(T1, T2),
2626
T1 == $+, T2 == $+;
2727
T1 == $-, T2 == $-;
28-
T1 == $*, T2 == $*).
29-
30-
-define(than_op(T1, T2),
31-
T1 == $<, T2 == $>).
28+
T1 == $*, T2 == $*;
29+
T1 == $<, T2 == $>;
30+
T1 == $., T2 == $.).
3231

3332
-define(mult_op(T),
3433
T == $* orelse T == $/).
3534

3635
-define(dual_op(T),
3736
T == $+ orelse T == $-).
3837

39-
-define(range_op(T1, T2),
40-
T1 == $., T2 == $.).
41-
4238
-define(arrow_op3(T1, T2, T3),
4339
T1 == $<, T2 == $<, T3 == $<;
4440
T1 == $>, T2 == $>, T3 == $>).
@@ -244,8 +240,7 @@ tokenize([$.,T1,T2,T3|Rest], Line, Scope, Tokens) when
244240
% ## Two Token Operators
245241
tokenize([$.,T1,T2|Rest], Line, Scope, Tokens) when
246242
?comp_op2(T1, T2); ?and_op(T1, T2); ?or_op(T1, T2); ?arrow_op(T1, T2);
247-
?range_op(T1, T2); ?than_op(T1, T2); ?default_op(T1, T2); ?two_op(T1, T2);
248-
?stab_op(T1, T2); ?type_op(T1, T2) ->
243+
?default_op(T1, T2); ?two_op(T1, T2); ?stab_op(T1, T2); ?type_op(T1, T2) ->
249244
handle_call_identifier(Rest, Line, list_to_atom([T1, T2]), Scope, Tokens);
250245

251246
% ## Single Token Operators
@@ -331,8 +326,7 @@ tokenize([$:,T1,T2,T3|Rest], Line, Scope, Tokens) when
331326
% ## Two Token Operators
332327
tokenize([$:,T1,T2|Rest], Line, Scope, Tokens) when
333328
?comp_op2(T1, T2); ?and_op(T1, T2); ?or_op(T1, T2); ?arrow_op(T1, T2);
334-
?range_op(T1, T2); ?than_op(T1, T2); ?default_op(T1, T2); ?two_op(T1, T2);
335-
?stab_op(T1, T2); ?type_op(T1, T2) ->
329+
?default_op(T1, T2); ?two_op(T1, T2); ?stab_op(T1, T2); ?type_op(T1, T2) ->
336330
tokenize(Rest, Line, Scope, [{ atom, Line, list_to_atom([T1,T2]) }|Tokens]);
337331

338332
% ## Single Token Operators
@@ -396,12 +390,6 @@ tokenize([T|Rest], Line, Scope, Tokens) when T == $(;
396390
tokenize([T1,T2|Rest], Line, Scope, Tokens) when ?two_op(T1, T2) ->
397391
handle_op(Rest, Line, two_op, list_to_atom([T1, T2]), Scope, Tokens);
398392

399-
tokenize([T1,T2|Rest], Line, Scope, Tokens) when ?than_op(T1, T2) ->
400-
handle_op(Rest, Line, than_op, list_to_atom([T1, T2]), Scope, Tokens);
401-
402-
tokenize([T1,T2|Rest], Line, Scope, Tokens) when ?range_op(T1, T2) ->
403-
handle_op(Rest, Line, range_op, list_to_atom([T1, T2]), Scope, Tokens);
404-
405393
tokenize([T1,T2|Rest], Line, Scope, Tokens) when ?arrow_op(T1, T2) ->
406394
handle_op(Rest, Line, arrow_op, list_to_atom([T1, T2]), Scope, Tokens);
407395

0 commit comments

Comments
 (0)