Files
kraken/kr/src/ast.rs

39 lines
884 B
Rust
Raw Normal View History

use std::rc::Rc;
#[derive(Debug)]
pub enum Form {
Int(i32),
Symbol(String),
Pair(Rc<Form>,Rc<Form>),
DeriComb { se: Rc<Form>, de: Option<String>, params: Rc<Form>, body: Rc<Form> },
PrimComb(String, fn(Rc<Form>, Rc<Form>) -> Rc<Form>),
Nil,
}
impl Form {
pub fn int(&self) -> Option<i32> {
match self {
Form::Int(i) => Some(*i),
_ => None,
}
}
pub fn sym(&self) -> Option<&str> {
match self {
Form::Symbol(s) => Some(s),
_ => None,
}
}
pub fn car(&self) -> Option<Rc<Form>> {
match self {
Form::Pair(car, cdr) => Some(Rc::clone(car)),
_ => None,
}
}
pub fn cdr(&self) -> Option<Rc<Form>> {
match self {
Form::Pair(car, cdr) => Some(Rc::clone(cdr)),
_ => None,
}
}
}