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