From b38c4b32985b14f128f4b080e5a7a25d656f450d Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 23 Oct 2019 14:45:12 -0700 Subject: [PATCH] SymbolTable passing, fix test for duplicate line --- schala-lang/language/src/ast/visitor_test.rs | 2 +- schala-lang/language/src/eval/test.rs | 4 ++-- schala-lang/language/src/symbol_table/test.rs | 16 ++++++++-------- schala-lang/language/src/typechecking.rs | 2 +- schala-lang/language/src/util.rs | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/schala-lang/language/src/ast/visitor_test.rs b/schala-lang/language/src/ast/visitor_test.rs index 7c92a7a..7c9246c 100644 --- a/schala-lang/language/src/ast/visitor_test.rs +++ b/schala-lang/language/src/ast/visitor_test.rs @@ -22,7 +22,7 @@ impl ASTVisitor for Tester { #[test] fn foo() { let mut tester = Tester { count: 0, float_count: 0 }; - let ast = quick_ast(r#" + let (ast, _) = quick_ast(r#" import gragh let a = 20 + 84 diff --git a/schala-lang/language/src/eval/test.rs b/schala-lang/language/src/eval/test.rs index 36b8281..c3971b4 100644 --- a/schala-lang/language/src/eval/test.rs +++ b/schala-lang/language/src/eval/test.rs @@ -10,10 +10,10 @@ use crate::reduced_ast::reduce; use crate::eval::State; fn evaluate_all_outputs(input: &str) -> Vec> { - let source_map = Rc::new(RefCell::new(SourceMap::new())); + let (mut ast, source_map) = crate::util::quick_ast(input); + let source_map = Rc::new(RefCell::new(source_map)); let symbol_table = Rc::new(RefCell::new(SymbolTable::new(source_map))); let mut state = State::new(symbol_table); - let mut ast = crate::util::quick_ast(input); state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap(); { let mut scope_resolver = ScopeResolver::new(state.symbol_table_handle.clone()); diff --git a/schala-lang/language/src/symbol_table/test.rs b/schala-lang/language/src/symbol_table/test.rs index 20cea64..7f69c87 100644 --- a/schala-lang/language/src/symbol_table/test.rs +++ b/schala-lang/language/src/symbol_table/test.rs @@ -7,9 +7,9 @@ use crate::util::quick_ast; use crate::source_map; fn add_symbols_from_source(src: &str) -> (SymbolTable, Result<(), String>) { - let source_map = Rc::new(RefCell::new(source_map::SourceMap::new())); + let (ast, source_map) = quick_ast(src); + let source_map = Rc::new(RefCell::new(source_map)); let mut symbol_table = SymbolTable::new(source_map); - let ast = quick_ast(src); let result = symbol_table.add_top_level_symbols(&ast); (symbol_table, result) } @@ -54,15 +54,15 @@ fn no_duplicates() { #[test] fn no_duplicates_2() { let source = r#" - let a = 20; - let q = 39; - let a = 30; + let x = 9 + let a = 20 + let q = 39 + let a = 30 "#; let (_, output) = add_symbols_from_source(source); let output = output.unwrap_err(); - println!("OUTPUT: {:?}", output); - assert!(output.contains("Duplicate")); - assert!(output.contains("Line 3")); + assert!(output.contains("Duplicate definition: a")); + assert!(output.contains("already defined at 2")); } #[test] diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index ad274f8..0284806 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -461,7 +461,7 @@ mod typechecking_tests { macro_rules! assert_type_in_fresh_context { ($string:expr, $type:expr) => { let mut tc = TypeContext::new(); - let ref ast = crate::util::quick_ast($string); + let (ref ast, _) = crate::util::quick_ast($string); let ty = tc.typecheck(ast).unwrap(); assert_eq!(ty, $type) } diff --git a/schala-lang/language/src/util.rs b/schala-lang/language/src/util.rs index d482cde..51a0847 100644 --- a/schala-lang/language/src/util.rs +++ b/schala-lang/language/src/util.rs @@ -48,11 +48,11 @@ impl<'a, T, V> ScopeStack<'a, T, V> where T: Hash + Eq { /// this is intended for use in tests, and does no error-handling whatsoever #[allow(dead_code)] -pub fn quick_ast(input: &str) -> crate::ast::AST { +pub fn quick_ast(input: &str) -> (crate::ast::AST, crate::source_map::SourceMap) { let mut source_map = crate::source_map::SourceMap::new(); let tokens = crate::tokenizing::tokenize(input); let mut parser = crate::parsing::Parser::new(tokens, &mut source_map); - parser.parse().unwrap() + (parser.parse().unwrap(), source_map) } #[allow(unused_macros)]