rename function
This commit is contained in:
parent
2d0f558415
commit
ad385d2f4f
@ -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)
|
||||
},
|
||||
|
@ -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, )"#);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user