Fix parser for index and call exprs, remove old test that didn't work, add visitor pattern

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-09-03 18:32:22 -07:00
parent 2fd340a688
commit f8819279f8
6 changed files with 325 additions and 65 deletions

24
src/syn/visit.rs Normal file
View File

@@ -0,0 +1,24 @@
use crate::syn::ast::*;
pub trait Accept<V: Visit + ?Sized> {
fn accept(&self, visitor: &mut V) -> V::Out;
}
pub trait DefaultAccept<V: Visit + ?Sized> {
fn default_accept(&self, visitor: &mut V) -> V::Out;
}
pub trait Visit {
type Out;
fn visit_stmt(&mut self, stmt: &Stmt) -> Self::Out;
fn visit_assign_stmt(&mut self, assign: &AssignStmt) -> Self::Out;
fn visit_lhs_expr(&mut self, lhs_expr: &LhsExpr) -> Self::Out;
fn visit_expr(&mut self, expr: &Expr) -> Self::Out;
fn visit_bin_expr(&mut self, expr: &BinExpr) -> Self::Out;
fn visit_un_expr(&mut self, expr: &UnExpr) -> Self::Out;
fn visit_call_expr(&mut self, expr: &CallExpr) -> Self::Out;
fn visit_index_expr(&mut self, expr: &IndexExpr) -> Self::Out;
fn visit_access_expr(&mut self, expr: &AccessExpr) -> Self::Out;
fn visit_atom(&mut self, atom: &Atom) -> Self::Out;
}