Skip to content
This repository has been archived by the owner on Aug 13, 2018. It is now read-only.

Commit

Permalink
Add three tests from Bertsch and Nederhof's '99 paper.
Browse files Browse the repository at this point in the history
These relate to problems with McKenzie's algorithm overly-aggressively pruning
out cycles.
  • Loading branch information
ltratt committed Mar 30, 2018
1 parent 2322811 commit 14e45c6
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/lib/mf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,87 @@ A: 'b';
&vec!["Insert \"a\""]);
}

#[test]
fn test_bertsch_nederhof1() {
// Example from p5 of Bertsch and Nederhof "On Failure of the Pruning Technique in 'Error
// Repair in Shift-reduce Parsers'"
let lexs = "%%
a a
b b
c c
d d
";

let grms = "%start S
%%
S: A A 'a' | 'b';
A: 'c' 'd';
";

let us = "";
let mut costs = HashMap::new();
costs.insert("a", 1);
costs.insert("b", 6);
costs.insert("c", 1);
costs.insert("d", 1);
let (grm, pr) = do_parse_with_costs(RecoveryKind::MF, &lexs, &grms, &us, &costs);
let (_, errs) = pr.unwrap_err();
check_all_repairs(&grm,
errs[0].repairs(),
&vec!["Insert \"c\", Insert \"d\", Insert \"c\", Insert \"d\", Insert \"a\""]);
}

#[test]
fn test_bertsch_nederhof2() {
// Example from p5 of Bertsch and Nederhof "On Failure of the Pruning Technique in 'Error
// Repair in Shift-reduce Parsers'"
let lexs = "%%
a a
c c
d d
";

let grms = "%start S
%%
S: A A 'a';
A: 'c' 'd';
";

let us = "";
let (grm, pr) = do_parse(RecoveryKind::MF, &lexs, &grms, &us);
let (_, errs) = pr.unwrap_err();
check_all_repairs(&grm,
errs[0].repairs(),
&vec!["Insert \"c\", Insert \"d\", Insert \"c\", Insert \"d\", Insert \"a\""]);
}

#[test]
fn test_bertsch_nederhof3() {
// Example from p8 of Bertsch and Nederhof "On Failure of the Pruning Technique in 'Error
// Repair in Shift-reduce Parsers'"
let lexs = "%%
a a
b b
c c
d d
";

let grms = "%start S
%%
S: C D 'a' | D C 'b';
C: 'c';
D: 'd';
";

let us = "";
let (grm, pr) = do_parse(RecoveryKind::MF, &lexs, &grms, &us);
let (_, errs) = pr.unwrap_err();
check_all_repairs(&grm,
errs[0].repairs(),
&vec!["Insert \"c\", Insert \"d\", Insert \"a\"",
"Insert \"d\", Insert \"c\", Insert \"b\""]);
}

#[test]
fn test_counting_shifts() {
let mut c = Cactus::new();
Expand Down

0 comments on commit 14e45c6

Please sign in to comment.