aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/grammar')
-rw-r--r--crates/ra_syntax/src/grammar/expressions/atom.rs58
-rw-r--r--crates/ra_syntax/src/grammar/expressions/mod.rs53
-rw-r--r--crates/ra_syntax/src/grammar/items/mod.rs45
-rw-r--r--crates/ra_syntax/src/grammar/items/traits.rs1
-rw-r--r--crates/ra_syntax/src/grammar/mod.rs31
-rw-r--r--crates/ra_syntax/src/grammar/params.rs13
-rw-r--r--crates/ra_syntax/src/grammar/paths.rs2
-rw-r--r--crates/ra_syntax/src/grammar/patterns.rs22
-rw-r--r--crates/ra_syntax/src/grammar/type_params.rs11
-rw-r--r--crates/ra_syntax/src/grammar/types.rs18
10 files changed, 137 insertions, 117 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs
index e21de68c5..11f766d33 100644
--- a/crates/ra_syntax/src/grammar/expressions/atom.rs
+++ b/crates/ra_syntax/src/grammar/expressions/atom.rs
@@ -13,9 +13,18 @@ use super::*;
13// let _ = b"e"; 13// let _ = b"e";
14// let _ = br"f"; 14// let _ = br"f";
15// } 15// }
16pub(crate) const LITERAL_FIRST: TokenSet = 16pub(crate) const LITERAL_FIRST: TokenSet = token_set![
17 token_set![TRUE_KW, FALSE_KW, INT_NUMBER, FLOAT_NUMBER, BYTE, CHAR, 17 TRUE_KW,
18 STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; 18 FALSE_KW,
19 INT_NUMBER,
20 FLOAT_NUMBER,
21 BYTE,
22 CHAR,
23 STRING,
24 RAW_STRING,
25 BYTE_STRING,
26 RAW_BYTE_STRING
27];
19 28
20pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { 29pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
21 if !p.at_ts(LITERAL_FIRST) { 30 if !p.at_ts(LITERAL_FIRST) {
@@ -26,15 +35,31 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
26 Some(m.complete(p, LITERAL)) 35 Some(m.complete(p, LITERAL))
27} 36}
28 37
29pub(super) const ATOM_EXPR_FIRST: TokenSet = 38pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![
30 token_set_union![ 39 LITERAL_FIRST,
31 LITERAL_FIRST, 40 token_set![
32 token_set![L_CURLY, L_PAREN, L_BRACK, PIPE, MOVE_KW, IF_KW, WHILE_KW, MATCH_KW, UNSAFE_KW, 41 L_CURLY,
33 RETURN_KW, IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, BREAK_KW, CONTINUE_KW, LIFETIME ], 42 L_PAREN,
34 ]; 43 L_BRACK,
44 PIPE,
45 MOVE_KW,
46 IF_KW,
47 WHILE_KW,
48 MATCH_KW,
49 UNSAFE_KW,
50 RETURN_KW,
51 IDENT,
52 SELF_KW,
53 SUPER_KW,
54 CRATE_KW,
55 COLONCOLON,
56 BREAK_KW,
57 CONTINUE_KW,
58 LIFETIME
59 ],
60];
35 61
36const EXPR_RECOVERY_SET: TokenSet = 62const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
37 token_set![LET_KW];
38 63
39pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { 64pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
40 match literal(p) { 65 match literal(p) {
@@ -80,7 +105,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
80 let m = p.start(); 105 let m = p.start();
81 p.bump(); 106 p.bump();
82 block_expr(p, Some(m)) 107 block_expr(p, Some(m))
83 }, 108 }
84 L_CURLY => block_expr(p, None), 109 L_CURLY => block_expr(p, None),
85 RETURN_KW => return_expr(p), 110 RETURN_KW => return_expr(p),
86 CONTINUE_KW => continue_expr(p), 111 CONTINUE_KW => continue_expr(p),
@@ -119,7 +144,14 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
119 } 144 }
120 } 145 }
121 p.expect(R_PAREN); 146 p.expect(R_PAREN);
122 m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR }) 147 m.complete(
148 p,
149 if saw_expr && !saw_comma {
150 PAREN_EXPR
151 } else {
152 TUPLE_EXPR
153 },
154 )
123} 155}
124 156
125// test array_expr 157// test array_expr
diff --git a/crates/ra_syntax/src/grammar/expressions/mod.rs b/crates/ra_syntax/src/grammar/expressions/mod.rs
index 20e0fa328..60c8602f9 100644
--- a/crates/ra_syntax/src/grammar/expressions/mod.rs
+++ b/crates/ra_syntax/src/grammar/expressions/mod.rs
@@ -1,23 +1,32 @@
1mod atom; 1mod atom;
2 2
3use super::*;
4pub(super) use self::atom::{literal, LITERAL_FIRST};
5pub(crate) use self::atom::match_arm_list; 3pub(crate) use self::atom::match_arm_list;
4pub(super) use self::atom::{literal, LITERAL_FIRST};
5use super::*;
6 6
7const EXPR_FIRST: TokenSet = LHS_FIRST; 7const EXPR_FIRST: TokenSet = LHS_FIRST;
8 8
9pub(super) fn expr(p: &mut Parser) -> BlockLike { 9pub(super) fn expr(p: &mut Parser) -> BlockLike {
10 let r = Restrictions { forbid_structs: false, prefer_stmt: false }; 10 let r = Restrictions {
11 forbid_structs: false,
12 prefer_stmt: false,
13 };
11 expr_bp(p, r, 1) 14 expr_bp(p, r, 1)
12} 15}
13 16
14pub(super) fn expr_stmt(p: &mut Parser) -> BlockLike { 17pub(super) fn expr_stmt(p: &mut Parser) -> BlockLike {
15 let r = Restrictions { forbid_structs: false, prefer_stmt: true }; 18 let r = Restrictions {
19 forbid_structs: false,
20 prefer_stmt: true,
21 };
16 expr_bp(p, r, 1) 22 expr_bp(p, r, 1)
17} 23}
18 24
19fn expr_no_struct(p: &mut Parser) { 25fn expr_no_struct(p: &mut Parser) {
20 let r = Restrictions { forbid_structs: true, prefer_stmt: false }; 26 let r = Restrictions {
27 forbid_structs: true,
28 prefer_stmt: false,
29 };
21 expr_bp(p, r, 1); 30 expr_bp(p, r, 1);
22} 31}
23 32
@@ -107,10 +116,8 @@ enum Op {
107fn current_op(p: &Parser) -> (u8, Op) { 116fn current_op(p: &Parser) -> (u8, Op) {
108 if let Some(t) = p.next3() { 117 if let Some(t) = p.next3() {
109 match t { 118 match t {
110 (L_ANGLE, L_ANGLE, EQ) => 119 (L_ANGLE, L_ANGLE, EQ) => return (1, Op::Composite(SHLEQ, 3)),
111 return (1, Op::Composite(SHLEQ, 3)), 120 (R_ANGLE, R_ANGLE, EQ) => return (1, Op::Composite(SHREQ, 3)),
112 (R_ANGLE, R_ANGLE, EQ) =>
113 return (1, Op::Composite(SHREQ, 3)),
114 _ => (), 121 _ => (),
115 } 122 }
116 } 123 }
@@ -201,11 +208,10 @@ fn is_block(kind: SyntaxKind) -> bool {
201 } 208 }
202} 209}
203 210
204const LHS_FIRST: TokenSet = 211const LHS_FIRST: TokenSet = token_set_union![
205 token_set_union![ 212 token_set![AMP, STAR, EXCL, DOTDOT, MINUS],
206 token_set![AMP, STAR, EXCL, DOTDOT, MINUS], 213 atom::ATOM_EXPR_FIRST,
207 atom::ATOM_EXPR_FIRST, 214];
208 ];
209 215
210fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { 216fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
211 let m; 217 let m;
@@ -265,11 +271,13 @@ fn postfix_expr(p: &mut Parser, r: Restrictions, mut lhs: CompletedMarker) -> Co
265 // } 271 // }
266 L_PAREN if allow_calls => call_expr(p, lhs), 272 L_PAREN if allow_calls => call_expr(p, lhs),
267 L_BRACK if allow_calls => index_expr(p, lhs), 273 L_BRACK if allow_calls => index_expr(p, lhs),
268 DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { 274 DOT if p.nth(1) == IDENT => {
269 method_call_expr(p, lhs) 275 if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON {
270 } else { 276 method_call_expr(p, lhs)
271 field_expr(p, lhs) 277 } else {
272 }, 278 field_expr(p, lhs)
279 }
280 }
273 DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs), 281 DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs),
274 // test postfix_range 282 // test postfix_range
275 // fn foo() { let x = 1..; } 283 // fn foo() { let x = 1..; }
@@ -318,10 +326,7 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
318// y.bar::<T>(1, 2,); 326// y.bar::<T>(1, 2,);
319// } 327// }
320fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 328fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
321 assert!( 329 assert!(p.at(DOT) && p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON));
322 p.at(DOT) && p.nth(1) == IDENT
323 && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON)
324 );
325 let m = lhs.precede(p); 330 let m = lhs.precede(p);
326 p.bump(); 331 p.bump();
327 name_ref(p); 332 name_ref(p);
@@ -410,7 +415,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
410 items::macro_call_after_excl(p); 415 items::macro_call_after_excl(p);
411 m.complete(p, MACRO_CALL) 416 m.complete(p, MACRO_CALL)
412 } 417 }
413 _ => m.complete(p, PATH_EXPR) 418 _ => m.complete(p, PATH_EXPR),
414 } 419 }
415} 420}
416 421
diff --git a/crates/ra_syntax/src/grammar/items/mod.rs b/crates/ra_syntax/src/grammar/items/mod.rs
index 2567313ab..dc4742bce 100644
--- a/crates/ra_syntax/src/grammar/items/mod.rs
+++ b/crates/ra_syntax/src/grammar/items/mod.rs
@@ -1,16 +1,15 @@
1
2mod consts; 1mod consts;
3mod nominal; 2mod nominal;
4mod traits; 3mod traits;
5mod use_item; 4mod use_item;
6 5
7use super::*;
8pub(crate) use self::{ 6pub(crate) use self::{
9 expressions::{named_field_list, match_arm_list}, 7 expressions::{match_arm_list, named_field_list},
10 nominal::{enum_variant_list, named_field_def_list}, 8 nominal::{enum_variant_list, named_field_def_list},
11 traits::{trait_item_list, impl_item_list}, 9 traits::{impl_item_list, trait_item_list},
12 use_item::use_tree_list, 10 use_item::use_tree_list,
13}; 11};
12use super::*;
14 13
15// test mod_contents 14// test mod_contents
16// fn foo() {} 15// fn foo() {}
@@ -26,12 +25,14 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
26} 25}
27 26
28pub(super) enum ItemFlavor { 27pub(super) enum ItemFlavor {
29 Mod, Trait 28 Mod,
29 Trait,
30} 30}
31 31
32const ITEM_RECOVERY_SET: TokenSet = 32const ITEM_RECOVERY_SET: TokenSet = token_set![
33 token_set![FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, 33 FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW,
34 MOD_KW, PUB_KW, CRATE_KW]; 34 CRATE_KW
35];
35 36
36pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { 37pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) {
37 let m = p.start(); 38 let m = p.start();
@@ -153,10 +154,12 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
153 traits::impl_item(p); 154 traits::impl_item(p);
154 IMPL_ITEM 155 IMPL_ITEM
155 } 156 }
156 _ => return if has_mods { 157 _ => {
157 MaybeItem::Modifiers 158 return if has_mods {
158 } else { 159 MaybeItem::Modifiers
159 MaybeItem::None 160 } else {
161 MaybeItem::None
162 }
160 } 163 }
161 }; 164 };
162 165
@@ -194,7 +197,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
194 if p.at(SEMI) { 197 if p.at(SEMI) {
195 p.err_and_bump( 198 p.err_and_bump(
196 "expected item, found `;`\n\ 199 "expected item, found `;`\n\
197 consider removing this semicolon" 200 consider removing this semicolon",
198 ); 201 );
199 } 202 }
200 STRUCT_DEF 203 STRUCT_DEF
@@ -227,7 +230,9 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
227 } 230 }
228 // test extern_block 231 // test extern_block
229 // extern {} 232 // extern {}
230 EXTERN_KW if la == L_CURLY || ((la == STRING || la == RAW_STRING) && p.nth(2) == L_CURLY) => { 233 EXTERN_KW
234 if la == L_CURLY || ((la == STRING || la == RAW_STRING) && p.nth(2) == L_CURLY) =>
235 {
231 abi(p); 236 abi(p);
232 extern_item_list(p); 237 extern_item_list(p);
233 EXTERN_BLOCK 238 EXTERN_BLOCK
@@ -267,10 +272,8 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
267 272
268 if p.at(L_PAREN) { 273 if p.at(L_PAREN) {
269 match flavor { 274 match flavor {
270 ItemFlavor::Mod => 275 ItemFlavor::Mod => params::param_list(p),
271 params::param_list(p), 276 ItemFlavor::Trait => params::param_list_opt_patterns(p),
272 ItemFlavor::Trait =>
273 params::param_list_opt_patterns(p),
274 } 277 }
275 } else { 278 } else {
276 p.error("expected function arguments"); 279 p.error("expected function arguments");
@@ -361,7 +364,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
361 _ => { 364 _ => {
362 p.error("expected `{`, `[`, `(`"); 365 p.error("expected `{`, `[`, `(`");
363 BlockLike::NotBlock 366 BlockLike::NotBlock
364 }, 367 }
365 }; 368 };
366 369
367 flavor 370 flavor
@@ -385,9 +388,9 @@ pub(crate) fn token_tree(p: &mut Parser) {
385 return; 388 return;
386 } 389 }
387 R_PAREN | R_BRACK => p.err_and_bump("unmatched brace"), 390 R_PAREN | R_BRACK => p.err_and_bump("unmatched brace"),
388 _ => p.bump() 391 _ => p.bump(),
389 } 392 }
390 }; 393 }
391 p.expect(closing_paren_kind); 394 p.expect(closing_paren_kind);
392 m.complete(p, TOKEN_TREE); 395 m.complete(p, TOKEN_TREE);
393} 396}
diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs
index 5dfdb470c..31258c253 100644
--- a/crates/ra_syntax/src/grammar/items/traits.rs
+++ b/crates/ra_syntax/src/grammar/items/traits.rs
@@ -128,4 +128,3 @@ pub(crate) fn impl_type(p: &mut Parser) {
128 } 128 }
129 types::type_(p); 129 types::type_(p);
130} 130}
131
diff --git a/crates/ra_syntax/src/grammar/mod.rs b/crates/ra_syntax/src/grammar/mod.rs
index 1199ba230..c87564073 100644
--- a/crates/ra_syntax/src/grammar/mod.rs
+++ b/crates/ra_syntax/src/grammar/mod.rs
@@ -31,28 +31,18 @@ mod type_args;
31mod type_params; 31mod type_params;
32mod types; 32mod types;
33 33
34use crate::{
35 token_set::TokenSet,
36 parser_api::{Marker, CompletedMarker, Parser},
37 SyntaxKind::{self, *},
38};
39pub(crate) use self::{ 34pub(crate) use self::{
40 expressions::{ 35 expressions::block,
41 block,
42 },
43 items::{ 36 items::{
44 enum_variant_list, 37 enum_variant_list, extern_item_list, impl_item_list, match_arm_list, mod_item_list,
45 extern_item_list, 38 named_field_def_list, named_field_list, token_tree, trait_item_list, use_tree_list,
46 impl_item_list,
47 match_arm_list,
48 mod_item_list,
49 named_field_def_list,
50 named_field_list,
51 token_tree,
52 trait_item_list,
53 use_tree_list,
54 }, 39 },
55}; 40};
41use crate::{
42 parser_api::{CompletedMarker, Marker, Parser},
43 token_set::TokenSet,
44 SyntaxKind::{self, *},
45};
56 46
57pub(crate) fn root(p: &mut Parser) { 47pub(crate) fn root(p: &mut Parser) {
58 let m = p.start(); 48 let m = p.start();
@@ -61,7 +51,6 @@ pub(crate) fn root(p: &mut Parser) {
61 m.complete(p, ROOT); 51 m.complete(p, ROOT);
62} 52}
63 53
64
65#[derive(Clone, Copy, PartialEq, Eq)] 54#[derive(Clone, Copy, PartialEq, Eq)]
66enum BlockLike { 55enum BlockLike {
67 Block, 56 Block,
@@ -69,7 +58,9 @@ enum BlockLike {
69} 58}
70 59
71impl BlockLike { 60impl BlockLike {
72 fn is_block(self) -> bool { self == BlockLike::Block } 61 fn is_block(self) -> bool {
62 self == BlockLike::Block
63 }
73} 64}
74 65
75fn opt_visibility(p: &mut Parser) { 66fn opt_visibility(p: &mut Parser) {
diff --git a/crates/ra_syntax/src/grammar/params.rs b/crates/ra_syntax/src/grammar/params.rs
index 903c25939..b71a72ca3 100644
--- a/crates/ra_syntax/src/grammar/params.rs
+++ b/crates/ra_syntax/src/grammar/params.rs
@@ -61,12 +61,8 @@ fn list_(p: &mut Parser, flavor: Flavor) {
61 m.complete(p, PARAM_LIST); 61 m.complete(p, PARAM_LIST);
62} 62}
63 63
64
65const VALUE_PARAMETER_FIRST: TokenSet = 64const VALUE_PARAMETER_FIRST: TokenSet =
66 token_set_union![ 65 token_set_union![patterns::PATTERN_FIRST, types::TYPE_FIRST,];
67 patterns::PATTERN_FIRST,
68 types::TYPE_FIRST,
69 ];
70 66
71fn value_parameter(p: &mut Parser, flavor: Flavor) { 67fn value_parameter(p: &mut Parser, flavor: Flavor) {
72 let m = p.start(); 68 let m = p.start();
@@ -76,7 +72,7 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
76 if p.at(COLON) || flavor.type_required() { 72 if p.at(COLON) || flavor.type_required() {
77 types::ascription(p) 73 types::ascription(p)
78 } 74 }
79 }, 75 }
80 // test value_parameters_no_patterns 76 // test value_parameters_no_patterns
81 // type F = Box<Fn(a: i32, &b: &i32, &mut c: &i32, ())>; 77 // type F = Box<Fn(a: i32, &b: &i32, &mut c: &i32, ())>;
82 Flavor::OptionalPattern => { 78 Flavor::OptionalPattern => {
@@ -86,13 +82,14 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
86 let la3 = p.nth(3); 82 let la3 = p.nth(3);
87 if la0 == IDENT && la1 == COLON 83 if la0 == IDENT && la1 == COLON
88 || la0 == AMP && la1 == IDENT && la2 == COLON 84 || la0 == AMP && la1 == IDENT && la2 == COLON
89 || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON { 85 || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON
86 {
90 patterns::pattern(p); 87 patterns::pattern(p);
91 types::ascription(p); 88 types::ascription(p);
92 } else { 89 } else {
93 types::type_(p); 90 types::type_(p);
94 } 91 }
95 }, 92 }
96 } 93 }
97 m.complete(p, PARAM); 94 m.complete(p, PARAM);
98} 95}
diff --git a/crates/ra_syntax/src/grammar/paths.rs b/crates/ra_syntax/src/grammar/paths.rs
index b6d44d53a..a35a339cc 100644
--- a/crates/ra_syntax/src/grammar/paths.rs
+++ b/crates/ra_syntax/src/grammar/paths.rs
@@ -97,7 +97,7 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) {
97 } else { 97 } else {
98 type_args::opt_type_arg_list(p, false) 98 type_args::opt_type_arg_list(p, false)
99 } 99 }
100 }, 100 }
101 Mode::Expr => type_args::opt_type_arg_list(p, true), 101 Mode::Expr => type_args::opt_type_arg_list(p, true),
102 } 102 }
103} 103}
diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs
index 420bae7a7..9d35dbb3d 100644
--- a/crates/ra_syntax/src/grammar/patterns.rs
+++ b/crates/ra_syntax/src/grammar/patterns.rs
@@ -1,11 +1,10 @@
1use super::*; 1use super::*;
2 2
3pub(super) const PATTERN_FIRST: TokenSet = 3pub(super) const PATTERN_FIRST: TokenSet = token_set_union![
4 token_set_union![ 4 token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE],
5 token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE], 5 expressions::LITERAL_FIRST,
6 expressions::LITERAL_FIRST, 6 paths::PATH_FIRST,
7 paths::PATH_FIRST, 7];
8 ];
9 8
10pub(super) fn pattern(p: &mut Parser) { 9pub(super) fn pattern(p: &mut Parser) {
11 pattern_r(p, PAT_RECOVERY_SET) 10 pattern_r(p, PAT_RECOVERY_SET)
@@ -29,12 +28,13 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) {
29const PAT_RECOVERY_SET: TokenSet = 28const PAT_RECOVERY_SET: TokenSet =
30 token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]; 29 token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA];
31 30
32
33fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { 31fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
34 let la0 = p.nth(0); 32 let la0 = p.nth(0);
35 let la1 = p.nth(1); 33 let la1 = p.nth(1);
36 if la0 == REF_KW || la0 == MUT_KW 34 if la0 == REF_KW
37 || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY)) { 35 || la0 == MUT_KW
36 || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY))
37 {
38 return Some(bind_pat(p, true)); 38 return Some(bind_pat(p, true));
39 } 39 }
40 if paths::is_path_start(p) { 40 if paths::is_path_start(p) {
@@ -87,7 +87,7 @@ fn path_pat(p: &mut Parser) -> CompletedMarker {
87 field_pat_list(p); 87 field_pat_list(p);
88 STRUCT_PAT 88 STRUCT_PAT
89 } 89 }
90 _ => PATH_PAT 90 _ => PATH_PAT,
91 }; 91 };
92 m.complete(p, kind) 92 m.complete(p, kind)
93} 93}
@@ -195,7 +195,7 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) {
195 break; 195 break;
196 } 196 }
197 pattern(p) 197 pattern(p)
198 }, 198 }
199 } 199 }
200 if !p.at(ket) { 200 if !p.at(ket) {
201 p.expect(COMMA); 201 p.expect(COMMA);
diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs
index 79bc95ce4..79f5036b4 100644
--- a/crates/ra_syntax/src/grammar/type_params.rs
+++ b/crates/ra_syntax/src/grammar/type_params.rs
@@ -72,12 +72,8 @@ pub(super) fn bounds_without_colon(p: &mut Parser) {
72 p.eat(QUESTION); 72 p.eat(QUESTION);
73 match p.current() { 73 match p.current() {
74 LIFETIME => p.bump(), 74 LIFETIME => p.bump(),
75 FOR_KW => { 75 FOR_KW => types::for_type(p),
76 types::for_type(p) 76 _ if paths::is_path_start(p) => types::path_type(p),
77 }
78 _ if paths::is_path_start(p) => {
79 types::path_type(p)
80 }
81 _ => break, 77 _ => break,
82 } 78 }
83 if has_paren { 79 if has_paren {
@@ -104,7 +100,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
104 p.bump(); 100 p.bump();
105 loop { 101 loop {
106 if !(paths::is_path_start(p) || p.current() == LIFETIME) { 102 if !(paths::is_path_start(p) || p.current() == LIFETIME) {
107 break 103 break;
108 } 104 }
109 where_predicate(p); 105 where_predicate(p);
110 if p.current() != L_CURLY && p.current() != SEMI { 106 if p.current() != L_CURLY && p.current() != SEMI {
@@ -130,7 +126,6 @@ fn where_predicate(p: &mut Parser) {
130 } else { 126 } else {
131 p.error("expected colon") 127 p.error("expected colon")
132 } 128 }
133
134 } 129 }
135 m.complete(p, WHERE_PRED); 130 m.complete(p, WHERE_PRED);
136} 131}
diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs
index 27e5b086e..f308aef89 100644
--- a/crates/ra_syntax/src/grammar/types.rs
+++ b/crates/ra_syntax/src/grammar/types.rs
@@ -1,15 +1,14 @@
1use super::*; 1use super::*;
2 2
3pub(super) const TYPE_FIRST: TokenSet = 3pub(super) const TYPE_FIRST: TokenSet = token_set_union![
4 token_set_union![ 4 token_set![
5 token_set![ 5 L_PAREN, EXCL, STAR, L_BRACK, AMP, UNDERSCORE, FN_KW, UNSAFE_KW, EXTERN_KW, FOR_KW,
6 L_PAREN, EXCL, STAR, L_BRACK, AMP, UNDERSCORE, FN_KW, UNSAFE_KW, EXTERN_KW, FOR_KW, IMPL_KW, DYN_KW, L_ANGLE, 6 IMPL_KW, DYN_KW, L_ANGLE,
7 ], 7 ],
8 paths::PATH_FIRST, 8 paths::PATH_FIRST,
9 ]; 9];
10 10
11const TYPE_RECOVERY_SET: TokenSet = 11const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA];
12 token_set![R_PAREN, COMMA];
13 12
14pub(super) fn type_(p: &mut Parser) { 13pub(super) fn type_(p: &mut Parser) {
15 match p.current() { 14 match p.current() {
@@ -200,7 +199,6 @@ pub(super) fn for_type(p: &mut Parser) {
200 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), 199 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
201 _ if paths::is_path_start(p) => path_type_(p, false), 200 _ if paths::is_path_start(p) => path_type_(p, false),
202 _ => p.error("expected a path"), 201 _ => p.error("expected a path"),
203
204 } 202 }
205 m.complete(p, FOR_TYPE); 203 m.complete(p, FOR_TYPE);
206} 204}