1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use nodes::expr::Expr;
use uuid::Uuid;
#[derive(Debug)]
pub enum ImportTarget<'c> {
Function { symbol: &'c str },
}
#[derive(Debug)]
pub enum Body<'c> {
List { items: Vec<Body<'c>> },
Text { value: &'c str, line: usize },
Print { expr: Box<Expr<'c>>, line: usize },
Import {
source: Box<Expr<'c>>,
targets: Vec<(Uuid, &'c str, ImportTarget<'c>)>,
line: usize
},
Macro {
name: &'c str,
body: Box<Body<'c>>,
arguments: Vec<(Option<&'c str>, Expr<'c>)>,
line: usize
}
}
impl<'c> Body<'c> {
pub fn new() -> Body<'c> {
Body::List { items: Vec::new() }
}
pub fn expect_print<'r>(&'r self) -> &'r Expr<'c> {
match *self {
Body::Print { expr: ref e, .. } => e,
ref what => panic!("Expected expect_print to return Expr but received {:?}", what),
}
}
pub fn expect_list<'r>(&'r self) -> &'r Vec<Body<'c>> {
match *self {
Body::List { items: ref list } => list,
ref what => panic!("Expected expect_list to return Vec but received {:?}", what),
}
}
}