chore: create helpers for expression testing in semantic analysis
This commit is contained in:
parent
71095deaa0
commit
4760eea8f4
@ -350,19 +350,30 @@ impl SemanticCheck for Expression<'_> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
lexic::token::Token,
|
||||
lexic::{self, get_tokens, token::Token},
|
||||
semantic::{impls::SemanticCheck, std::populate, symbol_table::SymbolTable},
|
||||
syntax::ast::{
|
||||
syntax::{
|
||||
ast::{
|
||||
functions::{ArgumentsList, FunctionCall},
|
||||
Expression,
|
||||
},
|
||||
parseable::Parseable,
|
||||
},
|
||||
};
|
||||
|
||||
fn t(i: &str) -> Vec<Token> {
|
||||
get_tokens(&i.into()).unwrap()
|
||||
}
|
||||
fn exp<'a>(t: &'a Vec<Token>) -> Expression<'a> {
|
||||
Expression::try_parse(t, 0).unwrap().0
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_error_on_undefined_symbol() {
|
||||
// source code: `print()`
|
||||
let expr_token = Token::new_identifier("print".into(), 0);
|
||||
let expr_function = Expression::Identifier(&expr_token);
|
||||
let b = t("print()");
|
||||
let expr_function = exp(&b);
|
||||
|
||||
let arguments = ArgumentsList {
|
||||
arguments: vec![],
|
||||
paren_open_pos: 5,
|
||||
|
@ -4,6 +4,10 @@ use super::symbol_table::SymbolTable;
|
||||
|
||||
/// Allows this type to have it's semantics checked.
|
||||
pub trait SemanticCheck {
|
||||
/// Checks the semantics of this AST node and performs typechecking
|
||||
///
|
||||
/// Types are provided by the Typed trait, because not every AST node
|
||||
/// will have a defined type
|
||||
fn check_semantics(&self, scope: &SymbolTable) -> Result<(), MistiError>;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::error_handling::MistiError;
|
||||
|
||||
mod functions;
|
||||
mod parseable;
|
||||
pub mod parseable;
|
||||
mod parsers;
|
||||
mod utils;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user