Skip to content

Fix comma fodder attributed to wrong AST #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion test_suite/formatter.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -118,7 +121,6 @@ limitations under the License.
f: 3,
},

local f(a, b) = null,
test_field7f: f
(
1,
Expand Down
4 changes: 3 additions & 1 deletion test_suite/formatter.jsonnet.fmt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -118,7 +121,6 @@ limitations under the License.
f: 3,
},

local f(a, b) = null,
test_field7f: f
(
1,
Expand Down
1 change: 1 addition & 0 deletions test_suite/formatter.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"func": null,
"test_field0A": {
"g": 1
},
Expand Down