diff options
author | Lukas Wirth <[email protected]> | 2020-12-20 20:01:36 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-12-20 20:01:36 +0000 |
commit | 64caa027b884b3458997318a01e99812e6bb6fca (patch) | |
tree | 01ddecdadffd74dae1e2f8f786ea246eb1d730da | |
parent | 4be9ed675ed2550e8cb10031fd4c4cfb01d2a2ed (diff) |
Parse attributes in tuple expressions
3 files changed, 56 insertions, 3 deletions
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 { | |||
156 | let mut saw_expr = false; | 156 | let mut saw_expr = false; |
157 | while !p.at(EOF) && !p.at(T![')']) { | 157 | while !p.at(EOF) && !p.at(T![')']) { |
158 | saw_expr = true; | 158 | saw_expr = true; |
159 | if !p.at_ts(EXPR_FIRST) { | 159 | |
160 | p.error("expected expression"); | 160 | // test tuple_attrs |
161 | // const A: (i64, i64) = (1, #[cfg(test)] 2); | ||
162 | if !expr_with_attrs(p) { | ||
161 | break; | 163 | break; |
162 | } | 164 | } |
163 | expr(p); | 165 | |
164 | if !p.at(T![')']) { | 166 | if !p.at(T![')']) { |
165 | saw_comma = true; | 167 | saw_comma = true; |
166 | p.expect(T![,]); | 168 | 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 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] "const" | ||
4 | [email protected] " " | ||
5 | [email protected] | ||
6 | [email protected] "A" | ||
7 | [email protected] ":" | ||
8 | [email protected] " " | ||
9 | [email protected] | ||
10 | [email protected] "(" | ||
11 | [email protected] | ||
12 | [email protected] | ||
13 | [email protected] | ||
14 | [email protected] | ||
15 | [email protected] "i64" | ||
16 | [email protected] "," | ||
17 | [email protected] " " | ||
18 | [email protected] | ||
19 | [email protected] | ||
20 | [email protected] | ||
21 | [email protected] | ||
22 | [email protected] "i64" | ||
23 | [email protected] ")" | ||
24 | [email protected] " " | ||
25 | [email protected] "=" | ||
26 | [email protected] " " | ||
27 | [email protected] | ||
28 | [email protected] "(" | ||
29 | [email protected] | ||
30 | [email protected] "1" | ||
31 | [email protected] "," | ||
32 | [email protected] " " | ||
33 | [email protected] | ||
34 | [email protected] | ||
35 | [email protected] "#" | ||
36 | [email protected] "[" | ||
37 | [email protected] | ||
38 | [email protected] | ||
39 | [email protected] | ||
40 | [email protected] "cfg" | ||
41 | [email protected] | ||
42 | [email protected] "(" | ||
43 | [email protected] "test" | ||
44 | [email protected] ")" | ||
45 | [email protected] "]" | ||
46 | [email protected] " " | ||
47 | [email protected] "2" | ||
48 | [email protected] ")" | ||
49 | [email protected] ";" | ||
50 | [email protected] "\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); | |||