Parse ConstBlockPat

This commit is contained in:
Lukas Wirth 2020-12-23 01:49:43 +01:00
parent be7260485e
commit 03a9bbacf2
3 changed files with 96 additions and 0 deletions

View file

@ -1,5 +1,7 @@
//! FIXME: write short doc here
use expressions::block_expr;
use super::*;
pub(super) const PATTERN_FIRST: TokenSet =
@ -89,6 +91,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
let m = match p.nth(0) {
T![box] => box_pat(p),
T![ref] | T![mut] => ident_pat(p, true),
T![const] => const_block_pat(p),
IDENT => match p.nth(1) {
// Checks the token after an IDENT to see if a pattern is a path (Struct { .. }) or macro
// (T![x]).
@ -386,3 +389,16 @@ fn box_pat(p: &mut Parser) -> CompletedMarker {
pattern_single(p);
m.complete(p, BOX_PAT)
}
// test const_block_pat
// fn main() {
// let const { 15 } = ();
// let const { foo(); bar() } = ();
// }
fn const_block_pat(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![const]));
let m = p.start();
p.bump(T![const]);
block_expr(p);
m.complete(p, CONST_BLOCK_PAT)
}