Replace owned strings with references in expressions
This commit is contained in:
parent
bab9cd1e1a
commit
c23697d386
1 changed files with 10 additions and 10 deletions
20
src/expr.rs
20
src/expr.rs
|
|
@ -3,11 +3,11 @@ use miette::{miette, Context, Result};
|
|||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Expr {
|
||||
Literal(String),
|
||||
Not(Box<Expr>),
|
||||
And(Vec<Expr>),
|
||||
Or(Vec<Expr>),
|
||||
pub enum Expr<'s> {
|
||||
Literal(&'s str),
|
||||
Not(Box<Expr<'s>>),
|
||||
And(Vec<Expr<'s>>),
|
||||
Or(Vec<Expr<'s>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -88,11 +88,11 @@ impl<'s> Iterator for Tokanizer<'s> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Expr {
|
||||
fn parse_expr(tokanizer: &mut Tokanizer) -> Result<Expr> {
|
||||
impl<'s> Expr<'s> {
|
||||
fn parse_expr(tokanizer: &mut Tokanizer<'s>) -> Result<Expr<'s>> {
|
||||
if let Some(token) = tokanizer.next().transpose()? {
|
||||
match token {
|
||||
Token::Literal(l) => Ok(Expr::Literal(l.to_string())),
|
||||
Token::Literal(l) => Ok(Expr::Literal(l)),
|
||||
Token::Not => Ok(Expr::Not(Box::new(Self::parse_expr(tokanizer)?))),
|
||||
Token::ParenOpen => {
|
||||
let first_expr = Self::parse_expr(tokanizer)?;
|
||||
|
|
@ -157,7 +157,7 @@ impl Expr {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(input: &str) -> Result<Self> {
|
||||
pub fn parse(input: &'s str) -> Result<Self> {
|
||||
let mut v = Vec::new();
|
||||
for (i, line) in input.lines().enumerate() {
|
||||
let mut tokanizer = Tokanizer::new(line);
|
||||
|
|
@ -275,7 +275,7 @@ impl Expr {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_dpll_cnf(self) -> (Vec<Vec<Index>>, HashMap<String, Index>) {
|
||||
pub fn to_dpll_cnf(self) -> (Vec<Vec<Index>>, HashMap<&'s str, Index>) {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
let mut cnf = Vec::new();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue