add classifications and occurrence counting

This commit is contained in:
Mark Thom
2022-10-04 09:24:37 -06:00
committed by Mark
parent d565f5901b
commit b9c9de5222
15 changed files with 153 additions and 148 deletions

View File

@@ -572,6 +572,44 @@ impl Literal {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Var {
Generated(usize),
Named(Rc<String>),
}
impl From<String> for Var {
#[inline(always)]
fn from(value: String) -> Var {
Var::Named(Rc::new(value))
}
}
impl From<&str> for Var {
#[inline(always)]
fn from(value: &str) -> Var {
Var::Named(Rc::new(value.to_owned()))
}
}
impl Var {
#[inline(always)]
pub fn as_str(&self) -> Option<&str> {
match self {
Var::Generated(_) => None,
Var::Named(value) => Some(&value),
}
}
#[inline(always)]
pub fn to_string(&self) -> String {
match self {
Var::Generated(n) => format!("_{}", n),
Var::Named(value) => value.to_string(),
}
}
}
#[derive(Debug, Clone)]
pub enum Term {
AnonVar,
@@ -582,7 +620,7 @@ pub enum Term {
// other PartialString variants in as_partial_string.
PartialString(Cell<RegType>, String, Box<Term>),
CompleteString(Cell<RegType>, Atom),
Var(Cell<VarReg>, Rc<String>),
Var(Cell<VarReg>, Var),
}
impl Term {

View File

@@ -8,7 +8,6 @@ use crate::parser::rug::ops::NegAssign;
use std::cell::Cell;
use std::mem;
use std::rc::Rc;
#[derive(Debug, Clone, Copy, PartialEq)]
enum TokenType {
@@ -427,7 +426,7 @@ impl<'a, R: CharRead> Parser<'a, R> {
if v.trim() == "_" {
self.terms.push(Term::AnonVar);
} else {
self.terms.push(Term::Var(Cell::default(), Rc::new(v)));
self.terms.push(Term::Var(Cell::default(), Var::from(v)));
}
TokenType::Term