use std::rc::Rc; use crate::ast::*; use crate::ast::visitor::ASTVisitor; pub fn ast(v: &mut V, ast: &AST) { v.block(&ast.statements); } pub fn block(v: &mut V, block: &Vec) { for statement in block { v.statement(statement); } } pub fn statement(v: &mut V, statement: &Statement) { use StatementKind::*; match statement.kind { Expression(ref expr) => v.expression(expr), Declaration(ref decl) => v.declaration(decl), Import(ref import_spec) => v.import(import_spec), } } pub fn declaration(v: &mut V, decl: &Declaration) { use Declaration::*; match decl { FuncSig(sig) => { v.signature(&sig); }, FuncDecl(sig, block) => { v.signature(&sig); v.block(&block); }, TypeDecl { .. } => unimplemented!(), TypeAlias(_, _) => unimplemented!(), Binding { name, constant, type_anno, expr } => { v.binding(name, *constant, type_anno.as_ref(), expr); }, /* Impl { type_name: TypeIdentifier, interface_name: Option, block: Vec, }, Interface { name: Rc, signatures: Vec } */ _ => (), } } pub fn expression(v: &mut V, expression: &Expression) { v.expression_kind(&expression.kind); v.maybe_type_identifier(expression.type_anno.as_ref()); } pub fn maybe_type_identifier(v: &mut V, maybe_ty_identifier: Option<&TypeIdentifier>) { } pub fn expression_kind(v: &mut V, expression_kind: &ExpressionKind) { use ExpressionKind::*; match expression_kind { NatLiteral(n) => v.nat_literal(*n), FloatLiteral(f) => v.float_literal(*f), StringLiteral(s) => v.string_literal(s), BoolLiteral(b) => v.bool_literal(*b), BinExp(op, lhs, rhs) => v.binexp(op, lhs, rhs), PrefixExp(op, arg) => v.prefix_exp(op, arg), TupleLiteral(exprs) => { for expr in exprs { v.expression(expr); } }, Value(name) => v.qualified_name(name), NamedStruct { name, fields } => v.named_struct(name, fields), _ => (), } /* Call { f: Box, arguments: Vec, }, Index { indexee: Box, indexers: Vec, }, IfExpression { discriminator: Box, body: Box, }, WhileExpression { condition: Option>, body: Block, }, ForExpression { enumerators: Vec, body: Box, }, Lambda { params: Vec, type_anno: Option, body: Block, }, ListLiteral(Vec), } */ }