Skip to content

Commit

Permalink
Fix/improve STS check
Browse files Browse the repository at this point in the history
* axiom/definition display
* page titles
  • Loading branch information
tirix committed Oct 29, 2023
1 parent 436c35c commit 8ae52bf
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/statement.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{{label}}</title>
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="/static/metamath.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
Expand Down
46 changes: 33 additions & 13 deletions src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,29 @@ impl ExpressionRenderer {
self,
proof_tree: &ProofTreeArray,
tree_index: usize,
#[allow(unused_variables)] use_provables: bool,
use_provables: bool,
) -> Result<String, String> {
match self {
ExpressionRenderer::Ascii => Ok(format!(
"<pre> |- {}</pre>",
&String::from_utf8_lossy(&proof_tree.exprs[tree_index])
)),
ExpressionRenderer::Unicode(uni) => uni.render_formula(
&ExpressionRenderer::as_formula(&uni.database, proof_tree, tree_index)?,
),
ExpressionRenderer::Unicode(uni) => {
uni.render_formula(&ExpressionRenderer::as_formula(
&uni.database,
proof_tree,
tree_index,
use_provables,
)?)
}
#[cfg(feature = "sts")]
ExpressionRenderer::Sts(sts) => sts.render_formula(
&ExpressionRenderer::as_formula(&sts.database, proof_tree, tree_index)?,
&ExpressionRenderer::as_formula(
&sts.database,
proof_tree,
tree_index,
use_provables,
)?,
use_provables,
),
}
Expand All @@ -146,18 +156,28 @@ impl ExpressionRenderer {
database: &Database,
proof_tree: &ProofTreeArray,
tree_index: usize,
use_provables: bool,
) -> Result<Formula, String> {
let formula_string = String::from_utf8_lossy(&proof_tree.exprs[tree_index]);
let nset = database.name_result();
let grammar = database.grammar_result();
let provable_symbol = as_str(nset.atom_name(grammar.provable_typecode()));
let formula = grammar
.parse_string(
format!("{} {}", provable_symbol, formula_string.trim()).as_str(),
nset,
)
.map_err(|diag| format!("{} - Could not parse formula: {:?}", formula_string, diag));
formula
let typecodes = if use_provables {
Box::new([grammar.provable_typecode()])
} else {
grammar.typecodes()
};
typecodes
.iter()
.find_map(|tc| {
grammar
.parse_string(
format!("{} {}", as_str(nset.atom_name(*tc)), formula_string.trim())
.as_str(),
nset,
)
.ok()
})
.ok_or_else(|| format!("{} - Could not parse formula", formula_string))
}
}

Expand Down
23 changes: 20 additions & 3 deletions src/sts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use metamath_knife::formula::Label;
use metamath_knife::formula::Substitutions;
use metamath_knife::formula::TypeCode;
use metamath_knife::grammar::FormulaToken;
use metamath_knife::statement::as_str;
use metamath_knife::statement::StatementRef;
use metamath_knife::Database;
Expand Down Expand Up @@ -148,11 +149,27 @@ impl StsDefinition {
}

pub fn check(&self) {
let stmt_parse = self.database.stmt_parse_result();
let provable = self.database.grammar_result().provable_typecode();
let nset = self.database.name_result();
for sref in self.database.statements() {
if sref.statement_type() == StatementType::Axiom {
if let Some(formula) = stmt_parse.get_formula(&sref) {
if let Err(error) = self.format(formula.get_typecode(), formula) {
let mut tokens = sref.math_iter();
let typecode = nset.get_atom(&tokens.next().unwrap());
if typecode != provable {
let formula = self
.database
.grammar_result()
.parse_formula(
&mut tokens.map(|t| FormulaToken {
symbol: nset.get_atom(&t),
span: metamath_knife::Span::NULL,
}),
&[typecode],
false,
nset,
)
.unwrap();
if let Err(error) = self.format(typecode, &formula) {
eprintln!("{}", error);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/toc.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{{name}}</title>
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="/static/metamath.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
Expand Down

0 comments on commit 8ae52bf

Please sign in to comment.