initial commit

This commit is contained in:
Romain Paquet 2023-06-12 20:19:19 +02:00
commit 43df8c4b0a
9 changed files with 596 additions and 0 deletions

38
src/parsing/mod.rs Normal file
View file

@ -0,0 +1,38 @@
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]));
}
}