From f1afc933530a87bd0cc7b25726c9a7fff3f3e007 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 9 Feb 2019 19:07:35 +0100 Subject: Fix handling of literal patterns Wrap them in a LiteralPat node so they can be distinguished from literal expressions. --- crates/ra_syntax/src/grammar/patterns.rs | 41 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index f3f400ae0..9d7da639d 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs @@ -43,21 +43,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { return Some(path_pat(p)); } - // test literal_pattern - // fn main() { - // match () { - // -1 => (), - // 92 => (), - // 'c' => (), - // "hello" => (), - // } - // } - if p.at(MINUS) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER) { - p.bump(); - } - - if let Some(m) = expressions::literal(p) { - return Some(m); + if is_literal_pat_start(p) { + return Some(literal_pat(p)); } let m = match la0 { @@ -73,6 +60,30 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { Some(m) } +fn is_literal_pat_start(p: &mut Parser) -> bool { + p.at(MINUS) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER) + || p.at_ts(expressions::LITERAL_FIRST) +} + +// test literal_pattern +// fn main() { +// match () { +// -1 => (), +// 92 => (), +// 'c' => (), +// "hello" => (), +// } +// } +fn literal_pat(p: &mut Parser) -> CompletedMarker { + assert!(is_literal_pat_start(p)); + let m = p.start(); + if p.at(MINUS) { + p.bump(); + } + expressions::literal(p); + m.complete(p, LITERAL_PAT) +} + // test path_part // fn foo() { // let foo::Bar = (); -- cgit v1.2.3