aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grammar.ron1
-rw-r--r--src/grammar/expressions/atom.rs19
-rw-r--r--src/syntax_kinds/generated.rs2
3 files changed, 21 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" },