Rename methods
make reduce() the entry point to evaluation
This commit is contained in:
parent
29d4cb53a4
commit
6bb227d052
@ -52,7 +52,7 @@ impl Evaluator {
|
|||||||
|
|
||||||
pub fn run(&mut self, ast: AST) -> Vec<String> {
|
pub fn run(&mut self, ast: AST) -> Vec<String> {
|
||||||
ast.into_iter().map(|astnode| {
|
ast.into_iter().map(|astnode| {
|
||||||
self.reduce_node(astnode)
|
self.reduce(astnode)
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ impl Evaluable for Expression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Evaluator {
|
impl Evaluator {
|
||||||
fn reduce_node(&mut self, mut node: ASTNode) -> String {
|
fn reduce(&mut self, mut node: ASTNode) -> String {
|
||||||
loop {
|
loop {
|
||||||
node = self.step(node);
|
node = self.step(node);
|
||||||
if !node.is_reducible() {
|
if !node.is_reducible() {
|
||||||
@ -96,10 +96,10 @@ impl Evaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn step(&mut self, node: ASTNode) -> ASTNode {
|
fn step(&mut self, node: ASTNode) -> ASTNode {
|
||||||
self.reduce(node)
|
self.reduce_astnode(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce(&mut self, node: ASTNode) -> ASTNode { //TODO swap the names of this and reduce_node
|
fn reduce_astnode(&mut self, node: ASTNode) -> ASTNode {
|
||||||
use parser::ASTNode::*;
|
use parser::ASTNode::*;
|
||||||
match node {
|
match node {
|
||||||
ExprNode(expr) => {
|
ExprNode(expr) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user