150 lines
2.7 KiB
Rust
150 lines
2.7 KiB
Rust
use log::info;
|
|
use owo_colors::{
|
|
OwoColorize, Style,
|
|
colors::css::{DarkGray, Gray},
|
|
};
|
|
use std::fmt::Display;
|
|
|
|
use crate::ast::Variable;
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub enum ProofType
|
|
{
|
|
Body,
|
|
And,
|
|
Predicate,
|
|
}
|
|
|
|
impl Display for ProofType
|
|
{
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
|
{
|
|
match self
|
|
{
|
|
ProofType::Body => write!(f, "body_prover"),
|
|
ProofType::And => write!(f, "and_prover"),
|
|
ProofType::Predicate => write!(f, "predicate_prover"),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait Tracer
|
|
{
|
|
fn begin_proof(&mut self, proof_type: ProofType) -> Self;
|
|
fn print_step<T: Display>(&mut self, show: T);
|
|
fn end_proof(self);
|
|
}
|
|
|
|
pub struct SimpleTracer
|
|
{
|
|
proof_type: ProofType,
|
|
}
|
|
|
|
impl SimpleTracer
|
|
{
|
|
pub fn new(proof_type: ProofType) -> Self
|
|
{
|
|
Self { proof_type }
|
|
}
|
|
}
|
|
|
|
impl Tracer for SimpleTracer
|
|
{
|
|
fn begin_proof(&mut self, proof_type: ProofType) -> Self
|
|
{
|
|
SimpleTracer { proof_type }
|
|
}
|
|
|
|
fn print_step<T: Display>(&mut self, show: T)
|
|
{
|
|
let str = format!("{}", self.proof_type);
|
|
info!(target: &str, "{}", show);
|
|
}
|
|
|
|
fn end_proof(self)
|
|
{
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
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>()
|
|
};
|
|
print!("{}", "│".style(style));
|
|
}
|
|
self.first = false;
|
|
println!("{}", show);
|
|
let _ = std::io::stdin().read_line(&mut String::new());
|
|
println!("\x1b[2A");
|
|
}
|
|
|
|
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;
|
|
for (i, char) in var.chars().enumerate()
|
|
{
|
|
if char == '['
|
|
{
|
|
idx = Some(i);
|
|
}
|
|
}
|
|
let (var, unique) = var.split_at(idx.unwrap_or(var.len()));
|
|
let unique = unique.fg::<Gray>();
|
|
format!("{}{}", var, unique)
|
|
}
|