From 0903277b692d046cf7f2184dd6b7e167775dfd2d Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 29 Jul 2019 19:44:46 -0700 Subject: [PATCH] simple expression --- schala-lang/language/src/visitor.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/schala-lang/language/src/visitor.rs b/schala-lang/language/src/visitor.rs index 4b30da1..a258186 100644 --- a/schala-lang/language/src/visitor.rs +++ b/schala-lang/language/src/visitor.rs @@ -1,4 +1,13 @@ +use crate::ast::ExpressionKind; -pub trait ASTVisitor { - +pub trait ExpressionKindVisitor { + fn nat_literal(&mut self, n: u64) -> T; +} + +pub fn dispatch(input: &mut ExpressionKind, visitor: &mut dyn ExpressionKindVisitor) -> T { + use ExpressionKind::*; + match input { + NatLiteral(n) => visitor.nat_literal(*n), + _ => panic!() + } }