Add macro pat parsing

This commit is contained in:
Edwin Cheng 2019-04-30 23:22:48 +08:00
parent 6618d1edc3
commit b454eb5a60
3 changed files with 49 additions and 1 deletions

View file

@ -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<CompletedMarker> {
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));
}

View file

@ -0,0 +1,3 @@
fn main() {
let m!(x) = 0;
}

View file

@ -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"