Speed sketch beginnings of a Rust implementation of new stripped-down Scheme-like Kraken
This commit is contained in:
37
kr/src/ast.rs
Normal file
37
kr/src/ast.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Form {
|
||||
Int(i32),
|
||||
Symbol(String),
|
||||
Pair(Rc<Form>,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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user