Skip to content

Commit 05b650f

Browse files
author
José Valim
committed
Change preference of |> to support constructs like 1..5 |> Enum.to_list
1 parent b3e8a3d commit 05b650f

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* backwards incompatible changes
3939
* [Kernel] `IO.gets`, `IO.getb` and friends now return binaries when reading from stdio
4040
* [Kernel] `List.Dict` was moved to `ListDict`
41+
* [Kernel] Precedence of `|>` has changed to lower to support constructs like `1..5 |> Enum.to_list`
4142
* [Mix] `mix escriptize` now receives arguments as binaries
4243

4344
# v0.8.2 (2013-04-20)

lib/elixir/src/elixir_parser.yrl

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Nonterminals
22
grammar expr_list
33
expr paren_expr block_expr fn_expr bracket_expr call_expr bracket_at_expr max_expr
44
base_expr matched_expr matched_op_expr unmatched_expr op_expr
5-
add_op mult_op unary_op two_op pipeline_op bin_concat_op
5+
add_op mult_op unary_op two_op right_op bin_concat_op
66
match_op send_op default_op when_op pipe_op in_op inc_op range_op
77
andand_op oror_op and_op or_op comp_expr_op colon_colon_op three_op at_op
88
open_paren close_paren empty_paren
@@ -30,7 +30,7 @@ Terminals
3030
'true' 'false' 'nil'
3131
'=' '+' '-' '*' '/' '++' '--' '**' '//'
3232
'(' ')' '[' ']' '{' '}' '<<' '>>' '::'
33-
eol ',' '&' '|' '.' '^' '@' '<-' '<>' '->' '|>' '/>' '=~'
33+
eol ',' '&' '|' '.' '^' '@' '<-' '<>' '->' '|>' '=~'
3434
'&&' '||' '!' '...' '..'
3535
'<<<' '>>>' '&&&' '|||' '^^^' '~~~'
3636
.
@@ -53,13 +53,13 @@ Left 140 or_op.
5353
Left 150 and_op.
5454
Left 160 comp_expr_op.
5555
Left 170 in_op.
56-
Left 180 range_op.
57-
Left 190 three_op.
58-
Left 200 add_op.
59-
Left 210 mult_op.
60-
Right 220 bin_concat_op.
61-
Right 230 two_op.
62-
Right 290 pipeline_op.
56+
Right 180 right_op.
57+
Left 190 range_op.
58+
Left 200 three_op.
59+
Left 210 add_op.
60+
Left 220 mult_op.
61+
Right 230 bin_concat_op.
62+
Right 240 two_op.
6363
Nonassoc 300 unary_op.
6464
Left 310 dot_call_op.
6565
Left 310 dot_op.
@@ -102,7 +102,7 @@ op_expr -> match_op expr : { '$1', '$2' }.
102102
op_expr -> add_op expr : { '$1', '$2' }.
103103
op_expr -> mult_op expr : { '$1', '$2' }.
104104
op_expr -> two_op expr : { '$1', '$2' }.
105-
op_expr -> pipeline_op expr : { '$1', '$2' }.
105+
op_expr -> right_op expr : { '$1', '$2' }.
106106
op_expr -> andand_op expr : { '$1', '$2' }.
107107
op_expr -> three_op expr : { '$1', '$2' }.
108108
op_expr -> oror_op expr : { '$1', '$2' }.
@@ -123,7 +123,7 @@ matched_op_expr -> match_op matched_expr : { '$1', '$2' }.
123123
matched_op_expr -> add_op matched_expr : { '$1', '$2' }.
124124
matched_op_expr -> mult_op matched_expr : { '$1', '$2' }.
125125
matched_op_expr -> two_op matched_expr : { '$1', '$2' }.
126-
matched_op_expr -> pipeline_op matched_expr : { '$1', '$2' }.
126+
matched_op_expr -> right_op matched_expr : { '$1', '$2' }.
127127
matched_op_expr -> andand_op matched_expr : { '$1', '$2' }.
128128
matched_op_expr -> three_op matched_expr : { '$1', '$2' }.
129129
matched_op_expr -> oror_op matched_expr : { '$1', '$2' }.
@@ -271,12 +271,10 @@ two_op -> '--' eol : '$1'.
271271
two_op -> '**' : '$1'.
272272
two_op -> '**' eol : '$1'.
273273

274-
pipeline_op -> '=~' : '$1'.
275-
pipeline_op -> '=~' eol : '$1'.
276-
pipeline_op -> '|>' : '$1'.
277-
pipeline_op -> '|>' eol : '$1'.
278-
pipeline_op -> '/>' : '$1'.
279-
pipeline_op -> '/>' eol : '$1'.
274+
right_op -> '=~' : '$1'.
275+
right_op -> '=~' eol : '$1'.
276+
right_op -> '|>' : '$1'.
277+
right_op -> '|>' eol : '$1'.
280278

281279
three_op -> '&&&' : '$1'.
282280
three_op -> '&&&' eol : '$1'.

lib/elixir/test/elixir/range_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Code.require_file "test_helper.exs", __DIR__
33
defmodule RangeTest do
44
use ExUnit.Case, async: true
55

6+
test :precedence do
7+
assert Enum.to_list(1..3+2) == [1,2,3,4,5]
8+
assert 1..3 |> Enum.to_list == [1,2,3]
9+
end
10+
611
test :first do
712
assert Range.new(first: 1, last: 3).first == 1
813
end

0 commit comments

Comments
 (0)