aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-15 13:45:58 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-15 13:45:58 +0100
commitec7d2f64ade9ffa35a64e82ac53e65ad5cbe9efd (patch)
treeb8693ce808a9ca2e7eaae5013644a1082fc7bb17 /crates/ra_parser/src/grammar
parent64ab5ab10d32e7e8ec085af818d3d94211aea39b (diff)
parent993abedd77cf23ce2281b6c8e60cab49ab4fa97e (diff)
Merge #1278
1278: Apply T! macro where posible r=matklad a=pasa apply T! macro implemented in #1248 Co-authored-by: Sergey Parilin <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r--crates/ra_parser/src/grammar/attributes.rs10
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs156
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs144
-rw-r--r--crates/ra_parser/src/grammar/items.rs114
-rw-r--r--crates/ra_parser/src/grammar/items/consts.rs10
-rw-r--r--crates/ra_parser/src/grammar/items/nominal.rs66
-rw-r--r--crates/ra_parser/src/grammar/items/traits.rs38
-rw-r--r--crates/ra_parser/src/grammar/items/use_item.rs30
-rw-r--r--crates/ra_parser/src/grammar/params.rs38
-rw-r--r--crates/ra_parser/src/grammar/paths.rs18
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs78
-rw-r--r--crates/ra_parser/src/grammar/type_args.rs14
-rw-r--r--crates/ra_parser/src/grammar/type_params.rs46
-rw-r--r--crates/ra_parser/src/grammar/types.rs84
14 files changed, 423 insertions, 423 deletions
diff --git a/crates/ra_parser/src/grammar/attributes.rs b/crates/ra_parser/src/grammar/attributes.rs
index cd30e8a45..20d58445f 100644
--- a/crates/ra_parser/src/grammar/attributes.rs
+++ b/crates/ra_parser/src/grammar/attributes.rs
@@ -1,28 +1,28 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn inner_attributes(p: &mut Parser) { 3pub(super) fn inner_attributes(p: &mut Parser) {
4 while p.current() == POUND && p.nth(1) == EXCL { 4 while p.current() == T![#] && p.nth(1) == T![!] {
5 attribute(p, true) 5 attribute(p, true)
6 } 6 }
7} 7}
8 8
9pub(super) fn outer_attributes(p: &mut Parser) { 9pub(super) fn outer_attributes(p: &mut Parser) {
10 while p.at(POUND) { 10 while p.at(T![#]) {
11 attribute(p, false) 11 attribute(p, false)
12 } 12 }
13} 13}
14 14
15fn attribute(p: &mut Parser, inner: bool) { 15fn attribute(p: &mut Parser, inner: bool) {
16 let attr = p.start(); 16 let attr = p.start();
17 assert!(p.at(POUND)); 17 assert!(p.at(T![#]));
18 p.bump(); 18 p.bump();
19 19
20 if inner { 20 if inner {
21 assert!(p.at(EXCL)); 21 assert!(p.at(T![!]));
22 p.bump(); 22 p.bump();
23 } 23 }
24 24
25 if p.at(L_BRACK) { 25 if p.at(T!['[']) {
26 items::token_tree(p); 26 items::token_tree(p);
27 } else { 27 } else {
28 p.error("expected `[`"); 28 p.error("expected `[`");
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 9fe529f53..bb6c78b5f 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -36,14 +36,14 @@ fn expr_no_struct(p: &mut Parser) {
36// fn c() { 1; 2; } 36// fn c() { 1; 2; }
37// fn d() { 1; 2 } 37// fn d() { 1; 2 }
38pub(crate) fn block(p: &mut Parser) { 38pub(crate) fn block(p: &mut Parser) {
39 if !p.at(L_CURLY) { 39 if !p.at(T!['{']) {
40 p.error("expected a block"); 40 p.error("expected a block");
41 return; 41 return;
42 } 42 }
43 let m = p.start(); 43 let m = p.start();
44 p.bump(); 44 p.bump();
45 expr_block_contents(p); 45 expr_block_contents(p);
46 p.expect(R_CURLY); 46 p.expect(T!['}']);
47 m.complete(p, BLOCK); 47 m.complete(p, BLOCK);
48} 48}
49 49
@@ -65,10 +65,10 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
65 // #[C] #[D] {} 65 // #[C] #[D] {}
66 // #[D] return (); 66 // #[D] return ();
67 // } 67 // }
68 let has_attrs = p.at(POUND); 68 let has_attrs = p.at(T![#]);
69 attributes::outer_attributes(p); 69 attributes::outer_attributes(p);
70 70
71 if p.at(LET_KW) { 71 if p.at(T![let]) {
72 let_stmt(p, m, with_semi); 72 let_stmt(p, m, with_semi);
73 return; 73 return;
74 } 74 }
@@ -90,7 +90,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
90 p.error(format!("attributes are not allowed on {:?}", kind)); 90 p.error(format!("attributes are not allowed on {:?}", kind));
91 } 91 }
92 92
93 if p.at(R_CURLY) { 93 if p.at(T!['}']) {
94 // test attr_on_last_expr_in_block 94 // test attr_on_last_expr_in_block
95 // fn foo() { 95 // fn foo() {
96 // { #[A] bar!()? } 96 // { #[A] bar!()? }
@@ -121,15 +121,15 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
121 match with_semi { 121 match with_semi {
122 StmtWithSemi::Yes => { 122 StmtWithSemi::Yes => {
123 if blocklike.is_block() { 123 if blocklike.is_block() {
124 p.eat(SEMI); 124 p.eat(T![;]);
125 } else { 125 } else {
126 p.expect(SEMI); 126 p.expect(T![;]);
127 } 127 }
128 } 128 }
129 StmtWithSemi::No => {} 129 StmtWithSemi::No => {}
130 StmtWithSemi::Optional => { 130 StmtWithSemi::Optional => {
131 if p.at(SEMI) { 131 if p.at(T![;]) {
132 p.eat(SEMI); 132 p.eat(T![;]);
133 } 133 }
134 } 134 }
135 } 135 }
@@ -145,24 +145,24 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
145 // let d: i32 = 92; 145 // let d: i32 = 92;
146 // } 146 // }
147 fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) { 147 fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) {
148 assert!(p.at(LET_KW)); 148 assert!(p.at(T![let]));
149 p.bump(); 149 p.bump();
150 patterns::pattern(p); 150 patterns::pattern(p);
151 if p.at(COLON) { 151 if p.at(T![:]) {
152 types::ascription(p); 152 types::ascription(p);
153 } 153 }
154 if p.eat(EQ) { 154 if p.eat(T![=]) {
155 expressions::expr(p); 155 expressions::expr(p);
156 } 156 }
157 157
158 match with_semi { 158 match with_semi {
159 StmtWithSemi::Yes => { 159 StmtWithSemi::Yes => {
160 p.expect(SEMI); 160 p.expect(T![;]);
161 } 161 }
162 StmtWithSemi::No => {} 162 StmtWithSemi::No => {}
163 StmtWithSemi::Optional => { 163 StmtWithSemi::Optional => {
164 if p.at(SEMI) { 164 if p.at(T![;]) {
165 p.eat(SEMI); 165 p.eat(T![;]);
166 } 166 }
167 } 167 }
168 } 168 }
@@ -174,12 +174,12 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
174 // This is checked by a validator 174 // This is checked by a validator
175 attributes::inner_attributes(p); 175 attributes::inner_attributes(p);
176 176
177 while !p.at(EOF) && !p.at(R_CURLY) { 177 while !p.at(EOF) && !p.at(T!['}']) {
178 // test nocontentexpr 178 // test nocontentexpr
179 // fn foo(){ 179 // fn foo(){
180 // ;;;some_expr();;;;{;;;};;;;Ok(()) 180 // ;;;some_expr();;;;{;;;};;;;Ok(())
181 // } 181 // }
182 if p.current() == SEMI { 182 if p.current() == T![;] {
183 p.bump(); 183 p.bump();
184 continue; 184 continue;
185 } 185 }
@@ -202,41 +202,41 @@ enum Op {
202fn current_op(p: &Parser) -> (u8, Op) { 202fn current_op(p: &Parser) -> (u8, Op) {
203 if let Some(t) = p.current3() { 203 if let Some(t) = p.current3() {
204 match t { 204 match t {
205 (L_ANGLE, L_ANGLE, EQ) => return (1, Op::Composite(SHLEQ, 3)), 205 (T![<], T![<], T![=]) => return (1, Op::Composite(T![<<=], 3)),
206 (R_ANGLE, R_ANGLE, EQ) => return (1, Op::Composite(SHREQ, 3)), 206 (T![>], T![>], T![=]) => return (1, Op::Composite(T![>>=], 3)),
207 _ => (), 207 _ => (),
208 } 208 }
209 } 209 }
210 210
211 if let Some(t) = p.current2() { 211 if let Some(t) = p.current2() {
212 match t { 212 match t {
213 (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)), 213 (T![+], T![=]) => return (1, Op::Composite(T![+=], 2)),
214 (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)), 214 (T![-], T![=]) => return (1, Op::Composite(T![-=], 2)),
215 (STAR, EQ) => return (1, Op::Composite(STAREQ, 2)), 215 (T![*], T![=]) => return (1, Op::Composite(T![*=], 2)),
216 (PERCENT, EQ) => return (1, Op::Composite(PERCENTEQ, 2)), 216 (T![%], T![=]) => return (1, Op::Composite(T![%=], 2)),
217 (SLASH, EQ) => return (1, Op::Composite(SLASHEQ, 2)), 217 (T![/], T![=]) => return (1, Op::Composite(T![/=], 2)),
218 (PIPE, EQ) => return (1, Op::Composite(PIPEEQ, 2)), 218 (T![|], T![=]) => return (1, Op::Composite(T![|=], 2)),
219 (AMP, EQ) => return (1, Op::Composite(AMPEQ, 2)), 219 (T![&], T![=]) => return (1, Op::Composite(T![&=], 2)),
220 (CARET, EQ) => return (1, Op::Composite(CARETEQ, 2)), 220 (T![^], T![=]) => return (1, Op::Composite(T![^=], 2)),
221 (PIPE, PIPE) => return (3, Op::Composite(PIPEPIPE, 2)), 221 (T![|], T![|]) => return (3, Op::Composite(T![||], 2)),
222 (AMP, AMP) => return (4, Op::Composite(AMPAMP, 2)), 222 (T![&], T![&]) => return (4, Op::Composite(T![&&], 2)),
223 (L_ANGLE, EQ) => return (5, Op::Composite(LTEQ, 2)), 223 (T![<], T![=]) => return (5, Op::Composite(T![<=], 2)),
224 (R_ANGLE, EQ) => return (5, Op::Composite(GTEQ, 2)), 224 (T![>], T![=]) => return (5, Op::Composite(T![>=], 2)),
225 (L_ANGLE, L_ANGLE) => return (9, Op::Composite(SHL, 2)), 225 (T![<], T![<]) => return (9, Op::Composite(T![<<], 2)),
226 (R_ANGLE, R_ANGLE) => return (9, Op::Composite(SHR, 2)), 226 (T![>], T![>]) => return (9, Op::Composite(T![>>], 2)),
227 _ => (), 227 _ => (),
228 } 228 }
229 } 229 }
230 230
231 let bp = match p.current() { 231 let bp = match p.current() {
232 EQ => 1, 232 T![=] => 1,
233 DOTDOT | DOTDOTEQ => 2, 233 T![..] | T![..=] => 2,
234 EQEQ | NEQ | L_ANGLE | R_ANGLE => 5, 234 T![==] | T![!=] | T![<] | T![>] => 5,
235 PIPE => 6, 235 T![|] => 6,
236 CARET => 7, 236 T![^] => 7,
237 AMP => 8, 237 T![&] => 8,
238 MINUS | PLUS => 10, 238 T![-] | T![+] => 10,
239 STAR | SLASH | PERCENT => 11, 239 T![*] | T![/] | T![%] => 11,
240 _ => 0, 240 _ => 0,
241 }; 241 };
242 (bp, Op::Simple) 242 (bp, Op::Simple)
@@ -284,7 +284,7 @@ fn expr_bp(
284 newly_dollar_open = false; 284 newly_dollar_open = false;
285 } 285 }
286 286
287 let is_range = p.current() == DOTDOT || p.current() == DOTDOTEQ; 287 let is_range = p.current() == T![..] || p.current() == T![..=];
288 let (op_bp, op) = current_op(p); 288 let (op_bp, op) = current_op(p);
289 if op_bp < bp { 289 if op_bp < bp {
290 break; 290 break;
@@ -318,10 +318,10 @@ fn lhs(
318 // let _ = &1; 318 // let _ = &1;
319 // let _ = &mut &f(); 319 // let _ = &mut &f();
320 // } 320 // }
321 AMP => { 321 T![&] => {
322 m = p.start(); 322 m = p.start();
323 p.bump(); 323 p.bump();
324 p.eat(MUT_KW); 324 p.eat(T![mut]);
325 REF_EXPR 325 REF_EXPR
326 } 326 }
327 // test unary_expr 327 // test unary_expr
@@ -330,14 +330,14 @@ fn lhs(
330 // !!true; 330 // !!true;
331 // --1; 331 // --1;
332 // } 332 // }
333 STAR | EXCL | MINUS => { 333 T![*] | T![!] | T![-] => {
334 m = p.start(); 334 m = p.start();
335 p.bump(); 335 p.bump();
336 PREFIX_EXPR 336 PREFIX_EXPR
337 } 337 }
338 // test full_range_expr 338 // test full_range_expr
339 // fn foo() { xs[..]; } 339 // fn foo() { xs[..]; }
340 DOTDOT | DOTDOTEQ => { 340 T![..] | T![..=] => {
341 m = p.start(); 341 m = p.start();
342 p.bump(); 342 p.bump();
343 if p.at_ts(EXPR_FIRST) { 343 if p.at_ts(EXPR_FIRST) {
@@ -375,21 +375,21 @@ fn postfix_expr(
375 // [] => {} 375 // [] => {}
376 // } 376 // }
377 // } 377 // }
378 L_PAREN if allow_calls => call_expr(p, lhs), 378 T!['('] if allow_calls => call_expr(p, lhs),
379 L_BRACK if allow_calls => index_expr(p, lhs), 379 T!['['] if allow_calls => index_expr(p, lhs),
380 DOT if p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON) => { 380 T![.] if p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth(2) == T![::]) => {
381 method_call_expr(p, lhs) 381 method_call_expr(p, lhs)
382 } 382 }
383 DOT => field_expr(p, lhs), 383 T![.] => field_expr(p, lhs),
384 // test postfix_range 384 // test postfix_range
385 // fn foo() { let x = 1..; } 385 // fn foo() { let x = 1..; }
386 DOTDOT | DOTDOTEQ if !EXPR_FIRST.contains(p.nth(1)) => { 386 T![..] | T![..=] if !EXPR_FIRST.contains(p.nth(1)) => {
387 let m = lhs.precede(p); 387 let m = lhs.precede(p);
388 p.bump(); 388 p.bump();
389 m.complete(p, RANGE_EXPR) 389 m.complete(p, RANGE_EXPR)
390 } 390 }
391 QUESTION => try_expr(p, lhs), 391 T![?] => try_expr(p, lhs),
392 AS_KW => cast_expr(p, lhs), 392 T![as] => cast_expr(p, lhs),
393 _ => break, 393 _ => break,
394 }; 394 };
395 allow_calls = true 395 allow_calls = true
@@ -405,7 +405,7 @@ fn postfix_expr(
405// f(<Foo as Trait>::func()); 405// f(<Foo as Trait>::func());
406// } 406// }
407fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 407fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
408 assert!(p.at(L_PAREN)); 408 assert!(p.at(T!['(']));
409 let m = lhs.precede(p); 409 let m = lhs.precede(p);
410 arg_list(p); 410 arg_list(p);
411 m.complete(p, CALL_EXPR) 411 m.complete(p, CALL_EXPR)
@@ -416,11 +416,11 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
416// x[1][2]; 416// x[1][2];
417// } 417// }
418fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 418fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
419 assert!(p.at(L_BRACK)); 419 assert!(p.at(T!['[']));
420 let m = lhs.precede(p); 420 let m = lhs.precede(p);
421 p.bump(); 421 p.bump();
422 expr(p); 422 expr(p);
423 p.expect(R_BRACK); 423 p.expect(T![']']);
424 m.complete(p, INDEX_EXPR) 424 m.complete(p, INDEX_EXPR)
425} 425}
426 426
@@ -430,12 +430,12 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
430// y.bar::<T>(1, 2,); 430// y.bar::<T>(1, 2,);
431// } 431// }
432fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 432fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
433 assert!(p.at(DOT) && p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON)); 433 assert!(p.at(T![.]) && p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth(2) == T![::]));
434 let m = lhs.precede(p); 434 let m = lhs.precede(p);
435 p.bump(); 435 p.bump();
436 name_ref(p); 436 name_ref(p);
437 type_args::opt_type_arg_list(p, true); 437 type_args::opt_type_arg_list(p, true);
438 if p.at(L_PAREN) { 438 if p.at(T!['(']) {
439 arg_list(p); 439 arg_list(p);
440 } 440 }
441 m.complete(p, METHOD_CALL_EXPR) 441 m.complete(p, METHOD_CALL_EXPR)
@@ -455,7 +455,7 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
455// x.0x01; 455// x.0x01;
456// } 456// }
457fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 457fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
458 assert!(p.at(DOT)); 458 assert!(p.at(T![.]));
459 let m = lhs.precede(p); 459 let m = lhs.precede(p);
460 p.bump(); 460 p.bump();
461 if p.at(IDENT) { 461 if p.at(IDENT) {
@@ -463,7 +463,7 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
463 } else if p.at(INT_NUMBER) { 463 } else if p.at(INT_NUMBER) {
464 p.bump(); 464 p.bump();
465 } else if p.at(FLOAT_NUMBER) { 465 } else if p.at(FLOAT_NUMBER) {
466 // FIXME: How to recover and instead parse INT + DOT? 466 // FIXME: How to recover and instead parse INT + T![.]?
467 p.bump(); 467 p.bump();
468 } else { 468 } else {
469 p.error("expected field name or number") 469 p.error("expected field name or number")
@@ -476,7 +476,7 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
476// x?; 476// x?;
477// } 477// }
478fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 478fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
479 assert!(p.at(QUESTION)); 479 assert!(p.at(T![?]));
480 let m = lhs.precede(p); 480 let m = lhs.precede(p);
481 p.bump(); 481 p.bump();
482 m.complete(p, TRY_EXPR) 482 m.complete(p, TRY_EXPR)
@@ -490,7 +490,7 @@ fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
490// 0x36 as u8 <= 0x37; 490// 0x36 as u8 <= 0x37;
491// } 491// }
492fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 492fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
493 assert!(p.at(AS_KW)); 493 assert!(p.at(T![as]));
494 let m = lhs.precede(p); 494 let m = lhs.precede(p);
495 p.bump(); 495 p.bump();
496 // Use type_no_bounds(), because cast expressions are not 496 // Use type_no_bounds(), because cast expressions are not
@@ -500,20 +500,20 @@ fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
500} 500}
501 501
502fn arg_list(p: &mut Parser) { 502fn arg_list(p: &mut Parser) {
503 assert!(p.at(L_PAREN)); 503 assert!(p.at(T!['(']));
504 let m = p.start(); 504 let m = p.start();
505 p.bump(); 505 p.bump();
506 while !p.at(R_PAREN) && !p.at(EOF) { 506 while !p.at(T![')']) && !p.at(EOF) {
507 if !p.at_ts(EXPR_FIRST) { 507 if !p.at_ts(EXPR_FIRST) {
508 p.error("expected expression"); 508 p.error("expected expression");
509 break; 509 break;
510 } 510 }
511 expr(p); 511 expr(p);
512 if !p.at(R_PAREN) && !p.expect(COMMA) { 512 if !p.at(T![')']) && !p.expect(T![,]) {
513 break; 513 break;
514 } 514 }
515 } 515 }
516 p.eat(R_PAREN); 516 p.eat(T![')']);
517 m.complete(p, ARG_LIST); 517 m.complete(p, ARG_LIST);
518} 518}
519 519
@@ -525,15 +525,15 @@ fn arg_list(p: &mut Parser) {
525// let _ = format!(); 525// let _ = format!();
526// } 526// }
527fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { 527fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
528 assert!(paths::is_path_start(p) || p.at(L_ANGLE)); 528 assert!(paths::is_path_start(p) || p.at(T![<]));
529 let m = p.start(); 529 let m = p.start();
530 paths::expr_path(p); 530 paths::expr_path(p);
531 match p.current() { 531 match p.current() {
532 L_CURLY if !r.forbid_structs => { 532 T!['{'] if !r.forbid_structs => {
533 named_field_list(p); 533 named_field_list(p);
534 (m.complete(p, STRUCT_LIT), BlockLike::NotBlock) 534 (m.complete(p, STRUCT_LIT), BlockLike::NotBlock)
535 } 535 }
536 EXCL => { 536 T![!] => {
537 let block_like = items::macro_call_after_excl(p); 537 let block_like = items::macro_call_after_excl(p);
538 (m.complete(p, MACRO_CALL), block_like) 538 (m.complete(p, MACRO_CALL), block_like)
539 } 539 }
@@ -548,35 +548,35 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
548// S { x, y: 32, ..Default::default() }; 548// S { x, y: 32, ..Default::default() };
549// } 549// }
550pub(crate) fn named_field_list(p: &mut Parser) { 550pub(crate) fn named_field_list(p: &mut Parser) {
551 assert!(p.at(L_CURLY)); 551 assert!(p.at(T!['{']));
552 let m = p.start(); 552 let m = p.start();
553 p.bump(); 553 p.bump();
554 while !p.at(EOF) && !p.at(R_CURLY) { 554 while !p.at(EOF) && !p.at(T!['}']) {
555 match p.current() { 555 match p.current() {
556 // test struct_literal_field_with_attr 556 // test struct_literal_field_with_attr
557 // fn main() { 557 // fn main() {
558 // S { #[cfg(test)] field: 1 } 558 // S { #[cfg(test)] field: 1 }
559 // } 559 // }
560 IDENT | POUND => { 560 IDENT | T![#] => {
561 let m = p.start(); 561 let m = p.start();
562 attributes::outer_attributes(p); 562 attributes::outer_attributes(p);
563 name_ref(p); 563 name_ref(p);
564 if p.eat(COLON) { 564 if p.eat(T![:]) {
565 expr(p); 565 expr(p);
566 } 566 }
567 m.complete(p, NAMED_FIELD); 567 m.complete(p, NAMED_FIELD);
568 } 568 }
569 DOTDOT => { 569 T![..] => {
570 p.bump(); 570 p.bump();
571 expr(p); 571 expr(p);
572 } 572 }
573 L_CURLY => error_block(p, "expected a field"), 573 T!['{'] => error_block(p, "expected a field"),
574 _ => p.err_and_bump("expected identifier"), 574 _ => p.err_and_bump("expected identifier"),
575 } 575 }
576 if !p.at(R_CURLY) { 576 if !p.at(T!['}']) {
577 p.expect(COMMA); 577 p.expect(T![,]);
578 } 578 }
579 } 579 }
580 p.expect(R_CURLY); 580 p.expect(T!['}']);
581 m.complete(p, NAMED_FIELD_LIST); 581 m.complete(p, NAMED_FIELD_LIST);
582} 582}
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 8dc7e44a9..8b1a1de49 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -60,29 +60,29 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
60 if let Some(m) = literal(p) { 60 if let Some(m) = literal(p) {
61 return Some((m, BlockLike::NotBlock)); 61 return Some((m, BlockLike::NotBlock));
62 } 62 }
63 if paths::is_path_start(p) || p.at(L_ANGLE) { 63 if paths::is_path_start(p) || p.at(T![<]) {
64 return Some(path_expr(p, r)); 64 return Some(path_expr(p, r));
65 } 65 }
66 let la = p.nth(1); 66 let la = p.nth(1);
67 let done = match p.current() { 67 let done = match p.current() {
68 L_PAREN => tuple_expr(p), 68 T!['('] => tuple_expr(p),
69 L_BRACK => array_expr(p), 69 T!['['] => array_expr(p),
70 PIPE => lambda_expr(p), 70 T![|] => lambda_expr(p),
71 MOVE_KW if la == PIPE => lambda_expr(p), 71 T![move] if la == T![|] => lambda_expr(p),
72 ASYNC_KW if la == PIPE || (la == MOVE_KW && p.nth(2) == PIPE) => lambda_expr(p), 72 T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => lambda_expr(p),
73 IF_KW => if_expr(p), 73 T![if] => if_expr(p),
74 74
75 LOOP_KW => loop_expr(p, None), 75 T![loop] => loop_expr(p, None),
76 FOR_KW => for_expr(p, None), 76 T![for] => for_expr(p, None),
77 WHILE_KW => while_expr(p, None), 77 T![while] => while_expr(p, None),
78 LIFETIME if la == COLON => { 78 LIFETIME if la == T![:] => {
79 let m = p.start(); 79 let m = p.start();
80 label(p); 80 label(p);
81 match p.current() { 81 match p.current() {
82 LOOP_KW => loop_expr(p, Some(m)), 82 T![loop] => loop_expr(p, Some(m)),
83 FOR_KW => for_expr(p, Some(m)), 83 T![for] => for_expr(p, Some(m)),
84 WHILE_KW => while_expr(p, Some(m)), 84 T![while] => while_expr(p, Some(m)),
85 L_CURLY => block_expr(p, Some(m)), 85 T!['{'] => block_expr(p, Some(m)),
86 _ => { 86 _ => {
87 // test_err misplaced_label_err 87 // test_err misplaced_label_err
88 // fn main() { 88 // fn main() {
@@ -94,22 +94,22 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
94 } 94 }
95 } 95 }
96 } 96 }
97 ASYNC_KW if la == L_CURLY || (la == MOVE_KW && p.nth(2) == L_CURLY) => { 97 T![async] if la == T!['{'] || (la == T![move] && p.nth(2) == T!['{']) => {
98 let m = p.start(); 98 let m = p.start();
99 p.bump(); 99 p.bump();
100 p.eat(MOVE_KW); 100 p.eat(T![move]);
101 block_expr(p, Some(m)) 101 block_expr(p, Some(m))
102 } 102 }
103 MATCH_KW => match_expr(p), 103 T![match] => match_expr(p),
104 UNSAFE_KW if la == L_CURLY => { 104 T![unsafe] if la == T!['{'] => {
105 let m = p.start(); 105 let m = p.start();
106 p.bump(); 106 p.bump();
107 block_expr(p, Some(m)) 107 block_expr(p, Some(m))
108 } 108 }
109 L_CURLY => block_expr(p, None), 109 T!['{'] => block_expr(p, None),
110 RETURN_KW => return_expr(p), 110 T![return] => return_expr(p),
111 CONTINUE_KW => continue_expr(p), 111 T![continue] => continue_expr(p),
112 BREAK_KW => break_expr(p, r), 112 T![break] => break_expr(p, r),
113 _ => { 113 _ => {
114 p.err_recover("expected expression", EXPR_RECOVERY_SET); 114 p.err_recover("expected expression", EXPR_RECOVERY_SET);
115 return None; 115 return None;
@@ -129,25 +129,25 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
129// (1,); 129// (1,);
130// } 130// }
131fn tuple_expr(p: &mut Parser) -> CompletedMarker { 131fn tuple_expr(p: &mut Parser) -> CompletedMarker {
132 assert!(p.at(L_PAREN)); 132 assert!(p.at(T!['(']));
133 let m = p.start(); 133 let m = p.start();
134 p.expect(L_PAREN); 134 p.expect(T!['(']);
135 135
136 let mut saw_comma = false; 136 let mut saw_comma = false;
137 let mut saw_expr = false; 137 let mut saw_expr = false;
138 while !p.at(EOF) && !p.at(R_PAREN) { 138 while !p.at(EOF) && !p.at(T![')']) {
139 saw_expr = true; 139 saw_expr = true;
140 if !p.at_ts(EXPR_FIRST) { 140 if !p.at_ts(EXPR_FIRST) {
141 p.error("expected expression"); 141 p.error("expected expression");
142 break; 142 break;
143 } 143 }
144 expr(p); 144 expr(p);
145 if !p.at(R_PAREN) { 145 if !p.at(T![')']) {
146 saw_comma = true; 146 saw_comma = true;
147 p.expect(COMMA); 147 p.expect(T![,]);
148 } 148 }
149 } 149 }
150 p.expect(R_PAREN); 150 p.expect(T![')']);
151 m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR }) 151 m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR })
152} 152}
153 153
@@ -159,21 +159,21 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
159// [1; 2]; 159// [1; 2];
160// } 160// }
161fn array_expr(p: &mut Parser) -> CompletedMarker { 161fn array_expr(p: &mut Parser) -> CompletedMarker {
162 assert!(p.at(L_BRACK)); 162 assert!(p.at(T!['[']));
163 let m = p.start(); 163 let m = p.start();
164 p.bump(); 164 p.bump();
165 if p.eat(R_BRACK) { 165 if p.eat(T![']']) {
166 return m.complete(p, ARRAY_EXPR); 166 return m.complete(p, ARRAY_EXPR);
167 } 167 }
168 expr(p); 168 expr(p);
169 if p.eat(SEMI) { 169 if p.eat(T![;]) {
170 expr(p); 170 expr(p);
171 p.expect(R_BRACK); 171 p.expect(T![']']);
172 return m.complete(p, ARRAY_EXPR); 172 return m.complete(p, ARRAY_EXPR);
173 } 173 }
174 while !p.at(EOF) && !p.at(R_BRACK) { 174 while !p.at(EOF) && !p.at(T![']']) {
175 p.expect(COMMA); 175 p.expect(T![,]);
176 if p.at(R_BRACK) { 176 if p.at(T![']']) {
177 break; 177 break;
178 } 178 }
179 if !p.at_ts(EXPR_FIRST) { 179 if !p.at_ts(EXPR_FIRST) {
@@ -182,7 +182,7 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
182 } 182 }
183 expr(p); 183 expr(p);
184 } 184 }
185 p.expect(R_BRACK); 185 p.expect(T![']']);
186 m.complete(p, ARRAY_EXPR) 186 m.complete(p, ARRAY_EXPR)
187} 187}
188 188
@@ -198,17 +198,17 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
198// } 198// }
199fn lambda_expr(p: &mut Parser) -> CompletedMarker { 199fn lambda_expr(p: &mut Parser) -> CompletedMarker {
200 assert!( 200 assert!(
201 p.at(PIPE) 201 p.at(T![|])
202 || (p.at(MOVE_KW) && p.nth(1) == PIPE) 202 || (p.at(T![move]) && p.nth(1) == T![|])
203 || (p.at(ASYNC_KW) && p.nth(1) == PIPE) 203 || (p.at(T![async]) && p.nth(1) == T![|])
204 || (p.at(ASYNC_KW) && p.nth(1) == MOVE_KW && p.nth(2) == PIPE) 204 || (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|])
205 ); 205 );
206 let m = p.start(); 206 let m = p.start();
207 p.eat(ASYNC_KW); 207 p.eat(T![async]);
208 p.eat(MOVE_KW); 208 p.eat(T![move]);
209 params::param_list_opt_types(p); 209 params::param_list_opt_types(p);
210 if opt_fn_ret_type(p) { 210 if opt_fn_ret_type(p) {
211 if !p.at(L_CURLY) { 211 if !p.at(T!['{']) {
212 p.error("expected `{`"); 212 p.error("expected `{`");
213 } 213 }
214 } 214 }
@@ -224,14 +224,14 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
224// if S {}; 224// if S {};
225// } 225// }
226fn if_expr(p: &mut Parser) -> CompletedMarker { 226fn if_expr(p: &mut Parser) -> CompletedMarker {
227 assert!(p.at(IF_KW)); 227 assert!(p.at(T![if]));
228 let m = p.start(); 228 let m = p.start();
229 p.bump(); 229 p.bump();
230 cond(p); 230 cond(p);
231 block(p); 231 block(p);
232 if p.at(ELSE_KW) { 232 if p.at(T![else]) {
233 p.bump(); 233 p.bump();
234 if p.at(IF_KW) { 234 if p.at(T![if]) {
235 if_expr(p); 235 if_expr(p);
236 } else { 236 } else {
237 block(p); 237 block(p);
@@ -247,7 +247,7 @@ fn if_expr(p: &mut Parser) -> CompletedMarker {
247// 'c: for x in () {} 247// 'c: for x in () {}
248// } 248// }
249fn label(p: &mut Parser) { 249fn label(p: &mut Parser) {
250 assert!(p.at(LIFETIME) && p.nth(1) == COLON); 250 assert!(p.at(LIFETIME) && p.nth(1) == T![:]);
251 let m = p.start(); 251 let m = p.start();
252 p.bump(); 252 p.bump();
253 p.bump(); 253 p.bump();
@@ -259,7 +259,7 @@ fn label(p: &mut Parser) {
259// loop {}; 259// loop {};
260// } 260// }
261fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 261fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
262 assert!(p.at(LOOP_KW)); 262 assert!(p.at(T![loop]));
263 let m = m.unwrap_or_else(|| p.start()); 263 let m = m.unwrap_or_else(|| p.start());
264 p.bump(); 264 p.bump();
265 block(p); 265 block(p);
@@ -272,7 +272,7 @@ fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
272// while let Some(x) = it.next() {}; 272// while let Some(x) = it.next() {};
273// } 273// }
274fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 274fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
275 assert!(p.at(WHILE_KW)); 275 assert!(p.at(T![while]));
276 let m = m.unwrap_or_else(|| p.start()); 276 let m = m.unwrap_or_else(|| p.start());
277 p.bump(); 277 p.bump();
278 cond(p); 278 cond(p);
@@ -285,11 +285,11 @@ fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
285// for x in [] {}; 285// for x in [] {};
286// } 286// }
287fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 287fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
288 assert!(p.at(FOR_KW)); 288 assert!(p.at(T![for]));
289 let m = m.unwrap_or_else(|| p.start()); 289 let m = m.unwrap_or_else(|| p.start());
290 p.bump(); 290 p.bump();
291 patterns::pattern(p); 291 patterns::pattern(p);
292 p.expect(IN_KW); 292 p.expect(T![in]);
293 expr_no_struct(p); 293 expr_no_struct(p);
294 block(p); 294 block(p);
295 m.complete(p, FOR_EXPR) 295 m.complete(p, FOR_EXPR)
@@ -305,9 +305,9 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
305// } 305// }
306fn cond(p: &mut Parser) { 306fn cond(p: &mut Parser) {
307 let m = p.start(); 307 let m = p.start();
308 if p.eat(LET_KW) { 308 if p.eat(T![let]) {
309 patterns::pattern_list(p); 309 patterns::pattern_list(p);
310 p.expect(EQ); 310 p.expect(T![=]);
311 } 311 }
312 expr_no_struct(p); 312 expr_no_struct(p);
313 m.complete(p, CONDITION); 313 m.complete(p, CONDITION);
@@ -319,11 +319,11 @@ fn cond(p: &mut Parser) {
319// match S {}; 319// match S {};
320// } 320// }
321fn match_expr(p: &mut Parser) -> CompletedMarker { 321fn match_expr(p: &mut Parser) -> CompletedMarker {
322 assert!(p.at(MATCH_KW)); 322 assert!(p.at(T![match]));
323 let m = p.start(); 323 let m = p.start();
324 p.bump(); 324 p.bump();
325 expr_no_struct(p); 325 expr_no_struct(p);
326 if p.at(L_CURLY) { 326 if p.at(T!['{']) {
327 match_arm_list(p); 327 match_arm_list(p);
328 } else { 328 } else {
329 p.error("expected `{`") 329 p.error("expected `{`")
@@ -332,9 +332,9 @@ fn match_expr(p: &mut Parser) -> CompletedMarker {
332} 332}
333 333
334pub(crate) fn match_arm_list(p: &mut Parser) { 334pub(crate) fn match_arm_list(p: &mut Parser) {
335 assert!(p.at(L_CURLY)); 335 assert!(p.at(T!['{']));
336 let m = p.start(); 336 let m = p.start();
337 p.eat(L_CURLY); 337 p.eat(T!['{']);
338 338
339 // test match_arms_inner_attribute 339 // test match_arms_inner_attribute
340 // fn foo() { 340 // fn foo() {
@@ -347,8 +347,8 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
347 // } 347 // }
348 attributes::inner_attributes(p); 348 attributes::inner_attributes(p);
349 349
350 while !p.at(EOF) && !p.at(R_CURLY) { 350 while !p.at(EOF) && !p.at(T!['}']) {
351 if p.at(L_CURLY) { 351 if p.at(T!['{']) {
352 error_block(p, "expected match arm"); 352 error_block(p, "expected match arm");
353 continue; 353 continue;
354 } 354 }
@@ -362,12 +362,12 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
362 // } 362 // }
363 // } 363 // }
364 if match_arm(p).is_block() { 364 if match_arm(p).is_block() {
365 p.eat(COMMA); 365 p.eat(T![,]);
366 } else if !p.at(R_CURLY) { 366 } else if !p.at(T!['}']) {
367 p.expect(COMMA); 367 p.expect(T![,]);
368 } 368 }
369 } 369 }
370 p.expect(R_CURLY); 370 p.expect(T!['}']);
371 m.complete(p, MATCH_ARM_LIST); 371 m.complete(p, MATCH_ARM_LIST);
372} 372}
373 373
@@ -399,10 +399,10 @@ fn match_arm(p: &mut Parser) -> BlockLike {
399 attributes::outer_attributes(p); 399 attributes::outer_attributes(p);
400 400
401 patterns::pattern_list_r(p, TokenSet::empty()); 401 patterns::pattern_list_r(p, TokenSet::empty());
402 if p.at(IF_KW) { 402 if p.at(T![if]) {
403 match_guard(p); 403 match_guard(p);
404 } 404 }
405 p.expect(FAT_ARROW); 405 p.expect(T![=>]);
406 let blocklike = expr_stmt(p).1; 406 let blocklike = expr_stmt(p).1;
407 m.complete(p, MATCH_ARM); 407 m.complete(p, MATCH_ARM);
408 blocklike 408 blocklike
@@ -415,7 +415,7 @@ fn match_arm(p: &mut Parser) -> BlockLike {
415// } 415// }
416// } 416// }
417fn match_guard(p: &mut Parser) -> CompletedMarker { 417fn match_guard(p: &mut Parser) -> CompletedMarker {
418 assert!(p.at(IF_KW)); 418 assert!(p.at(T![if]));
419 let m = p.start(); 419 let m = p.start();
420 p.bump(); 420 p.bump();
421 expr(p); 421 expr(p);
@@ -429,7 +429,7 @@ fn match_guard(p: &mut Parser) -> CompletedMarker {
429// 'label: {}; 429// 'label: {};
430// } 430// }
431fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 431fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
432 assert!(p.at(L_CURLY)); 432 assert!(p.at(T!['{']));
433 let m = m.unwrap_or_else(|| p.start()); 433 let m = m.unwrap_or_else(|| p.start());
434 block(p); 434 block(p);
435 m.complete(p, BLOCK_EXPR) 435 m.complete(p, BLOCK_EXPR)
@@ -441,7 +441,7 @@ fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
441// return 92; 441// return 92;
442// } 442// }
443fn return_expr(p: &mut Parser) -> CompletedMarker { 443fn return_expr(p: &mut Parser) -> CompletedMarker {
444 assert!(p.at(RETURN_KW)); 444 assert!(p.at(T![return]));
445 let m = p.start(); 445 let m = p.start();
446 p.bump(); 446 p.bump();
447 if p.at_ts(EXPR_FIRST) { 447 if p.at_ts(EXPR_FIRST) {
@@ -458,7 +458,7 @@ fn return_expr(p: &mut Parser) -> CompletedMarker {
458// } 458// }
459// } 459// }
460fn continue_expr(p: &mut Parser) -> CompletedMarker { 460fn continue_expr(p: &mut Parser) -> CompletedMarker {
461 assert!(p.at(CONTINUE_KW)); 461 assert!(p.at(T![continue]));
462 let m = p.start(); 462 let m = p.start();
463 p.bump(); 463 p.bump();
464 p.eat(LIFETIME); 464 p.eat(LIFETIME);
@@ -475,7 +475,7 @@ fn continue_expr(p: &mut Parser) -> CompletedMarker {
475// } 475// }
476// } 476// }
477fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { 477fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
478 assert!(p.at(BREAK_KW)); 478 assert!(p.at(T![break]));
479 let m = p.start(); 479 let m = p.start();
480 p.bump(); 480 p.bump();
481 p.eat(LIFETIME); 481 p.eat(LIFETIME);
@@ -486,7 +486,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
486 // for i in break {} 486 // for i in break {}
487 // match break {} 487 // match break {}
488 // } 488 // }
489 if p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(L_CURLY)) { 489 if p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(T!['{'])) {
490 expr(p); 490 expr(p);
491 } 491 }
492 m.complete(p, BREAK_EXPR) 492 m.complete(p, BREAK_EXPR)
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 97f8122a9..6728e395f 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -19,7 +19,7 @@ use super::*;
19// struct S; 19// struct S;
20pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { 20pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
21 attributes::inner_attributes(p); 21 attributes::inner_attributes(p);
22 while !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) { 22 while !p.at(EOF) && !(stop_on_r_curly && p.at(T!['}'])) {
23 item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod) 23 item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod)
24 } 24 }
25} 25}
@@ -45,20 +45,20 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
45 match macro_call(p) { 45 match macro_call(p) {
46 BlockLike::Block => (), 46 BlockLike::Block => (),
47 BlockLike::NotBlock => { 47 BlockLike::NotBlock => {
48 p.expect(SEMI); 48 p.expect(T![;]);
49 } 49 }
50 } 50 }
51 m.complete(p, MACRO_CALL); 51 m.complete(p, MACRO_CALL);
52 } else { 52 } else {
53 m.abandon(p); 53 m.abandon(p);
54 if p.at(L_CURLY) { 54 if p.at(T!['{']) {
55 error_block(p, "expected an item"); 55 error_block(p, "expected an item");
56 } else if p.at(R_CURLY) && !stop_on_r_curly { 56 } else if p.at(T!['}']) && !stop_on_r_curly {
57 let e = p.start(); 57 let e = p.start();
58 p.error("unmatched `}`"); 58 p.error("unmatched `}`");
59 p.bump(); 59 p.bump();
60 e.complete(p, ERROR); 60 e.complete(p, ERROR);
61 } else if !p.at(EOF) && !p.at(R_CURLY) { 61 } else if !p.at(EOF) && !p.at(T!['}']) {
62 p.err_and_bump("expected an item"); 62 p.err_and_bump("expected an item");
63 } else { 63 } else {
64 p.error("expected an item"); 64 p.error("expected an item");
@@ -79,32 +79,32 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
79 let mut has_mods = false; 79 let mut has_mods = false;
80 80
81 // modifiers 81 // modifiers
82 has_mods |= p.eat(CONST_KW); 82 has_mods |= p.eat(T![const]);
83 83
84 // test_err unsafe_block_in_mod 84 // test_err unsafe_block_in_mod
85 // fn foo(){} unsafe { } fn bar(){} 85 // fn foo(){} unsafe { } fn bar(){}
86 if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY { 86 if p.at(T![unsafe]) && p.nth(1) != T!['{'] {
87 p.eat(UNSAFE_KW); 87 p.eat(T![unsafe]);
88 has_mods = true; 88 has_mods = true;
89 } 89 }
90 90
91 // test_err async_without_semicolon 91 // test_err async_without_semicolon
92 // fn foo() { let _ = async {} } 92 // fn foo() { let _ = async {} }
93 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW && p.nth(1) != PIPE { 93 if p.at(T![async]) && p.nth(1) != T!['{'] && p.nth(1) != T![move] && p.nth(1) != T![|] {
94 p.eat(ASYNC_KW); 94 p.eat(T![async]);
95 has_mods = true; 95 has_mods = true;
96 } 96 }
97 97
98 if p.at(EXTERN_KW) { 98 if p.at(T![extern]) {
99 has_mods = true; 99 has_mods = true;
100 abi(p); 100 abi(p);
101 } 101 }
102 if p.at(IDENT) && p.at_contextual_kw("auto") && p.nth(1) == TRAIT_KW { 102 if p.at(IDENT) && p.at_contextual_kw("auto") && p.nth(1) == T![trait] {
103 p.bump_remap(AUTO_KW); 103 p.bump_remap(T![auto]);
104 has_mods = true; 104 has_mods = true;
105 } 105 }
106 if p.at(IDENT) && p.at_contextual_kw("default") && p.nth(1) == IMPL_KW { 106 if p.at(IDENT) && p.at_contextual_kw("default") && p.nth(1) == T![impl ] {
107 p.bump_remap(DEFAULT_KW); 107 p.bump_remap(T![default]);
108 has_mods = true; 108 has_mods = true;
109 } 109 }
110 110
@@ -135,7 +135,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
135 // test_err wrong_order_fns 135 // test_err wrong_order_fns
136 // async unsafe fn foo() {} 136 // async unsafe fn foo() {}
137 // unsafe const fn bar() {} 137 // unsafe const fn bar() {}
138 FN_KW => { 138 T![fn] => {
139 fn_def(p, flavor); 139 fn_def(p, flavor);
140 m.complete(p, FN_DEF); 140 m.complete(p, FN_DEF);
141 } 141 }
@@ -148,7 +148,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
148 148
149 // test unsafe_auto_trait 149 // test unsafe_auto_trait
150 // unsafe auto trait T {} 150 // unsafe auto trait T {}
151 TRAIT_KW => { 151 T![trait] => {
152 traits::trait_def(p); 152 traits::trait_def(p);
153 m.complete(p, TRAIT_DEF); 153 m.complete(p, TRAIT_DEF);
154 } 154 }
@@ -161,7 +161,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
161 161
162 // test unsafe_default_impl 162 // test unsafe_default_impl
163 // unsafe default impl Foo {} 163 // unsafe default impl Foo {}
164 IMPL_KW => { 164 T![impl ] => {
165 traits::impl_block(p); 165 traits::impl_block(p);
166 m.complete(p, IMPL_BLOCK); 166 m.complete(p, IMPL_BLOCK);
167 } 167 }
@@ -186,10 +186,10 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
186 match p.current() { 186 match p.current() {
187 // test extern_crate 187 // test extern_crate
188 // extern crate foo; 188 // extern crate foo;
189 EXTERN_KW if la == CRATE_KW => extern_crate_item(p, m), 189 T![extern] if la == T![crate] => extern_crate_item(p, m),
190 TYPE_KW => type_def(p, m), 190 T![type] => type_def(p, m),
191 MOD_KW => mod_item(p, m), 191 T![mod] => mod_item(p, m),
192 STRUCT_KW => { 192 T![struct] => {
193 // test struct_items 193 // test struct_items
194 // struct Foo; 194 // struct Foo;
195 // struct Foo {} 195 // struct Foo {}
@@ -199,7 +199,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
199 // a: i32, 199 // a: i32,
200 // b: f32, 200 // b: f32,
201 // } 201 // }
202 nominal::struct_def(p, m, STRUCT_KW); 202 nominal::struct_def(p, m, T![struct]);
203 } 203 }
204 IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => { 204 IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => {
205 // test union_items 205 // test union_items
@@ -208,16 +208,16 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
208 // a: i32, 208 // a: i32,
209 // b: f32, 209 // b: f32,
210 // } 210 // }
211 nominal::struct_def(p, m, UNION_KW); 211 nominal::struct_def(p, m, T![union]);
212 } 212 }
213 ENUM_KW => nominal::enum_def(p, m), 213 T![enum] => nominal::enum_def(p, m),
214 USE_KW => use_item::use_item(p, m), 214 T![use] => use_item::use_item(p, m),
215 CONST_KW if (la == IDENT || la == MUT_KW) => consts::const_def(p, m), 215 T![const] if (la == IDENT || la == T![mut]) => consts::const_def(p, m),
216 STATIC_KW => consts::static_def(p, m), 216 T![static] => consts::static_def(p, m),
217 // test extern_block 217 // test extern_block
218 // extern {} 218 // extern {}
219 EXTERN_KW 219 T![extern]
220 if la == L_CURLY || ((la == STRING || la == RAW_STRING) && p.nth(2) == L_CURLY) => 220 if la == T!['{'] || ((la == STRING || la == RAW_STRING) && p.nth(2) == T!['{']) =>
221 { 221 {
222 abi(p); 222 abi(p);
223 extern_item_list(p); 223 extern_item_list(p);
@@ -225,7 +225,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
225 } 225 }
226 _ => return Err(m), 226 _ => return Err(m),
227 }; 227 };
228 if p.at(SEMI) { 228 if p.at(T![;]) {
229 p.err_and_bump( 229 p.err_and_bump(
230 "expected item, found `;`\n\ 230 "expected item, found `;`\n\
231 consider removing this semicolon", 231 consider removing this semicolon",
@@ -235,27 +235,27 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
235} 235}
236 236
237fn extern_crate_item(p: &mut Parser, m: Marker) { 237fn extern_crate_item(p: &mut Parser, m: Marker) {
238 assert!(p.at(EXTERN_KW)); 238 assert!(p.at(T![extern]));
239 p.bump(); 239 p.bump();
240 assert!(p.at(CRATE_KW)); 240 assert!(p.at(T![crate]));
241 p.bump(); 241 p.bump();
242 name_ref(p); 242 name_ref(p);
243 opt_alias(p); 243 opt_alias(p);
244 p.expect(SEMI); 244 p.expect(T![;]);
245 m.complete(p, EXTERN_CRATE_ITEM); 245 m.complete(p, EXTERN_CRATE_ITEM);
246} 246}
247 247
248pub(crate) fn extern_item_list(p: &mut Parser) { 248pub(crate) fn extern_item_list(p: &mut Parser) {
249 assert!(p.at(L_CURLY)); 249 assert!(p.at(T!['{']));
250 let m = p.start(); 250 let m = p.start();
251 p.bump(); 251 p.bump();
252 mod_contents(p, true); 252 mod_contents(p, true);
253 p.expect(R_CURLY); 253 p.expect(T!['}']);
254 m.complete(p, EXTERN_ITEM_LIST); 254 m.complete(p, EXTERN_ITEM_LIST);
255} 255}
256 256
257fn fn_def(p: &mut Parser, flavor: ItemFlavor) { 257fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
258 assert!(p.at(FN_KW)); 258 assert!(p.at(T![fn]));
259 p.bump(); 259 p.bump();
260 260
261 name_r(p, ITEM_RECOVERY_SET); 261 name_r(p, ITEM_RECOVERY_SET);
@@ -263,7 +263,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
263 // fn foo<T: Clone + Copy>(){} 263 // fn foo<T: Clone + Copy>(){}
264 type_params::opt_type_param_list(p); 264 type_params::opt_type_param_list(p);
265 265
266 if p.at(L_PAREN) { 266 if p.at(T!['(']) {
267 match flavor { 267 match flavor {
268 ItemFlavor::Mod => params::param_list(p), 268 ItemFlavor::Mod => params::param_list(p),
269 ItemFlavor::Trait => params::param_list_opt_patterns(p), 269 ItemFlavor::Trait => params::param_list_opt_patterns(p),
@@ -282,7 +282,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
282 282
283 // test fn_decl 283 // test fn_decl
284 // trait T { fn foo(); } 284 // trait T { fn foo(); }
285 if p.at(SEMI) { 285 if p.at(T![;]) {
286 p.bump(); 286 p.bump();
287 } else { 287 } else {
288 expressions::block(p) 288 expressions::block(p)
@@ -292,7 +292,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
292// test type_item 292// test type_item
293// type Foo = Bar; 293// type Foo = Bar;
294fn type_def(p: &mut Parser, m: Marker) { 294fn type_def(p: &mut Parser, m: Marker) {
295 assert!(p.at(TYPE_KW)); 295 assert!(p.at(T![type]));
296 p.bump(); 296 p.bump();
297 297
298 name(p); 298 name(p);
@@ -301,7 +301,7 @@ fn type_def(p: &mut Parser, m: Marker) {
301 // type Result<T> = (); 301 // type Result<T> = ();
302 type_params::opt_type_param_list(p); 302 type_params::opt_type_param_list(p);
303 303
304 if p.at(COLON) { 304 if p.at(T![:]) {
305 type_params::bounds(p); 305 type_params::bounds(p);
306 } 306 }
307 307
@@ -309,32 +309,32 @@ fn type_def(p: &mut Parser, m: Marker) {
309 // type Foo where Foo: Copy = (); 309 // type Foo where Foo: Copy = ();
310 type_params::opt_where_clause(p); 310 type_params::opt_where_clause(p);
311 311
312 if p.eat(EQ) { 312 if p.eat(T![=]) {
313 types::type_(p); 313 types::type_(p);
314 } 314 }
315 p.expect(SEMI); 315 p.expect(T![;]);
316 m.complete(p, TYPE_ALIAS_DEF); 316 m.complete(p, TYPE_ALIAS_DEF);
317} 317}
318 318
319pub(crate) fn mod_item(p: &mut Parser, m: Marker) { 319pub(crate) fn mod_item(p: &mut Parser, m: Marker) {
320 assert!(p.at(MOD_KW)); 320 assert!(p.at(T![mod]));
321 p.bump(); 321 p.bump();
322 322
323 name(p); 323 name(p);
324 if p.at(L_CURLY) { 324 if p.at(T!['{']) {
325 mod_item_list(p); 325 mod_item_list(p);
326 } else if !p.eat(SEMI) { 326 } else if !p.eat(T![;]) {
327 p.error("expected `;` or `{`"); 327 p.error("expected `;` or `{`");
328 } 328 }
329 m.complete(p, MODULE); 329 m.complete(p, MODULE);
330} 330}
331 331
332pub(crate) fn mod_item_list(p: &mut Parser) { 332pub(crate) fn mod_item_list(p: &mut Parser) {
333 assert!(p.at(L_CURLY)); 333 assert!(p.at(T!['{']));
334 let m = p.start(); 334 let m = p.start();
335 p.bump(); 335 p.bump();
336 mod_contents(p, true); 336 mod_contents(p, true);
337 p.expect(R_CURLY); 337 p.expect(T!['}']);
338 m.complete(p, ITEM_LIST); 338 m.complete(p, ITEM_LIST);
339} 339}
340 340
@@ -345,16 +345,16 @@ fn macro_call(p: &mut Parser) -> BlockLike {
345} 345}
346 346
347pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { 347pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
348 p.expect(EXCL); 348 p.expect(T![!]);
349 if p.at(IDENT) { 349 if p.at(IDENT) {
350 name(p); 350 name(p);
351 } 351 }
352 match p.current() { 352 match p.current() {
353 L_CURLY => { 353 T!['{'] => {
354 token_tree(p); 354 token_tree(p);
355 BlockLike::Block 355 BlockLike::Block
356 } 356 }
357 L_PAREN | L_BRACK => { 357 T!['('] | T!['['] => {
358 token_tree(p); 358 token_tree(p);
359 BlockLike::NotBlock 359 BlockLike::NotBlock
360 } 360 }
@@ -367,22 +367,22 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
367 367
368pub(crate) fn token_tree(p: &mut Parser) { 368pub(crate) fn token_tree(p: &mut Parser) {
369 let closing_paren_kind = match p.current() { 369 let closing_paren_kind = match p.current() {
370 L_CURLY => R_CURLY, 370 T!['{'] => T!['}'],
371 L_PAREN => R_PAREN, 371 T!['('] => T![')'],
372 L_BRACK => R_BRACK, 372 T!['['] => T![']'],
373 _ => unreachable!(), 373 _ => unreachable!(),
374 }; 374 };
375 let m = p.start(); 375 let m = p.start();
376 p.bump(); 376 p.bump();
377 while !p.at(EOF) && !p.at(closing_paren_kind) { 377 while !p.at(EOF) && !p.at(closing_paren_kind) {
378 match p.current() { 378 match p.current() {
379 L_CURLY | L_PAREN | L_BRACK => token_tree(p), 379 T!['{'] | T!['('] | T!['['] => token_tree(p),
380 R_CURLY => { 380 T!['}'] => {
381 p.error("unmatched `}`"); 381 p.error("unmatched `}`");
382 m.complete(p, TOKEN_TREE); 382 m.complete(p, TOKEN_TREE);
383 return; 383 return;
384 } 384 }
385 R_PAREN | R_BRACK => p.err_and_bump("unmatched brace"), 385 T![')'] | T![']'] => p.err_and_bump("unmatched brace"),
386 _ => p.bump_raw(), 386 _ => p.bump_raw(),
387 } 387 }
388 } 388 }
diff --git a/crates/ra_parser/src/grammar/items/consts.rs b/crates/ra_parser/src/grammar/items/consts.rs
index 1f802246f..b4908ebba 100644
--- a/crates/ra_parser/src/grammar/items/consts.rs
+++ b/crates/ra_parser/src/grammar/items/consts.rs
@@ -1,22 +1,22 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn static_def(p: &mut Parser, m: Marker) { 3pub(super) fn static_def(p: &mut Parser, m: Marker) {
4 const_or_static(p, m, STATIC_KW, STATIC_DEF) 4 const_or_static(p, m, T![static], STATIC_DEF)
5} 5}
6 6
7pub(super) fn const_def(p: &mut Parser, m: Marker) { 7pub(super) fn const_def(p: &mut Parser, m: Marker) {
8 const_or_static(p, m, CONST_KW, CONST_DEF) 8 const_or_static(p, m, T![const], CONST_DEF)
9} 9}
10 10
11fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { 11fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
12 assert!(p.at(kw)); 12 assert!(p.at(kw));
13 p.bump(); 13 p.bump();
14 p.eat(MUT_KW); // FIXME: validator to forbid const mut 14 p.eat(T![mut]); // FIXME: validator to forbid const mut
15 name(p); 15 name(p);
16 types::ascription(p); 16 types::ascription(p);
17 if p.eat(EQ) { 17 if p.eat(T![=]) {
18 expressions::expr(p); 18 expressions::expr(p);
19 } 19 }
20 p.expect(SEMI); 20 p.expect(T![;]);
21 m.complete(p, def); 21 m.complete(p, def);
22} 22}
diff --git a/crates/ra_parser/src/grammar/items/nominal.rs b/crates/ra_parser/src/grammar/items/nominal.rs
index e93bd76b8..bd4edab89 100644
--- a/crates/ra_parser/src/grammar/items/nominal.rs
+++ b/crates/ra_parser/src/grammar/items/nominal.rs
@@ -1,38 +1,38 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { 3pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
4 assert!(p.at(STRUCT_KW) || p.at_contextual_kw("union")); 4 assert!(p.at(T![struct]) || p.at_contextual_kw("union"));
5 p.bump_remap(kind); 5 p.bump_remap(kind);
6 6
7 name_r(p, ITEM_RECOVERY_SET); 7 name_r(p, ITEM_RECOVERY_SET);
8 type_params::opt_type_param_list(p); 8 type_params::opt_type_param_list(p);
9 match p.current() { 9 match p.current() {
10 WHERE_KW => { 10 T![where] => {
11 type_params::opt_where_clause(p); 11 type_params::opt_where_clause(p);
12 match p.current() { 12 match p.current() {
13 SEMI => { 13 T![;] => {
14 p.bump(); 14 p.bump();
15 } 15 }
16 L_CURLY => named_field_def_list(p), 16 T!['{'] => named_field_def_list(p),
17 _ => { 17 _ => {
18 //FIXME: special case `(` error message 18 //FIXME: special case `(` error message
19 p.error("expected `;` or `{`"); 19 p.error("expected `;` or `{`");
20 } 20 }
21 } 21 }
22 } 22 }
23 SEMI if kind == STRUCT_KW => { 23 T![;] if kind == T![struct] => {
24 p.bump(); 24 p.bump();
25 } 25 }
26 L_CURLY => named_field_def_list(p), 26 T!['{'] => named_field_def_list(p),
27 L_PAREN if kind == STRUCT_KW => { 27 T!['('] if kind == T![struct] => {
28 pos_field_def_list(p); 28 pos_field_def_list(p);
29 // test tuple_struct_where 29 // test tuple_struct_where
30 // struct Test<T>(T) where T: Clone; 30 // struct Test<T>(T) where T: Clone;
31 // struct Test<T>(T); 31 // struct Test<T>(T);
32 type_params::opt_where_clause(p); 32 type_params::opt_where_clause(p);
33 p.expect(SEMI); 33 p.expect(T![;]);
34 } 34 }
35 _ if kind == STRUCT_KW => { 35 _ if kind == T![struct] => {
36 p.error("expected `;`, `{`, or `(`"); 36 p.error("expected `;`, `{`, or `(`");
37 } 37 }
38 _ => { 38 _ => {
@@ -43,12 +43,12 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
43} 43}
44 44
45pub(super) fn enum_def(p: &mut Parser, m: Marker) { 45pub(super) fn enum_def(p: &mut Parser, m: Marker) {
46 assert!(p.at(ENUM_KW)); 46 assert!(p.at(T![enum]));
47 p.bump(); 47 p.bump();
48 name_r(p, ITEM_RECOVERY_SET); 48 name_r(p, ITEM_RECOVERY_SET);
49 type_params::opt_type_param_list(p); 49 type_params::opt_type_param_list(p);
50 type_params::opt_where_clause(p); 50 type_params::opt_where_clause(p);
51 if p.at(L_CURLY) { 51 if p.at(T!['{']) {
52 enum_variant_list(p); 52 enum_variant_list(p);
53 } else { 53 } else {
54 p.error("expected `{`") 54 p.error("expected `{`")
@@ -57,11 +57,11 @@ pub(super) fn enum_def(p: &mut Parser, m: Marker) {
57} 57}
58 58
59pub(crate) fn enum_variant_list(p: &mut Parser) { 59pub(crate) fn enum_variant_list(p: &mut Parser) {
60 assert!(p.at(L_CURLY)); 60 assert!(p.at(T!['{']));
61 let m = p.start(); 61 let m = p.start();
62 p.bump(); 62 p.bump();
63 while !p.at(EOF) && !p.at(R_CURLY) { 63 while !p.at(EOF) && !p.at(T!['}']) {
64 if p.at(L_CURLY) { 64 if p.at(T!['{']) {
65 error_block(p, "expected enum variant"); 65 error_block(p, "expected enum variant");
66 continue; 66 continue;
67 } 67 }
@@ -70,9 +70,9 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
70 if p.at(IDENT) { 70 if p.at(IDENT) {
71 name(p); 71 name(p);
72 match p.current() { 72 match p.current() {
73 L_CURLY => named_field_def_list(p), 73 T!['{'] => named_field_def_list(p),
74 L_PAREN => pos_field_def_list(p), 74 T!['('] => pos_field_def_list(p),
75 EQ => { 75 T![=] => {
76 p.bump(); 76 p.bump();
77 expressions::expr(p); 77 expressions::expr(p);
78 } 78 }
@@ -83,29 +83,29 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
83 var.abandon(p); 83 var.abandon(p);
84 p.err_and_bump("expected enum variant"); 84 p.err_and_bump("expected enum variant");
85 } 85 }
86 if !p.at(R_CURLY) { 86 if !p.at(T!['}']) {
87 p.expect(COMMA); 87 p.expect(T![,]);
88 } 88 }
89 } 89 }
90 p.expect(R_CURLY); 90 p.expect(T!['}']);
91 m.complete(p, ENUM_VARIANT_LIST); 91 m.complete(p, ENUM_VARIANT_LIST);
92} 92}
93 93
94pub(crate) fn named_field_def_list(p: &mut Parser) { 94pub(crate) fn named_field_def_list(p: &mut Parser) {
95 assert!(p.at(L_CURLY)); 95 assert!(p.at(T!['{']));
96 let m = p.start(); 96 let m = p.start();
97 p.bump(); 97 p.bump();
98 while !p.at(R_CURLY) && !p.at(EOF) { 98 while !p.at(T!['}']) && !p.at(EOF) {
99 if p.at(L_CURLY) { 99 if p.at(T!['{']) {
100 error_block(p, "expected field"); 100 error_block(p, "expected field");
101 continue; 101 continue;
102 } 102 }
103 named_field_def(p); 103 named_field_def(p);
104 if !p.at(R_CURLY) { 104 if !p.at(T!['}']) {
105 p.expect(COMMA); 105 p.expect(T![,]);
106 } 106 }
107 } 107 }
108 p.expect(R_CURLY); 108 p.expect(T!['}']);
109 m.complete(p, NAMED_FIELD_DEF_LIST); 109 m.complete(p, NAMED_FIELD_DEF_LIST);
110 110
111 fn named_field_def(p: &mut Parser) { 111 fn named_field_def(p: &mut Parser) {
@@ -119,7 +119,7 @@ pub(crate) fn named_field_def_list(p: &mut Parser) {
119 opt_visibility(p); 119 opt_visibility(p);
120 if p.at(IDENT) { 120 if p.at(IDENT) {
121 name(p); 121 name(p);
122 p.expect(COLON); 122 p.expect(T![:]);
123 types::type_(p); 123 types::type_(p);
124 m.complete(p, NAMED_FIELD_DEF); 124 m.complete(p, NAMED_FIELD_DEF);
125 } else { 125 } else {
@@ -130,12 +130,12 @@ pub(crate) fn named_field_def_list(p: &mut Parser) {
130} 130}
131 131
132fn pos_field_def_list(p: &mut Parser) { 132fn pos_field_def_list(p: &mut Parser) {
133 assert!(p.at(L_PAREN)); 133 assert!(p.at(T!['(']));
134 let m = p.start(); 134 let m = p.start();
135 if !p.expect(L_PAREN) { 135 if !p.expect(T!['(']) {
136 return; 136 return;
137 } 137 }
138 while !p.at(R_PAREN) && !p.at(EOF) { 138 while !p.at(T![')']) && !p.at(EOF) {
139 let m = p.start(); 139 let m = p.start();
140 // test pos_field_attrs 140 // test pos_field_attrs
141 // struct S ( 141 // struct S (
@@ -156,10 +156,10 @@ fn pos_field_def_list(p: &mut Parser) {
156 types::type_(p); 156 types::type_(p);
157 m.complete(p, POS_FIELD_DEF); 157 m.complete(p, POS_FIELD_DEF);
158 158
159 if !p.at(R_PAREN) { 159 if !p.at(T![')']) {
160 p.expect(COMMA); 160 p.expect(T![,]);
161 } 161 }
162 } 162 }
163 p.expect(R_PAREN); 163 p.expect(T![')']);
164 m.complete(p, POS_FIELD_DEF_LIST); 164 m.complete(p, POS_FIELD_DEF_LIST);
165} 165}
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs
index d03a6be0d..09ab3bfd4 100644
--- a/crates/ra_parser/src/grammar/items/traits.rs
+++ b/crates/ra_parser/src/grammar/items/traits.rs
@@ -4,15 +4,15 @@ use super::*;
4// trait T<U>: Hash + Clone where U: Copy {} 4// trait T<U>: Hash + Clone where U: Copy {}
5// trait X<U: Debug + Display>: Hash + Clone where U: Copy {} 5// trait X<U: Debug + Display>: Hash + Clone where U: Copy {}
6pub(super) fn trait_def(p: &mut Parser) { 6pub(super) fn trait_def(p: &mut Parser) {
7 assert!(p.at(TRAIT_KW)); 7 assert!(p.at(T![trait]));
8 p.bump(); 8 p.bump();
9 name_r(p, ITEM_RECOVERY_SET); 9 name_r(p, ITEM_RECOVERY_SET);
10 type_params::opt_type_param_list(p); 10 type_params::opt_type_param_list(p);
11 if p.at(COLON) { 11 if p.at(T![:]) {
12 type_params::bounds(p); 12 type_params::bounds(p);
13 } 13 }
14 type_params::opt_where_clause(p); 14 type_params::opt_where_clause(p);
15 if p.at(L_CURLY) { 15 if p.at(T!['{']) {
16 trait_item_list(p); 16 trait_item_list(p);
17 } else { 17 } else {
18 p.error("expected `{`"); 18 p.error("expected `{`");
@@ -27,24 +27,24 @@ pub(super) fn trait_def(p: &mut Parser) {
27// fn bar(&self); 27// fn bar(&self);
28// } 28// }
29pub(crate) fn trait_item_list(p: &mut Parser) { 29pub(crate) fn trait_item_list(p: &mut Parser) {
30 assert!(p.at(L_CURLY)); 30 assert!(p.at(T!['{']));
31 let m = p.start(); 31 let m = p.start();
32 p.bump(); 32 p.bump();
33 while !p.at(EOF) && !p.at(R_CURLY) { 33 while !p.at(EOF) && !p.at(T!['}']) {
34 if p.at(L_CURLY) { 34 if p.at(T!['{']) {
35 error_block(p, "expected an item"); 35 error_block(p, "expected an item");
36 continue; 36 continue;
37 } 37 }
38 item_or_macro(p, true, ItemFlavor::Trait); 38 item_or_macro(p, true, ItemFlavor::Trait);
39 } 39 }
40 p.expect(R_CURLY); 40 p.expect(T!['}']);
41 m.complete(p, ITEM_LIST); 41 m.complete(p, ITEM_LIST);
42} 42}
43 43
44// test impl_block 44// test impl_block
45// impl Foo {} 45// impl Foo {}
46pub(super) fn impl_block(p: &mut Parser) { 46pub(super) fn impl_block(p: &mut Parser) {
47 assert!(p.at(IMPL_KW)); 47 assert!(p.at(T![impl ]));
48 p.bump(); 48 p.bump();
49 if choose_type_params_over_qpath(p) { 49 if choose_type_params_over_qpath(p) {
50 type_params::opt_type_param_list(p); 50 type_params::opt_type_param_list(p);
@@ -55,13 +55,13 @@ pub(super) fn impl_block(p: &mut Parser) {
55 55
56 // test impl_block_neg 56 // test impl_block_neg
57 // impl !Send for X {} 57 // impl !Send for X {}
58 p.eat(EXCL); 58 p.eat(T![!]);
59 impl_type(p); 59 impl_type(p);
60 if p.eat(FOR_KW) { 60 if p.eat(T![for]) {
61 impl_type(p); 61 impl_type(p);
62 } 62 }
63 type_params::opt_where_clause(p); 63 type_params::opt_where_clause(p);
64 if p.at(L_CURLY) { 64 if p.at(T!['{']) {
65 impl_item_list(p); 65 impl_item_list(p);
66 } else { 66 } else {
67 p.error("expected `{`"); 67 p.error("expected `{`");
@@ -76,7 +76,7 @@ pub(super) fn impl_block(p: &mut Parser) {
76// fn bar(&self) {} 76// fn bar(&self) {}
77// } 77// }
78pub(crate) fn impl_item_list(p: &mut Parser) { 78pub(crate) fn impl_item_list(p: &mut Parser) {
79 assert!(p.at(L_CURLY)); 79 assert!(p.at(T!['{']));
80 let m = p.start(); 80 let m = p.start();
81 p.bump(); 81 p.bump();
82 // test impl_inner_attributes 82 // test impl_inner_attributes
@@ -87,14 +87,14 @@ pub(crate) fn impl_item_list(p: &mut Parser) {
87 // } 87 // }
88 attributes::inner_attributes(p); 88 attributes::inner_attributes(p);
89 89
90 while !p.at(EOF) && !p.at(R_CURLY) { 90 while !p.at(EOF) && !p.at(T!['}']) {
91 if p.at(L_CURLY) { 91 if p.at(T!['{']) {
92 error_block(p, "expected an item"); 92 error_block(p, "expected an item");
93 continue; 93 continue;
94 } 94 }
95 item_or_macro(p, true, ItemFlavor::Mod); 95 item_or_macro(p, true, ItemFlavor::Mod);
96 } 96 }
97 p.expect(R_CURLY); 97 p.expect(T!['}']);
98 m.complete(p, ITEM_LIST); 98 m.complete(p, ITEM_LIST);
99} 99}
100 100
@@ -114,14 +114,14 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
114 // we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`) 114 // we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`)
115 // because this is what almost always expected in practice, qualified paths in impls 115 // because this is what almost always expected in practice, qualified paths in impls
116 // (`impl <Type>::AssocTy { ... }`) aren't even allowed by type checker at the moment. 116 // (`impl <Type>::AssocTy { ... }`) aren't even allowed by type checker at the moment.
117 if !p.at(L_ANGLE) { 117 if !p.at(T![<]) {
118 return false; 118 return false;
119 } 119 }
120 if p.nth(1) == POUND || p.nth(1) == R_ANGLE { 120 if p.nth(1) == T![#] || p.nth(1) == T![>] {
121 return true; 121 return true;
122 } 122 }
123 (p.nth(1) == LIFETIME || p.nth(1) == IDENT) 123 (p.nth(1) == LIFETIME || p.nth(1) == IDENT)
124 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) 124 && (p.nth(2) == T![>] || p.nth(2) == T![,] || p.nth(2) == T![:] || p.nth(2) == T![=])
125} 125}
126 126
127// test_err impl_type 127// test_err impl_type
@@ -130,7 +130,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
130// impl impl NotType {} 130// impl impl NotType {}
131// impl Trait2 for impl NotType {} 131// impl Trait2 for impl NotType {}
132pub(crate) fn impl_type(p: &mut Parser) { 132pub(crate) fn impl_type(p: &mut Parser) {
133 if p.at(IMPL_KW) { 133 if p.at(T![impl ]) {
134 p.error("expected trait or type"); 134 p.error("expected trait or type");
135 return; 135 return;
136 } 136 }
diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs
index 908493789..c3a0b4410 100644
--- a/crates/ra_parser/src/grammar/items/use_item.rs
+++ b/crates/ra_parser/src/grammar/items/use_item.rs
@@ -1,10 +1,10 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn use_item(p: &mut Parser, m: Marker) { 3pub(super) fn use_item(p: &mut Parser, m: Marker) {
4 assert!(p.at(USE_KW)); 4 assert!(p.at(T![use]));
5 p.bump(); 5 p.bump();
6 use_tree(p); 6 use_tree(p);
7 p.expect(SEMI); 7 p.expect(T![;]);
8 m.complete(p, USE_ITEM); 8 m.complete(p, USE_ITEM);
9} 9}
10 10
@@ -28,8 +28,8 @@ fn use_tree(p: &mut Parser) {
28 // use ::*; 28 // use ::*;
29 // use some::path::{*}; 29 // use some::path::{*};
30 // use some::path::{::*}; 30 // use some::path::{::*};
31 (STAR, _) => p.bump(), 31 (T![*], _) => p.bump(),
32 (COLONCOLON, STAR) => { 32 (T![::], T![*]) => {
33 // Parse `use ::*;`, which imports all from the crate root in Rust 2015 33 // Parse `use ::*;`, which imports all from the crate root in Rust 2015
34 // This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`) 34 // This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`)
35 // but still parses and errors later: ('crate root in paths can only be used in start position') 35 // but still parses and errors later: ('crate root in paths can only be used in start position')
@@ -47,8 +47,8 @@ fn use_tree(p: &mut Parser) {
47 // use {path::from::root}; // Rust 2015 47 // use {path::from::root}; // Rust 2015
48 // use ::{some::arbritrary::path}; // Rust 2015 48 // use ::{some::arbritrary::path}; // Rust 2015
49 // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig 49 // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig
50 (L_CURLY, _) | (COLONCOLON, L_CURLY) => { 50 (T!['{'], _) | (T![::], T!['{']) => {
51 if p.at(COLONCOLON) { 51 if p.at(T![::]) {
52 p.bump(); 52 p.bump();
53 } 53 }
54 use_tree_list(p); 54 use_tree_list(p);
@@ -68,7 +68,7 @@ fn use_tree(p: &mut Parser) {
68 _ if paths::is_path_start(p) => { 68 _ if paths::is_path_start(p) => {
69 paths::use_path(p); 69 paths::use_path(p);
70 match p.current() { 70 match p.current() {
71 AS_KW => { 71 T![as] => {
72 // test use_alias 72 // test use_alias
73 // use some::path as some_name; 73 // use some::path as some_name;
74 // use some::{ 74 // use some::{
@@ -80,16 +80,16 @@ fn use_tree(p: &mut Parser) {
80 // use Trait as _; 80 // use Trait as _;
81 opt_alias(p); 81 opt_alias(p);
82 } 82 }
83 COLONCOLON => { 83 T![::] => {
84 p.bump(); 84 p.bump();
85 match p.current() { 85 match p.current() {
86 STAR => { 86 T![*] => {
87 p.bump(); 87 p.bump();
88 } 88 }
89 // test use_tree_list_after_path 89 // test use_tree_list_after_path
90 // use crate::{Item}; 90 // use crate::{Item};
91 // use self::{Item}; 91 // use self::{Item};
92 L_CURLY => use_tree_list(p), 92 T!['{'] => use_tree_list(p),
93 _ => { 93 _ => {
94 // is this unreachable? 94 // is this unreachable?
95 p.error("expected `{` or `*`"); 95 p.error("expected `{` or `*`");
@@ -109,15 +109,15 @@ fn use_tree(p: &mut Parser) {
109} 109}
110 110
111pub(crate) fn use_tree_list(p: &mut Parser) { 111pub(crate) fn use_tree_list(p: &mut Parser) {
112 assert!(p.at(L_CURLY)); 112 assert!(p.at(T!['{']));
113 let m = p.start(); 113 let m = p.start();
114 p.bump(); 114 p.bump();
115 while !p.at(EOF) && !p.at(R_CURLY) { 115 while !p.at(EOF) && !p.at(T!['}']) {
116 use_tree(p); 116 use_tree(p);
117 if !p.at(R_CURLY) { 117 if !p.at(T!['}']) {
118 p.expect(COMMA); 118 p.expect(T![,]);
119 } 119 }
120 } 120 }
121 p.expect(R_CURLY); 121 p.expect(T!['}']);
122 m.complete(p, USE_TREE_LIST); 122 m.complete(p, USE_TREE_LIST);
123} 123}
diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs
index 3d3bd4cc1..723b56343 100644
--- a/crates/ra_parser/src/grammar/params.rs
+++ b/crates/ra_parser/src/grammar/params.rs
@@ -36,27 +36,27 @@ impl Flavor {
36} 36}
37 37
38fn list_(p: &mut Parser, flavor: Flavor) { 38fn list_(p: &mut Parser, flavor: Flavor) {
39 let (bra, ket) = if flavor.type_required() { (L_PAREN, R_PAREN) } else { (PIPE, PIPE) }; 39 let (bra, ket) = if flavor.type_required() { (T!['('], T![')']) } else { (T![|], T![|]) };
40 assert!(p.at(bra)); 40 assert!(p.at(bra));
41 let m = p.start(); 41 let m = p.start();
42 p.bump(); 42 p.bump();
43 if flavor.type_required() { 43 if flavor.type_required() {
44 opt_self_param(p); 44 opt_self_param(p);
45 } 45 }
46 while !p.at(EOF) && !p.at(ket) && !(flavor.type_required() && p.at(DOTDOTDOT)) { 46 while !p.at(EOF) && !p.at(ket) && !(flavor.type_required() && p.at(T![...])) {
47 if !p.at_ts(VALUE_PARAMETER_FIRST) { 47 if !p.at_ts(VALUE_PARAMETER_FIRST) {
48 p.error("expected value parameter"); 48 p.error("expected value parameter");
49 break; 49 break;
50 } 50 }
51 value_parameter(p, flavor); 51 value_parameter(p, flavor);
52 if !p.at(ket) { 52 if !p.at(ket) {
53 p.expect(COMMA); 53 p.expect(T![,]);
54 } 54 }
55 } 55 }
56 // test param_list_vararg 56 // test param_list_vararg
57 // extern "C" { fn printf(format: *const i8, ...) -> i32; } 57 // extern "C" { fn printf(format: *const i8, ...) -> i32; }
58 if flavor.type_required() { 58 if flavor.type_required() {
59 p.eat(DOTDOTDOT); 59 p.eat(T![...]);
60 } 60 }
61 p.expect(ket); 61 p.expect(ket);
62 m.complete(p, PARAM_LIST); 62 m.complete(p, PARAM_LIST);
@@ -69,7 +69,7 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
69 match flavor { 69 match flavor {
70 Flavor::OptionalType | Flavor::Normal => { 70 Flavor::OptionalType | Flavor::Normal => {
71 patterns::pattern(p); 71 patterns::pattern(p);
72 if p.at(COLON) || flavor.type_required() { 72 if p.at(T![:]) || flavor.type_required() {
73 types::ascription(p) 73 types::ascription(p)
74 } 74 }
75 } 75 }
@@ -85,10 +85,10 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
85 // trait Foo { 85 // trait Foo {
86 // fn bar(_: u64, mut x: i32); 86 // fn bar(_: u64, mut x: i32);
87 // } 87 // }
88 if (la0 == IDENT || la0 == UNDERSCORE) && la1 == COLON 88 if (la0 == IDENT || la0 == T![_]) && la1 == T![:]
89 || la0 == MUT_KW && la1 == IDENT && la2 == COLON 89 || la0 == T![mut] && la1 == IDENT && la2 == T![:]
90 || la0 == AMP && la1 == IDENT && la2 == COLON 90 || la0 == T![&] && la1 == IDENT && la2 == T![:]
91 || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON 91 || la0 == T![&] && la1 == T![mut] && la2 == IDENT && la3 == T![:]
92 { 92 {
93 patterns::pattern(p); 93 patterns::pattern(p);
94 types::ascription(p); 94 types::ascription(p);
@@ -110,16 +110,16 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
110// } 110// }
111fn opt_self_param(p: &mut Parser) { 111fn opt_self_param(p: &mut Parser) {
112 let m; 112 let m;
113 if p.at(SELF_KW) || p.at(MUT_KW) && p.nth(1) == SELF_KW { 113 if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] {
114 m = p.start(); 114 m = p.start();
115 p.eat(MUT_KW); 115 p.eat(T![mut]);
116 p.eat(SELF_KW); 116 p.eat(T![self]);
117 // test arb_self_types 117 // test arb_self_types
118 // impl S { 118 // impl S {
119 // fn a(self: &Self) {} 119 // fn a(self: &Self) {}
120 // fn b(mut self: Box<Self>) {} 120 // fn b(mut self: Box<Self>) {}
121 // } 121 // }
122 if p.at(COLON) { 122 if p.at(T![:]) {
123 types::ascription(p); 123 types::ascription(p);
124 } 124 }
125 } else { 125 } else {
@@ -127,10 +127,10 @@ fn opt_self_param(p: &mut Parser) {
127 let la2 = p.nth(2); 127 let la2 = p.nth(2);
128 let la3 = p.nth(3); 128 let la3 = p.nth(3);
129 let n_toks = match (p.current(), la1, la2, la3) { 129 let n_toks = match (p.current(), la1, la2, la3) {
130 (AMP, SELF_KW, _, _) => 2, 130 (T![&], T![self], _, _) => 2,
131 (AMP, MUT_KW, SELF_KW, _) => 3, 131 (T![&], T![mut], T![self], _) => 3,
132 (AMP, LIFETIME, SELF_KW, _) => 3, 132 (T![&], LIFETIME, T![self], _) => 3,
133 (AMP, LIFETIME, MUT_KW, SELF_KW) => 4, 133 (T![&], LIFETIME, T![mut], T![self]) => 4,
134 _ => return, 134 _ => return,
135 }; 135 };
136 m = p.start(); 136 m = p.start();
@@ -139,7 +139,7 @@ fn opt_self_param(p: &mut Parser) {
139 } 139 }
140 } 140 }
141 m.complete(p, SELF_PARAM); 141 m.complete(p, SELF_PARAM);
142 if !p.at(R_PAREN) { 142 if !p.at(T![')']) {
143 p.expect(COMMA); 143 p.expect(T![,]);
144 } 144 }
145} 145}
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs
index 33a11886c..3537b0da1 100644
--- a/crates/ra_parser/src/grammar/paths.rs
+++ b/crates/ra_parser/src/grammar/paths.rs
@@ -5,7 +5,7 @@ pub(super) const PATH_FIRST: TokenSet =
5 5
6pub(super) fn is_path_start(p: &Parser) -> bool { 6pub(super) fn is_path_start(p: &Parser) -> bool {
7 match p.current() { 7 match p.current() {
8 IDENT | SELF_KW | SUPER_KW | CRATE_KW | COLONCOLON => true, 8 IDENT | T![self] | T![super] | T![crate] | T![::] => true,
9 _ => false, 9 _ => false,
10 } 10 }
11} 11}
@@ -35,10 +35,10 @@ fn path(p: &mut Parser, mode: Mode) {
35 let mut qual = path.complete(p, PATH); 35 let mut qual = path.complete(p, PATH);
36 loop { 36 loop {
37 let use_tree = match p.nth(1) { 37 let use_tree = match p.nth(1) {
38 STAR | L_CURLY => true, 38 T![*] | T!['{'] => true,
39 _ => false, 39 _ => false,
40 }; 40 };
41 if p.at(COLONCOLON) && !use_tree { 41 if p.at(T![::]) && !use_tree {
42 let path = qual.precede(p); 42 let path = qual.precede(p);
43 p.bump(); 43 p.bump();
44 path_segment(p, mode, false); 44 path_segment(p, mode, false);
@@ -55,19 +55,19 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
55 // test qual_paths 55 // test qual_paths
56 // type X = <A as B>::Output; 56 // type X = <A as B>::Output;
57 // fn foo() { <usize as Default>::default(); } 57 // fn foo() { <usize as Default>::default(); }
58 if first && p.eat(L_ANGLE) { 58 if first && p.eat(T![<]) {
59 types::type_(p); 59 types::type_(p);
60 if p.eat(AS_KW) { 60 if p.eat(T![as]) {
61 if is_path_start(p) { 61 if is_path_start(p) {
62 types::path_type(p); 62 types::path_type(p);
63 } else { 63 } else {
64 p.error("expected a trait"); 64 p.error("expected a trait");
65 } 65 }
66 } 66 }
67 p.expect(R_ANGLE); 67 p.expect(T![>]);
68 } else { 68 } else {
69 if first { 69 if first {
70 p.eat(COLONCOLON); 70 p.eat(T![::]);
71 } 71 }
72 match p.current() { 72 match p.current() {
73 IDENT => { 73 IDENT => {
@@ -76,7 +76,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
76 } 76 }
77 // test crate_path 77 // test crate_path
78 // use crate::foo; 78 // use crate::foo;
79 SELF_KW | SUPER_KW | CRATE_KW => p.bump(), 79 T![self] | T![super] | T![crate] => p.bump(),
80 _ => { 80 _ => {
81 p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); 81 p.err_recover("expected identifier", items::ITEM_RECOVERY_SET);
82 } 82 }
@@ -91,7 +91,7 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) {
91 Mode::Type => { 91 Mode::Type => {
92 // test path_fn_trait_args 92 // test path_fn_trait_args
93 // type F = Box<Fn(x: i32) -> ()>; 93 // type F = Box<Fn(x: i32) -> ()>;
94 if p.at(L_PAREN) { 94 if p.at(T!['(']) {
95 params::param_list_opt_patterns(p); 95 params::param_list_opt_patterns(p);
96 opt_fn_ret_type(p); 96 opt_fn_ret_type(p);
97 } else { 97 } else {
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs
index 12dd22bde..16ae9da63 100644
--- a/crates/ra_parser/src/grammar/patterns.rs
+++ b/crates/ra_parser/src/grammar/patterns.rs
@@ -16,10 +16,10 @@ pub(super) fn pattern_list(p: &mut Parser) {
16/// Parses a pattern list separated by pipes `|` 16/// Parses a pattern list separated by pipes `|`
17/// using the given `recovery_set` 17/// using the given `recovery_set`
18pub(super) fn pattern_list_r(p: &mut Parser, recovery_set: TokenSet) { 18pub(super) fn pattern_list_r(p: &mut Parser, recovery_set: TokenSet) {
19 p.eat(PIPE); 19 p.eat(T![|]);
20 pattern_r(p, recovery_set); 20 pattern_r(p, recovery_set);
21 21
22 while p.eat(PIPE) { 22 while p.eat(T![|]) {
23 pattern_r(p, recovery_set); 23 pattern_r(p, recovery_set);
24 } 24 }
25} 25}
@@ -34,7 +34,7 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) {
34 // 200 .. 301=> (), 34 // 200 .. 301=> (),
35 // } 35 // }
36 // } 36 // }
37 if p.at(DOTDOTDOT) || p.at(DOTDOTEQ) || p.at(DOTDOT) { 37 if p.at(T![...]) || p.at(T![..=]) || p.at(T![..]) {
38 let m = lhs.precede(p); 38 let m = lhs.precede(p);
39 p.bump(); 39 p.bump();
40 atom_pat(p, recovery_set); 40 atom_pat(p, recovery_set);
@@ -44,7 +44,7 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) {
44 // fn main() { 44 // fn main() {
45 // let m!(x) = 0; 45 // let m!(x) = 0;
46 // } 46 // }
47 else if lhs.kind() == PATH_PAT && p.at(EXCL) { 47 else if lhs.kind() == PATH_PAT && p.at(T![!]) {
48 let m = lhs.precede(p); 48 let m = lhs.precede(p);
49 items::macro_call_after_excl(p); 49 items::macro_call_after_excl(p);
50 m.complete(p, MACRO_CALL); 50 m.complete(p, MACRO_CALL);
@@ -58,9 +58,9 @@ const PAT_RECOVERY_SET: TokenSet =
58fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { 58fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
59 let la0 = p.nth(0); 59 let la0 = p.nth(0);
60 let la1 = p.nth(1); 60 let la1 = p.nth(1);
61 if la0 == REF_KW 61 if la0 == T![ref]
62 || la0 == MUT_KW 62 || la0 == T![mut]
63 || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY || la1 == EXCL)) 63 || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!]))
64 { 64 {
65 return Some(bind_pat(p, true)); 65 return Some(bind_pat(p, true));
66 } 66 }
@@ -73,10 +73,10 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
73 } 73 }
74 74
75 let m = match la0 { 75 let m = match la0 {
76 UNDERSCORE => placeholder_pat(p), 76 T![_] => placeholder_pat(p),
77 AMP => ref_pat(p), 77 T![&] => ref_pat(p),
78 L_PAREN => tuple_pat(p), 78 T!['('] => tuple_pat(p),
79 L_BRACK => slice_pat(p), 79 T!['['] => slice_pat(p),
80 _ => { 80 _ => {
81 p.err_recover("expected pattern", recovery_set); 81 p.err_recover("expected pattern", recovery_set);
82 return None; 82 return None;
@@ -86,7 +86,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
86} 86}
87 87
88fn is_literal_pat_start(p: &mut Parser) -> bool { 88fn is_literal_pat_start(p: &mut Parser) -> bool {
89 p.at(MINUS) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER) 89 p.at(T![-]) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER)
90 || p.at_ts(expressions::LITERAL_FIRST) 90 || p.at_ts(expressions::LITERAL_FIRST)
91} 91}
92 92
@@ -102,7 +102,7 @@ fn is_literal_pat_start(p: &mut Parser) -> bool {
102fn literal_pat(p: &mut Parser) -> CompletedMarker { 102fn literal_pat(p: &mut Parser) -> CompletedMarker {
103 assert!(is_literal_pat_start(p)); 103 assert!(is_literal_pat_start(p));
104 let m = p.start(); 104 let m = p.start();
105 if p.at(MINUS) { 105 if p.at(T![-]) {
106 p.bump(); 106 p.bump();
107 } 107 }
108 expressions::literal(p); 108 expressions::literal(p);
@@ -121,11 +121,11 @@ fn path_pat(p: &mut Parser) -> CompletedMarker {
121 let m = p.start(); 121 let m = p.start();
122 paths::expr_path(p); 122 paths::expr_path(p);
123 let kind = match p.current() { 123 let kind = match p.current() {
124 L_PAREN => { 124 T!['('] => {
125 tuple_pat_fields(p); 125 tuple_pat_fields(p);
126 TUPLE_STRUCT_PAT 126 TUPLE_STRUCT_PAT
127 } 127 }
128 L_CURLY => { 128 T!['{'] => {
129 field_pat_list(p); 129 field_pat_list(p);
130 STRUCT_PAT 130 STRUCT_PAT
131 } 131 }
@@ -142,10 +142,10 @@ fn path_pat(p: &mut Parser) -> CompletedMarker {
142// let S(_, .. , x) = (); 142// let S(_, .. , x) = ();
143// } 143// }
144fn tuple_pat_fields(p: &mut Parser) { 144fn tuple_pat_fields(p: &mut Parser) {
145 assert!(p.at(L_PAREN)); 145 assert!(p.at(T!['(']));
146 p.bump(); 146 p.bump();
147 pat_list(p, R_PAREN); 147 pat_list(p, T![')']);
148 p.expect(R_PAREN); 148 p.expect(T![')']);
149} 149}
150 150
151// test field_pat_list 151// test field_pat_list
@@ -156,29 +156,29 @@ fn tuple_pat_fields(p: &mut Parser) {
156// let S { h: _, } = (); 156// let S { h: _, } = ();
157// } 157// }
158fn field_pat_list(p: &mut Parser) { 158fn field_pat_list(p: &mut Parser) {
159 assert!(p.at(L_CURLY)); 159 assert!(p.at(T!['{']));
160 let m = p.start(); 160 let m = p.start();
161 p.bump(); 161 p.bump();
162 while !p.at(EOF) && !p.at(R_CURLY) { 162 while !p.at(EOF) && !p.at(T!['}']) {
163 match p.current() { 163 match p.current() {
164 DOTDOT => p.bump(), 164 T![..] => p.bump(),
165 IDENT if p.nth(1) == COLON => field_pat(p), 165 IDENT if p.nth(1) == T![:] => field_pat(p),
166 L_CURLY => error_block(p, "expected ident"), 166 T!['{'] => error_block(p, "expected ident"),
167 _ => { 167 _ => {
168 bind_pat(p, false); 168 bind_pat(p, false);
169 } 169 }
170 } 170 }
171 if !p.at(R_CURLY) { 171 if !p.at(T!['}']) {
172 p.expect(COMMA); 172 p.expect(T![,]);
173 } 173 }
174 } 174 }
175 p.expect(R_CURLY); 175 p.expect(T!['}']);
176 m.complete(p, FIELD_PAT_LIST); 176 m.complete(p, FIELD_PAT_LIST);
177} 177}
178 178
179fn field_pat(p: &mut Parser) { 179fn field_pat(p: &mut Parser) {
180 assert!(p.at(IDENT)); 180 assert!(p.at(IDENT));
181 assert!(p.nth(1) == COLON); 181 assert!(p.nth(1) == T![:]);
182 182
183 let m = p.start(); 183 let m = p.start();
184 name(p); 184 name(p);
@@ -190,7 +190,7 @@ fn field_pat(p: &mut Parser) {
190// test placeholder_pat 190// test placeholder_pat
191// fn main() { let _ = (); } 191// fn main() { let _ = (); }
192fn placeholder_pat(p: &mut Parser) -> CompletedMarker { 192fn placeholder_pat(p: &mut Parser) -> CompletedMarker {
193 assert!(p.at(UNDERSCORE)); 193 assert!(p.at(T![_]));
194 let m = p.start(); 194 let m = p.start();
195 p.bump(); 195 p.bump();
196 m.complete(p, PLACEHOLDER_PAT) 196 m.complete(p, PLACEHOLDER_PAT)
@@ -202,10 +202,10 @@ fn placeholder_pat(p: &mut Parser) -> CompletedMarker {
202// let &mut b = (); 202// let &mut b = ();
203// } 203// }
204fn ref_pat(p: &mut Parser) -> CompletedMarker { 204fn ref_pat(p: &mut Parser) -> CompletedMarker {
205 assert!(p.at(AMP)); 205 assert!(p.at(T![&]));
206 let m = p.start(); 206 let m = p.start();
207 p.bump(); 207 p.bump();
208 p.eat(MUT_KW); 208 p.eat(T![mut]);
209 pattern(p); 209 pattern(p);
210 m.complete(p, REF_PAT) 210 m.complete(p, REF_PAT)
211} 211}
@@ -215,7 +215,7 @@ fn ref_pat(p: &mut Parser) -> CompletedMarker {
215// let (a, b, ..) = (); 215// let (a, b, ..) = ();
216// } 216// }
217fn tuple_pat(p: &mut Parser) -> CompletedMarker { 217fn tuple_pat(p: &mut Parser) -> CompletedMarker {
218 assert!(p.at(L_PAREN)); 218 assert!(p.at(T!['(']));
219 let m = p.start(); 219 let m = p.start();
220 tuple_pat_fields(p); 220 tuple_pat_fields(p);
221 m.complete(p, TUPLE_PAT) 221 m.complete(p, TUPLE_PAT)
@@ -226,18 +226,18 @@ fn tuple_pat(p: &mut Parser) -> CompletedMarker {
226// let [a, b, ..] = []; 226// let [a, b, ..] = [];
227// } 227// }
228fn slice_pat(p: &mut Parser) -> CompletedMarker { 228fn slice_pat(p: &mut Parser) -> CompletedMarker {
229 assert!(p.at(L_BRACK)); 229 assert!(p.at(T!['[']));
230 let m = p.start(); 230 let m = p.start();
231 p.bump(); 231 p.bump();
232 pat_list(p, R_BRACK); 232 pat_list(p, T![']']);
233 p.expect(R_BRACK); 233 p.expect(T![']']);
234 m.complete(p, SLICE_PAT) 234 m.complete(p, SLICE_PAT)
235} 235}
236 236
237fn pat_list(p: &mut Parser, ket: SyntaxKind) { 237fn pat_list(p: &mut Parser, ket: SyntaxKind) {
238 while !p.at(EOF) && !p.at(ket) { 238 while !p.at(EOF) && !p.at(ket) {
239 match p.current() { 239 match p.current() {
240 DOTDOT => p.bump(), 240 T![..] => p.bump(),
241 _ => { 241 _ => {
242 if !p.at_ts(PATTERN_FIRST) { 242 if !p.at_ts(PATTERN_FIRST) {
243 p.error("expected a pattern"); 243 p.error("expected a pattern");
@@ -247,7 +247,7 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) {
247 } 247 }
248 } 248 }
249 if !p.at(ket) { 249 if !p.at(ket) {
250 p.expect(COMMA); 250 p.expect(T![,]);
251 } 251 }
252 } 252 }
253} 253}
@@ -263,10 +263,10 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) {
263// } 263// }
264fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { 264fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker {
265 let m = p.start(); 265 let m = p.start();
266 p.eat(REF_KW); 266 p.eat(T![ref]);
267 p.eat(MUT_KW); 267 p.eat(T![mut]);
268 name(p); 268 name(p);
269 if with_at && p.eat(AT) { 269 if with_at && p.eat(T![@]) {
270 pattern(p); 270 pattern(p);
271 } 271 }
272 m.complete(p, BIND_PAT) 272 m.complete(p, BIND_PAT)
diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs
index 684976b99..f391b63db 100644
--- a/crates/ra_parser/src/grammar/type_args.rs
+++ b/crates/ra_parser/src/grammar/type_args.rs
@@ -3,26 +3,26 @@ use super::*;
3pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) { 3pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
4 let m; 4 let m;
5 match (colon_colon_required, p.nth(0), p.nth(1)) { 5 match (colon_colon_required, p.nth(0), p.nth(1)) {
6 (_, COLONCOLON, L_ANGLE) => { 6 (_, T![::], T![<]) => {
7 m = p.start(); 7 m = p.start();
8 p.bump(); 8 p.bump();
9 p.bump(); 9 p.bump();
10 } 10 }
11 (false, L_ANGLE, EQ) => return, 11 (false, T![<], T![=]) => return,
12 (false, L_ANGLE, _) => { 12 (false, T![<], _) => {
13 m = p.start(); 13 m = p.start();
14 p.bump(); 14 p.bump();
15 } 15 }
16 _ => return, 16 _ => return,
17 }; 17 };
18 18
19 while !p.at(EOF) && !p.at(R_ANGLE) { 19 while !p.at(EOF) && !p.at(T![>]) {
20 type_arg(p); 20 type_arg(p);
21 if !p.at(R_ANGLE) && !p.expect(COMMA) { 21 if !p.at(T![>]) && !p.expect(T![,]) {
22 break; 22 break;
23 } 23 }
24 } 24 }
25 p.expect(R_ANGLE); 25 p.expect(T![>]);
26 m.complete(p, TYPE_ARG_LIST); 26 m.complete(p, TYPE_ARG_LIST);
27} 27}
28 28
@@ -35,7 +35,7 @@ fn type_arg(p: &mut Parser) {
35 p.bump(); 35 p.bump();
36 m.complete(p, LIFETIME_ARG); 36 m.complete(p, LIFETIME_ARG);
37 } 37 }
38 IDENT if p.nth(1) == EQ => { 38 IDENT if p.nth(1) == T![=] => {
39 name_ref(p); 39 name_ref(p);
40 p.bump(); 40 p.bump();
41 types::type_(p); 41 types::type_(p);
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs
index 07d9b0792..4bbfed780 100644
--- a/crates/ra_parser/src/grammar/type_params.rs
+++ b/crates/ra_parser/src/grammar/type_params.rs
@@ -1,18 +1,18 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn opt_type_param_list(p: &mut Parser) { 3pub(super) fn opt_type_param_list(p: &mut Parser) {
4 if !p.at(L_ANGLE) { 4 if !p.at(T![<]) {
5 return; 5 return;
6 } 6 }
7 type_param_list(p); 7 type_param_list(p);
8} 8}
9 9
10fn type_param_list(p: &mut Parser) { 10fn type_param_list(p: &mut Parser) {
11 assert!(p.at(L_ANGLE)); 11 assert!(p.at(T![<]));
12 let m = p.start(); 12 let m = p.start();
13 p.bump(); 13 p.bump();
14 14
15 while !p.at(EOF) && !p.at(R_ANGLE) { 15 while !p.at(EOF) && !p.at(T![>]) {
16 let m = p.start(); 16 let m = p.start();
17 17
18 // test generic_lifetime_type_attribute 18 // test generic_lifetime_type_attribute
@@ -28,18 +28,18 @@ fn type_param_list(p: &mut Parser) {
28 p.err_and_bump("expected type parameter") 28 p.err_and_bump("expected type parameter")
29 } 29 }
30 } 30 }
31 if !p.at(R_ANGLE) && !p.expect(COMMA) { 31 if !p.at(T![>]) && !p.expect(T![,]) {
32 break; 32 break;
33 } 33 }
34 } 34 }
35 p.expect(R_ANGLE); 35 p.expect(T![>]);
36 m.complete(p, TYPE_PARAM_LIST); 36 m.complete(p, TYPE_PARAM_LIST);
37} 37}
38 38
39fn lifetime_param(p: &mut Parser, m: Marker) { 39fn lifetime_param(p: &mut Parser, m: Marker) {
40 assert!(p.at(LIFETIME)); 40 assert!(p.at(LIFETIME));
41 p.bump(); 41 p.bump();
42 if p.at(COLON) { 42 if p.at(T![:]) {
43 lifetime_bounds(p); 43 lifetime_bounds(p);
44 } 44 }
45 m.complete(p, LIFETIME_PARAM); 45 m.complete(p, LIFETIME_PARAM);
@@ -48,12 +48,12 @@ fn lifetime_param(p: &mut Parser, m: Marker) {
48fn type_param(p: &mut Parser, m: Marker) { 48fn type_param(p: &mut Parser, m: Marker) {
49 assert!(p.at(IDENT)); 49 assert!(p.at(IDENT));
50 name(p); 50 name(p);
51 if p.at(COLON) { 51 if p.at(T![:]) {
52 bounds(p); 52 bounds(p);
53 } 53 }
54 // test type_param_default 54 // test type_param_default
55 // struct S<T = i32>; 55 // struct S<T = i32>;
56 if p.at(EQ) { 56 if p.at(T![=]) {
57 p.bump(); 57 p.bump();
58 types::type_(p) 58 types::type_(p)
59 } 59 }
@@ -63,17 +63,17 @@ fn type_param(p: &mut Parser, m: Marker) {
63// test type_param_bounds 63// test type_param_bounds
64// struct S<T: 'a + ?Sized + (Copy)>; 64// struct S<T: 'a + ?Sized + (Copy)>;
65pub(super) fn bounds(p: &mut Parser) { 65pub(super) fn bounds(p: &mut Parser) {
66 assert!(p.at(COLON)); 66 assert!(p.at(T![:]));
67 p.bump(); 67 p.bump();
68 bounds_without_colon(p); 68 bounds_without_colon(p);
69} 69}
70 70
71fn lifetime_bounds(p: &mut Parser) { 71fn lifetime_bounds(p: &mut Parser) {
72 assert!(p.at(COLON)); 72 assert!(p.at(T![:]));
73 p.bump(); 73 p.bump();
74 while p.at(LIFETIME) { 74 while p.at(LIFETIME) {
75 p.bump(); 75 p.bump();
76 if !p.eat(PLUS) { 76 if !p.eat(T![+]) {
77 break; 77 break;
78 } 78 }
79 } 79 }
@@ -81,7 +81,7 @@ fn lifetime_bounds(p: &mut Parser) {
81 81
82pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> CompletedMarker { 82pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> CompletedMarker {
83 while type_bound(p) { 83 while type_bound(p) {
84 if !p.eat(PLUS) { 84 if !p.eat(T![+]) {
85 break; 85 break;
86 } 86 }
87 } 87 }
@@ -96,11 +96,11 @@ pub(super) fn bounds_without_colon(p: &mut Parser) {
96 96
97fn type_bound(p: &mut Parser) -> bool { 97fn type_bound(p: &mut Parser) -> bool {
98 let m = p.start(); 98 let m = p.start();
99 let has_paren = p.eat(L_PAREN); 99 let has_paren = p.eat(T!['(']);
100 p.eat(QUESTION); 100 p.eat(T![?]);
101 match p.current() { 101 match p.current() {
102 LIFETIME => p.bump(), 102 LIFETIME => p.bump(),
103 FOR_KW => types::for_type(p), 103 T![for] => types::for_type(p),
104 _ if paths::is_path_start(p) => types::path_type_(p, false), 104 _ if paths::is_path_start(p) => types::path_type_(p, false),
105 _ => { 105 _ => {
106 m.abandon(p); 106 m.abandon(p);
@@ -108,7 +108,7 @@ fn type_bound(p: &mut Parser) -> bool {
108 } 108 }
109 } 109 }
110 if has_paren { 110 if has_paren {
111 p.expect(R_PAREN); 111 p.expect(T![')']);
112 } 112 }
113 m.complete(p, TYPE_BOUND); 113 m.complete(p, TYPE_BOUND);
114 114
@@ -124,7 +124,7 @@ fn type_bound(p: &mut Parser) -> bool {
124// <T as Iterator>::Item: 'a 124// <T as Iterator>::Item: 'a
125// {} 125// {}
126pub(super) fn opt_where_clause(p: &mut Parser) { 126pub(super) fn opt_where_clause(p: &mut Parser) {
127 if !p.at(WHERE_KW) { 127 if !p.at(T![where]) {
128 return; 128 return;
129 } 129 }
130 let m = p.start(); 130 let m = p.start();
@@ -133,7 +133,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
133 while is_where_predicate(p) { 133 while is_where_predicate(p) {
134 where_predicate(p); 134 where_predicate(p);
135 135
136 let comma = p.eat(COMMA); 136 let comma = p.eat(T![,]);
137 137
138 if is_where_clause_end(p) { 138 if is_where_clause_end(p) {
139 break; 139 break;
@@ -150,13 +150,13 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
150fn is_where_predicate(p: &mut Parser) -> bool { 150fn is_where_predicate(p: &mut Parser) -> bool {
151 match p.current() { 151 match p.current() {
152 LIFETIME => true, 152 LIFETIME => true,
153 IMPL_KW => false, 153 T![impl ] => false,
154 token => types::TYPE_FIRST.contains(token), 154 token => types::TYPE_FIRST.contains(token),
155 } 155 }
156} 156}
157 157
158fn is_where_clause_end(p: &mut Parser) -> bool { 158fn is_where_clause_end(p: &mut Parser) -> bool {
159 p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ 159 p.current() == T!['{'] || p.current() == T![;] || p.current() == T![=]
160} 160}
161 161
162fn where_predicate(p: &mut Parser) { 162fn where_predicate(p: &mut Parser) {
@@ -164,13 +164,13 @@ fn where_predicate(p: &mut Parser) {
164 match p.current() { 164 match p.current() {
165 LIFETIME => { 165 LIFETIME => {
166 p.bump(); 166 p.bump();
167 if p.at(COLON) { 167 if p.at(T![:]) {
168 bounds(p); 168 bounds(p);
169 } else { 169 } else {
170 p.error("expected colon"); 170 p.error("expected colon");
171 } 171 }
172 } 172 }
173 IMPL_KW => { 173 T![impl ] => {
174 p.error("expected lifetime or type"); 174 p.error("expected lifetime or type");
175 } 175 }
176 _ => { 176 _ => {
@@ -181,7 +181,7 @@ fn where_predicate(p: &mut Parser) {
181 // { } 181 // { }
182 types::type_(p); 182 types::type_(p);
183 183
184 if p.at(COLON) { 184 if p.at(T![:]) {
185 bounds(p); 185 bounds(p);
186 } else { 186 } else {
187 p.error("expected colon"); 187 p.error("expected colon");
diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs
index 686c80f3c..438e3ab0e 100644
--- a/crates/ra_parser/src/grammar/types.rs
+++ b/crates/ra_parser/src/grammar/types.rs
@@ -17,18 +17,18 @@ pub(super) fn type_no_bounds(p: &mut Parser) {
17 17
18fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { 18fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
19 match p.current() { 19 match p.current() {
20 L_PAREN => paren_or_tuple_type(p), 20 T!['('] => paren_or_tuple_type(p),
21 EXCL => never_type(p), 21 T![!] => never_type(p),
22 STAR => pointer_type(p), 22 T![*] => pointer_type(p),
23 L_BRACK => array_or_slice_type(p), 23 T!['['] => array_or_slice_type(p),
24 AMP => reference_type(p), 24 T![&] => reference_type(p),
25 UNDERSCORE => placeholder_type(p), 25 T![_] => placeholder_type(p),
26 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), 26 T![fn] | T![unsafe] | T![extern] => fn_pointer_type(p),
27 FOR_KW => for_type(p), 27 T![for] => for_type(p),
28 IMPL_KW => impl_trait_type(p), 28 T![impl ] => impl_trait_type(p),
29 DYN_KW => dyn_trait_type(p), 29 T![dyn ] => dyn_trait_type(p),
30 // Some path types are not allowed to have bounds (no plus) 30 // Some path types are not allowed to have bounds (no plus)
31 L_ANGLE => path_type_(p, allow_bounds), 31 T![<] => path_type_(p, allow_bounds),
32 _ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds), 32 _ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds),
33 _ => { 33 _ => {
34 p.err_recover("expected type", TYPE_RECOVERY_SET); 34 p.err_recover("expected type", TYPE_RECOVERY_SET);
@@ -37,27 +37,27 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
37} 37}
38 38
39pub(super) fn ascription(p: &mut Parser) { 39pub(super) fn ascription(p: &mut Parser) {
40 p.expect(COLON); 40 p.expect(T![:]);
41 type_(p) 41 type_(p)
42} 42}
43 43
44fn paren_or_tuple_type(p: &mut Parser) { 44fn paren_or_tuple_type(p: &mut Parser) {
45 assert!(p.at(L_PAREN)); 45 assert!(p.at(T!['(']));
46 let m = p.start(); 46 let m = p.start();
47 p.bump(); 47 p.bump();
48 let mut n_types: u32 = 0; 48 let mut n_types: u32 = 0;
49 let mut trailing_comma: bool = false; 49 let mut trailing_comma: bool = false;
50 while !p.at(EOF) && !p.at(R_PAREN) { 50 while !p.at(EOF) && !p.at(T![')']) {
51 n_types += 1; 51 n_types += 1;
52 type_(p); 52 type_(p);
53 if p.eat(COMMA) { 53 if p.eat(T![,]) {
54 trailing_comma = true; 54 trailing_comma = true;
55 } else { 55 } else {
56 trailing_comma = false; 56 trailing_comma = false;
57 break; 57 break;
58 } 58 }
59 } 59 }
60 p.expect(R_PAREN); 60 p.expect(T![')']);
61 61
62 let kind = if n_types == 1 && !trailing_comma { 62 let kind = if n_types == 1 && !trailing_comma {
63 // test paren_type 63 // test paren_type
@@ -77,14 +77,14 @@ fn paren_or_tuple_type(p: &mut Parser) {
77// test never_type 77// test never_type
78// type Never = !; 78// type Never = !;
79fn never_type(p: &mut Parser) { 79fn never_type(p: &mut Parser) {
80 assert!(p.at(EXCL)); 80 assert!(p.at(T![!]));
81 let m = p.start(); 81 let m = p.start();
82 p.bump(); 82 p.bump();
83 m.complete(p, NEVER_TYPE); 83 m.complete(p, NEVER_TYPE);
84} 84}
85 85
86fn pointer_type(p: &mut Parser) { 86fn pointer_type(p: &mut Parser) {
87 assert!(p.at(STAR)); 87 assert!(p.at(T![*]));
88 let m = p.start(); 88 let m = p.start();
89 p.bump(); 89 p.bump();
90 90
@@ -92,7 +92,7 @@ fn pointer_type(p: &mut Parser) {
92 // test pointer_type_mut 92 // test pointer_type_mut
93 // type M = *mut (); 93 // type M = *mut ();
94 // type C = *mut (); 94 // type C = *mut ();
95 MUT_KW | CONST_KW => p.bump(), 95 T![mut] | T![const] => p.bump(),
96 _ => { 96 _ => {
97 // test_err pointer_type_no_mutability 97 // test_err pointer_type_no_mutability
98 // type T = *(); 98 // type T = *();
@@ -108,7 +108,7 @@ fn pointer_type(p: &mut Parser) {
108} 108}
109 109
110fn array_or_slice_type(p: &mut Parser) { 110fn array_or_slice_type(p: &mut Parser) {
111 assert!(p.at(L_BRACK)); 111 assert!(p.at(T!['[']));
112 let m = p.start(); 112 let m = p.start();
113 p.bump(); 113 p.bump();
114 114
@@ -116,17 +116,17 @@ fn array_or_slice_type(p: &mut Parser) {
116 let kind = match p.current() { 116 let kind = match p.current() {
117 // test slice_type 117 // test slice_type
118 // type T = [()]; 118 // type T = [()];
119 R_BRACK => { 119 T![']'] => {
120 p.bump(); 120 p.bump();
121 SLICE_TYPE 121 SLICE_TYPE
122 } 122 }
123 123
124 // test array_type 124 // test array_type
125 // type T = [(); 92]; 125 // type T = [(); 92];
126 SEMI => { 126 T![;] => {
127 p.bump(); 127 p.bump();
128 expressions::expr(p); 128 expressions::expr(p);
129 p.expect(R_BRACK); 129 p.expect(T![']']);
130 ARRAY_TYPE 130 ARRAY_TYPE
131 } 131 }
132 // test_err array_type_missing_semi 132 // test_err array_type_missing_semi
@@ -144,11 +144,11 @@ fn array_or_slice_type(p: &mut Parser) {
144// type B = &'static (); 144// type B = &'static ();
145// type C = &mut (); 145// type C = &mut ();
146fn reference_type(p: &mut Parser) { 146fn reference_type(p: &mut Parser) {
147 assert!(p.at(AMP)); 147 assert!(p.at(T![&]));
148 let m = p.start(); 148 let m = p.start();
149 p.bump(); 149 p.bump();
150 p.eat(LIFETIME); 150 p.eat(LIFETIME);
151 p.eat(MUT_KW); 151 p.eat(T![mut]);
152 type_no_bounds(p); 152 type_no_bounds(p);
153 m.complete(p, REFERENCE_TYPE); 153 m.complete(p, REFERENCE_TYPE);
154} 154}
@@ -156,7 +156,7 @@ fn reference_type(p: &mut Parser) {
156// test placeholder_type 156// test placeholder_type
157// type Placeholder = _; 157// type Placeholder = _;
158fn placeholder_type(p: &mut Parser) { 158fn placeholder_type(p: &mut Parser) {
159 assert!(p.at(UNDERSCORE)); 159 assert!(p.at(T![_]));
160 let m = p.start(); 160 let m = p.start();
161 p.bump(); 161 p.bump();
162 m.complete(p, PLACEHOLDER_TYPE); 162 m.complete(p, PLACEHOLDER_TYPE);
@@ -169,18 +169,18 @@ fn placeholder_type(p: &mut Parser) {
169// type D = extern "C" fn ( u8 , ... ) -> u8; 169// type D = extern "C" fn ( u8 , ... ) -> u8;
170fn fn_pointer_type(p: &mut Parser) { 170fn fn_pointer_type(p: &mut Parser) {
171 let m = p.start(); 171 let m = p.start();
172 p.eat(UNSAFE_KW); 172 p.eat(T![unsafe]);
173 if p.at(EXTERN_KW) { 173 if p.at(T![extern]) {
174 abi(p); 174 abi(p);
175 } 175 }
176 // test_err fn_pointer_type_missing_fn 176 // test_err fn_pointer_type_missing_fn
177 // type F = unsafe (); 177 // type F = unsafe ();
178 if !p.eat(FN_KW) { 178 if !p.eat(T![fn]) {
179 m.abandon(p); 179 m.abandon(p);
180 p.error("expected `fn`"); 180 p.error("expected `fn`");
181 return; 181 return;
182 } 182 }
183 if p.at(L_PAREN) { 183 if p.at(T!['(']) {
184 params::param_list_opt_patterns(p); 184 params::param_list_opt_patterns(p);
185 } else { 185 } else {
186 p.error("expected parameters") 186 p.error("expected parameters")
@@ -192,9 +192,9 @@ fn fn_pointer_type(p: &mut Parser) {
192} 192}
193 193
194pub(super) fn for_binder(p: &mut Parser) { 194pub(super) fn for_binder(p: &mut Parser) {
195 assert!(p.at(FOR_KW)); 195 assert!(p.at(T![for]));
196 p.bump(); 196 p.bump();
197 if p.at(L_ANGLE) { 197 if p.at(T![<]) {
198 type_params::opt_type_param_list(p); 198 type_params::opt_type_param_list(p);
199 } else { 199 } else {
200 p.error("expected `<`"); 200 p.error("expected `<`");
@@ -206,12 +206,12 @@ pub(super) fn for_binder(p: &mut Parser) {
206// fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {} 206// fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {}
207// fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {} 207// fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {}
208pub(super) fn for_type(p: &mut Parser) { 208pub(super) fn for_type(p: &mut Parser) {
209 assert!(p.at(FOR_KW)); 209 assert!(p.at(T![for]));
210 let m = p.start(); 210 let m = p.start();
211 for_binder(p); 211 for_binder(p);
212 match p.current() { 212 match p.current() {
213 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), 213 T![fn] | T![unsafe] | T![extern] => fn_pointer_type(p),
214 AMP => reference_type(p), 214 T![&] => reference_type(p),
215 _ if paths::is_path_start(p) => path_type_(p, false), 215 _ if paths::is_path_start(p) => path_type_(p, false),
216 _ => p.error("expected a path"), 216 _ => p.error("expected a path"),
217 } 217 }
@@ -221,7 +221,7 @@ pub(super) fn for_type(p: &mut Parser) {
221// test impl_trait_type 221// test impl_trait_type
222// type A = impl Iterator<Item=Foo<'a>> + 'a; 222// type A = impl Iterator<Item=Foo<'a>> + 'a;
223fn impl_trait_type(p: &mut Parser) { 223fn impl_trait_type(p: &mut Parser) {
224 assert!(p.at(IMPL_KW)); 224 assert!(p.at(T![impl ]));
225 let m = p.start(); 225 let m = p.start();
226 p.bump(); 226 p.bump();
227 type_params::bounds_without_colon(p); 227 type_params::bounds_without_colon(p);
@@ -231,7 +231,7 @@ fn impl_trait_type(p: &mut Parser) {
231// test dyn_trait_type 231// test dyn_trait_type
232// type A = dyn Iterator<Item=Foo<'a>> + 'a; 232// type A = dyn Iterator<Item=Foo<'a>> + 'a;
233fn dyn_trait_type(p: &mut Parser) { 233fn dyn_trait_type(p: &mut Parser) {
234 assert!(p.at(DYN_KW)); 234 assert!(p.at(T![dyn ]));
235 let m = p.start(); 235 let m = p.start();
236 p.bump(); 236 p.bump();
237 type_params::bounds_without_colon(p); 237 type_params::bounds_without_colon(p);
@@ -251,11 +251,11 @@ pub(super) fn path_type(p: &mut Parser) {
251// type A = foo!(); 251// type A = foo!();
252// type B = crate::foo!(); 252// type B = crate::foo!();
253fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { 253fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
254 assert!(paths::is_path_start(p) || p.at(L_ANGLE)); 254 assert!(paths::is_path_start(p) || p.at(T![<]));
255 let m = p.start(); 255 let m = p.start();
256 paths::type_path(p); 256 paths::type_path(p);
257 257
258 let kind = if p.at(EXCL) { 258 let kind = if p.at(T![!]) {
259 items::macro_call_after_excl(p); 259 items::macro_call_after_excl(p);
260 MACRO_CALL 260 MACRO_CALL
261 } else { 261 } else {
@@ -270,7 +270,7 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
270} 270}
271 271
272pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { 272pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
273 assert!(paths::is_path_start(p) || p.at(L_ANGLE)); 273 assert!(paths::is_path_start(p) || p.at(T![<]));
274 let m = p.start(); 274 let m = p.start();
275 paths::type_path(p); 275 paths::type_path(p);
276 276
@@ -286,7 +286,7 @@ pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
286/// This turns a parsed PATH_TYPE optionally into a DYN_TRAIT_TYPE 286/// This turns a parsed PATH_TYPE optionally into a DYN_TRAIT_TYPE
287/// with a TYPE_BOUND_LIST 287/// with a TYPE_BOUND_LIST
288fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: CompletedMarker) { 288fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: CompletedMarker) {
289 if !p.at(PLUS) { 289 if !p.at(T![+]) {
290 return; 290 return;
291 } 291 }
292 292
@@ -298,7 +298,7 @@ fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: Comp
298 298
299 // This gets consumed here so it gets properly set 299 // This gets consumed here so it gets properly set
300 // in the TYPE_BOUND_LIST 300 // in the TYPE_BOUND_LIST
301 p.eat(PLUS); 301 p.eat(T![+]);
302 302
303 // Parse rest of the bounds into the TYPE_BOUND_LIST 303 // Parse rest of the bounds into the TYPE_BOUND_LIST
304 let m = type_params::bounds_without_colon_m(p, m); 304 let m = type_params::bounds_without_colon_m(p, m);