diff --git a/pymbolic/parser.py b/pymbolic/parser.py index 85f75afa5f5e548a914524c2a6a77bb271f44b93..26cabd41fb8b0d790e29b4dd17d7e8e6651aeca6 100644 --- a/pymbolic/parser.py +++ b/pymbolic/parser.py @@ -469,7 +469,12 @@ class Parser(object): pstate.advance() if pstate.is_at_end() or pstate.next_tag() is _closepar: - left_exp = (left_exp,) + if isinstance(left_exp, (tuple, list)) \ + and not isinstance(left_exp, FinalizedContainer): + # left_expr is a container with trailing commas + pass + else: + left_exp = (left_exp,) else: new_el = self.parse_expression(pstate, _PREC_COMMA) if isinstance(left_exp, (tuple, list)) \ diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index 2d6f3f786a3ef9c60d9299a2907785a4370a3b42..e199c763ba47de2b88b2e13c070a443c5417191f 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -253,8 +253,6 @@ def test_parser(): assert_parse_roundtrip("(3,)") assert_parse_roundtrip("[x + 3, 3, 5]") - # FIXME: trailing commas not allowed - # assert parse("[x + 3, 3, 5]") == parse("[x + 3, 3, 5]") assert_parse_roundtrip("[]") assert_parse_roundtrip("[x]") @@ -289,6 +287,7 @@ def test_parser(): assert_parsed_same_as_python('5+i if i>=0 else (0 if i<-1 else 10)') assert_parsed_same_as_python("0 if 1 if 2 else 3 else 4") assert_parsed_same_as_python("0 if (1 if 2 else 3) else 4") + assert_parsed_same_as_python("(2, 3,)") with pytest.deprecated_call(): parse('1+if(0, 1, 2)')