aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron1
-rw-r--r--src/grammar/expressions/atom.rs19
-rw-r--r--src/syntax_kinds/generated.rs2
-rw-r--r--tests/data/parser/inline/0080_tuple_expr.rs5
-rw-r--r--tests/data/parser/inline/0080_tuple_expr.txt38
5 files changed, 64 insertions, 1 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index 67022b296..a73e4e1f1 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -138,6 +138,7 @@ Grammar(
138 138
139 // atoms 139 // atoms
140 "TUPLE_EXPR", 140 "TUPLE_EXPR",
141 "PAREN_EXPR",
141 "PATH_EXPR", 142 "PATH_EXPR",
142 "LAMBDA_EXPR", 143 "LAMBDA_EXPR",
143 "IF_EXPR", 144 "IF_EXPR",
diff --git a/src/grammar/expressions/atom.rs b/src/grammar/expressions/atom.rs
index 6a0d47d82..4eb638c3c 100644
--- a/src/grammar/expressions/atom.rs
+++ b/src/grammar/expressions/atom.rs
@@ -60,12 +60,29 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
60 Some(done) 60 Some(done)
61} 61}
62 62
63// test tuple_expr
64// fn foo() {
65// ();
66// (1);
67// (1,);
68// }
63fn tuple_expr(p: &mut Parser) -> CompletedMarker { 69fn tuple_expr(p: &mut Parser) -> CompletedMarker {
64 assert!(p.at(L_PAREN)); 70 assert!(p.at(L_PAREN));
65 let m = p.start(); 71 let m = p.start();
66 p.expect(L_PAREN); 72 p.expect(L_PAREN);
73
74 let mut saw_comma = false;
75 let mut saw_expr = false;
76 while !p.at(EOF) && !p.at(R_PAREN) {
77 saw_expr = true;
78 expr(p);
79 if !p.at(R_PAREN) {
80 saw_comma = true;
81 p.expect(COMMA);
82 }
83 }
67 p.expect(R_PAREN); 84 p.expect(R_PAREN);
68 m.complete(p, TUPLE_EXPR) 85 m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR })
69} 86}
70 87
71// test lambda_expr 88// test lambda_expr
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 8dfeb2b82..fe1a6694c 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -128,6 +128,7 @@ pub enum SyntaxKind {
128 STRUCT_PAT, 128 STRUCT_PAT,
129 TUPLE_PAT, 129 TUPLE_PAT,
130 TUPLE_EXPR, 130 TUPLE_EXPR,
131 PAREN_EXPR,
131 PATH_EXPR, 132 PATH_EXPR,
132 LAMBDA_EXPR, 133 LAMBDA_EXPR,
133 IF_EXPR, 134 IF_EXPR,
@@ -353,6 +354,7 @@ impl SyntaxKind {
353 STRUCT_PAT => &SyntaxInfo { name: "STRUCT_PAT" }, 354 STRUCT_PAT => &SyntaxInfo { name: "STRUCT_PAT" },
354 TUPLE_PAT => &SyntaxInfo { name: "TUPLE_PAT" }, 355 TUPLE_PAT => &SyntaxInfo { name: "TUPLE_PAT" },
355 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" }, 356 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" },
357 PAREN_EXPR => &SyntaxInfo { name: "PAREN_EXPR" },
356 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" }, 358 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" },
357 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" }, 359 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" },
358 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" }, 360 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" },
diff --git a/tests/data/parser/inline/0080_tuple_expr.rs b/tests/data/parser/inline/0080_tuple_expr.rs
new file mode 100644
index 000000000..e4f774280
--- /dev/null
+++ b/tests/data/parser/inline/0080_tuple_expr.rs
@@ -0,0 +1,5 @@
1fn foo() {
2 ();
3 (1);
4 (1,);
5}
diff --git a/tests/data/parser/inline/0080_tuple_expr.txt b/tests/data/parser/inline/0080_tuple_expr.txt
new file mode 100644
index 000000000..bf0223c1c
--- /dev/null
+++ b/tests/data/parser/inline/0080_tuple_expr.txt
@@ -0,0 +1,38 @@
1FILE@[0; 40)
2 FN_ITEM@[0; 40)
3 FN_KW@[0; 2)
4 NAME@[2; 6)
5 WHITESPACE@[2; 3)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 9)
8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9)
11 BLOCK_EXPR@[9; 40)
12 L_CURLY@[9; 10)
13 EXPR_STMT@[10; 23)
14 TUPLE_EXPR@[10; 17)
15 WHITESPACE@[10; 15)
16 L_PAREN@[15; 16)
17 R_PAREN@[16; 17)
18 SEMI@[17; 18)
19 WHITESPACE@[18; 23)
20 EXPR_STMT@[23; 32)
21 PAREN_EXPR@[23; 26)
22 L_PAREN@[23; 24)
23 LITERAL@[24; 25)
24 INT_NUMBER@[24; 25) "1"
25 R_PAREN@[25; 26)
26 SEMI@[26; 27)
27 WHITESPACE@[27; 32)
28 EXPR_STMT@[32; 38)
29 TUPLE_EXPR@[32; 36)
30 L_PAREN@[32; 33)
31 LITERAL@[33; 34)
32 INT_NUMBER@[33; 34) "1"
33 COMMA@[34; 35)
34 R_PAREN@[35; 36)
35 SEMI@[36; 37)
36 WHITESPACE@[37; 38)
37 R_CURLY@[38; 39)
38 WHITESPACE@[39; 40)