diff options
Diffstat (limited to 'crates')
6 files changed, 158 insertions, 37 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index a9449c7bf..bca32f707 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs | |||
@@ -143,7 +143,7 @@ fn current_op(p: &Parser) -> (u8, Op) { | |||
143 | 143 | ||
144 | let bp = match p.current() { | 144 | let bp = match p.current() { |
145 | EQ => 1, | 145 | EQ => 1, |
146 | DOTDOT => 2, | 146 | DOTDOT | DOTDOTEQ => 2, |
147 | EQEQ | NEQ | L_ANGLE | R_ANGLE => 5, | 147 | EQEQ | NEQ | L_ANGLE | R_ANGLE => 5, |
148 | PIPE => 6, | 148 | PIPE => 6, |
149 | CARET => 7, | 149 | CARET => 7, |
@@ -173,7 +173,7 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike { | |||
173 | }; | 173 | }; |
174 | 174 | ||
175 | loop { | 175 | loop { |
176 | let is_range = p.current() == DOTDOT; | 176 | let is_range = p.current() == DOTDOT || p.current() == DOTDOTEQ; |
177 | let (op_bp, op) = current_op(p); | 177 | let (op_bp, op) = current_op(p); |
178 | if op_bp < bp { | 178 | if op_bp < bp { |
179 | break; | 179 | break; |
diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index 10fa0e0be..64cdf0b1b 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs | |||
@@ -14,9 +14,13 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { | |||
14 | if let Some(lhs) = atom_pat(p, recovery_set) { | 14 | if let Some(lhs) = atom_pat(p, recovery_set) { |
15 | // test range_pat | 15 | // test range_pat |
16 | // fn main() { | 16 | // fn main() { |
17 | // match 92 { 0 ... 100 => () } | 17 | // match 92 { |
18 | // 0 ... 100 => (), | ||
19 | // 101 ..= 200 => (), | ||
20 | // 200 .. 301=> (), | ||
21 | // } | ||
18 | // } | 22 | // } |
19 | if p.at(DOTDOTDOT) { | 23 | if p.at(DOTDOTDOT) || p.at(DOTDOTEQ) || p.at(DOTDOT) { |
20 | let m = lhs.precede(p); | 24 | let m = lhs.precede(p); |
21 | p.bump(); | 25 | p.bump(); |
22 | atom_pat(p, recovery_set); | 26 | atom_pat(p, recovery_set); |
diff --git a/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.rs b/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.rs index 657467e75..3bca7bf5d 100644 --- a/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.rs +++ b/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.rs | |||
@@ -1,3 +1,7 @@ | |||
1 | fn main() { | 1 | fn main() { |
2 | match 92 { 0 ... 100 => () } | 2 | match 92 { |
3 | 0 ... 100 => (), | ||
4 | 101 ..= 200 => (), | ||
5 | 200 .. 301=> (), | ||
6 | } | ||
3 | } | 7 | } |
diff --git a/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.txt b/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.txt index 12ccc1314..7eb0fcdf4 100644 --- a/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.txt +++ b/crates/ra_syntax/tests/data/parser/inline/0094_range_pat.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 47) | 1 | SOURCE_FILE@[0; 113) |
2 | FN_DEF@[0; 46) | 2 | FN_DEF@[0; 112) |
3 | FN_KW@[0; 2) | 3 | FN_KW@[0; 2) |
4 | WHITESPACE@[2; 3) | 4 | WHITESPACE@[2; 3) |
5 | NAME@[3; 7) | 5 | NAME@[3; 7) |
@@ -8,35 +8,69 @@ SOURCE_FILE@[0; 47) | |||
8 | L_PAREN@[7; 8) | 8 | L_PAREN@[7; 8) |
9 | R_PAREN@[8; 9) | 9 | R_PAREN@[8; 9) |
10 | WHITESPACE@[9; 10) | 10 | WHITESPACE@[9; 10) |
11 | BLOCK@[10; 46) | 11 | BLOCK@[10; 112) |
12 | L_CURLY@[10; 11) | 12 | L_CURLY@[10; 11) |
13 | WHITESPACE@[11; 16) | 13 | WHITESPACE@[11; 16) |
14 | MATCH_EXPR@[16; 44) | 14 | MATCH_EXPR@[16; 110) |
15 | MATCH_KW@[16; 21) | 15 | MATCH_KW@[16; 21) |
16 | WHITESPACE@[21; 22) | 16 | WHITESPACE@[21; 22) |
17 | LITERAL@[22; 24) | 17 | LITERAL@[22; 24) |
18 | INT_NUMBER@[22; 24) "92" | 18 | INT_NUMBER@[22; 24) "92" |
19 | WHITESPACE@[24; 25) | 19 | WHITESPACE@[24; 25) |
20 | MATCH_ARM_LIST@[25; 44) | 20 | MATCH_ARM_LIST@[25; 110) |
21 | L_CURLY@[25; 26) | 21 | L_CURLY@[25; 26) |
22 | WHITESPACE@[26; 27) | 22 | WHITESPACE@[26; 36) |
23 | MATCH_ARM@[27; 42) | 23 | MATCH_ARM@[36; 51) |
24 | RANGE_PAT@[27; 36) | 24 | RANGE_PAT@[36; 45) |
25 | LITERAL@[27; 28) | 25 | LITERAL@[36; 37) |
26 | INT_NUMBER@[27; 28) "0" | 26 | INT_NUMBER@[36; 37) "0" |
27 | WHITESPACE@[28; 29) | 27 | WHITESPACE@[37; 38) |
28 | DOTDOTDOT@[29; 32) | 28 | DOTDOTDOT@[38; 41) |
29 | WHITESPACE@[32; 33) | 29 | WHITESPACE@[41; 42) |
30 | LITERAL@[33; 36) | 30 | LITERAL@[42; 45) |
31 | INT_NUMBER@[33; 36) "100" | 31 | INT_NUMBER@[42; 45) "100" |
32 | WHITESPACE@[36; 37) | 32 | WHITESPACE@[45; 46) |
33 | FAT_ARROW@[37; 39) | 33 | FAT_ARROW@[46; 48) |
34 | WHITESPACE@[39; 40) | 34 | WHITESPACE@[48; 49) |
35 | TUPLE_EXPR@[40; 42) | 35 | TUPLE_EXPR@[49; 51) |
36 | L_PAREN@[40; 41) | 36 | L_PAREN@[49; 50) |
37 | R_PAREN@[41; 42) | 37 | R_PAREN@[50; 51) |
38 | WHITESPACE@[42; 43) | 38 | COMMA@[51; 52) |
39 | R_CURLY@[43; 44) | 39 | WHITESPACE@[52; 61) |
40 | WHITESPACE@[44; 45) | 40 | MATCH_ARM@[61; 78) |
41 | R_CURLY@[45; 46) | 41 | RANGE_PAT@[61; 72) |
42 | WHITESPACE@[46; 47) | 42 | LITERAL@[61; 64) |
43 | INT_NUMBER@[61; 64) "101" | ||
44 | WHITESPACE@[64; 65) | ||
45 | DOTDOTEQ@[65; 68) | ||
46 | WHITESPACE@[68; 69) | ||
47 | LITERAL@[69; 72) | ||
48 | INT_NUMBER@[69; 72) "200" | ||
49 | WHITESPACE@[72; 73) | ||
50 | FAT_ARROW@[73; 75) | ||
51 | WHITESPACE@[75; 76) | ||
52 | TUPLE_EXPR@[76; 78) | ||
53 | L_PAREN@[76; 77) | ||
54 | R_PAREN@[77; 78) | ||
55 | COMMA@[78; 79) | ||
56 | WHITESPACE@[79; 88) | ||
57 | MATCH_ARM@[88; 103) | ||
58 | RANGE_PAT@[88; 98) | ||
59 | LITERAL@[88; 91) | ||
60 | INT_NUMBER@[88; 91) "200" | ||
61 | WHITESPACE@[91; 92) | ||
62 | DOTDOT@[92; 94) | ||
63 | WHITESPACE@[94; 95) | ||
64 | LITERAL@[95; 98) | ||
65 | INT_NUMBER@[95; 98) "301" | ||
66 | FAT_ARROW@[98; 100) | ||
67 | WHITESPACE@[100; 101) | ||
68 | TUPLE_EXPR@[101; 103) | ||
69 | L_PAREN@[101; 102) | ||
70 | R_PAREN@[102; 103) | ||
71 | COMMA@[103; 104) | ||
72 | WHITESPACE@[104; 109) | ||
73 | R_CURLY@[109; 110) | ||
74 | WHITESPACE@[110; 111) | ||
75 | R_CURLY@[111; 112) | ||
76 | WHITESPACE@[112; 113) | ||
diff --git a/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.rs b/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.rs index 03f4ae7b2..f9ff444d4 100644 --- a/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.rs +++ b/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.rs | |||
@@ -3,4 +3,9 @@ fn foo() { | |||
3 | ..z = 2; | 3 | ..z = 2; |
4 | x = false..1 == 1; | 4 | x = false..1 == 1; |
5 | let x = 1..; | 5 | let x = 1..; |
6 | |||
7 | ..=1 + 1; | ||
8 | ..=z = 2; | ||
9 | x = false..=1 == 1; | ||
10 | let x = 1..; | ||
6 | } | 11 | } |
diff --git a/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.txt b/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.txt index 2e7703c21..e3706bfbd 100644 --- a/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.txt +++ b/crates/ra_syntax/tests/data/parser/ok/0029_range_forms.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 79) | 1 | SOURCE_FILE@[0; 153) |
2 | FN_DEF@[0; 78) | 2 | FN_DEF@[0; 152) |
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 @@ SOURCE_FILE@[0; 79) | |||
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@[9; 78) | 11 | BLOCK@[9; 152) |
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) |
@@ -78,6 +78,80 @@ SOURCE_FILE@[0; 79) | |||
78 | INT_NUMBER@[72; 73) "1" | 78 | INT_NUMBER@[72; 73) "1" |
79 | DOTDOT@[73; 75) | 79 | DOTDOT@[73; 75) |
80 | SEMI@[75; 76) | 80 | SEMI@[75; 76) |
81 | WHITESPACE@[76; 77) | 81 | WHITESPACE@[76; 86) |
82 | R_CURLY@[77; 78) | 82 | err: `expected expression` |
83 | WHITESPACE@[78; 79) | 83 | EXPR_STMT@[86; 89) |
84 | ERROR@[86; 89) | ||
85 | DOTDOTEQ@[86; 89) | ||
86 | err: `expected SEMI` | ||
87 | EXPR_STMT@[89; 95) | ||
88 | BIN_EXPR@[89; 94) | ||
89 | LITERAL@[89; 90) | ||
90 | INT_NUMBER@[89; 90) "1" | ||
91 | WHITESPACE@[90; 91) | ||
92 | PLUS@[91; 92) | ||
93 | WHITESPACE@[92; 93) | ||
94 | LITERAL@[93; 94) | ||
95 | INT_NUMBER@[93; 94) "1" | ||
96 | SEMI@[94; 95) | ||
97 | WHITESPACE@[95; 100) | ||
98 | err: `expected expression` | ||
99 | EXPR_STMT@[100; 103) | ||
100 | ERROR@[100; 103) | ||
101 | DOTDOTEQ@[100; 103) | ||
102 | err: `expected SEMI` | ||
103 | EXPR_STMT@[103; 109) | ||
104 | BIN_EXPR@[103; 108) | ||
105 | PATH_EXPR@[103; 104) | ||
106 | PATH@[103; 104) | ||
107 | PATH_SEGMENT@[103; 104) | ||
108 | NAME_REF@[103; 104) | ||
109 | IDENT@[103; 104) "z" | ||
110 | WHITESPACE@[104; 105) | ||
111 | EQ@[105; 106) | ||
112 | WHITESPACE@[106; 107) | ||
113 | LITERAL@[107; 108) | ||
114 | INT_NUMBER@[107; 108) "2" | ||
115 | SEMI@[108; 109) | ||
116 | WHITESPACE@[109; 114) | ||
117 | EXPR_STMT@[114; 133) | ||
118 | BIN_EXPR@[114; 132) | ||
119 | PATH_EXPR@[114; 115) | ||
120 | PATH@[114; 115) | ||
121 | PATH_SEGMENT@[114; 115) | ||
122 | NAME_REF@[114; 115) | ||
123 | IDENT@[114; 115) "x" | ||
124 | WHITESPACE@[115; 116) | ||
125 | EQ@[116; 117) | ||
126 | WHITESPACE@[117; 118) | ||
127 | RANGE_EXPR@[118; 132) | ||
128 | LITERAL@[118; 123) | ||
129 | FALSE_KW@[118; 123) | ||
130 | DOTDOTEQ@[123; 126) | ||
131 | BIN_EXPR@[126; 132) | ||
132 | LITERAL@[126; 127) | ||
133 | INT_NUMBER@[126; 127) "1" | ||
134 | WHITESPACE@[127; 128) | ||
135 | EQEQ@[128; 130) | ||
136 | WHITESPACE@[130; 131) | ||
137 | LITERAL@[131; 132) | ||
138 | INT_NUMBER@[131; 132) "1" | ||
139 | SEMI@[132; 133) | ||
140 | WHITESPACE@[133; 138) | ||
141 | LET_STMT@[138; 150) | ||
142 | LET_KW@[138; 141) | ||
143 | WHITESPACE@[141; 142) | ||
144 | BIND_PAT@[142; 143) | ||
145 | NAME@[142; 143) | ||
146 | IDENT@[142; 143) "x" | ||
147 | WHITESPACE@[143; 144) | ||
148 | EQ@[144; 145) | ||
149 | WHITESPACE@[145; 146) | ||
150 | RANGE_EXPR@[146; 149) | ||
151 | LITERAL@[146; 147) | ||
152 | INT_NUMBER@[146; 147) "1" | ||
153 | DOTDOT@[147; 149) | ||
154 | SEMI@[149; 150) | ||
155 | WHITESPACE@[150; 151) | ||
156 | R_CURLY@[151; 152) | ||
157 | WHITESPACE@[152; 153) | ||