diff options
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 10 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items.rs | 30 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/patterns.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/type_params.rs | 11 | ||||
-rw-r--r-- | crates/ra_parser/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_parser/src/parser.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 9 | ||||
-rw-r--r-- | crates/ra_parser/src/token_set.rs | 8 |
9 files changed, 63 insertions, 12 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 6e9e212b7..22f64a9f4 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs | |||
@@ -264,7 +264,7 @@ fn name_r(p: &mut Parser, recovery: TokenSet) { | |||
264 | } | 264 | } |
265 | 265 | ||
266 | fn name(p: &mut Parser) { | 266 | fn name(p: &mut Parser) { |
267 | name_r(p, TokenSet::empty()) | 267 | name_r(p, TokenSet::EMPTY) |
268 | } | 268 | } |
269 | 269 | ||
270 | fn name_ref(p: &mut Parser) { | 270 | fn name_ref(p: &mut Parser) { |
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index f06191963..4ac1d6334 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -43,6 +43,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = | |||
43 | T!['('], | 43 | T!['('], |
44 | T!['{'], | 44 | T!['{'], |
45 | T!['['], | 45 | T!['['], |
46 | L_DOLLAR, | ||
46 | T![|], | 47 | T![|], |
47 | T![move], | 48 | T![move], |
48 | T![box], | 49 | T![box], |
@@ -248,7 +249,12 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { | |||
248 | p.error("expected `{`"); | 249 | p.error("expected `{`"); |
249 | } | 250 | } |
250 | } | 251 | } |
251 | expr(p); | 252 | |
253 | if p.at_ts(EXPR_FIRST) { | ||
254 | expr(p); | ||
255 | } else { | ||
256 | p.error("expected expression"); | ||
257 | } | ||
252 | m.complete(p, LAMBDA_EXPR) | 258 | m.complete(p, LAMBDA_EXPR) |
253 | } | 259 | } |
254 | 260 | ||
@@ -438,7 +444,7 @@ fn match_arm(p: &mut Parser) -> BlockLike { | |||
438 | // } | 444 | // } |
439 | attributes::outer_attributes(p); | 445 | attributes::outer_attributes(p); |
440 | 446 | ||
441 | patterns::pattern_list_r(p, TokenSet::empty()); | 447 | patterns::pattern_list_r(p, TokenSet::EMPTY); |
442 | if p.at(T![if]) { | 448 | if p.at(T![if]) { |
443 | match_guard(p); | 449 | match_guard(p); |
444 | } | 450 | } |
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 370990e21..6e23d9b72 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -33,7 +33,7 @@ pub(super) enum ItemFlavor { | |||
33 | 33 | ||
34 | pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ | 34 | pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ |
35 | FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, | 35 | FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, |
36 | CRATE_KW, USE_KW | 36 | CRATE_KW, USE_KW, MACRO_KW |
37 | ]; | 37 | ]; |
38 | 38 | ||
39 | pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { | 39 | pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { |
@@ -249,6 +249,11 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { | |||
249 | // } | 249 | // } |
250 | adt::struct_def(p, m); | 250 | adt::struct_def(p, m); |
251 | } | 251 | } |
252 | // test pub_macro_def | ||
253 | // pub macro m($:ident) {} | ||
254 | T![macro] => { | ||
255 | macro_def(p, m); | ||
256 | } | ||
252 | IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => { | 257 | IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => { |
253 | // test union_items | 258 | // test union_items |
254 | // union Foo {} | 259 | // union Foo {} |
@@ -379,6 +384,29 @@ pub(crate) fn mod_item_list(p: &mut Parser) { | |||
379 | m.complete(p, ITEM_LIST); | 384 | m.complete(p, ITEM_LIST); |
380 | } | 385 | } |
381 | 386 | ||
387 | // test macro_def | ||
388 | // macro m { ($i:ident) => {} } | ||
389 | // macro m($i:ident) {} | ||
390 | fn macro_def(p: &mut Parser, m: Marker) { | ||
391 | p.expect(T![macro]); | ||
392 | name_r(p, ITEM_RECOVERY_SET); | ||
393 | if p.at(T!['{']) { | ||
394 | token_tree(p); | ||
395 | } else if !p.at(T!['(']) { | ||
396 | p.error("unmatched `(`"); | ||
397 | } else { | ||
398 | let m = p.start(); | ||
399 | token_tree(p); | ||
400 | match p.current() { | ||
401 | T!['{'] | T!['['] | T!['('] => token_tree(p), | ||
402 | _ => p.error("expected `{`, `[`, `(`"), | ||
403 | } | ||
404 | m.complete(p, TOKEN_TREE); | ||
405 | } | ||
406 | |||
407 | m.complete(p, MACRO_DEF); | ||
408 | } | ||
409 | |||
382 | fn macro_call(p: &mut Parser) -> BlockLike { | 410 | fn macro_call(p: &mut Parser) -> BlockLike { |
383 | assert!(paths::is_use_path_start(p)); | 411 | assert!(paths::is_use_path_start(p)); |
384 | paths::use_path(p); | 412 | paths::use_path(p); |
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index f5d12278c..422a4e3dc 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs | |||
@@ -50,7 +50,7 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { | |||
50 | // let m!(x) = 0; | 50 | // let m!(x) = 0; |
51 | // } | 51 | // } |
52 | if lhs.kind() == PATH_PAT && p.at(T![!]) { | 52 | if lhs.kind() == PATH_PAT && p.at(T![!]) { |
53 | let m = lhs.precede(p); | 53 | let m = lhs.undo_completion(p); |
54 | items::macro_call_after_excl(p); | 54 | items::macro_call_after_excl(p); |
55 | m.complete(p, MACRO_CALL); | 55 | m.complete(p, MACRO_CALL); |
56 | } | 56 | } |
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/lib.rs b/crates/ra_parser/src/lib.rs index 45241e566..65134277e 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs | |||
@@ -83,6 +83,7 @@ pub fn parse(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | |||
83 | parse_from_tokens(token_source, tree_sink, grammar::root); | 83 | parse_from_tokens(token_source, tree_sink, grammar::root); |
84 | } | 84 | } |
85 | 85 | ||
86 | #[derive(Clone, Copy)] | ||
86 | pub enum FragmentKind { | 87 | pub enum FragmentKind { |
87 | Path, | 88 | Path, |
88 | Expr, | 89 | Expr, |
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index dafd5247b..1071c46dc 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs | |||
@@ -208,7 +208,7 @@ impl<'t> Parser<'t> { | |||
208 | 208 | ||
209 | /// Create an error node and consume the next token. | 209 | /// Create an error node and consume the next token. |
210 | pub(crate) fn err_and_bump(&mut self, message: &str) { | 210 | pub(crate) fn err_and_bump(&mut self, message: &str) { |
211 | self.err_recover(message, TokenSet::empty()); | 211 | self.err_recover(message, TokenSet::EMPTY); |
212 | } | 212 | } |
213 | 213 | ||
214 | /// Create an error node and consume the next token. | 214 | /// Create an error node and consume the next token. |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index fe0fcdb33..af2945f57 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -100,6 +100,7 @@ pub enum SyntaxKind { | |||
100 | TRY_KW, | 100 | TRY_KW, |
101 | BOX_KW, | 101 | BOX_KW, |
102 | AWAIT_KW, | 102 | AWAIT_KW, |
103 | MACRO_KW, | ||
103 | AUTO_KW, | 104 | AUTO_KW, |
104 | DEFAULT_KW, | 105 | DEFAULT_KW, |
105 | EXISTENTIAL_KW, | 106 | EXISTENTIAL_KW, |
@@ -136,6 +137,7 @@ pub enum SyntaxKind { | |||
136 | TYPE_ALIAS_DEF, | 137 | TYPE_ALIAS_DEF, |
137 | MACRO_CALL, | 138 | MACRO_CALL, |
138 | TOKEN_TREE, | 139 | TOKEN_TREE, |
140 | MACRO_DEF, | ||
139 | PAREN_TYPE, | 141 | PAREN_TYPE, |
140 | TUPLE_TYPE, | 142 | TUPLE_TYPE, |
141 | NEVER_TYPE, | 143 | NEVER_TYPE, |
@@ -227,6 +229,7 @@ pub enum SyntaxKind { | |||
227 | TYPE_PARAM_LIST, | 229 | TYPE_PARAM_LIST, |
228 | LIFETIME_PARAM, | 230 | LIFETIME_PARAM, |
229 | TYPE_PARAM, | 231 | TYPE_PARAM, |
232 | CONST_PARAM, | ||
230 | TYPE_ARG_LIST, | 233 | TYPE_ARG_LIST, |
231 | LIFETIME_ARG, | 234 | LIFETIME_ARG, |
232 | TYPE_ARG, | 235 | TYPE_ARG, |
@@ -251,7 +254,7 @@ impl SyntaxKind { | |||
251 | | SUPER_KW | IN_KW | WHERE_KW | FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW | 254 | | SUPER_KW | IN_KW | WHERE_KW | FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW |
252 | | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW | CONST_KW | STATIC_KW | MUT_KW | UNSAFE_KW | 255 | | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW | CONST_KW | STATIC_KW | MUT_KW | UNSAFE_KW |
253 | | TYPE_KW | REF_KW | LET_KW | MOVE_KW | RETURN_KW | TRY_KW | BOX_KW | AWAIT_KW | 256 | | TYPE_KW | REF_KW | LET_KW | MOVE_KW | RETURN_KW | TRY_KW | BOX_KW | AWAIT_KW |
254 | | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW => true, | 257 | | MACRO_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW => true, |
255 | _ => false, | 258 | _ => false, |
256 | } | 259 | } |
257 | } | 260 | } |
@@ -314,6 +317,7 @@ impl SyntaxKind { | |||
314 | "try" => TRY_KW, | 317 | "try" => TRY_KW, |
315 | "box" => BOX_KW, | 318 | "box" => BOX_KW, |
316 | "await" => AWAIT_KW, | 319 | "await" => AWAIT_KW, |
320 | "macro" => MACRO_KW, | ||
317 | _ => return None, | 321 | _ => return None, |
318 | }; | 322 | }; |
319 | Some(kw) | 323 | Some(kw) |
@@ -628,6 +632,9 @@ macro_rules! T { | |||
628 | ( await ) => { | 632 | ( await ) => { |
629 | $crate::SyntaxKind::AWAIT_KW | 633 | $crate::SyntaxKind::AWAIT_KW |
630 | }; | 634 | }; |
635 | ( macro ) => { | ||
636 | $crate::SyntaxKind::MACRO_KW | ||
637 | }; | ||
631 | ( auto ) => { | 638 | ( auto ) => { |
632 | $crate::SyntaxKind::AUTO_KW | 639 | $crate::SyntaxKind::AUTO_KW |
633 | }; | 640 | }; |
diff --git a/crates/ra_parser/src/token_set.rs b/crates/ra_parser/src/token_set.rs index 2a6952c01..994017acf 100644 --- a/crates/ra_parser/src/token_set.rs +++ b/crates/ra_parser/src/token_set.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! A bit-set of `SyntaxKind`s. |
2 | 2 | ||
3 | use crate::SyntaxKind; | 3 | use crate::SyntaxKind; |
4 | 4 | ||
@@ -7,9 +7,7 @@ use crate::SyntaxKind; | |||
7 | pub(crate) struct TokenSet(u128); | 7 | pub(crate) struct TokenSet(u128); |
8 | 8 | ||
9 | impl TokenSet { | 9 | impl TokenSet { |
10 | pub(crate) const fn empty() -> TokenSet { | 10 | pub(crate) const EMPTY: TokenSet = TokenSet(0); |
11 | TokenSet(0) | ||
12 | } | ||
13 | 11 | ||
14 | pub(crate) const fn singleton(kind: SyntaxKind) -> TokenSet { | 12 | pub(crate) const fn singleton(kind: SyntaxKind) -> TokenSet { |
15 | TokenSet(mask(kind)) | 13 | TokenSet(mask(kind)) |
@@ -30,7 +28,7 @@ const fn mask(kind: SyntaxKind) -> u128 { | |||
30 | 28 | ||
31 | #[macro_export] | 29 | #[macro_export] |
32 | macro_rules! token_set { | 30 | macro_rules! token_set { |
33 | ($($t:expr),*) => { TokenSet::empty()$(.union(TokenSet::singleton($t)))* }; | 31 | ($($t:expr),*) => { TokenSet::EMPTY$(.union(TokenSet::singleton($t)))* }; |
34 | ($($t:expr),* ,) => { token_set!($($t),*) }; | 32 | ($($t:expr),* ,) => { token_set!($($t),*) }; |
35 | } | 33 | } |
36 | 34 | ||