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

Right-recursive productions Fail to Match #118

Closed
amascolo opened this issue Dec 7, 2022 · 0 comments · Fixed by #120
Closed

Right-recursive productions Fail to Match #118

amascolo opened this issue Dec 7, 2022 · 0 comments · Fixed by #120

Comments

@amascolo
Copy link
Contributor

amascolo commented Dec 7, 2022

Looks related to nullable productions: #108 #112 #117

This grammar fails to match when we change a production from left-recursive to right-recursive.

The left-recursive grammar failed on 0.4.0 ≤ bnf ≤ 0.4.1 – the right-recursive still fails on 0.4.0 ≤ bnf ≤ 0.4.3

So this issue must have been partially addressed by @CrockAgile in #109 (0.4.2)

Happy to help battle-testing any proposed fixes ⚔️

use bnf::Grammar;

#[test]
fn test() {
    let input = "aa a";

    let left_recursive: &str = "
    <conjunction> ::= <conjunction> <ws> <predicate> | <predicate>
    <predicate> ::= <string_null_one> | <special-string> '.'

    <string_null_one> ::= <string_null_two>
    <string_null_two> ::= <string_null_three>
    <string_null_three> ::= <string>

    <string> ::= <char_null> | <string> <char_null>
    <special-string> ::= <special-char> | <special-string> <special-char>

    <char_null> ::= <char>
    <char> ::= 'a'

    <special-char> ::= <char_null> | <whitespace>
    <whitespace> ::= ' '

    <ws> ::= ' ' | ' ' <ws>
    ";
    assert!(left_recursive.parse::<Grammar>().unwrap().parse_input(input).next().is_some());

    let right_recursive = left_recursive.replace(
        // rewrite production from left- to right- recursive
        "<string> ::= <char_null> | <string> <char_null>",
        "<string> ::= <char_null> | <char_null> <string>",
    );
    assert!(
        right_recursive.parse::<Grammar>().unwrap().parse_input(input).next().is_some(),
        "right-recursive grammar failed to parse: {input}"
    );
}
CrockAgile added a commit that referenced this issue Dec 22, 2022
CrockAgile added a commit that referenced this issue Feb 4, 2023
CrockAgile added a commit that referenced this issue Feb 11, 2023
* test example from issue #118

* tracing events earley traversals

* stash

* minimal reproduction

* working?

* test nullable productions issue #117

* remove test logging

* repro wip test

* traversal tree wip

* wip, completion ownership hard

* borrow checked

* infinite recursion

* ughhhh

* reverse matching iter walk

* cleanup unused

* hmmm

* hmmmmmm

* rename

* maybe working?

* tomorrow

* limit nullable hack

* all passing

* remove nullability detection

* tracing instead of prints

* log parse trees

* infinite parse benchmark

* polish

* clippy

* snapshot testing

* btree for ordered term completions

* snapshot test bugs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant