Skip to content

Commit

Permalink
wip: lexical ambiguity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Dec 29, 2023
1 parent 07c895e commit cb9ab7c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ fn main() {
("glr/errors", Box::new(|s| s.parser_algo(ParserAlgo::GLR))),
("glr/forest", Box::new(|s| s.parser_algo(ParserAlgo::GLR))),
("glr/build", Box::new(|s| s.parser_algo(ParserAlgo::GLR))),
(
"glr/lexical_ambiguity",
Box::new(|s| s.parser_algo(ParserAlgo::GLR)),
),
(
"glr/evaluate",
Box::new(|s| {
Expand Down
22 changes: 22 additions & 0 deletions tests/src/glr/lexical_ambiguity/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use rustemo::{rustemo_mod, Parser};
use rustemo_compiler::output_cmp;

rustemo_mod!(most_specific, "/src/glr/lexical_ambiguity");
rustemo_mod!(most_specific_actions, "/src/glr/lexical_ambiguity");

use self::most_specific::MostSpecificParser;

#[test]
fn glr_lexical_ambiguity_most_specific() {
let forest = MostSpecificParser::new().parse("s a 42.42").unwrap();
assert_eq!(forest.solutions(), 2);

let mut trees = String::new();
for tree in &forest {
trees.push_str(&format!("{tree:#?}\n\n"));
}
output_cmp!(
"src/glr/lexical_ambiguity/most_specific.ast",
format!("{trees}")
);
}
15 changes: 15 additions & 0 deletions tests/src/glr/lexical_ambiguity/most_specific.ast
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
"s",
[
"a 42.42",
],
]

[
"s",
[
"a",
"42.42",
],
]

13 changes: 13 additions & 0 deletions tests/src/glr/lexical_ambiguity/most_specific.rustemo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
S: 's' A;
// These two alternative overlaps at the lexical level but the first one wins as
// it uses a string match which is more specific than regex match.
//
// This stategy is by default on but can be turned off in the settings.
A: 'a' Float | Complex;


terminals
Ta: 'a';
Ts: 's';
Float: /\d+\.\d+/;
Complex: /a \d+\.\d+/;
1 change: 1 addition & 0 deletions tests/src/glr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ mod build;
mod errors;
mod evaluate;
mod forest;
mod lexical_ambiguity;
mod special;

0 comments on commit cb9ab7c

Please sign in to comment.