Skip to content

Commit

Permalink
Fix for metamath#135
Browse files Browse the repository at this point in the history
  • Loading branch information
tirix committed Sep 29, 2023
1 parent 81c83b8 commit c01e167
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ impl Grammar {
typecode,
} = *self.nodes.get(next_node.next_node_id)
{
let mut reduce_vec = ReduceVec::new();
let mut reduce_vec = next_node.leaf_label.clone();
for reduce in stored_reduces {
reduce_vec.push(reduce);
}
Expand Down
36 changes: 36 additions & 0 deletions src/grammar_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::nameck::Nameset;
use crate::statement::SegmentId;
use crate::statement::StatementAddress;
use crate::Span;
use simple_logger::SimpleLogger;

macro_rules! sa {
($id: expr, $index:expr) => {
Expand Down Expand Up @@ -329,6 +330,40 @@ macro_rules! grammar_test {
};
}

const ISSUE_135: &[u8] = b"
$c = class wff setvar -> ( ) |- + [ ] $.
$( $j syntax 'setvar' 'class' 'wff'; syntax '|-' as 'wff'; $)
$( $j type_conversions; garden_path ( x => ( ph ; $)
$v x A B ph ps $.
vx $f setvar x $.
wph $f wff ph $.
wps $f wff ps $.
cA $f class A $.
cB $f class B $.
cv $a class x $.
wn $a wff [ A ] $.
wceq $a wff A = B $.
wi $a wff ( ph -> ps ) $.
cdif $a class ( A + B ) $.
ax1 $a |- [ x ] $.
ax2 $a |- ( x = x -> ph ) $.
";

#[test]
fn test_issue_135() {
SimpleLogger::new().without_timestamps().init().unwrap();
let mut db = mkdb(ISSUE_135);
let stmt_parse = db.stmt_parse_pass().clone();
let sref = db.statement(b"ax1").unwrap();
let formula = stmt_parse.get_formula(&sref).unwrap();
assert_eq!(formula.as_ref(&db).as_sexpr(), "(wn (cv vx))");
let sref = db.statement(b"ax2").unwrap();
let formula = stmt_parse.get_formula(&sref).unwrap();
assert_eq!(
formula.as_ref(&db).as_sexpr(),
"(wi (wceq (cv vx) (cv vx)) wph)"
);
}
grammar_test!(
test_missing_float,
b"$c setvar $. $v x $. vx $a setvar x $.",
Expand All @@ -343,6 +378,7 @@ grammar_test!(
2,
Diagnostic::GrammarAmbiguous(sa!(2, 1))
);

grammar_test!(
test_float_not_var,
b"$c setvar $. vx $f setvar x $.",
Expand Down

0 comments on commit c01e167

Please sign in to comment.