Somewhat indented trace + Or prover

This commit is contained in:
2026-02-09 22:32:01 +01:00
parent 1ab7d7bf95
commit 5b9df71704
4 changed files with 273 additions and 48 deletions

View File

@ -1,7 +1,10 @@
use std::{default, fmt::Display};
use std::{cell::RefCell, default, fmt::Display, rc::Rc};
use log::info;
use owo_colors::{OwoColorize, colors::css::Gray};
use owo_colors::{
OwoColorize, Style,
colors::css::{DarkGray, Gray},
};
use crate::ast::Variable;
@ -28,8 +31,8 @@ impl Display for ProofType
pub trait Tracer
{
fn begin_proof(&self, proof_type: ProofType) -> Self;
fn print_step<T: Display>(&self, show: T);
fn begin_proof(&mut self, proof_type: ProofType) -> Self;
fn print_step<T: Display>(&mut self, show: T);
fn end_proof(self);
}
@ -48,12 +51,12 @@ impl SimpleTracer
impl Tracer for SimpleTracer
{
fn begin_proof(&self, proof_type: ProofType) -> Self
fn begin_proof(&mut self, proof_type: ProofType) -> Self
{
SimpleTracer { proof_type }
}
fn print_step<T: Display>(&self, show: T)
fn print_step<T: Display>(&mut self, show: T)
{
let str = format!("{}", self.proof_type);
info!(target: &str, "{}", show);
@ -65,6 +68,77 @@ impl Tracer for SimpleTracer
}
}
pub struct IndentedTracer
{
first: bool,
depth: usize,
}
impl IndentedTracer
{
pub fn new() -> IndentedTracer
{
IndentedTracer {
first: true,
depth: 0,
}
}
}
impl Tracer for IndentedTracer
{
fn begin_proof(&mut self, _proof_type: ProofType) -> Self
{
IndentedTracer {
first: true,
depth: self.depth + 1,
}
}
fn print_step<T: Display>(&mut self, show: T)
{
for i in 0..self.depth
{
let style = if i % 2 == 0
{
Style::new().fg::<Gray>()
}
else
{
Style::new().fg::<DarkGray>()
};
if i == self.depth - 1 && self.first
{
print!("{}", "🭋".style(style));
}
else
{
print!("{}", "".style(style));
}
}
self.first = false;
println!("{}", show);
}
fn end_proof(self)
{
drop(self);
}
}
impl Drop for IndentedTracer
{
fn drop(&mut self) {}
}
impl Default for IndentedTracer
{
fn default() -> Self
{
Self::new()
}
}
pub fn colored_var(var: &Variable) -> String
{
let mut idx = None;