aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar/items.rs28
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs8
2 files changed, 35 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 370990e21..7e345f733 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -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) {}
390fn macro_def(p: &mut Parser, m: Marker) {
391 p.expect(T![macro]);
392 p.expect(IDENT);
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
382fn macro_call(p: &mut Parser) -> BlockLike { 410fn 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/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs
index fe0fcdb33..afe4ce51a 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,
@@ -251,7 +253,7 @@ impl SyntaxKind {
251 | SUPER_KW | IN_KW | WHERE_KW | FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW 253 | 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 254 | 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 255 | 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, 256 | MACRO_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW => true,
255 _ => false, 257 _ => false,
256 } 258 }
257 } 259 }
@@ -314,6 +316,7 @@ impl SyntaxKind {
314 "try" => TRY_KW, 316 "try" => TRY_KW,
315 "box" => BOX_KW, 317 "box" => BOX_KW,
316 "await" => AWAIT_KW, 318 "await" => AWAIT_KW,
319 "macro" => MACRO_KW,
317 _ => return None, 320 _ => return None,
318 }; 321 };
319 Some(kw) 322 Some(kw)
@@ -628,6 +631,9 @@ macro_rules! T {
628 ( await ) => { 631 ( await ) => {
629 $crate::SyntaxKind::AWAIT_KW 632 $crate::SyntaxKind::AWAIT_KW
630 }; 633 };
634 ( macro ) => {
635 $crate::SyntaxKind::MACRO_KW
636 };
631 ( auto ) => { 637 ( auto ) => {
632 $crate::SyntaxKind::AUTO_KW 638 $crate::SyntaxKind::AUTO_KW
633 }; 639 };