diff options
Diffstat (limited to 'crates/parser/src/grammar')
-rw-r--r-- | crates/parser/src/grammar/expressions/atom.rs | 28 | ||||
-rw-r--r-- | crates/parser/src/grammar/items.rs | 28 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/traits.rs | 2 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/use_item.rs | 2 | ||||
-rw-r--r-- | crates/parser/src/grammar/params.rs | 31 | ||||
-rw-r--r-- | crates/parser/src/grammar/paths.rs | 6 | ||||
-rw-r--r-- | crates/parser/src/grammar/patterns.rs | 2 | ||||
-rw-r--r-- | crates/parser/src/grammar/type_args.rs | 6 | ||||
-rw-r--r-- | crates/parser/src/grammar/type_params.rs | 4 |
9 files changed, 74 insertions, 35 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index c7a3556a7..093a9890d 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs | |||
@@ -15,8 +15,16 @@ use super::*; | |||
15 | // let _ = b"e"; | 15 | // let _ = b"e"; |
16 | // let _ = br"f"; | 16 | // let _ = br"f"; |
17 | // } | 17 | // } |
18 | pub(crate) const LITERAL_FIRST: TokenSet = | 18 | pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[ |
19 | TokenSet::new(&[TRUE_KW, FALSE_KW, INT_NUMBER, FLOAT_NUMBER, BYTE, CHAR, STRING, BYTE_STRING]); | 19 | T![true], |
20 | T![false], | ||
21 | INT_NUMBER, | ||
22 | FLOAT_NUMBER, | ||
23 | BYTE, | ||
24 | CHAR, | ||
25 | STRING, | ||
26 | BYTE_STRING, | ||
27 | ]); | ||
20 | 28 | ||
21 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { | 29 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { |
22 | if !p.at_ts(LITERAL_FIRST) { | 30 | if !p.at_ts(LITERAL_FIRST) { |
@@ -42,6 +50,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = | |||
42 | T![match], | 50 | T![match], |
43 | T![unsafe], | 51 | T![unsafe], |
44 | T![return], | 52 | T![return], |
53 | T![yield], | ||
45 | T![break], | 54 | T![break], |
46 | T![continue], | 55 | T![continue], |
47 | T![async], | 56 | T![async], |
@@ -134,6 +143,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
134 | block_expr_unchecked(p) | 143 | block_expr_unchecked(p) |
135 | } | 144 | } |
136 | T![return] => return_expr(p), | 145 | T![return] => return_expr(p), |
146 | T![yield] => yield_expr(p), | ||
137 | T![continue] => continue_expr(p), | 147 | T![continue] => continue_expr(p), |
138 | T![break] => break_expr(p, r), | 148 | T![break] => break_expr(p, r), |
139 | _ => { | 149 | _ => { |
@@ -500,6 +510,20 @@ fn return_expr(p: &mut Parser) -> CompletedMarker { | |||
500 | } | 510 | } |
501 | m.complete(p, RETURN_EXPR) | 511 | m.complete(p, RETURN_EXPR) |
502 | } | 512 | } |
513 | // test yield_expr | ||
514 | // fn foo() { | ||
515 | // yield; | ||
516 | // yield 1; | ||
517 | // } | ||
518 | fn yield_expr(p: &mut Parser) -> CompletedMarker { | ||
519 | assert!(p.at(T![yield])); | ||
520 | let m = p.start(); | ||
521 | p.bump(T![yield]); | ||
522 | if p.at_ts(EXPR_FIRST) { | ||
523 | expr(p); | ||
524 | } | ||
525 | m.complete(p, YIELD_EXPR) | ||
526 | } | ||
503 | 527 | ||
504 | // test continue_expr | 528 | // test continue_expr |
505 | // fn foo() { | 529 | // fn foo() { |
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index cf4168d32..1d894e907 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs | |||
@@ -27,19 +27,19 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { | |||
27 | } | 27 | } |
28 | 28 | ||
29 | pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[ | 29 | pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[ |
30 | FN_KW, | 30 | T![fn], |
31 | STRUCT_KW, | 31 | T![struct], |
32 | ENUM_KW, | 32 | T![enum], |
33 | IMPL_KW, | 33 | T![impl], |
34 | TRAIT_KW, | 34 | T![trait], |
35 | CONST_KW, | 35 | T![const], |
36 | STATIC_KW, | 36 | T![static], |
37 | LET_KW, | 37 | T![let], |
38 | MOD_KW, | 38 | T![mod], |
39 | PUB_KW, | 39 | T![pub], |
40 | CRATE_KW, | 40 | T![crate], |
41 | USE_KW, | 41 | T![use], |
42 | MACRO_KW, | 42 | T![macro], |
43 | T![;], | 43 | T![;], |
44 | ]); | 44 | ]); |
45 | 45 | ||
@@ -270,7 +270,9 @@ fn extern_crate(p: &mut Parser, m: Marker) { | |||
270 | p.bump(T![crate]); | 270 | p.bump(T![crate]); |
271 | 271 | ||
272 | if p.at(T![self]) { | 272 | if p.at(T![self]) { |
273 | let m = p.start(); | ||
273 | p.bump(T![self]); | 274 | p.bump(T![self]); |
275 | m.complete(p, NAME_REF); | ||
274 | } else { | 276 | } else { |
275 | name_ref(p); | 277 | name_ref(p); |
276 | } | 278 | } |
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index ab9a12b4d..d076974ed 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs | |||
@@ -110,7 +110,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { | |||
110 | if !p.at(T![<]) { | 110 | if !p.at(T![<]) { |
111 | return false; | 111 | return false; |
112 | } | 112 | } |
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) == T![const] { |
114 | return true; | 114 | return true; |
115 | } | 115 | } |
116 | (p.nth(1) == LIFETIME_IDENT || p.nth(1) == IDENT) | 116 | (p.nth(1) == LIFETIME_IDENT || p.nth(1) == IDENT) |
diff --git a/crates/parser/src/grammar/items/use_item.rs b/crates/parser/src/grammar/items/use_item.rs index 20e6a13cf..5cb8b08e7 100644 --- a/crates/parser/src/grammar/items/use_item.rs +++ b/crates/parser/src/grammar/items/use_item.rs | |||
@@ -46,7 +46,7 @@ fn use_tree(p: &mut Parser, top_level: bool) { | |||
46 | // test use_tree_list | 46 | // test use_tree_list |
47 | // use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`) | 47 | // use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`) |
48 | // use {path::from::root}; // Rust 2015 | 48 | // use {path::from::root}; // Rust 2015 |
49 | // use ::{some::arbritrary::path}; // Rust 2015 | 49 | // use ::{some::arbitrary::path}; // Rust 2015 |
50 | // use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting | 50 | // use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting |
51 | T!['{'] => { | 51 | T!['{'] => { |
52 | use_tree_list(p); | 52 | use_tree_list(p); |
diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs index 2d006a1d5..6a98d7368 100644 --- a/crates/parser/src/grammar/params.rs +++ b/crates/parser/src/grammar/params.rs | |||
@@ -156,7 +156,7 @@ fn variadic_param(p: &mut Parser) -> bool { | |||
156 | fn opt_self_param(p: &mut Parser, m: Marker) { | 156 | fn opt_self_param(p: &mut Parser, m: Marker) { |
157 | if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { | 157 | if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { |
158 | p.eat(T![mut]); | 158 | p.eat(T![mut]); |
159 | p.eat(T![self]); | 159 | self_as_name(p); |
160 | // test arb_self_types | 160 | // test arb_self_types |
161 | // impl S { | 161 | // impl S { |
162 | // fn a(self: &Self) {} | 162 | // fn a(self: &Self) {} |
@@ -169,24 +169,29 @@ fn opt_self_param(p: &mut Parser, m: Marker) { | |||
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 mut n_toks = match (p.current(), la1, la2, la3) { | 172 | if !matches!((p.current(), la1, la2, la3), |
173 | (T![&], T![self], _, _) => 2, | 173 | (T![&], T![self], _, _) |
174 | (T![&], T![mut], T![self], _) => 3, | 174 | | (T![&], T![mut], T![self], _) |
175 | (T![&], LIFETIME_IDENT, T![self], _) => 3, | 175 | | (T![&], LIFETIME_IDENT, T![self], _) |
176 | (T![&], LIFETIME_IDENT, T![mut], T![self]) => 4, | 176 | | (T![&], LIFETIME_IDENT, T![mut], T![self]) |
177 | _ => return m.abandon(p), | 177 | ) { |
178 | }; | 178 | return m.abandon(p); |
179 | p.bump_any(); | 179 | } |
180 | p.bump(T![&]); | ||
180 | if p.at(LIFETIME_IDENT) { | 181 | if p.at(LIFETIME_IDENT) { |
181 | lifetime(p); | 182 | lifetime(p); |
182 | n_toks -= 1; | ||
183 | } | ||
184 | for _ in 1..n_toks { | ||
185 | p.bump_any(); | ||
186 | } | 183 | } |
184 | p.eat(T![mut]); | ||
185 | self_as_name(p); | ||
187 | } | 186 | } |
188 | m.complete(p, SELF_PARAM); | 187 | m.complete(p, SELF_PARAM); |
189 | if !p.at(T![')']) { | 188 | if !p.at(T![')']) { |
190 | p.expect(T![,]); | 189 | p.expect(T![,]); |
191 | } | 190 | } |
192 | } | 191 | } |
192 | |||
193 | fn self_as_name(p: &mut Parser) { | ||
194 | let m = p.start(); | ||
195 | p.bump(T![self]); | ||
196 | m.complete(p, NAME); | ||
197 | } | ||
diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs index 5d297e2d6..b10f48fe1 100644 --- a/crates/parser/src/grammar/paths.rs +++ b/crates/parser/src/grammar/paths.rs | |||
@@ -82,7 +82,11 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { | |||
82 | } | 82 | } |
83 | // test crate_path | 83 | // test crate_path |
84 | // use crate::foo; | 84 | // use crate::foo; |
85 | T![self] | T![super] | T![crate] => p.bump_any(), | 85 | T![self] | T![super] | T![crate] => { |
86 | let m = p.start(); | ||
87 | p.bump_any(); | ||
88 | m.complete(p, NAME_REF); | ||
89 | } | ||
86 | _ => { | 90 | _ => { |
87 | p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); | 91 | p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); |
88 | if empty { | 92 | if empty { |
diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index b53d5749f..da71498a8 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs | |||
@@ -83,7 +83,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) { | |||
83 | } | 83 | } |
84 | 84 | ||
85 | const PAT_RECOVERY_SET: TokenSet = | 85 | const PAT_RECOVERY_SET: TokenSet = |
86 | TokenSet::new(&[LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]); | 86 | TokenSet::new(&[T![let], T![if], T![while], T![loop], T![match], T![')'], T![,]]); |
87 | 87 | ||
88 | fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { | 88 | fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { |
89 | let m = match p.nth(0) { | 89 | let m = match p.nth(0) { |
diff --git a/crates/parser/src/grammar/type_args.rs b/crates/parser/src/grammar/type_args.rs index a013c49b9..42cd426bd 100644 --- a/crates/parser/src/grammar/type_args.rs +++ b/crates/parser/src/grammar/type_args.rs | |||
@@ -26,7 +26,7 @@ pub(super) fn opt_generic_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, 1, { 2 }, Item=u64>; | 29 | // type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>; |
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() { |
@@ -55,6 +55,10 @@ fn generic_arg(p: &mut Parser) { | |||
55 | expressions::literal(p); | 55 | expressions::literal(p); |
56 | m.complete(p, CONST_ARG); | 56 | m.complete(p, CONST_ARG); |
57 | } | 57 | } |
58 | T![true] | T![false] => { | ||
59 | expressions::literal(p); | ||
60 | m.complete(p, CONST_ARG); | ||
61 | } | ||
58 | _ => { | 62 | _ => { |
59 | types::type_(p); | 63 | types::type_(p); |
60 | m.complete(p, TYPE_ARG); | 64 | m.complete(p, TYPE_ARG); |
diff --git a/crates/parser/src/grammar/type_params.rs b/crates/parser/src/grammar/type_params.rs index 4aeccd193..3de5248da 100644 --- a/crates/parser/src/grammar/type_params.rs +++ b/crates/parser/src/grammar/type_params.rs | |||
@@ -25,7 +25,7 @@ fn generic_param_list(p: &mut Parser) { | |||
25 | match p.current() { | 25 | match p.current() { |
26 | LIFETIME_IDENT => 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 | T![const] => const_param(p, m), |
29 | _ => { | 29 | _ => { |
30 | m.abandon(p); | 30 | m.abandon(p); |
31 | p.err_and_bump("expected type parameter") | 31 | p.err_and_bump("expected type parameter") |
@@ -66,7 +66,7 @@ fn type_param(p: &mut Parser, m: Marker) { | |||
66 | // test const_param | 66 | // test const_param |
67 | // struct S<const N: u32>; | 67 | // struct S<const N: u32>; |
68 | fn const_param(p: &mut Parser, m: Marker) { | 68 | fn const_param(p: &mut Parser, m: Marker) { |
69 | assert!(p.at(CONST_KW)); | 69 | assert!(p.at(T![const])); |
70 | p.bump(T![const]); | 70 | p.bump(T![const]); |
71 | name(p); | 71 | name(p); |
72 | types::ascription(p); | 72 | types::ascription(p); |