From b454eb5a600779a9ab6f7bea251772bdd98b81b9 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 30 Apr 2019 23:22:48 +0800 Subject: Add macro pat parsing --- crates/ra_parser/src/grammar/patterns.rs | 11 ++++++- .../tests/data/parser/inline/ok/0129_marco_pat.rs | 3 ++ .../tests/data/parser/inline/ok/0129_marco_pat.txt | 36 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.rs create mode 100644 crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.txt (limited to 'crates') diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 03fa9b71e..12dd22bde 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -40,6 +40,15 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { atom_pat(p, recovery_set); m.complete(p, RANGE_PAT); } + // test marco_pat + // fn main() { + // let m!(x) = 0; + // } + else if lhs.kind() == PATH_PAT && p.at(EXCL) { + let m = lhs.precede(p); + items::macro_call_after_excl(p); + m.complete(p, MACRO_CALL); + } } } @@ -51,7 +60,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { let la1 = p.nth(1); if la0 == REF_KW || la0 == MUT_KW - || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY)) + || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY || la1 == EXCL)) { return Some(bind_pat(p, true)); } diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.rs new file mode 100644 index 000000000..811181d9b --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.rs @@ -0,0 +1,3 @@ +fn main() { + let m!(x) = 0; +} diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.txt new file mode 100644 index 000000000..50b4ab2e7 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.txt @@ -0,0 +1,36 @@ +SOURCE_FILE@[0; 33) + FN_DEF@[0; 32) + FN_KW@[0; 2) "fn" + WHITESPACE@[2; 3) " " + NAME@[3; 7) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 9) + L_PAREN@[7; 8) "(" + R_PAREN@[8; 9) ")" + WHITESPACE@[9; 10) " " + BLOCK@[10; 32) + L_CURLY@[10; 11) "{" + WHITESPACE@[11; 16) "\n " + LET_STMT@[16; 30) + LET_KW@[16; 19) "let" + WHITESPACE@[19; 20) " " + MACRO_CALL@[20; 25) + PATH_PAT@[20; 21) + PATH@[20; 21) + PATH_SEGMENT@[20; 21) + NAME_REF@[20; 21) + IDENT@[20; 21) "m" + EXCL@[21; 22) "!" + TOKEN_TREE@[22; 25) + L_PAREN@[22; 23) "(" + IDENT@[23; 24) "x" + R_PAREN@[24; 25) ")" + WHITESPACE@[25; 26) " " + EQ@[26; 27) "=" + WHITESPACE@[27; 28) " " + LITERAL@[28; 29) + INT_NUMBER@[28; 29) "0" + SEMI@[29; 30) ";" + WHITESPACE@[30; 31) "\n" + R_CURLY@[31; 32) "}" + WHITESPACE@[32; 33) "\n" -- cgit v1.2.3