Skip to content
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

Band-Aid: fix one of the left recursion bugs (fixes #1047) #1048

Merged
merged 3 commits into from
Oct 18, 2024
Merged
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
24 changes: 23 additions & 1 deletion meta/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,13 @@ fn left_recursion<'a, 'i: 'a>(rules: HashMap<String, &'a ParserNode<'i>>) -> Vec
None
}
ParserExpr::Seq(ref lhs, ref rhs) => {
if is_non_failing(&lhs.expr, rules, &mut vec![trace.last().unwrap().clone()]) {
if is_non_failing(&lhs.expr, rules, &mut vec![trace.last().unwrap().clone()])
|| is_non_progressing(
&lhs.expr,
rules,
&mut vec![trace.last().unwrap().clone()],
)
{
check_expr(rhs, rules, trace)
} else {
check_expr(lhs, rules, trace)
Expand Down Expand Up @@ -1811,6 +1817,22 @@ mod tests {
#[test]
#[should_panic(expected = "grammar error

--> 1:14
|
1 | a = { !\"a\" ~ a }
| ^
|
= rule a is left-recursive (a -> a); pest::pratt_parser might be useful in this case")]
fn non_progressing_left_recursion() {
let input = "a = { !\"a\" ~ a }";
unwrap_or_report(consume_rules(
PestParser::parse(Rule::grammar_rules, input).unwrap(),
));
}

#[test]
#[should_panic(expected = "grammar error

--> 1:7
|
1 | a = { \"a\"* | \"a\" | \"b\" }
Expand Down
Loading