aboutsummaryrefslogtreecommitdiff
path: root/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'src/grammar')
-rw-r--r--src/grammar/expressions/atom.rs19
1 files changed, 18 insertions, 1 deletions
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