diff options
-rw-r--r-- | crates/ra_parser/src/grammar/type_params.rs | 11 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 30 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 5 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.txt | 23 |
6 files changed, 71 insertions, 0 deletions
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index 34406b5bd..50e4900c3 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs | |||
@@ -25,6 +25,7 @@ fn type_param_list(p: &mut Parser) { | |||
25 | match p.current() { | 25 | match p.current() { |
26 | LIFETIME => lifetime_param(p, m), | 26 | LIFETIME => lifetime_param(p, m), |
27 | IDENT => type_param(p, m), | 27 | IDENT => type_param(p, m), |
28 | CONST_KW => type_const_param(p, m), | ||
28 | _ => { | 29 | _ => { |
29 | m.abandon(p); | 30 | m.abandon(p); |
30 | p.err_and_bump("expected type parameter") | 31 | p.err_and_bump("expected type parameter") |
@@ -62,6 +63,16 @@ fn type_param(p: &mut Parser, m: Marker) { | |||
62 | m.complete(p, TYPE_PARAM); | 63 | m.complete(p, TYPE_PARAM); |
63 | } | 64 | } |
64 | 65 | ||
66 | // test const_param | ||
67 | // struct S<const N: u32>; | ||
68 | fn type_const_param(p: &mut Parser, m: Marker) { | ||
69 | assert!(p.at(CONST_KW)); | ||
70 | p.bump(T![const]); | ||
71 | name(p); | ||
72 | types::ascription(p); | ||
73 | m.complete(p, CONST_PARAM); | ||
74 | } | ||
75 | |||
65 | // test type_param_bounds | 76 | // test type_param_bounds |
66 | // struct S<T: 'a + ?Sized + (Copy)>; | 77 | // struct S<T: 'a + ?Sized + (Copy)>; |
67 | pub(super) fn bounds(p: &mut Parser) { | 78 | pub(super) fn bounds(p: &mut Parser) { |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index fe0fcdb33..bee1f1134 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -227,6 +227,7 @@ pub enum SyntaxKind { | |||
227 | TYPE_PARAM_LIST, | 227 | TYPE_PARAM_LIST, |
228 | LIFETIME_PARAM, | 228 | LIFETIME_PARAM, |
229 | TYPE_PARAM, | 229 | TYPE_PARAM, |
230 | CONST_PARAM, | ||
230 | TYPE_ARG_LIST, | 231 | TYPE_ARG_LIST, |
231 | LIFETIME_ARG, | 232 | LIFETIME_ARG, |
232 | TYPE_ARG, | 233 | TYPE_ARG, |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 9dd6bd3ea..b917f77fe 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -551,6 +551,36 @@ impl ConstDef { | |||
551 | } | 551 | } |
552 | } | 552 | } |
553 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 553 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
554 | pub struct ConstParam { | ||
555 | pub(crate) syntax: SyntaxNode, | ||
556 | } | ||
557 | impl AstNode for ConstParam { | ||
558 | fn can_cast(kind: SyntaxKind) -> bool { | ||
559 | match kind { | ||
560 | CONST_PARAM => true, | ||
561 | _ => false, | ||
562 | } | ||
563 | } | ||
564 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
565 | if Self::can_cast(syntax.kind()) { | ||
566 | Some(Self { syntax }) | ||
567 | } else { | ||
568 | None | ||
569 | } | ||
570 | } | ||
571 | fn syntax(&self) -> &SyntaxNode { | ||
572 | &self.syntax | ||
573 | } | ||
574 | } | ||
575 | impl ast::NameOwner for ConstParam {} | ||
576 | impl ast::AttrsOwner for ConstParam {} | ||
577 | impl ast::TypeAscriptionOwner for ConstParam {} | ||
578 | impl ConstParam { | ||
579 | pub fn default_val(&self) -> Option<Expr> { | ||
580 | AstChildren::new(&self.syntax).next() | ||
581 | } | ||
582 | } | ||
583 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
554 | pub struct ContinueExpr { | 584 | pub struct ContinueExpr { |
555 | pub(crate) syntax: SyntaxNode, | 585 | pub(crate) syntax: SyntaxNode, |
556 | } | 586 | } |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 9ffa9095b..d6802b6fb 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -243,6 +243,7 @@ Grammar( | |||
243 | "TYPE_PARAM_LIST", | 243 | "TYPE_PARAM_LIST", |
244 | "LIFETIME_PARAM", | 244 | "LIFETIME_PARAM", |
245 | "TYPE_PARAM", | 245 | "TYPE_PARAM", |
246 | "CONST_PARAM", | ||
246 | "TYPE_ARG_LIST", | 247 | "TYPE_ARG_LIST", |
247 | "LIFETIME_ARG", | 248 | "LIFETIME_ARG", |
248 | "TYPE_ARG", | 249 | "TYPE_ARG", |
@@ -602,6 +603,10 @@ Grammar( | |||
602 | options: [("default_type", "TypeRef")], | 603 | options: [("default_type", "TypeRef")], |
603 | traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"], | 604 | traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"], |
604 | ), | 605 | ), |
606 | "ConstParam": ( | ||
607 | options: [("default_val", "Expr")], | ||
608 | traits: ["NameOwner", "AttrsOwner", "TypeAscriptionOwner"], | ||
609 | ), | ||
605 | "LifetimeParam": ( | 610 | "LifetimeParam": ( |
606 | traits: ["AttrsOwner"], | 611 | traits: ["AttrsOwner"], |
607 | ), | 612 | ), |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs new file mode 100644 index 000000000..8cdb3b703 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs | |||
@@ -0,0 +1 @@ | |||
struct S<const N: u32>; | |||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.txt b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.txt new file mode 100644 index 000000000..f81de7bac --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.txt | |||
@@ -0,0 +1,23 @@ | |||
1 | SOURCE_FILE@[0; 24) | ||
2 | STRUCT_DEF@[0; 23) | ||
3 | STRUCT_KW@[0; 6) "struct" | ||
4 | WHITESPACE@[6; 7) " " | ||
5 | NAME@[7; 8) | ||
6 | IDENT@[7; 8) "S" | ||
7 | TYPE_PARAM_LIST@[8; 22) | ||
8 | L_ANGLE@[8; 9) "<" | ||
9 | CONST_PARAM@[9; 21) | ||
10 | CONST_KW@[9; 14) "const" | ||
11 | WHITESPACE@[14; 15) " " | ||
12 | NAME@[15; 16) | ||
13 | IDENT@[15; 16) "N" | ||
14 | COLON@[16; 17) ":" | ||
15 | WHITESPACE@[17; 18) " " | ||
16 | PATH_TYPE@[18; 21) | ||
17 | PATH@[18; 21) | ||
18 | PATH_SEGMENT@[18; 21) | ||
19 | NAME_REF@[18; 21) | ||
20 | IDENT@[18; 21) "u32" | ||
21 | R_ANGLE@[21; 22) ">" | ||
22 | SEMI@[22; 23) ";" | ||
23 | WHITESPACE@[23; 24) "\n" | ||