diff --git a/core/parser.cpp b/core/parser.cpp index 277b7790f..0dd76928d 100644 --- a/core/parser.cpp +++ b/core/parser.cpp @@ -158,16 +158,7 @@ class Parser { got_comma = false; bool first = true; do { - Fodder comma_fodder; Token next = peek(); - if (!first && !got_comma) { - if (next.kind == Token::COMMA) { - Token comma = pop(); - comma_fodder = comma.fodder; - next = peek(); - got_comma = true; - } - } if (next.kind == end) { // got_comma can be true or false here. return pop(); @@ -193,11 +184,15 @@ class Parser { } } AST *expr = parse(MAX_PRECEDENCE); - // TODO(dcunnin): comma fodder attributed to the wrong AST. - // test case: 'f(x /*1*/, y)' - args.emplace_back(id_fodder, id, eq_fodder, expr, comma_fodder); got_comma = false; first = false; + Fodder comma_fodder; + if (peek().kind == Token::COMMA) { + Token comma = pop(); + comma_fodder = comma.fodder; + got_comma = true; + } + args.emplace_back(id_fodder, id, eq_fodder, expr, comma_fodder); } while (true); } diff --git a/test_suite/formatter.jsonnet b/test_suite/formatter.jsonnet index 8795b04d3..a7ca2139e 100644 --- a/test_suite/formatter.jsonnet +++ b/test_suite/formatter.jsonnet @@ -47,6 +47,8 @@ limitations under the License. g: 2, }, + func: /*0*/ f/*1*/(/*2*/ x/*3*/, /*4*/y/*5*/,/*6*/)/*7*/, + test_field0A: { g: 1, }, diff --git a/test_suite/formatter.jsonnet.fmt.golden b/test_suite/formatter.jsonnet.fmt.golden index 1747134ee..fb310f5ca 100644 --- a/test_suite/formatter.jsonnet.fmt.golden +++ b/test_suite/formatter.jsonnet.fmt.golden @@ -47,6 +47,8 @@ limitations under the License. g: 2, }, + func: /*0*/ f/*1*/(/*2*/ x/*3*/, /*4*/ y/*5*/,/*6*/)/*7*/, + test_field0A: { g: 1, },