initial commit
This commit is contained in:
commit
43df8c4b0a
9 changed files with 596 additions and 0 deletions
38
src/parsing/mod.rs
Normal file
38
src/parsing/mod.rs
Normal 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]));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue