rename function

This commit is contained in:
greg 2019-11-11 03:53:51 -08:00
parent 2d0f558415
commit ad385d2f4f
2 changed files with 6 additions and 6 deletions

View File

@ -56,20 +56,20 @@ pub trait ExpressionVisitor {
fn done(&mut self, kind: Self::Output, anno: Option<Self::Output>) -> Self::Output;
}
pub fn dispatch_expression_visitor<T>(input: &Expression, visitor: &mut dyn ExpressionVisitor<Output=T>) -> Result<T, String> {
pub fn dispatch_expression<T>(input: &Expression, visitor: &mut dyn ExpressionVisitor<Output=T>) -> Result<T, String> {
let output = match input.kind {
ExpressionKind::NatLiteral(ref n) => visitor.nat_literal(n),
ExpressionKind::StringLiteral(ref s) => visitor.string_literal(s),
ExpressionKind::BinExp(ref op, ref lhs, ref rhs) => {
let lhs = dispatch_expression_visitor(lhs, visitor)?;
let rhs = dispatch_expression_visitor(rhs, visitor)?;
let lhs = dispatch_expression(lhs, visitor)?;
let rhs = dispatch_expression(rhs, visitor)?;
visitor.binexp(op, lhs, rhs)
},
ExpressionKind::TupleLiteral(ref exprs) => {
let mut output = vec![];
for ex in exprs {
output.push(dispatch_expression_visitor(&ex, visitor)?);
output.push(dispatch_expression(&ex, visitor)?);
}
visitor.tuple_literal(output)
},

View File

@ -1,7 +1,7 @@
#![cfg(test)]
use crate::ast::*;
use crate::ast::visitor::{ASTVisitor, ExpressionVisitor, dispatch_expression_visitor};
use crate::ast::visitor::*;
use crate::ast::walker;
use crate::util::quick_ast;
@ -95,6 +95,6 @@ fn new_visitor() {
let expr: Expression = make_expr("7+\"nueces\"*(33,32)");
let mut printer = ExprPrinter { };
let s = dispatch_expression_visitor(&expr, &mut printer).unwrap();
let s = dispatch_expression(&expr, &mut printer).unwrap();
assert_eq!(s, r#"7 + "nueces" * (33, 32, )"#);
}