aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src
diff options
context:
space:
mode:
authorMichael Chesser <[email protected]>2020-01-06 22:59:03 +0000
committerMichael Chesser <[email protected]>2020-01-06 22:59:03 +0000
commitce1b34fd59a6145a4bb5682d672c846e101725d4 (patch)
tree8a9535261dac04f171caa68d4b908cdde0b4a34c /crates/ra_parser/src
parentc92a090f49cad2fa540562536f07fcb619f16680 (diff)
Improve const generics parsing
- Handle const generics type args - Fix issue with const generic as first parameter in trait impl
Diffstat (limited to 'crates/ra_parser/src')
-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.rs1
3 files changed, 14 insertions, 2 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 262c545e4..4b301d67a 100644
--- a/crates/ra_parser/src/syntax_kind/generated.rs
+++ b/crates/ra_parser/src/syntax_kind/generated.rs
@@ -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,