Skip to content

Commit

Permalink
Fix comma fodder attributed to wrong AST
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkprime committed Apr 26, 2016
1 parent 140d65f commit aaf5599
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
19 changes: 7 additions & 12 deletions core/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions test_suite/formatter.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 2 additions & 0 deletions test_suite/formatter.jsonnet.fmt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit aaf5599

Please sign in to comment.