Make sigil field private

This commit is contained in:
greg 2018-02-24 14:39:45 -08:00
parent e7cabb2a79
commit 4333563d03
2 changed files with 13 additions and 7 deletions

View File

@ -2,18 +2,21 @@ use std::rc::Rc;
#[derive(Debug, PartialEq, Clone)]
pub struct BinOp {
pub sigil: Rc<String>
sigil: Rc<String>
}
#[derive(Debug, PartialEq, Clone)]
pub struct PrefixOp {
pub sigil: Rc<String>
sigil: Rc<String>
}
impl BinOp {
pub fn from_sigil(sigil: Rc<String>) -> BinOp {
BinOp { sigil }
}
pub fn sigil(&self) -> &Rc<String> {
&self.sigil
}
pub fn min_precedence() -> i32 {
i32::min_value()
}
@ -31,6 +34,9 @@ impl PrefixOp {
pub fn from_sigil(sigil: Rc<String>) -> PrefixOp {
PrefixOp { sigil }
}
pub fn sigil(&self) -> &Rc<String> {
&self.sigil
}
pub fn is_prefix(op: &str) -> bool {
match op {
"+" | "-" | "!" | "~" => true,

View File

@ -176,8 +176,9 @@ impl<'a> State<'a> {
use self::FullyEvaluatedExpr::*;
let evaled_lhs = self.eval_expr(*lhs)?;
let evaled_rhs = self.eval_expr(*rhs)?;
let sigil: &str = op.sigil.as_ref().as_str();
Ok(match (sigil, evaled_lhs, evaled_rhs) {
let sigil = op.sigil();
//let sigil: &str = op.sigil().as_ref().as_str();
Ok(match (sigil.as_str(), evaled_lhs, evaled_rhs) {
("+", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l + r),
("++", Str(s1), Str(s2)) => Str(format!("{}{}", s1, s2)),
("-", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l - r),
@ -191,10 +192,9 @@ impl<'a> State<'a> {
fn eval_prefix_exp(&mut self, op: PrefixOp, expr: Box<Expression>) -> EvalResult<FullyEvaluatedExpr> {
use self::FullyEvaluatedExpr::*;
let evaled_expr = self.eval_expr(*expr)?;
let sigil = op.sigil();
let sigil: &str = op.sigil.as_ref().as_str();
Ok(match (sigil, evaled_expr) {
Ok(match (sigil.as_str(), evaled_expr) {
("!", Bool(true)) => Bool(false),
("!", Bool(false)) => Bool(true),
("-", UnsignedInt(n)) => SignedInt(-1*(n as i64)),