Skip to content

Commit aaf5599

Browse files
committed
Fix comma fodder attributed to wrong AST
1 parent 140d65f commit aaf5599

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

core/parser.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,7 @@ class Parser {
158158
got_comma = false;
159159
bool first = true;
160160
do {
161-
Fodder comma_fodder;
162161
Token next = peek();
163-
if (!first && !got_comma) {
164-
if (next.kind == Token::COMMA) {
165-
Token comma = pop();
166-
comma_fodder = comma.fodder;
167-
next = peek();
168-
got_comma = true;
169-
}
170-
}
171162
if (next.kind == end) {
172163
// got_comma can be true or false here.
173164
return pop();
@@ -193,11 +184,15 @@ class Parser {
193184
}
194185
}
195186
AST *expr = parse(MAX_PRECEDENCE);
196-
// TODO(dcunnin): comma fodder attributed to the wrong AST.
197-
// test case: 'f(x /*1*/, y)'
198-
args.emplace_back(id_fodder, id, eq_fodder, expr, comma_fodder);
199187
got_comma = false;
200188
first = false;
189+
Fodder comma_fodder;
190+
if (peek().kind == Token::COMMA) {
191+
Token comma = pop();
192+
comma_fodder = comma.fodder;
193+
got_comma = true;
194+
}
195+
args.emplace_back(id_fodder, id, eq_fodder, expr, comma_fodder);
201196
} while (true);
202197
}
203198

test_suite/formatter.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ limitations under the License.
4747
g: 2,
4848
},
4949

50+
func: /*0*/ f/*1*/(/*2*/ x/*3*/, /*4*/y/*5*/,/*6*/)/*7*/,
51+
5052
test_field0A: {
5153
g: 1,
5254
},

test_suite/formatter.jsonnet.fmt.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ limitations under the License.
4747
g: 2,
4848
},
4949

50+
func: /*0*/ f/*1*/(/*2*/ x/*3*/, /*4*/ y/*5*/,/*6*/)/*7*/,
51+
5052
test_field0A: {
5153
g: 1,
5254
},

0 commit comments

Comments
 (0)