diff --git a/src/grammar.ron b/src/grammar.ron index 0620a8b8c32..5181e296ebc 100644 --- a/src/grammar.ron +++ b/src/grammar.ron @@ -140,6 +140,7 @@ Grammar( "PLACEHOLDER_PAT", "PATH_PAT", "STRUCT_PAT", + "TUPLE_STRUCT_PAT", "TUPLE_PAT", // atoms diff --git a/src/grammar/patterns.rs b/src/grammar/patterns.rs index d67f180fae6..f1d48b5faca 100644 --- a/src/grammar/patterns.rs +++ b/src/grammar/patterns.rs @@ -16,6 +16,7 @@ pub(super) fn pattern(p: &mut Parser) { match la0 { UNDERSCORE => placeholder_pat(p), AMP => ref_pat(p), + L_PAREN => tuple_pat(p), _ => p.err_and_bump("expected pattern"), } } @@ -33,7 +34,7 @@ fn path_pat(p: &mut Parser) { let kind = match p.current() { L_PAREN => { tuple_pat_fields(p); - TUPLE_PAT + TUPLE_STRUCT_PAT } L_CURLY => { struct_pat_fields(p); @@ -116,6 +117,17 @@ fn ref_pat(p: &mut Parser) { m.complete(p, REF_PAT); } +// test tuple_pat +// fn main() { +// let (a, b, ..) = (); +// } +fn tuple_pat(p: &mut Parser) { + assert!(p.at(L_PAREN)); + let m = p.start(); + tuple_pat_fields(p); + m.complete(p, TUPLE_PAT); +} + // test bind_pat // fn main() { // let a = (); diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index db8c2000449..c8ddf333cb6 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs @@ -132,6 +132,7 @@ pub enum SyntaxKind { PLACEHOLDER_PAT, PATH_PAT, STRUCT_PAT, + TUPLE_STRUCT_PAT, TUPLE_PAT, TUPLE_EXPR, ARRAY_EXPR, @@ -371,6 +372,7 @@ impl SyntaxKind { PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, PATH_PAT => &SyntaxInfo { name: "PATH_PAT" }, STRUCT_PAT => &SyntaxInfo { name: "STRUCT_PAT" }, + TUPLE_STRUCT_PAT => &SyntaxInfo { name: "TUPLE_STRUCT_PAT" }, TUPLE_PAT => &SyntaxInfo { name: "TUPLE_PAT" }, TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" }, ARRAY_EXPR => &SyntaxInfo { name: "ARRAY_EXPR" }, diff --git a/tests/data/parser/inline/0071_tuple_pat_fields.txt b/tests/data/parser/inline/0071_tuple_pat_fields.txt index a6bfd3256f8..1eca6d37016 100644 --- a/tests/data/parser/inline/0071_tuple_pat_fields.txt +++ b/tests/data/parser/inline/0071_tuple_pat_fields.txt @@ -14,7 +14,7 @@ FILE@[0; 97) LET_STMT@[15; 28) LET_KW@[15; 18) WHITESPACE@[18; 19) - TUPLE_PAT@[19; 22) + TUPLE_STRUCT_PAT@[19; 22) PATH@[19; 20) PATH_SEGMENT@[19; 20) NAME_REF@[19; 20) @@ -32,7 +32,7 @@ FILE@[0; 97) LET_STMT@[33; 47) LET_KW@[33; 36) WHITESPACE@[36; 37) - TUPLE_PAT@[37; 41) + TUPLE_STRUCT_PAT@[37; 41) PATH@[37; 38) PATH_SEGMENT@[37; 38) NAME_REF@[37; 38) @@ -52,7 +52,7 @@ FILE@[0; 97) LET_STMT@[52; 67) LET_KW@[52; 55) WHITESPACE@[55; 56) - TUPLE_PAT@[56; 61) + TUPLE_STRUCT_PAT@[56; 61) PATH@[56; 57) PATH_SEGMENT@[56; 57) NAME_REF@[56; 57) @@ -73,7 +73,7 @@ FILE@[0; 97) LET_STMT@[72; 94) LET_KW@[72; 75) WHITESPACE@[75; 76) - TUPLE_PAT@[76; 88) + TUPLE_STRUCT_PAT@[76; 88) PATH@[76; 77) PATH_SEGMENT@[76; 77) NAME_REF@[76; 77) diff --git a/tests/data/parser/inline/0072_path_part.txt b/tests/data/parser/inline/0072_path_part.txt index 696de200e70..0c7865998a1 100644 --- a/tests/data/parser/inline/0072_path_part.txt +++ b/tests/data/parser/inline/0072_path_part.txt @@ -74,7 +74,7 @@ FILE@[0; 103) LET_STMT@[83; 100) LET_KW@[83; 86) WHITESPACE@[86; 87) - TUPLE_PAT@[87; 94) + TUPLE_STRUCT_PAT@[87; 94) PATH@[87; 90) PATH_SEGMENT@[87; 90) NAME_REF@[87; 90) diff --git a/tests/data/parser/inline/0076_cond.txt b/tests/data/parser/inline/0076_cond.txt index c4924574f1b..e8cf677cff3 100644 --- a/tests/data/parser/inline/0076_cond.txt +++ b/tests/data/parser/inline/0076_cond.txt @@ -16,7 +16,7 @@ FILE@[0; 38) WHITESPACE@[13; 14) LET_KW@[14; 17) WHITESPACE@[17; 18) - TUPLE_PAT@[18; 25) + TUPLE_STRUCT_PAT@[18; 25) PATH@[18; 22) PATH_SEGMENT@[18; 22) NAME_REF@[18; 22) diff --git a/tests/data/parser/inline/0077_while_expr.txt b/tests/data/parser/inline/0077_while_expr.txt index fffbb37de8b..5c936a607f6 100644 --- a/tests/data/parser/inline/0077_while_expr.txt +++ b/tests/data/parser/inline/0077_while_expr.txt @@ -29,7 +29,7 @@ FILE@[0; 70) WHITESPACE@[39; 40) LET_KW@[40; 43) WHITESPACE@[43; 44) - TUPLE_PAT@[44; 51) + TUPLE_STRUCT_PAT@[44; 51) PATH@[44; 48) PATH_SEGMENT@[44; 48) NAME_REF@[44; 48) diff --git a/tests/data/parser/inline/0086_tuple_pat.rs b/tests/data/parser/inline/0086_tuple_pat.rs new file mode 100644 index 00000000000..f785acd36d9 --- /dev/null +++ b/tests/data/parser/inline/0086_tuple_pat.rs @@ -0,0 +1,3 @@ +fn main() { + let (a, b, ..) = (); +} diff --git a/tests/data/parser/inline/0086_tuple_pat.txt b/tests/data/parser/inline/0086_tuple_pat.txt new file mode 100644 index 00000000000..6c2f25d3660 --- /dev/null +++ b/tests/data/parser/inline/0086_tuple_pat.txt @@ -0,0 +1,40 @@ +FILE@[0; 39) + FN_ITEM@[0; 38) + FN_KW@[0; 2) + WHITESPACE@[2; 3) + NAME@[3; 7) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 9) + L_PAREN@[7; 8) + R_PAREN@[8; 9) + WHITESPACE@[9; 10) + BLOCK_EXPR@[10; 38) + L_CURLY@[10; 11) + WHITESPACE@[11; 16) + LET_STMT@[16; 36) + LET_KW@[16; 19) + WHITESPACE@[19; 20) + TUPLE_PAT@[20; 30) + L_PAREN@[20; 21) + BIND_PAT@[21; 22) + NAME@[21; 22) + IDENT@[21; 22) "a" + COMMA@[22; 23) + WHITESPACE@[23; 24) + BIND_PAT@[24; 25) + NAME@[24; 25) + IDENT@[24; 25) "b" + COMMA@[25; 26) + WHITESPACE@[26; 27) + DOTDOT@[27; 29) + R_PAREN@[29; 30) + WHITESPACE@[30; 31) + EQ@[31; 32) + WHITESPACE@[32; 33) + TUPLE_EXPR@[33; 35) + L_PAREN@[33; 34) + R_PAREN@[34; 35) + SEMI@[35; 36) + WHITESPACE@[36; 37) + R_CURLY@[37; 38) + WHITESPACE@[38; 39)