Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Sep 15, 2024
1 parent bb6eb56 commit 82aa17e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
5 changes: 3 additions & 2 deletions src/elements/arithmetic_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use super::word::Word;
pub struct ArithmeticExpr {
pub text: String,
elements: Vec<Elem>,
paren_stack: Vec<char>,
output_base: String,
hide_base: bool,
}
Expand Down Expand Up @@ -48,6 +47,9 @@ impl ArithmeticExpr {
}

pub fn eval_elems(&mut self, core: &mut ShellCore) -> Result<Elem, String> {
if self.elements.len() == 0 {
return Err("operand expexted (error token: \")\")".to_string());
}
let es = match self.decompose_increments() {
Ok(data) => data,
Err(err_msg) => return Err(err_msg),
Expand Down Expand Up @@ -177,7 +179,6 @@ impl ArithmeticExpr {
ArithmeticExpr {
text: String::new(),
elements: vec![],
paren_stack: vec![],
output_base: "10".to_string(),
hide_base: false,
}
Expand Down
8 changes: 1 addition & 7 deletions src/elements/arithmetic_expr/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ use super::{elem, float, int, rev_polish, trenary, word};
pub fn pop_operand(stack: &mut Vec<Elem>, core: &mut ShellCore) -> Result<Elem, String> {
match stack.pop() {
Some(Elem::Word(w, inc)) => word::to_operand(&w, 0, inc, core),
Some(Elem::InParen(mut a)) => {
if a.elements.len() == 0 {
return Err("operand expected".to_string());
}

a.eval_elems(core)
},
Some(Elem::InParen(mut a)) => a.eval_elems(core),
Some(elem) => Ok(elem),
None => Err("no operand".to_string()),
}
Expand Down
21 changes: 0 additions & 21 deletions src/elements/arithmetic_expr/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl ArithmeticExpr {
return false;
}

ans.paren_stack.push( '(' );
ans.text += &feeder.consume(1);

let arith = Self::parse(feeder, core);
Expand All @@ -138,30 +137,10 @@ impl ArithmeticExpr {
}

ans.text += &arith.as_ref().unwrap().text;
ans.paren_stack.pop();
ans.elements.push( Elem::InParen(arith.unwrap()) );

ans.text += &feeder.consume(1);
return true;

/*
if feeder.starts_with("(") {
ans.paren_stack.push( '(' );
ans.elements.push( Elem::LeftParen );
ans.text += &feeder.consume(1);
return true;
}
if feeder.starts_with(")") {
if let Some('(') = ans.paren_stack.last() {
ans.paren_stack.pop();
ans.elements.push( Elem::RightParen );
ans.text += &feeder.consume(1);
return true;
}
}
*/
}

fn eat_binary_operator(feeder: &mut Feeder, ans: &mut Self, core: &mut ShellCore) -> bool {
Expand Down

0 comments on commit 82aa17e

Please sign in to comment.