From 5a65d4d9fb84c324e8364f4d89adae258d5a1789 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 20 Sep 2019 11:43:34 -0400 Subject: Add indexing to record_field_pat --- crates/ra_parser/src/grammar/patterns.rs | 15 ++++- .../parser/inline/ok/0145_record_field_pat.rs | 4 ++ .../parser/inline/ok/0145_record_field_pat.txt | 75 ++++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rs create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.txt (limited to 'crates') diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index a4ffd6960..cf722eef4 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -168,6 +168,7 @@ fn record_field_pat_list(p: &mut Parser) { T![.] if p.at(T![..]) => p.bump(T![..]), IDENT if p.nth(1) == T![:] => record_field_pat(p), + INT_NUMBER if p.nth(1) == T![:] => record_field_pat(p), T!['{'] => error_block(p, "expected ident"), T![box] => { box_pat(p); @@ -184,12 +185,22 @@ fn record_field_pat_list(p: &mut Parser) { m.complete(p, RECORD_FIELD_PAT_LIST); } +// test record_field_pat +// fn foo() { +// let S { 0: 1 } = (); +// let S { x: 1 } = (); +// } fn record_field_pat(p: &mut Parser) { - assert!(p.at(IDENT)); + assert!(p.at(IDENT) || p.at(INT_NUMBER)); assert!(p.nth(1) == T![:]); let m = p.start(); - name(p); + + match p.current() { + IDENT => name(p), + _ => p.bump_any(), + } + p.bump_any(); pattern(p); m.complete(p, RECORD_FIELD_PAT); diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rs b/crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rs new file mode 100644 index 000000000..26b1d5f89 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rs @@ -0,0 +1,4 @@ +fn foo() { + let S { 0: 1 } = (); + let S { x: 1 } = (); +} diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.txt b/crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.txt new file mode 100644 index 000000000..06fbdfabf --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.txt @@ -0,0 +1,75 @@ +SOURCE_FILE@[0; 63) + FN_DEF@[0; 62) + FN_KW@[0; 2) "fn" + WHITESPACE@[2; 3) " " + NAME@[3; 6) + IDENT@[3; 6) "foo" + PARAM_LIST@[6; 8) + L_PAREN@[6; 7) "(" + R_PAREN@[7; 8) ")" + WHITESPACE@[8; 9) " " + BLOCK_EXPR@[9; 62) + BLOCK@[9; 62) + L_CURLY@[9; 10) "{" + WHITESPACE@[10; 15) "\n " + LET_STMT@[15; 35) + LET_KW@[15; 18) "let" + WHITESPACE@[18; 19) " " + RECORD_PAT@[19; 29) + PATH@[19; 20) + PATH_SEGMENT@[19; 20) + NAME_REF@[19; 20) + IDENT@[19; 20) "S" + WHITESPACE@[20; 21) " " + RECORD_FIELD_PAT_LIST@[21; 29) + L_CURLY@[21; 22) "{" + WHITESPACE@[22; 23) " " + RECORD_FIELD_PAT@[23; 27) + INT_NUMBER@[23; 24) "0" + COLON@[24; 25) ":" + WHITESPACE@[25; 26) " " + LITERAL_PAT@[26; 27) + LITERAL@[26; 27) + INT_NUMBER@[26; 27) "1" + WHITESPACE@[27; 28) " " + R_CURLY@[28; 29) "}" + WHITESPACE@[29; 30) " " + EQ@[30; 31) "=" + WHITESPACE@[31; 32) " " + TUPLE_EXPR@[32; 34) + L_PAREN@[32; 33) "(" + R_PAREN@[33; 34) ")" + SEMI@[34; 35) ";" + WHITESPACE@[35; 40) "\n " + LET_STMT@[40; 60) + LET_KW@[40; 43) "let" + WHITESPACE@[43; 44) " " + RECORD_PAT@[44; 54) + PATH@[44; 45) + PATH_SEGMENT@[44; 45) + NAME_REF@[44; 45) + IDENT@[44; 45) "S" + WHITESPACE@[45; 46) " " + RECORD_FIELD_PAT_LIST@[46; 54) + L_CURLY@[46; 47) "{" + WHITESPACE@[47; 48) " " + RECORD_FIELD_PAT@[48; 52) + NAME@[48; 49) + IDENT@[48; 49) "x" + COLON@[49; 50) ":" + WHITESPACE@[50; 51) " " + LITERAL_PAT@[51; 52) + LITERAL@[51; 52) + INT_NUMBER@[51; 52) "1" + WHITESPACE@[52; 53) " " + R_CURLY@[53; 54) "}" + WHITESPACE@[54; 55) " " + EQ@[55; 56) "=" + WHITESPACE@[56; 57) " " + TUPLE_EXPR@[57; 59) + L_PAREN@[57; 58) "(" + R_PAREN@[58; 59) ")" + SEMI@[59; 60) ";" + WHITESPACE@[60; 61) "\n" + R_CURLY@[61; 62) "}" + WHITESPACE@[62; 63) "\n" -- cgit v1.2.3 From 17a45a686c42522ffb668b1989d58219f76caf51 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 20 Sep 2019 11:49:45 -0400 Subject: Apply suggestion --- crates/ra_parser/src/grammar/patterns.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index cf722eef4..877ae5b7a 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -196,9 +196,8 @@ fn record_field_pat(p: &mut Parser) { let m = p.start(); - match p.current() { - IDENT => name(p), - _ => p.bump_any(), + if !p.eat(INT_NUMBER) { + name(p) } p.bump_any(); -- cgit v1.2.3