Parse inline const pattern in nested patterns

This commit is contained in:
Ryo Yoshida 2023-04-16 02:30:59 +09:00
parent 89a1439de3
commit 83a93f4bd3
No known key found for this signature in database
GPG Key ID: E25698A930586171
3 changed files with 138 additions and 1 deletions

View File

@ -5,6 +5,7 @@
T![box],
T![ref],
T![mut],
T![const],
T!['('],
T!['['],
T![&],
@ -17,7 +18,7 @@
/// Set of possible tokens at the start of a range pattern's end bound.
const RANGE_PAT_END_FIRST: TokenSet =
expressions::LITERAL_FIRST.union(paths::PATH_FIRST).union(TokenSet::new(&[T![-]]));
expressions::LITERAL_FIRST.union(paths::PATH_FIRST).union(TokenSet::new(&[T![-], T![const]]));
pub(crate) fn pattern(p: &mut Parser<'_>) {
pattern_r(p, PAT_RECOVERY_SET);
@ -499,6 +500,14 @@ fn box_pat(p: &mut Parser<'_>) -> CompletedMarker {
// fn main() {
// let const { 15 } = ();
// let const { foo(); bar() } = ();
//
// match 42 {
// const { 0 } .. const { 1 } => (),
// .. const { 0 } => (),
// const { 2 } .. => (),
// }
//
// let (const { () },) = ();
// }
fn const_block_pat(p: &mut Parser<'_>) -> CompletedMarker {
assert!(p.at(T![const]));

View File

@ -74,6 +74,126 @@ SOURCE_FILE
L_PAREN "("
R_PAREN ")"
SEMICOLON ";"
WHITESPACE "\n\n "
EXPR_STMT
MATCH_EXPR
MATCH_KW "match"
WHITESPACE " "
LITERAL
INT_NUMBER "42"
WHITESPACE " "
MATCH_ARM_LIST
L_CURLY "{"
WHITESPACE "\n "
MATCH_ARM
RANGE_PAT
CONST_BLOCK_PAT
CONST_KW "const"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE " "
LITERAL
INT_NUMBER "0"
WHITESPACE " "
R_CURLY "}"
WHITESPACE " "
DOT2 ".."
WHITESPACE " "
CONST_BLOCK_PAT
CONST_KW "const"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE " "
LITERAL
INT_NUMBER "1"
WHITESPACE " "
R_CURLY "}"
WHITESPACE " "
FAT_ARROW "=>"
WHITESPACE " "
TUPLE_EXPR
L_PAREN "("
R_PAREN ")"
COMMA ","
WHITESPACE "\n "
MATCH_ARM
RANGE_PAT
DOT2 ".."
WHITESPACE " "
CONST_BLOCK_PAT
CONST_KW "const"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE " "
LITERAL
INT_NUMBER "0"
WHITESPACE " "
R_CURLY "}"
WHITESPACE " "
FAT_ARROW "=>"
WHITESPACE " "
TUPLE_EXPR
L_PAREN "("
R_PAREN ")"
COMMA ","
WHITESPACE "\n "
MATCH_ARM
RANGE_PAT
CONST_BLOCK_PAT
CONST_KW "const"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE " "
LITERAL
INT_NUMBER "2"
WHITESPACE " "
R_CURLY "}"
WHITESPACE " "
DOT2 ".."
WHITESPACE " "
FAT_ARROW "=>"
WHITESPACE " "
TUPLE_EXPR
L_PAREN "("
R_PAREN ")"
COMMA ","
WHITESPACE "\n "
R_CURLY "}"
WHITESPACE "\n\n "
LET_STMT
LET_KW "let"
WHITESPACE " "
TUPLE_PAT
L_PAREN "("
CONST_BLOCK_PAT
CONST_KW "const"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE " "
TUPLE_EXPR
L_PAREN "("
R_PAREN ")"
WHITESPACE " "
R_CURLY "}"
COMMA ","
R_PAREN ")"
WHITESPACE " "
EQ "="
WHITESPACE " "
TUPLE_EXPR
L_PAREN "("
R_PAREN ")"
SEMICOLON ";"
WHITESPACE "\n"
R_CURLY "}"
WHITESPACE "\n"

View File

@ -1,4 +1,12 @@
fn main() {
let const { 15 } = ();
let const { foo(); bar() } = ();
match 42 {
const { 0 } .. const { 1 } => (),
.. const { 0 } => (),
const { 2 } .. => (),
}
let (const { () },) = ();
}