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..23da4ef78 100644 --- a/test_suite/formatter.jsonnet +++ b/test_suite/formatter.jsonnet @@ -47,6 +47,9 @@ limitations under the License. g: 2, }, + local f(a, b) = null, + func: /*0*/ f/*1*/(/*2*/ "x"/*3*/, /*4*/"y"/*5*/,/*6*/)/*7*/, + test_field0A: { g: 1, }, @@ -118,7 +121,6 @@ limitations under the License. f: 3, }, - local f(a, b) = null, test_field7f: f ( 1, diff --git a/test_suite/formatter.jsonnet.fmt.golden b/test_suite/formatter.jsonnet.fmt.golden index 1747134ee..0419085a5 100644 --- a/test_suite/formatter.jsonnet.fmt.golden +++ b/test_suite/formatter.jsonnet.fmt.golden @@ -47,6 +47,9 @@ limitations under the License. g: 2, }, + local f(a, b) = null, + func: /*0*/ f/*1*/(/*2*/ "x"/*3*/, /*4*/ "y"/*5*/,/*6*/)/*7*/, + test_field0A: { g: 1, }, @@ -118,7 +121,6 @@ limitations under the License. f: 3, }, - local f(a, b) = null, test_field7f: f ( 1, diff --git a/test_suite/formatter.jsonnet.golden b/test_suite/formatter.jsonnet.golden index 6d3986213..410786497 100644 --- a/test_suite/formatter.jsonnet.golden +++ b/test_suite/formatter.jsonnet.golden @@ -1,4 +1,5 @@ { + "func": null, "test_field0A": { "g": 1 },