gonna show this

This commit is contained in:
mehbark 2023-07-06 14:31:00 -04:00
parent a4012b8a72
commit 2909fc5ffd

View file

@ -26,6 +26,7 @@ pub fn main() {
}
}
#[must_use]
pub fn do_it() -> Option<String> {
let buf = if let Some(buf) = env::args().nth(1) {
buf
@ -48,6 +49,7 @@ pub enum Sexp {
}
impl Sexp {
#[must_use]
pub fn nil() -> Self {
Self::List(Vec::new())
}
@ -80,7 +82,7 @@ impl Sexp {
pub fn list(&self) -> Option<&[Sexp]> {
match self {
Sexp::Atom(_) => None,
Sexp::List(xs) => Some(&xs),
Sexp::List(xs) => Some(xs),
}
}
@ -204,6 +206,7 @@ pub enum Token<'src> {
Atom(&'src str),
}
#[must_use]
pub fn lex(src: &str) -> Vec<Token> {
// maybe a bad idea?
let mut out = Vec::with_capacity(src.len());
@ -323,14 +326,17 @@ pub enum Rule {
}
impl Rule {
#[must_use]
pub fn forall(vars: Vec<Symbol>, lhs: Sexp, rhs: Sexp) -> Rule {
Rule::Forall { vars, lhs, rhs }
}
#[must_use]
pub fn concrete(lhs: Sexp, rhs: Sexp) -> Rule {
Rule::Concrete { lhs, rhs }
}
#[must_use]
pub fn concrify(&self, sexp: &Sexp) -> Rule {
match self {
Rule::Forall { vars, lhs, rhs } => {
@ -359,6 +365,7 @@ impl Rule {
}
}
#[must_use]
pub fn concretions(&self, targets: &HashSet<&Sexp>) -> HashSet<Rule> {
if self.is_concrete() {
let mut out = HashSet::with_capacity(1);
@ -438,6 +445,7 @@ impl Rule {
matches!(self, Self::Concrete { .. })
}
#[must_use]
pub fn var_replace(from: Symbol, to: &Sexp) -> Rule {
Rule::Concrete {
lhs: Sexp::Atom(from),
@ -480,6 +488,7 @@ impl fmt::Display for Rule {
}
}
#[must_use]
pub fn could_match(vars: Option<&[Symbol]>, lhs: &Sexp, expr: &Sexp) -> bool {
let is_var = |var: &Symbol| -> bool {
match vars {