Skip to content

Commit dfb9173

Browse files
committed
parser: fix ambiguous grammar rules
1 parent bc7debe commit dfb9173

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/config/config_parser.yy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ lterm_items: /* empty */
309309
| lterm_items_inner sep
310310
;
311311

312-
lterm_items_inner: lterm %dprec 2
312+
lterm_items_inner: lterm %dprec 3
313313
{
314314
$$ = new std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> >();
315315
$$->emplace_back(std::unique_ptr<Expression>($1), EItemInfo{true, @1});
316316
}
317-
| rterm_no_side_effect
317+
| rterm_no_side_effect %dprec 4
318318
{
319319
$$ = new std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> >();
320320
$$->emplace_back(std::unique_ptr<Expression>($1), EItemInfo{false, @1});
@@ -330,7 +330,7 @@ lterm_items_inner: lterm %dprec 2
330330
$$->emplace_back(std::unique_ptr<Expression>($3), EItemInfo{true, @3});
331331
}
332332
}
333-
| lterm_items_inner sep rterm_no_side_effect %dprec 1
333+
| lterm_items_inner sep rterm_no_side_effect %dprec 2
334334
{
335335
if ($1)
336336
$$ = $1;

test/config-ops.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ BOOST_AUTO_TEST_CASE(advanced)
241241
expr = ConfigCompiler::CompileText("<test>", "{{ 3 }}");
242242
func = expr->Evaluate(frame).GetValue();
243243
BOOST_CHECK(func->Invoke() == 3);
244+
245+
expr = ConfigCompiler::CompileText("<test>", "var something; var different; () => { {{ {{{foo}}} }} }()");
246+
auto assertExpectedErr = [](const std::exception& e) {
247+
String message = e.what();
248+
bool isExpectedError = message.Contains("Value computed is not used.");
249+
BOOST_REQUIRE_MESSAGE(isExpectedError, "Unexpected error message: " << message);
250+
return isExpectedError;
251+
};
252+
BOOST_CHECK_EXCEPTION(expr->Evaluate(frame), ScriptError, assertExpectedErr);
253+
254+
expr = ConfigCompiler::CompileText("<test>", "() => { {{ {{{foo}}} }} }()");
255+
BOOST_CHECK_EXCEPTION(expr->Evaluate(frame), ScriptError, assertExpectedErr);
244256
}
245257

246258
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)