Module evaltrees::cst [−][src]
The concrete syntax tree.
Note that Decl
and Expr
both impl FromStr
; hence they can be parsed
with a simple .parse()
call:
let expr: Expr = "(1 + 2) :: 3 :: []".parse().unwrap(); assert_eq!(expr, Expr::Op(Op::Cons, Box::new(Expr::Op(Op::Add, Box::new(Expr::Literal(Literal::Int(1))), Box::new(Expr::Literal(Literal::Int(2))), )), Box::new(Expr::Op(Op::Cons, Box::new(Expr::Literal(Literal::Int(3))), Box::new(Expr::Literal(Literal::Nil)), )), )); let decl: Decl = "id x = x".parse().unwrap(); assert_eq!(decl, Decl { name: "id".into(), args: vec![ Pattern::Binding("x".into(), ()), ], body: Expr::Variable("x".into()), });
Structs
Decl |
A function or value declaration. |
Enums
Expr |
An expression. |
Functions
parse_decls |
Parses multiple semicolon-terminated decls. |