aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/grammar')
-rw-r--r--crates/ra_syntax/src/grammar/patterns.rs41
1 files changed, 26 insertions, 15 deletions
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<CompletedMarker> {
43 return Some(path_pat(p)); 43 return Some(path_pat(p));
44 } 44 }
45 45
46 // test literal_pattern 46 if is_literal_pat_start(p) {
47 // fn main() { 47 return Some(literal_pat(p));
48 // match () {
49 // -1 => (),
50 // 92 => (),
51 // 'c' => (),
52 // "hello" => (),
53 // }
54 // }
55 if p.at(MINUS) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER) {
56 p.bump();
57 }
58
59 if let Some(m) = expressions::literal(p) {
60 return Some(m);
61 } 48 }
62 49
63 let m = match la0 { 50 let m = match la0 {
@@ -73,6 +60,30 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
73 Some(m) 60 Some(m)
74} 61}
75 62
63fn is_literal_pat_start(p: &mut Parser) -> bool {
64 p.at(MINUS) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER)
65 || p.at_ts(expressions::LITERAL_FIRST)
66}
67
68// test literal_pattern
69// fn main() {
70// match () {
71// -1 => (),
72// 92 => (),
73// 'c' => (),
74// "hello" => (),
75// }
76// }
77fn literal_pat(p: &mut Parser) -> CompletedMarker {
78 assert!(is_literal_pat_start(p));
79 let m = p.start();
80 if p.at(MINUS) {
81 p.bump();
82 }
83 expressions::literal(p);
84 m.complete(p, LITERAL_PAT)
85}
86
76// test path_part 87// test path_part
77// fn foo() { 88// fn foo() {
78// let foo::Bar = (); 89// let foo::Bar = ();