aboutsummaryrefslogtreecommitdiff
path: root/src/lisp/mod.rs
blob: 5d8965f93153ccbf7ce5c0df3251b5b028a12cd9 (plain)
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
use std::fmt;

use number::LispNumber;

mod error;
mod lex;
mod number;

#[derive(Debug, PartialEq)]
pub enum LispExpr {
    Number(LispNumber),
    List(Vec<LispExpr>),
    StringLit(String),
    BoolLit(bool),
    Ident(String),
    Function(LispFunction),
}

impl fmt::Display for LispExpr {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            LispExpr::Number(n) => write!(f, "{}", n)?,
            LispExpr::List(l) => {
                for expr in l.iter() {
                    write!(f, " {} ", expr)?
                }
            }
            LispExpr::StringLit(s) => write!(f, "{:?}", s)?,
            LispExpr::BoolLit(b) => {
                if *b {
                    write!(f, "#t")?
                } else {
                    write!(f, "#f")?
                }
            }
            LispExpr::Ident(s) => write!(f, "{}", s)?,
            LispExpr::Function(_) => write!(f, "<#procedure>")?,
        };
        Ok(())
    }
}

pub type Environment = Vec<(String, LispExpr)>;

#[derive(Debug, PartialEq)]
struct LispFunction {}