start tests

This commit is contained in:
greg 2018-11-17 19:24:11 -08:00
parent 401d5aabd6
commit 627a740b0d

View File

@ -1,3 +1,5 @@
use std::rc::Rc;
use ast::*; use ast::*;
pub fn dispatch<T, V: ASTVisitor<T>>(visitor: &mut V, ast: &AST) -> T { pub fn dispatch<T, V: ASTVisitor<T>>(visitor: &mut V, ast: &AST) -> T {
@ -45,7 +47,7 @@ pub trait DeclarationVisitor<T> {
FuncSig(sig) => visitor.func_signature(sig), FuncSig(sig) => visitor.func_signature(sig),
FuncDecl(sig, block) => visitor.func_declaration(sig, block), FuncDecl(sig, block) => visitor.func_declaration(sig, block),
TypeDecl { name, body, mutable } => visitor.type_declaration(name, body, mutable), TypeDecl { name, body, mutable } => visitor.type_declaration(name, body, mutable),
TypeAlias(..) => unimplemented!(), TypeAlias(alias, name) => visitor.type_alias(alias, name),
Binding { .. } => unimplemented!(), Binding { .. } => unimplemented!(),
Impl { .. } => unimplemented!(), Impl { .. } => unimplemented!(),
Interface { .. } => unimplemented!(), Interface { .. } => unimplemented!(),
@ -57,6 +59,7 @@ pub trait DeclarationVisitor<T> {
fn func_signature(&mut self, _sig: &Signature) { } fn func_signature(&mut self, _sig: &Signature) { }
fn func_declaration(&mut self, _sig: &Signature, _block: &Vec<Statement>) { } fn func_declaration(&mut self, _sig: &Signature, _block: &Vec<Statement>) { }
fn type_declaration(&mut self, _name: &TypeSingletonName, _body: &TypeBody, _mutable: &bool) { } fn type_declaration(&mut self, _name: &TypeSingletonName, _body: &TypeBody, _mutable: &bool) { }
fn type_alias(&mut self, _alias: &Rc<String>, _name: &Rc<String>) { }
fn done(&mut self) -> T; fn done(&mut self) -> T;
} }
@ -92,3 +95,20 @@ impl DeclarationVisitor<()> for NullVisitor {
} }
} }
#[cfg(test)]
mod visitor_tests {
use ::tokenizing::{Token, tokenize};
use ::parsing::ParseResult;
use ::ast::AST;
fn parse(input: &str) -> ParseResult<AST> {
let tokens = tokenize(input);
let mut parser = ::parsing::Parser::new(tokens);
parser.parse()
}
#[test]
fn test() {
let q = parse("foo");
}
}