Skip to content

Commit

Permalink
test example from issue #118
Browse files Browse the repository at this point in the history
  • Loading branch information
CrockAgile committed Feb 4, 2023
1 parent 5a51585 commit cf2a121
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,52 @@ mod tests {
assert!(matches!(parses.next(), Some(_)));
}

#[test]
fn issue() {
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}"
);
}

#[test]
fn format_parse_tree() {
let grammar: Grammar = "<dna> ::= <base> | <base> <dna>
Expand Down

0 comments on commit cf2a121

Please sign in to comment.