setup a simple lisp
This commit is contained in:
@@ -6,17 +6,17 @@ grammar;
|
||||
|
||||
pub Term: Rc<Form> = {
|
||||
NUM => Rc::new(Form::Int(i32::from_str(<>).unwrap())),
|
||||
SYM => Rc::new(Form::Symbol(<>.to_owned())),
|
||||
SYM => Rc::new(Form::Symbol(<>.to_owned(),None)),
|
||||
"(" <ListInside?> ")" => <>.unwrap_or(Rc::new(Form::Nil)),
|
||||
"'" <Term> => Rc::new(Form::Pair(Rc::new(Form::Symbol("quote".to_owned())), Rc::new(Form::Pair(<>, Rc::new(Form::Nil))))),
|
||||
"'" <Term> => Rc::new(Form::Pair(Rc::new(Form::Symbol("quote".to_owned(),None)), Rc::new(Form::Pair(<>, Rc::new(Form::Nil),None)),None)),
|
||||
"!" <h: Term> <t: Term> => {
|
||||
h.append(t).unwrap()
|
||||
},
|
||||
};
|
||||
ListInside: Rc<Form> = {
|
||||
<Term> => Rc::new(Form::Pair(<>, Rc::new(Form::Nil))),
|
||||
<h: Term> <t: ListInside> => Rc::new(Form::Pair(h, t)),
|
||||
<a: Term> "." <d: Term> => Rc::new(Form::Pair(a, d)),
|
||||
<Term> => Rc::new(Form::Pair(<>, Rc::new(Form::Nil),None)),
|
||||
<h: Term> <t: ListInside> => Rc::new(Form::Pair(h, t,None)),
|
||||
<a: Term> "." <d: Term> => Rc::new(Form::Pair(a, d,None)),
|
||||
}
|
||||
match {
|
||||
"(",
|
||||
|
||||
Reference in New Issue
Block a user