Skip to content

Commit

Permalink
--verify-parse-stmt does nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
digama0 committed Oct 28, 2024
1 parent ed0e85c commit cf8254c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
13 changes: 8 additions & 5 deletions metamath-knife/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ fn main() {
db.typesetting_pass();
}

if cli.verify_parse_stmt {
db.stmt_parse_pass();
db.verify_parse_stmt();
}

if cli.verify_usage {
db.verify_usage_pass();
}
Expand Down Expand Up @@ -225,6 +220,14 @@ fn main() {
.render_diags(diags, |msg| println!("{}", r.render(msg)))
.len();

if cli.verify_parse_stmt {
db.stmt_parse_pass();
let diags = db.verify_parse_stmt();
count += db
.render_diags(diags, |msg| println!("{}", r.render(msg)))
.len();
}

#[cfg(feature = "verify_markup")]
if cli.verify_markup {
use metamath_rs::diag::BibError;
Expand Down
5 changes: 3 additions & 2 deletions metamath-rs/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,10 @@ impl Database {

/// Verify that printing the formulas of this database gives back the original formulas.
/// Requires: [`Database::name_pass`], [`Database::stmt_parse_pass`]
pub fn verify_parse_stmt(&self) {
#[must_use]
pub fn verify_parse_stmt(&self) -> Vec<(StatementAddress, Diagnostic)> {
time(&self.options, "verify_parse_stmt", || {
drop(self.stmt_parse_result().verify(self));
self.stmt_parse_result().verify(self)
})
}

Expand Down
9 changes: 5 additions & 4 deletions metamath-rs/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,13 +1705,14 @@ impl StmtParse {

/// Check that printing parsed statements gives back the original formulas
// TODO(tirix): this could be parallelized
pub(crate) fn verify(&self, db: &Database) -> Result<(), (StatementAddress, Diagnostic)> {
pub(crate) fn verify(&self, db: &Database) -> Vec<(StatementAddress, Diagnostic)> {
let sset = db.parse_result();
let nset = db.name_result();
let mut diags = vec![];
for sps in self.segments.values() {
for (&sa, formula) in &sps.formulas {
let sref = sset.statement(sa);
let math_iter = sref.math_iter().flat_map(|token| {
let math_iter = sref.math_iter().skip(1).flat_map(|token| {
nset.lookup_symbol(token.slice)
.ok_or_else(|| {
(
Expand All @@ -1723,11 +1724,11 @@ impl StmtParse {
});
let fmla_iter = formula.as_ref(db).iter();
if math_iter.ne(fmla_iter) {
return Err((sa, Diagnostic::FormulaVerificationFailed));
diags.push((sa, Diagnostic::FormulaVerificationFailed));
}
}
}
Ok(())
diags
}

/// Writes down all formulas
Expand Down

0 comments on commit cf8254c

Please sign in to comment.