aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar/items/traits.rs5
-rw-r--r--crates/ra_parser/src/grammar/type_args.rs10
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs271
3 files changed, 149 insertions, 137 deletions
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs
index 2c560e824..964fd3041 100644
--- a/crates/ra_parser/src/grammar/items/traits.rs
+++ b/crates/ra_parser/src/grammar/items/traits.rs
@@ -100,6 +100,8 @@ pub(crate) fn impl_item_list(p: &mut Parser) {
100 m.complete(p, ITEM_LIST); 100 m.complete(p, ITEM_LIST);
101} 101}
102 102
103// test impl_type_params
104// impl<const N: u32> Bar<N> {}
103fn choose_type_params_over_qpath(p: &Parser) -> bool { 105fn choose_type_params_over_qpath(p: &Parser) -> bool {
104 // There's an ambiguity between generic parameters and qualified paths in impls. 106 // There's an ambiguity between generic parameters and qualified paths in impls.
105 // If we see `<` it may start both, so we have to inspect some following tokens. 107 // If we see `<` it may start both, so we have to inspect some following tokens.
@@ -107,6 +109,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
107 // but not qualified paths (with one exception): 109 // but not qualified paths (with one exception):
108 // `<` `>` - empty generic parameters 110 // `<` `>` - empty generic parameters
109 // `<` `#` - generic parameters with attributes 111 // `<` `#` - generic parameters with attributes
112 // `<` `const` - const generic parameters
110 // `<` (LIFETIME|IDENT) `>` - single generic parameter 113 // `<` (LIFETIME|IDENT) `>` - single generic parameter
111 // `<` (LIFETIME|IDENT) `,` - first generic parameter in a list 114 // `<` (LIFETIME|IDENT) `,` - first generic parameter in a list
112 // `<` (LIFETIME|IDENT) `:` - generic parameter with bounds 115 // `<` (LIFETIME|IDENT) `:` - generic parameter with bounds
@@ -119,7 +122,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
119 if !p.at(T![<]) { 122 if !p.at(T![<]) {
120 return false; 123 return false;
121 } 124 }
122 if p.nth(1) == T![#] || p.nth(1) == T![>] { 125 if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == CONST_KW {
123 return true; 126 return true;
124 } 127 }
125 (p.nth(1) == LIFETIME || p.nth(1) == IDENT) 128 (p.nth(1) == LIFETIME || p.nth(1) == IDENT)
diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs
index 7256c2697..33d9973e9 100644
--- a/crates/ra_parser/src/grammar/type_args.rs
+++ b/crates/ra_parser/src/grammar/type_args.rs
@@ -26,7 +26,7 @@ pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
26} 26}
27 27
28// test type_arg 28// test type_arg
29// type A = B<'static, i32, Item=u64>; 29// type A = B<'static, i32, 1, { 2 }, Item=u64>;
30fn type_arg(p: &mut Parser) { 30fn type_arg(p: &mut Parser) {
31 let m = p.start(); 31 let m = p.start();
32 match p.current() { 32 match p.current() {
@@ -47,6 +47,14 @@ fn type_arg(p: &mut Parser) {
47 types::type_(p); 47 types::type_(p);
48 m.complete(p, ASSOC_TYPE_ARG); 48 m.complete(p, ASSOC_TYPE_ARG);
49 } 49 }
50 T!['{'] => {
51 expressions::block(p);
52 m.complete(p, CONST_ARG);
53 }
54 k if k.is_literal() => {
55 p.bump(k);
56 m.complete(p, CONST_ARG);
57 }
50 _ => { 58 _ => {
51 types::type_(p); 59 types::type_(p);
52 m.complete(p, TYPE_ARG); 60 m.complete(p, TYPE_ARG);
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs
index af2945f57..4b301d67a 100644
--- a/crates/ra_parser/src/syntax_kind/generated.rs
+++ b/crates/ra_parser/src/syntax_kind/generated.rs
@@ -61,46 +61,46 @@ pub enum SyntaxKind {
61 SHR, 61 SHR,
62 SHLEQ, 62 SHLEQ,
63 SHREQ, 63 SHREQ,
64 AS_KW,
64 ASYNC_KW, 65 ASYNC_KW,
65 USE_KW, 66 AWAIT_KW,
66 FN_KW, 67 BOX_KW,
67 STRUCT_KW, 68 BREAK_KW,
68 ENUM_KW, 69 CONST_KW,
69 TRAIT_KW, 70 CONTINUE_KW,
70 IMPL_KW, 71 CRATE_KW,
71 DYN_KW, 72 DYN_KW,
72 TRUE_KW, 73 ELSE_KW,
73 FALSE_KW, 74 ENUM_KW,
74 AS_KW,
75 EXTERN_KW, 75 EXTERN_KW,
76 CRATE_KW, 76 FALSE_KW,
77 MOD_KW, 77 FN_KW,
78 PUB_KW,
79 SELF_KW,
80 SUPER_KW,
81 IN_KW,
82 WHERE_KW,
83 FOR_KW, 78 FOR_KW,
84 LOOP_KW,
85 WHILE_KW,
86 CONTINUE_KW,
87 BREAK_KW,
88 IF_KW, 79 IF_KW,
89 ELSE_KW, 80 IMPL_KW,
81 IN_KW,
82 LET_KW,
83 LOOP_KW,
84 MACRO_KW,
90 MATCH_KW, 85 MATCH_KW,
91 CONST_KW, 86 MOD_KW,
92 STATIC_KW, 87 MOVE_KW,
93 MUT_KW, 88 MUT_KW,
94 UNSAFE_KW, 89 PUB_KW,
95 TYPE_KW,
96 REF_KW, 90 REF_KW,
97 LET_KW,
98 MOVE_KW,
99 RETURN_KW, 91 RETURN_KW,
92 SELF_KW,
93 STATIC_KW,
94 STRUCT_KW,
95 SUPER_KW,
96 TRAIT_KW,
97 TRUE_KW,
100 TRY_KW, 98 TRY_KW,
101 BOX_KW, 99 TYPE_KW,
102 AWAIT_KW, 100 UNSAFE_KW,
103 MACRO_KW, 101 USE_KW,
102 WHERE_KW,
103 WHILE_KW,
104 AUTO_KW, 104 AUTO_KW,
105 DEFAULT_KW, 105 DEFAULT_KW,
106 EXISTENTIAL_KW, 106 EXISTENTIAL_KW,
@@ -234,6 +234,7 @@ pub enum SyntaxKind {
234 LIFETIME_ARG, 234 LIFETIME_ARG,
235 TYPE_ARG, 235 TYPE_ARG,
236 ASSOC_TYPE_ARG, 236 ASSOC_TYPE_ARG,
237 CONST_ARG,
237 PARAM_LIST, 238 PARAM_LIST,
238 PARAM, 239 PARAM,
239 SELF_PARAM, 240 SELF_PARAM,
@@ -249,12 +250,12 @@ use self::SyntaxKind::*;
249impl SyntaxKind { 250impl SyntaxKind {
250 pub fn is_keyword(self) -> bool { 251 pub fn is_keyword(self) -> bool {
251 match self { 252 match self {
252 ASYNC_KW | USE_KW | FN_KW | STRUCT_KW | ENUM_KW | TRAIT_KW | IMPL_KW | DYN_KW 253 AS_KW | ASYNC_KW | AWAIT_KW | BOX_KW | BREAK_KW | CONST_KW | CONTINUE_KW | CRATE_KW
253 | TRUE_KW | FALSE_KW | AS_KW | EXTERN_KW | CRATE_KW | MOD_KW | PUB_KW | SELF_KW 254 | DYN_KW | ELSE_KW | ENUM_KW | EXTERN_KW | FALSE_KW | FN_KW | FOR_KW | IF_KW
254 | SUPER_KW | IN_KW | WHERE_KW | FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW 255 | IMPL_KW | IN_KW | LET_KW | LOOP_KW | MACRO_KW | MATCH_KW | MOD_KW | MOVE_KW
255 | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW | CONST_KW | STATIC_KW | MUT_KW | UNSAFE_KW 256 | MUT_KW | PUB_KW | REF_KW | RETURN_KW | SELF_KW | STATIC_KW | STRUCT_KW | SUPER_KW
256 | TYPE_KW | REF_KW | LET_KW | MOVE_KW | RETURN_KW | TRY_KW | BOX_KW | AWAIT_KW 257 | TRAIT_KW | TRUE_KW | TRY_KW | TYPE_KW | UNSAFE_KW | USE_KW | WHERE_KW | WHILE_KW
257 | MACRO_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW => true, 258 | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW => true,
258 _ => false, 259 _ => false,
259 } 260 }
260 } 261 }
@@ -278,46 +279,46 @@ impl SyntaxKind {
278 } 279 }
279 pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { 280 pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
280 let kw = match ident { 281 let kw = match ident {
282 "as" => AS_KW,
281 "async" => ASYNC_KW, 283 "async" => ASYNC_KW,
282 "use" => USE_KW, 284 "await" => AWAIT_KW,
283 "fn" => FN_KW, 285 "box" => BOX_KW,
284 "struct" => STRUCT_KW, 286 "break" => BREAK_KW,
285 "enum" => ENUM_KW, 287 "const" => CONST_KW,
286 "trait" => TRAIT_KW, 288 "continue" => CONTINUE_KW,
287 "impl" => IMPL_KW, 289 "crate" => CRATE_KW,
288 "dyn" => DYN_KW, 290 "dyn" => DYN_KW,
289 "true" => TRUE_KW, 291 "else" => ELSE_KW,
290 "false" => FALSE_KW, 292 "enum" => ENUM_KW,
291 "as" => AS_KW,
292 "extern" => EXTERN_KW, 293 "extern" => EXTERN_KW,
293 "crate" => CRATE_KW, 294 "false" => FALSE_KW,
294 "mod" => MOD_KW, 295 "fn" => FN_KW,
295 "pub" => PUB_KW,
296 "self" => SELF_KW,
297 "super" => SUPER_KW,
298 "in" => IN_KW,
299 "where" => WHERE_KW,
300 "for" => FOR_KW, 296 "for" => FOR_KW,
301 "loop" => LOOP_KW,
302 "while" => WHILE_KW,
303 "continue" => CONTINUE_KW,
304 "break" => BREAK_KW,
305 "if" => IF_KW, 297 "if" => IF_KW,
306 "else" => ELSE_KW, 298 "impl" => IMPL_KW,
299 "in" => IN_KW,
300 "let" => LET_KW,
301 "loop" => LOOP_KW,
302 "macro" => MACRO_KW,
307 "match" => MATCH_KW, 303 "match" => MATCH_KW,
308 "const" => CONST_KW, 304 "mod" => MOD_KW,
309 "static" => STATIC_KW, 305 "move" => MOVE_KW,
310 "mut" => MUT_KW, 306 "mut" => MUT_KW,
311 "unsafe" => UNSAFE_KW, 307 "pub" => PUB_KW,
312 "type" => TYPE_KW,
313 "ref" => REF_KW, 308 "ref" => REF_KW,
314 "let" => LET_KW,
315 "move" => MOVE_KW,
316 "return" => RETURN_KW, 309 "return" => RETURN_KW,
310 "self" => SELF_KW,
311 "static" => STATIC_KW,
312 "struct" => STRUCT_KW,
313 "super" => SUPER_KW,
314 "trait" => TRAIT_KW,
315 "true" => TRUE_KW,
317 "try" => TRY_KW, 316 "try" => TRY_KW,
318 "box" => BOX_KW, 317 "type" => TYPE_KW,
319 "await" => AWAIT_KW, 318 "unsafe" => UNSAFE_KW,
320 "macro" => MACRO_KW, 319 "use" => USE_KW,
320 "where" => WHERE_KW,
321 "while" => WHILE_KW,
321 _ => return None, 322 _ => return None,
322 }; 323 };
323 Some(kw) 324 Some(kw)
@@ -515,125 +516,125 @@ macro_rules! T {
515 ( >>= ) => { 516 ( >>= ) => {
516 $crate::SyntaxKind::SHREQ 517 $crate::SyntaxKind::SHREQ
517 }; 518 };
519 ( as ) => {
520 $crate::SyntaxKind::AS_KW
521 };
518 ( async ) => { 522 ( async ) => {
519 $crate::SyntaxKind::ASYNC_KW 523 $crate::SyntaxKind::ASYNC_KW
520 }; 524 };
521 ( use ) => { 525 ( await ) => {
522 $crate::SyntaxKind::USE_KW 526 $crate::SyntaxKind::AWAIT_KW
523 }; 527 };
524 ( fn ) => { 528 ( box ) => {
525 $crate::SyntaxKind::FN_KW 529 $crate::SyntaxKind::BOX_KW
526 }; 530 };
527 ( struct ) => { 531 ( break ) => {
528 $crate::SyntaxKind::STRUCT_KW 532 $crate::SyntaxKind::BREAK_KW
529 }; 533 };
530 ( enum ) => { 534 ( const ) => {
531 $crate::SyntaxKind::ENUM_KW 535 $crate::SyntaxKind::CONST_KW
532 }; 536 };
533 ( trait ) => { 537 ( continue ) => {
534 $crate::SyntaxKind::TRAIT_KW 538 $crate::SyntaxKind::CONTINUE_KW
535 }; 539 };
536 ( impl ) => { 540 ( crate ) => {
537 $crate::SyntaxKind::IMPL_KW 541 $crate::SyntaxKind::CRATE_KW
538 }; 542 };
539 ( dyn ) => { 543 ( dyn ) => {
540 $crate::SyntaxKind::DYN_KW 544 $crate::SyntaxKind::DYN_KW
541 }; 545 };
542 ( true ) => { 546 ( else ) => {
543 $crate::SyntaxKind::TRUE_KW 547 $crate::SyntaxKind::ELSE_KW
544 };
545 ( false ) => {
546 $crate::SyntaxKind::FALSE_KW
547 }; 548 };
548 ( as ) => { 549 ( enum ) => {
549 $crate::SyntaxKind::AS_KW 550 $crate::SyntaxKind::ENUM_KW
550 }; 551 };
551 ( extern ) => { 552 ( extern ) => {
552 $crate::SyntaxKind::EXTERN_KW 553 $crate::SyntaxKind::EXTERN_KW
553 }; 554 };
554 ( crate ) => { 555 ( false ) => {
555 $crate::SyntaxKind::CRATE_KW 556 $crate::SyntaxKind::FALSE_KW
556 }; 557 };
557 ( mod ) => { 558 ( fn ) => {
558 $crate::SyntaxKind::MOD_KW 559 $crate::SyntaxKind::FN_KW
559 }; 560 };
560 ( pub ) => { 561 ( for ) => {
561 $crate::SyntaxKind::PUB_KW 562 $crate::SyntaxKind::FOR_KW
562 }; 563 };
563 ( self ) => { 564 ( if ) => {
564 $crate::SyntaxKind::SELF_KW 565 $crate::SyntaxKind::IF_KW
565 }; 566 };
566 ( super ) => { 567 ( impl ) => {
567 $crate::SyntaxKind::SUPER_KW 568 $crate::SyntaxKind::IMPL_KW
568 }; 569 };
569 ( in ) => { 570 ( in ) => {
570 $crate::SyntaxKind::IN_KW 571 $crate::SyntaxKind::IN_KW
571 }; 572 };
572 ( where ) => { 573 ( let ) => {
573 $crate::SyntaxKind::WHERE_KW 574 $crate::SyntaxKind::LET_KW
574 };
575 ( for ) => {
576 $crate::SyntaxKind::FOR_KW
577 }; 575 };
578 ( loop ) => { 576 ( loop ) => {
579 $crate::SyntaxKind::LOOP_KW 577 $crate::SyntaxKind::LOOP_KW
580 }; 578 };
581 ( while ) => { 579 ( macro ) => {
582 $crate::SyntaxKind::WHILE_KW 580 $crate::SyntaxKind::MACRO_KW
583 };
584 ( continue ) => {
585 $crate::SyntaxKind::CONTINUE_KW
586 };
587 ( break ) => {
588 $crate::SyntaxKind::BREAK_KW
589 };
590 ( if ) => {
591 $crate::SyntaxKind::IF_KW
592 };
593 ( else ) => {
594 $crate::SyntaxKind::ELSE_KW
595 }; 581 };
596 ( match ) => { 582 ( match ) => {
597 $crate::SyntaxKind::MATCH_KW 583 $crate::SyntaxKind::MATCH_KW
598 }; 584 };
599 ( const ) => { 585 ( mod ) => {
600 $crate::SyntaxKind::CONST_KW 586 $crate::SyntaxKind::MOD_KW
601 }; 587 };
602 ( static ) => { 588 ( move ) => {
603 $crate::SyntaxKind::STATIC_KW 589 $crate::SyntaxKind::MOVE_KW
604 }; 590 };
605 ( mut ) => { 591 ( mut ) => {
606 $crate::SyntaxKind::MUT_KW 592 $crate::SyntaxKind::MUT_KW
607 }; 593 };
608 ( unsafe ) => { 594 ( pub ) => {
609 $crate::SyntaxKind::UNSAFE_KW 595 $crate::SyntaxKind::PUB_KW
610 };
611 ( type ) => {
612 $crate::SyntaxKind::TYPE_KW
613 }; 596 };
614 ( ref ) => { 597 ( ref ) => {
615 $crate::SyntaxKind::REF_KW 598 $crate::SyntaxKind::REF_KW
616 }; 599 };
617 ( let ) => {
618 $crate::SyntaxKind::LET_KW
619 };
620 ( move ) => {
621 $crate::SyntaxKind::MOVE_KW
622 };
623 ( return ) => { 600 ( return ) => {
624 $crate::SyntaxKind::RETURN_KW 601 $crate::SyntaxKind::RETURN_KW
625 }; 602 };
603 ( self ) => {
604 $crate::SyntaxKind::SELF_KW
605 };
606 ( static ) => {
607 $crate::SyntaxKind::STATIC_KW
608 };
609 ( struct ) => {
610 $crate::SyntaxKind::STRUCT_KW
611 };
612 ( super ) => {
613 $crate::SyntaxKind::SUPER_KW
614 };
615 ( trait ) => {
616 $crate::SyntaxKind::TRAIT_KW
617 };
618 ( true ) => {
619 $crate::SyntaxKind::TRUE_KW
620 };
626 ( try ) => { 621 ( try ) => {
627 $crate::SyntaxKind::TRY_KW 622 $crate::SyntaxKind::TRY_KW
628 }; 623 };
629 ( box ) => { 624 ( type ) => {
630 $crate::SyntaxKind::BOX_KW 625 $crate::SyntaxKind::TYPE_KW
631 }; 626 };
632 ( await ) => { 627 ( unsafe ) => {
633 $crate::SyntaxKind::AWAIT_KW 628 $crate::SyntaxKind::UNSAFE_KW
634 }; 629 };
635 ( macro ) => { 630 ( use ) => {
636 $crate::SyntaxKind::MACRO_KW 631 $crate::SyntaxKind::USE_KW
632 };
633 ( where ) => {
634 $crate::SyntaxKind::WHERE_KW
635 };
636 ( while ) => {
637 $crate::SyntaxKind::WHILE_KW
637 }; 638 };
638 ( auto ) => { 639 ( auto ) => {
639 $crate::SyntaxKind::AUTO_KW 640 $crate::SyntaxKind::AUTO_KW