From 03a9bbacf2a82faaecc269c1d97dea392f4f9874 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 23 Dec 2020 01:49:43 +0100 Subject: Parse ConstBlockPat --- crates/parser/src/grammar/patterns.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/parser') diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index 7e7f73dee..44400c9f8 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs @@ -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 { 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) +} -- cgit v1.2.3