From 64caa027b884b3458997318a01e99812e6bb6fca Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 20 Dec 2020 21:01:36 +0100 Subject: Parse attributes in tuple expressions --- crates/parser/src/grammar/expressions/atom.rs | 8 ++-- .../parser/inline/ok/0154_tuple_attrs.rast | 50 ++++++++++++++++++++++ .../test_data/parser/inline/ok/0154_tuple_attrs.rs | 1 + 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rast create mode 100644 crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rs (limited to 'crates') diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 18b63feb7..e897d5a52 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -156,11 +156,13 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { let mut saw_expr = false; while !p.at(EOF) && !p.at(T![')']) { saw_expr = true; - if !p.at_ts(EXPR_FIRST) { - p.error("expected expression"); + + // test tuple_attrs + // const A: (i64, i64) = (1, #[cfg(test)] 2); + if !expr_with_attrs(p) { break; } - expr(p); + if !p.at(T![')']) { saw_comma = true; p.expect(T![,]); diff --git a/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rast b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rast new file mode 100644 index 000000000..d34b21abe --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rast @@ -0,0 +1,50 @@ +SOURCE_FILE@0..43 + CONST@0..42 + CONST_KW@0..5 "const" + WHITESPACE@5..6 " " + NAME@6..7 + IDENT@6..7 "A" + COLON@7..8 ":" + WHITESPACE@8..9 " " + TUPLE_TYPE@9..19 + L_PAREN@9..10 "(" + PATH_TYPE@10..13 + PATH@10..13 + PATH_SEGMENT@10..13 + NAME_REF@10..13 + IDENT@10..13 "i64" + COMMA@13..14 "," + WHITESPACE@14..15 " " + PATH_TYPE@15..18 + PATH@15..18 + PATH_SEGMENT@15..18 + NAME_REF@15..18 + IDENT@15..18 "i64" + R_PAREN@18..19 ")" + WHITESPACE@19..20 " " + EQ@20..21 "=" + WHITESPACE@21..22 " " + TUPLE_EXPR@22..41 + L_PAREN@22..23 "(" + LITERAL@23..24 + INT_NUMBER@23..24 "1" + COMMA@24..25 "," + WHITESPACE@25..26 " " + LITERAL@26..40 + ATTR@26..38 + POUND@26..27 "#" + L_BRACK@27..28 "[" + PATH@28..31 + PATH_SEGMENT@28..31 + NAME_REF@28..31 + IDENT@28..31 "cfg" + TOKEN_TREE@31..37 + L_PAREN@31..32 "(" + IDENT@32..36 "test" + R_PAREN@36..37 ")" + R_BRACK@37..38 "]" + WHITESPACE@38..39 " " + INT_NUMBER@39..40 "2" + R_PAREN@40..41 ")" + SEMICOLON@41..42 ";" + WHITESPACE@42..43 "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rs b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rs new file mode 100644 index 000000000..f84b7ab31 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rs @@ -0,0 +1 @@ +const A: (i64, i64) = (1, #[cfg(test)] 2); -- cgit v1.2.3