lila/src/parsing/mod.rs
2023-06-12 20:19:19 +02:00

38 lines
1.1 KiB
Rust

pub mod pest;
pub use self::pest::parse;
mod tests {
#[test]
fn test_addition_function() {
use crate::ast::*;
use crate::parsing::pest::parse;
let source = "fn add(a: int, b: int) int { a + b }";
let ast = Ast::FunctionDefinition(FunctionDefinition {
name: Identifier::from("add"),
parameters: vec![
Parameter {
name: Identifier::from("a"),
typ: Type::Int,
},
Parameter {
name: Identifier::from("b"),
typ: Type::Int,
},
],
return_type: Some(Type::Int),
body: Box::new(Block {
statements: vec![],
value: Some(Expr::BinaryExpression(
Box::new(Expr::Identifier(Identifier::from("a"))),
BinaryOperator::Add,
Box::new(Expr::Identifier(Identifier::from("b"))),
)),
}),
});
assert_eq!(parse(source).unwrap(), Ast::Module(vec![ast]));
}
}