From 8cf962f1f56717646af7f67642d2724cb27928d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 Aug 2018 17:19:03 +0300 Subject: Paren expr --- src/grammar/expressions/atom.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/grammar') 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 CompletedMarker { assert!(p.at(L_PAREN)); let m = p.start(); p.expect(L_PAREN); + + let mut saw_comma = false; + let mut saw_expr = false; + while !p.at(EOF) && !p.at(R_PAREN) { + saw_expr = true; + expr(p); + if !p.at(R_PAREN) { + saw_comma = true; + p.expect(COMMA); + } + } p.expect(R_PAREN); - m.complete(p, TUPLE_EXPR) + m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR }) } // test lambda_expr -- cgit v1.2.3