aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-04-30 16:22:48 +0100
committerEdwin Cheng <[email protected]>2019-04-30 16:22:48 +0100
commitb454eb5a600779a9ab6f7bea251772bdd98b81b9 (patch)
tree572a20acd744ee57f44db1acd7219d3235f03a32
parent6618d1edc3edaad9ebdc216e6d7423ac9ac6a265 (diff)
Add macro pat parsing
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs11
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.rs3
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0129_marco_pat.txt36
3 files changed, 49 insertions, 1 deletions
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) {
40 atom_pat(p, recovery_set); 40 atom_pat(p, recovery_set);
41 m.complete(p, RANGE_PAT); 41 m.complete(p, RANGE_PAT);
42 } 42 }
43 // test marco_pat
44 // fn main() {
45 // let m!(x) = 0;
46 // }
47 else if lhs.kind() == PATH_PAT && p.at(EXCL) {
48 let m = lhs.precede(p);
49 items::macro_call_after_excl(p);
50 m.complete(p, MACRO_CALL);
51 }
43 } 52 }
44} 53}
45 54
@@ -51,7 +60,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
51 let la1 = p.nth(1); 60 let la1 = p.nth(1);
52 if la0 == REF_KW 61 if la0 == REF_KW
53 || la0 == MUT_KW 62 || la0 == MUT_KW
54 || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY)) 63 || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY || la1 == EXCL))
55 { 64 {
56 return Some(bind_pat(p, true)); 65 return Some(bind_pat(p, true));
57 } 66 }
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 @@
1fn main() {
2 let m!(x) = 0;
3}
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 @@
1SOURCE_FILE@[0; 33)
2 FN_DEF@[0; 32)
3 FN_KW@[0; 2) "fn"
4 WHITESPACE@[2; 3) " "
5 NAME@[3; 7)
6 IDENT@[3; 7) "main"
7 PARAM_LIST@[7; 9)
8 L_PAREN@[7; 8) "("
9 R_PAREN@[8; 9) ")"
10 WHITESPACE@[9; 10) " "
11 BLOCK@[10; 32)
12 L_CURLY@[10; 11) "{"
13 WHITESPACE@[11; 16) "\n "
14 LET_STMT@[16; 30)
15 LET_KW@[16; 19) "let"
16 WHITESPACE@[19; 20) " "
17 MACRO_CALL@[20; 25)
18 PATH_PAT@[20; 21)
19 PATH@[20; 21)
20 PATH_SEGMENT@[20; 21)
21 NAME_REF@[20; 21)
22 IDENT@[20; 21) "m"
23 EXCL@[21; 22) "!"
24 TOKEN_TREE@[22; 25)
25 L_PAREN@[22; 23) "("
26 IDENT@[23; 24) "x"
27 R_PAREN@[24; 25) ")"
28 WHITESPACE@[25; 26) " "
29 EQ@[26; 27) "="
30 WHITESPACE@[27; 28) " "
31 LITERAL@[28; 29)
32 INT_NUMBER@[28; 29) "0"
33 SEMI@[29; 30) ";"
34 WHITESPACE@[30; 31) "\n"
35 R_CURLY@[31; 32) "}"
36 WHITESPACE@[32; 33) "\n"