Skip to content

Commit 843706e

Browse files
author
José Valim
committed
Add free operators
<<~, ~>>, <~, ~>, <~>, <|>
1 parent 172bfdb commit 843706e

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

lib/elixir/lib/macro.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule Macro do
1717
:<, :>, :->,
1818
:+, :-, :*, :/, :=, :|, :.,
1919
:and, :or, :when, :in,
20+
:~>>, :<<~, :~>, :<~, :<~>, :<|>,
2021
:<<<, :>>>, :|||, :&&&, :^^^, :~~~]
2122

2223
@doc false
@@ -39,7 +40,8 @@ defmodule Macro do
3940
o when o in [:&&, :&&&, :and] -> {:left, 140}
4041
o when o in [:==, :!=, :=~, :===, :!==] -> {:left, 150}
4142
o when o in [:<, :<=, :>=, :>] -> {:left, 160}
42-
o when o in [:|>, :<<<, :>>>] -> {:left, 170}
43+
o when o in [:|>, :<<<, :>>>, :<~, :~>,
44+
:<<~, :~>>, :<~>, :<|>] -> {:left, 170}
4345
:in -> {:left, 180}
4446
o when o in [:++, :--, :.., :<>] -> {:right, 200}
4547
o when o in [:+, :-] -> {:left, 210}

lib/elixir/src/elixir_parser.yrl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ Left 130 or_op_eol. %% ||, |||, or
5858
Left 140 and_op_eol. %% &&, &&&, and
5959
Left 150 comp_op_eol. %% ==, !=, =~, ===, !==
6060
Left 160 rel_op_eol. %% <, >, <=, >=
61-
Left 170 arrow_op_eol. %% < (op), (op) > (e.g |>, <<<, >>>)
61+
Left 170 arrow_op_eol. %% < (op), (op) > (|>, <<<, >>>, ~>>, <<~, ~>, <~, <~>, <|>)
6262
Left 180 in_op_eol. %% in
6363
Right 200 two_op_eol. %% ++, --, .., <>
6464
Left 210 add_op_eol. %% + (op), - (op)
6565
Left 220 mult_op_eol. %% * (op), / (op)
66-
Left 250 hat_op_eol. %% ^ (op) (e.g ^^^)
66+
Left 250 hat_op_eol. %% ^ (op) (^^^)
6767
Nonassoc 300 unary_op_eol. %% +, -, !, ^, not, ~~~
6868
Left 310 dot_call_op.
6969
Left 310 dot_op. %% .

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@
3333

3434
-define(arrow_op3(T1, T2, T3),
3535
T1 == $<, T2 == $<, T3 == $<;
36-
T1 == $>, T2 == $>, T3 == $>).
36+
T1 == $>, T2 == $>, T3 == $>;
37+
T1 == $~, T2 == $>, T3 == $>;
38+
T1 == $<, T2 == $<, T3 == $~;
39+
T1 == $<, T2 == $~, T3 == $>;
40+
T1 == $<, T2 == $|, T3 == $>).
3741

3842
-define(arrow_op(T1, T2),
39-
T1 == $|, T2 == $>).
43+
T1 == $|, T2 == $>;
44+
T1 == $~, T2 == $>;
45+
T1 == $<, T2 == $~).
4046

4147
-define(rel_op(T),
4248
T == $<;

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ defmodule Inspect.AtomTest do
4141

4242
test :op do
4343
assert inspect(:+) == ":+"
44+
assert inspect(:<~) == ":<~"
45+
assert inspect(:~>) == ":~>"
4446
assert inspect(:&&&) == ":&&&"
4547
assert inspect(:~~~) == ":~~~"
48+
assert inspect(:<<~) == ":<<~"
49+
assert inspect(:~>>) == ":<<~"
50+
assert inspect(:<~>) == ":<~>"
51+
assert inspect(:<|>) == ":<|>"
4652
end
4753

4854
test :... do

0 commit comments

Comments
 (0)