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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
lexic::token::Token,
|
lexic::{self, get_tokens, token::Token},
|
||||||
semantic::{impls::SemanticCheck, std::populate, symbol_table::SymbolTable},
|
semantic::{impls::SemanticCheck, std::populate, symbol_table::SymbolTable},
|
||||||
syntax::ast::{
|
syntax::{
|
||||||
|
ast::{
|
||||||
functions::{ArgumentsList, FunctionCall},
|
functions::{ArgumentsList, FunctionCall},
|
||||||
Expression,
|
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]
|
#[test]
|
||||||
fn should_error_on_undefined_symbol() {
|
fn should_error_on_undefined_symbol() {
|
||||||
// source code: `print()`
|
// source code: `print()`
|
||||||
let expr_token = Token::new_identifier("print".into(), 0);
|
let b = t("print()");
|
||||||
let expr_function = Expression::Identifier(&expr_token);
|
let expr_function = exp(&b);
|
||||||
|
|
||||||
let arguments = ArgumentsList {
|
let arguments = ArgumentsList {
|
||||||
arguments: vec![],
|
arguments: vec![],
|
||||||
paren_open_pos: 5,
|
paren_open_pos: 5,
|
||||||
|
@ -4,6 +4,10 @@ use super::symbol_table::SymbolTable;
|
|||||||
|
|
||||||
/// Allows this type to have it's semantics checked.
|
/// Allows this type to have it's semantics checked.
|
||||||
pub trait SemanticCheck {
|
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>;
|
fn check_semantics(&self, scope: &SymbolTable) -> Result<(), MistiError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::error_handling::MistiError;
|
use crate::error_handling::MistiError;
|
||||||
|
|
||||||
mod functions;
|
mod functions;
|
||||||
mod parseable;
|
pub mod parseable;
|
||||||
mod parsers;
|
mod parsers;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user