diff options
author | Aleksey Kladov <[email protected]> | 2018-08-07 13:21:15 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-07 13:23:05 +0100 |
commit | 42e3a8ef77d75cdd0abf4f0729082a112beefb67 (patch) | |
tree | 41df9eb51fa2abfdd9449cb2bac700f47d806184 | |
parent | ede506e0314a0560710cad291c1f91d939068cec (diff) |
infix range is range
-rw-r--r-- | src/grammar/expressions/mod.rs | 11 | ||||
-rw-r--r-- | tests/data/parser/ok/0029_range_forms.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/ok/0029_range_forms.txt | 29 |
3 files changed, 27 insertions, 14 deletions
diff --git a/src/grammar/expressions/mod.rs b/src/grammar/expressions/mod.rs index a94964c39..55e965ff4 100644 --- a/src/grammar/expressions/mod.rs +++ b/src/grammar/expressions/mod.rs | |||
@@ -92,17 +92,20 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) { | |||
92 | }; | 92 | }; |
93 | 93 | ||
94 | loop { | 94 | loop { |
95 | let is_range = p.current() == DOTDOT; | ||
95 | let (op_bp, op) = current_op(p); | 96 | let (op_bp, op) = current_op(p); |
96 | if op_bp < bp { | 97 | if op_bp < bp { |
97 | break; | 98 | break; |
98 | } | 99 | } |
100 | let m = lhs.precede(p); | ||
99 | match op { | 101 | match op { |
100 | Op::Simple => p.bump(), | 102 | Op::Simple => p.bump(), |
101 | Op::Composite(kind, n) => { | 103 | Op::Composite(kind, n) => { |
102 | p.bump_compound(kind, n); | 104 | p.bump_compound(kind, n); |
103 | } | 105 | } |
104 | } | 106 | } |
105 | lhs = bin_expr(p, r, lhs, op_bp + 1); | 107 | expr_bp(p, r, op_bp + 1); |
108 | lhs = m.complete(p, if is_range { RANGE_EXPR } else { BIN_EXPR }); | ||
106 | } | 109 | } |
107 | } | 110 | } |
108 | 111 | ||
@@ -330,9 +333,3 @@ fn struct_lit(p: &mut Parser) { | |||
330 | } | 333 | } |
331 | p.expect(R_CURLY); | 334 | p.expect(R_CURLY); |
332 | } | 335 | } |
333 | |||
334 | fn bin_expr(p: &mut Parser, r: Restrictions, lhs: CompletedMarker, bp: u8) -> CompletedMarker { | ||
335 | let m = lhs.precede(p); | ||
336 | expr_bp(p, r, bp); | ||
337 | m.complete(p, BIN_EXPR) | ||
338 | } | ||
diff --git a/tests/data/parser/ok/0029_range_forms.rs b/tests/data/parser/ok/0029_range_forms.rs index 74de11a7e..03f4ae7b2 100644 --- a/tests/data/parser/ok/0029_range_forms.rs +++ b/tests/data/parser/ok/0029_range_forms.rs | |||
@@ -2,4 +2,5 @@ fn foo() { | |||
2 | ..1 + 1; | 2 | ..1 + 1; |
3 | ..z = 2; | 3 | ..z = 2; |
4 | x = false..1 == 1; | 4 | x = false..1 == 1; |
5 | let x = 1..; | ||
5 | } | 6 | } |
diff --git a/tests/data/parser/ok/0029_range_forms.txt b/tests/data/parser/ok/0029_range_forms.txt index 8599f7dfc..2dbc6bdee 100644 --- a/tests/data/parser/ok/0029_range_forms.txt +++ b/tests/data/parser/ok/0029_range_forms.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | FILE@[0; 62) | 1 | FILE@[0; 79) |
2 | FN_ITEM@[0; 61) | 2 | FN_ITEM@[0; 78) |
3 | FN_KW@[0; 2) | 3 | FN_KW@[0; 2) |
4 | WHITESPACE@[2; 3) | 4 | WHITESPACE@[2; 3) |
5 | NAME@[3; 6) | 5 | NAME@[3; 6) |
@@ -8,7 +8,7 @@ FILE@[0; 62) | |||
8 | L_PAREN@[6; 7) | 8 | L_PAREN@[6; 7) |
9 | R_PAREN@[7; 8) | 9 | R_PAREN@[7; 8) |
10 | WHITESPACE@[8; 9) | 10 | WHITESPACE@[8; 9) |
11 | BLOCK_EXPR@[9; 61) | 11 | BLOCK_EXPR@[9; 78) |
12 | L_CURLY@[9; 10) | 12 | L_CURLY@[9; 10) |
13 | WHITESPACE@[10; 15) | 13 | WHITESPACE@[10; 15) |
14 | EXPR_STMT@[15; 23) | 14 | EXPR_STMT@[15; 23) |
@@ -50,7 +50,7 @@ FILE@[0; 62) | |||
50 | WHITESPACE@[42; 43) | 50 | WHITESPACE@[42; 43) |
51 | EQ@[43; 44) | 51 | EQ@[43; 44) |
52 | WHITESPACE@[44; 45) | 52 | WHITESPACE@[44; 45) |
53 | BIN_EXPR@[45; 58) | 53 | RANGE_EXPR@[45; 58) |
54 | LITERAL@[45; 50) | 54 | LITERAL@[45; 50) |
55 | FALSE_KW@[45; 50) | 55 | FALSE_KW@[45; 50) |
56 | DOTDOT@[50; 52) | 56 | DOTDOT@[50; 52) |
@@ -63,6 +63,21 @@ FILE@[0; 62) | |||
63 | LITERAL@[57; 58) | 63 | LITERAL@[57; 58) |
64 | INT_NUMBER@[57; 58) "1" | 64 | INT_NUMBER@[57; 58) "1" |
65 | SEMI@[58; 59) | 65 | SEMI@[58; 59) |
66 | WHITESPACE@[59; 60) | 66 | WHITESPACE@[59; 64) |
67 | R_CURLY@[60; 61) | 67 | LET_STMT@[64; 76) |
68 | WHITESPACE@[61; 62) | 68 | LET_KW@[64; 67) |
69 | WHITESPACE@[67; 68) | ||
70 | BIND_PAT@[68; 69) | ||
71 | NAME@[68; 69) | ||
72 | IDENT@[68; 69) "x" | ||
73 | WHITESPACE@[69; 70) | ||
74 | EQ@[70; 71) | ||
75 | WHITESPACE@[71; 72) | ||
76 | RANGE_EXPR@[72; 75) | ||
77 | LITERAL@[72; 73) | ||
78 | INT_NUMBER@[72; 73) "1" | ||
79 | DOTDOT@[73; 75) | ||
80 | SEMI@[75; 76) | ||
81 | WHITESPACE@[76; 77) | ||
82 | R_CURLY@[77; 78) | ||
83 | WHITESPACE@[78; 79) | ||