Small refactors
This commit is contained in:
parent
83c0c59ae9
commit
af0eb6414a
@ -19,23 +19,3 @@ trait Transpilable {
|
||||
pub fn codegen<'a>(ast: &'a ModuleAST) -> String {
|
||||
ast.transpile()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{lexic, syntax};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_codegen_1() {
|
||||
/*
|
||||
let input = String::from("val id = 322");
|
||||
let tokens = lexic::get_tokens(&input).unwrap();
|
||||
let ast = syntax::construct_ast(&tokens).unwrap();
|
||||
|
||||
let out_str = codegen(&ast);
|
||||
|
||||
assert_eq!("$id = 322;", out_str);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -117,12 +117,12 @@ fn get_line_number(chars: &Vec<char>, target_pos: usize) -> usize {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
error_handling::{MistiError, PrintableError},
|
||||
error_handling::MistiError,
|
||||
lexic::get_tokens,
|
||||
syntax::construct_ast,
|
||||
};
|
||||
|
||||
fn get_error_data(input: String) -> (Vec<char>, MistiError) {
|
||||
fn _get_error_data(input: String) -> (Vec<char>, MistiError) {
|
||||
let tokens = get_tokens(&input).unwrap();
|
||||
let error_holder = construct_ast(&tokens);
|
||||
|
||||
@ -139,38 +139,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_show_an_error_for_missing_binding_name() {
|
||||
let (chars, error) = get_error_data(String::from("val"));
|
||||
let actual_err = error.get_error_str(&chars);
|
||||
// TODO: Write a better error message (something that explains why it failed)
|
||||
let expected_str = format!(
|
||||
"\n{}\n{}\n\n{}\n{}",
|
||||
"val",
|
||||
"^^^",
|
||||
"Syntax error at pos 0:",
|
||||
"There should be an identifier after a `val` token"
|
||||
);
|
||||
|
||||
// assert_eq!(expected_str, actual_err);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_show_an_error_for_missing_equal_operator() {
|
||||
let (chars, error) = get_error_data(String::from("val name"));
|
||||
let actual_err = error.get_error_str(&chars);
|
||||
// TODO: Write a better error message (something that explains why it failed)
|
||||
let expected_str = format!(
|
||||
"\n{}\n{}\n\n{}\n{}",
|
||||
"val name",
|
||||
" ^^^^",
|
||||
"Syntax error at pos 4:",
|
||||
"There should be an equal sign `=` after the identifier"
|
||||
);
|
||||
|
||||
// assert_eq!(expected_str, actual_err);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_get_line() {
|
||||
let input: Vec<char> = String::from("\n\nval number == 50\n\n")
|
||||
|
@ -1,7 +1,5 @@
|
||||
mod symbol_table;
|
||||
|
||||
use symbol_table::{SymbolEntry, SymbolTable};
|
||||
|
||||
// What to do?
|
||||
// 1. Create a mutable symbol table
|
||||
// 2. Walk the AST
|
||||
@ -10,13 +8,11 @@ use symbol_table::{SymbolEntry, SymbolTable};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{borrow::BorrowMut, rc::Rc};
|
||||
|
||||
use super::*;
|
||||
use super::symbol_table::{SymbolEntry, SymbolTable};
|
||||
|
||||
#[test]
|
||||
fn test_1() {
|
||||
let mut global_scope = SymbolTable::new();
|
||||
let global_scope = SymbolTable::new();
|
||||
let main_function = SymbolEntry::new_function(vec![], String::from("Unit"));
|
||||
|
||||
global_scope.insert("main".into(), main_function);
|
||||
@ -44,7 +40,7 @@ mod tests {
|
||||
assert!(main_function_scope.test(&"db_url".into()));
|
||||
assert_eq!(main_function_scope.test(&"non_existant".into()), false);
|
||||
|
||||
let mut add_function_scope = SymbolTable::new_from_parent(&global_scope);
|
||||
let add_function_scope = SymbolTable::new_from_parent(&global_scope);
|
||||
|
||||
add_function_scope.insert("a".into(), SymbolEntry::Variable("Int".into()));
|
||||
add_function_scope.insert("b".into(), SymbolEntry::Variable("Int".into()));
|
||||
|
Loading…
Reference in New Issue
Block a user