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
49
50
use crate::env::Environment;
use crate::error::Error;
use crate::repr::Expr;
mod env;
pub mod error;
mod eval;
mod funcs;
mod lex;
mod parse;
pub mod repr;
pub struct Furs {
env: Environment,
}
impl Furs {
pub fn new() -> Furs {
let mut env = Environment::new();
funcs::register(&mut env);
Furs { env }
}
pub fn eval(&mut self, input: &str) -> Result<Expr, Error> {
let mut tokens = lex::lex(input);
let ast = parse::parse(&mut tokens)?;
eval::eval(ast, &mut self.env)
}
}
#[macro_use]
mod macros {
#[macro_export]
macro_rules! list {
() => {
std::collections::LinkedList::new();
};
( $( $x:expr ),+ ) => {
{
use std::collections::LinkedList;
let mut temp_list = LinkedList::new();
$(
temp_list.push_back($x);
)+
temp_list
}
};
}
}