From 36d0c825306120ec2655f1d3d54579bf6992b906 Mon Sep 17 00:00:00 2001 From: Dave Cunningham Date: Mon, 25 Apr 2016 21:33:48 -0400 Subject: [PATCH] Fix comma fodder attributed to wrong AST --- core/parser.cpp | 17 +++++++---------- test_suite/formatter.jsonnet | 2 ++ test_suite/formatter.jsonnet.fmt.golden | 2 ++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/parser.cpp b/core/parser.cpp index 277b7790f..052d6a794 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(); @@ -195,9 +186,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, },