blob: 6e4f2236bfdf27c9f619b8e828ec7e328c560724 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
use super::*;
pub(super) fn pattern(p: &mut Parser) {
match p.current() {
UNDERSCORE => placeholder_pat(p),
AMPERSAND => ref_pat(p),
IDENT | REF_KW => bind_pat(p),
_ => p.err_and_bump("expected pattern"),
}
}
// test placeholder_pat
// fn main() { let _ = (); }
fn placeholder_pat(p: &mut Parser) {
assert!(p.at(UNDERSCORE));
let m = p.start();
p.bump();
m.complete(p, PLACEHOLDER_PAT);
}
// test ref_pat
// fn main() {
// let &a = ();
// let &mut b = ();
// }
fn ref_pat(p: &mut Parser) {
assert!(p.at(AMPERSAND));
let m = p.start();
p.bump();
p.eat(MUT_KW);
pattern(p);
m.complete(p, REF_PAT);
}
// test bind_pat
// fn main() {
// let a = ();
// let ref b = ();
// let ref mut c = ();
// let d @ _ = ();
// }
fn bind_pat(p: &mut Parser) {
let m = p.start();
if p.eat(REF_KW) {
p.eat(MUT_KW);
}
name(p);
if p.eat(AT) {
pattern(p);
}
m.complete(p, BIND_PAT);
}
|