Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--verify-parse-stmt does nothing #171

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading