diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-16 17:08:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-16 17:08:03 +0000 |
commit | 067067a6c11bb5afda98f5af14bfdec4744e7812 (patch) | |
tree | 1c0b6c4c78ee040ebdf818dada804fce311382a6 /crates/parser/src/grammar | |
parent | 63bbdb31e5148c804bbf940963c9c8f3481ad258 (diff) | |
parent | dd496223f50232fe98312ee8edc89eb4b5ee3d85 (diff) |
Merge #6896
6896: Node-ify lifetimes r=jonas-schievink a=Veykril
Let's see if this passes the tests 🤞
Depends on https://github.com/rust-analyzer/ungrammar/pull/15
Co-authored-by: Jonas Schievink <[email protected]>
Co-authored-by: Jonas Schievink <[email protected]>
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/parser/src/grammar')
-rw-r--r-- | crates/parser/src/grammar/expressions/atom.rs | 16 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/traits.rs | 10 | ||||
-rw-r--r-- | crates/parser/src/grammar/params.rs | 13 | ||||
-rw-r--r-- | crates/parser/src/grammar/type_args.rs | 4 | ||||
-rw-r--r-- | crates/parser/src/grammar/type_params.rs | 18 | ||||
-rw-r--r-- | crates/parser/src/grammar/types.rs | 4 |
6 files changed, 38 insertions, 27 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 31f42f161..18b63feb7 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs | |||
@@ -48,7 +48,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = | |||
48 | T![try], | 48 | T![try], |
49 | T![loop], | 49 | T![loop], |
50 | T![for], | 50 | T![for], |
51 | LIFETIME, | 51 | LIFETIME_IDENT, |
52 | ])); | 52 | ])); |
53 | 53 | ||
54 | const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[LET_KW, R_DOLLAR]); | 54 | const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[LET_KW, R_DOLLAR]); |
@@ -75,7 +75,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
75 | T![for] => for_expr(p, None), | 75 | T![for] => for_expr(p, None), |
76 | T![while] => while_expr(p, None), | 76 | T![while] => while_expr(p, None), |
77 | T![try] => try_block_expr(p, None), | 77 | T![try] => try_block_expr(p, None), |
78 | LIFETIME if la == T![:] => { | 78 | LIFETIME_IDENT 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() { |
@@ -275,9 +275,9 @@ fn if_expr(p: &mut Parser) -> CompletedMarker { | |||
275 | // 'c: for x in () {} | 275 | // 'c: for x in () {} |
276 | // } | 276 | // } |
277 | fn label(p: &mut Parser) { | 277 | fn label(p: &mut Parser) { |
278 | assert!(p.at(LIFETIME) && p.nth(1) == T![:]); | 278 | assert!(p.at(LIFETIME_IDENT) && p.nth(1) == T![:]); |
279 | let m = p.start(); | 279 | let m = p.start(); |
280 | p.bump(LIFETIME); | 280 | lifetime(p); |
281 | p.bump_any(); | 281 | p.bump_any(); |
282 | m.complete(p, LABEL); | 282 | m.complete(p, LABEL); |
283 | } | 283 | } |
@@ -501,7 +501,9 @@ fn continue_expr(p: &mut Parser) -> CompletedMarker { | |||
501 | assert!(p.at(T![continue])); | 501 | assert!(p.at(T![continue])); |
502 | let m = p.start(); | 502 | let m = p.start(); |
503 | p.bump(T![continue]); | 503 | p.bump(T![continue]); |
504 | p.eat(LIFETIME); | 504 | if p.at(LIFETIME_IDENT) { |
505 | lifetime(p); | ||
506 | } | ||
505 | m.complete(p, CONTINUE_EXPR) | 507 | m.complete(p, CONTINUE_EXPR) |
506 | } | 508 | } |
507 | 509 | ||
@@ -518,7 +520,9 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { | |||
518 | assert!(p.at(T![break])); | 520 | assert!(p.at(T![break])); |
519 | let m = p.start(); | 521 | let m = p.start(); |
520 | p.bump(T![break]); | 522 | p.bump(T![break]); |
521 | p.eat(LIFETIME); | 523 | if p.at(LIFETIME_IDENT) { |
524 | lifetime(p); | ||
525 | } | ||
522 | // test break_ambiguity | 526 | // test break_ambiguity |
523 | // fn foo(){ | 527 | // fn foo(){ |
524 | // if break {} | 528 | // if break {} |
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index 8394020da..ab9a12b4d 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs | |||
@@ -98,10 +98,10 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { | |||
98 | // `<` `>` - empty generic parameters | 98 | // `<` `>` - empty generic parameters |
99 | // `<` `#` - generic parameters with attributes | 99 | // `<` `#` - generic parameters with attributes |
100 | // `<` `const` - const generic parameters | 100 | // `<` `const` - const generic parameters |
101 | // `<` (LIFETIME|IDENT) `>` - single generic parameter | 101 | // `<` (LIFETIME_IDENT|IDENT) `>` - single generic parameter |
102 | // `<` (LIFETIME|IDENT) `,` - first generic parameter in a list | 102 | // `<` (LIFETIME_IDENT|IDENT) `,` - first generic parameter in a list |
103 | // `<` (LIFETIME|IDENT) `:` - generic parameter with bounds | 103 | // `<` (LIFETIME_IDENT|IDENT) `:` - generic parameter with bounds |
104 | // `<` (LIFETIME|IDENT) `=` - generic parameter with a default | 104 | // `<` (LIFETIME_IDENT|IDENT) `=` - generic parameter with a default |
105 | // The only truly ambiguous case is | 105 | // The only truly ambiguous case is |
106 | // `<` IDENT `>` `::` IDENT ... | 106 | // `<` IDENT `>` `::` IDENT ... |
107 | // we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`) | 107 | // we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`) |
@@ -113,7 +113,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { | |||
113 | if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == CONST_KW { | 113 | if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == CONST_KW { |
114 | return true; | 114 | return true; |
115 | } | 115 | } |
116 | (p.nth(1) == LIFETIME || p.nth(1) == IDENT) | 116 | (p.nth(1) == LIFETIME_IDENT || p.nth(1) == IDENT) |
117 | && (p.nth(2) == T![>] || p.nth(2) == T![,] || p.nth(2) == T![:] || p.nth(2) == T![=]) | 117 | && (p.nth(2) == T![>] || p.nth(2) == T![,] || p.nth(2) == T![:] || p.nth(2) == T![=]) |
118 | } | 118 | } |
119 | 119 | ||
diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs index a665ffc13..3ee4e4fca 100644 --- a/crates/parser/src/grammar/params.rs +++ b/crates/parser/src/grammar/params.rs | |||
@@ -169,15 +169,20 @@ fn opt_self_param(p: &mut Parser) { | |||
169 | let la1 = p.nth(1); | 169 | let la1 = p.nth(1); |
170 | let la2 = p.nth(2); | 170 | let la2 = p.nth(2); |
171 | let la3 = p.nth(3); | 171 | let la3 = p.nth(3); |
172 | let n_toks = match (p.current(), la1, la2, la3) { | 172 | let mut n_toks = match (p.current(), la1, la2, la3) { |
173 | (T![&], T![self], _, _) => 2, | 173 | (T![&], T![self], _, _) => 2, |
174 | (T![&], T![mut], T![self], _) => 3, | 174 | (T![&], T![mut], T![self], _) => 3, |
175 | (T![&], LIFETIME, T![self], _) => 3, | 175 | (T![&], LIFETIME_IDENT, T![self], _) => 3, |
176 | (T![&], LIFETIME, T![mut], T![self]) => 4, | 176 | (T![&], LIFETIME_IDENT, T![mut], T![self]) => 4, |
177 | _ => return, | 177 | _ => return, |
178 | }; | 178 | }; |
179 | m = p.start(); | 179 | m = p.start(); |
180 | for _ in 0..n_toks { | 180 | p.bump_any(); |
181 | if p.at(LIFETIME_IDENT) { | ||
182 | lifetime(p); | ||
183 | n_toks -= 1; | ||
184 | } | ||
185 | for _ in 1..n_toks { | ||
181 | p.bump_any(); | 186 | p.bump_any(); |
182 | } | 187 | } |
183 | } | 188 | } |
diff --git a/crates/parser/src/grammar/type_args.rs b/crates/parser/src/grammar/type_args.rs index f2d34a749..a013c49b9 100644 --- a/crates/parser/src/grammar/type_args.rs +++ b/crates/parser/src/grammar/type_args.rs | |||
@@ -30,8 +30,8 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) { | |||
30 | fn generic_arg(p: &mut Parser) { | 30 | fn generic_arg(p: &mut Parser) { |
31 | let m = p.start(); | 31 | let m = p.start(); |
32 | match p.current() { | 32 | match p.current() { |
33 | LIFETIME => { | 33 | LIFETIME_IDENT => { |
34 | p.bump(LIFETIME); | 34 | lifetime(p); |
35 | m.complete(p, LIFETIME_ARG); | 35 | m.complete(p, LIFETIME_ARG); |
36 | } | 36 | } |
37 | // test associated_type_bounds | 37 | // test associated_type_bounds |
diff --git a/crates/parser/src/grammar/type_params.rs b/crates/parser/src/grammar/type_params.rs index bc7d8d724..9c3f7c28a 100644 --- a/crates/parser/src/grammar/type_params.rs +++ b/crates/parser/src/grammar/type_params.rs | |||
@@ -23,7 +23,7 @@ fn generic_param_list(p: &mut Parser) { | |||
23 | attributes::outer_attrs(p); | 23 | attributes::outer_attrs(p); |
24 | 24 | ||
25 | match p.current() { | 25 | match p.current() { |
26 | LIFETIME => lifetime_param(p, m), | 26 | LIFETIME_IDENT => lifetime_param(p, m), |
27 | IDENT => type_param(p, m), | 27 | IDENT => type_param(p, m), |
28 | CONST_KW => const_param(p, m), | 28 | CONST_KW => const_param(p, m), |
29 | _ => { | 29 | _ => { |
@@ -40,8 +40,8 @@ fn generic_param_list(p: &mut Parser) { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | fn lifetime_param(p: &mut Parser, m: Marker) { | 42 | fn lifetime_param(p: &mut Parser, m: Marker) { |
43 | assert!(p.at(LIFETIME)); | 43 | assert!(p.at(LIFETIME_IDENT)); |
44 | p.bump(LIFETIME); | 44 | lifetime(p); |
45 | if p.at(T![:]) { | 45 | if p.at(T![:]) { |
46 | lifetime_bounds(p); | 46 | lifetime_bounds(p); |
47 | } | 47 | } |
@@ -84,8 +84,8 @@ pub(super) fn bounds(p: &mut Parser) { | |||
84 | fn lifetime_bounds(p: &mut Parser) { | 84 | fn lifetime_bounds(p: &mut Parser) { |
85 | assert!(p.at(T![:])); | 85 | assert!(p.at(T![:])); |
86 | p.bump(T![:]); | 86 | p.bump(T![:]); |
87 | while p.at(LIFETIME) { | 87 | while p.at(LIFETIME_IDENT) { |
88 | p.bump(LIFETIME); | 88 | lifetime(p); |
89 | if !p.eat(T![+]) { | 89 | if !p.eat(T![+]) { |
90 | break; | 90 | break; |
91 | } | 91 | } |
@@ -112,7 +112,7 @@ fn type_bound(p: &mut Parser) -> bool { | |||
112 | let has_paren = p.eat(T!['(']); | 112 | let has_paren = p.eat(T!['(']); |
113 | p.eat(T![?]); | 113 | p.eat(T![?]); |
114 | match p.current() { | 114 | match p.current() { |
115 | LIFETIME => p.bump(LIFETIME), | 115 | LIFETIME_IDENT => lifetime(p), |
116 | T![for] => types::for_type(p), | 116 | T![for] => types::for_type(p), |
117 | _ if paths::is_use_path_start(p) => types::path_type_(p, false), | 117 | _ if paths::is_use_path_start(p) => types::path_type_(p, false), |
118 | _ => { | 118 | _ => { |
@@ -162,7 +162,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) { | |||
162 | 162 | ||
163 | fn is_where_predicate(p: &mut Parser) -> bool { | 163 | fn is_where_predicate(p: &mut Parser) -> bool { |
164 | match p.current() { | 164 | match p.current() { |
165 | LIFETIME => true, | 165 | LIFETIME_IDENT => true, |
166 | T![impl] => false, | 166 | T![impl] => false, |
167 | token => types::TYPE_FIRST.contains(token), | 167 | token => types::TYPE_FIRST.contains(token), |
168 | } | 168 | } |
@@ -175,8 +175,8 @@ fn is_where_clause_end(p: &mut Parser) -> bool { | |||
175 | fn where_predicate(p: &mut Parser) { | 175 | fn where_predicate(p: &mut Parser) { |
176 | let m = p.start(); | 176 | let m = p.start(); |
177 | match p.current() { | 177 | match p.current() { |
178 | LIFETIME => { | 178 | LIFETIME_IDENT => { |
179 | p.bump(LIFETIME); | 179 | lifetime(p); |
180 | if p.at(T![:]) { | 180 | if p.at(T![:]) { |
181 | bounds(p); | 181 | bounds(p); |
182 | } else { | 182 | } else { |
diff --git a/crates/parser/src/grammar/types.rs b/crates/parser/src/grammar/types.rs index 1ea130ac5..36a15eace 100644 --- a/crates/parser/src/grammar/types.rs +++ b/crates/parser/src/grammar/types.rs | |||
@@ -167,7 +167,9 @@ fn ref_type(p: &mut Parser) { | |||
167 | assert!(p.at(T![&])); | 167 | assert!(p.at(T![&])); |
168 | let m = p.start(); | 168 | let m = p.start(); |
169 | p.bump(T![&]); | 169 | p.bump(T![&]); |
170 | p.eat(LIFETIME); | 170 | if p.at(LIFETIME_IDENT) { |
171 | lifetime(p); | ||
172 | } | ||
171 | p.eat(T![mut]); | 173 | p.eat(T![mut]); |
172 | type_no_bounds(p); | 174 | type_no_bounds(p); |
173 | m.complete(p, REF_TYPE); | 175 | m.complete(p, REF_TYPE); |