pub enum SExp {
Null,
Atom(Primitive),
Pair {
head: Box<SExp>,
tail: Box<SExp>,
},
}
Expand description
An S-Expression. Can be parsed from a string via FromStr
, or constructed
programmatically.
§Examples
use parsley::SExp;
let null = "()".parse::<SExp>().unwrap();
assert_eq!(null, SExp::Null);
use parsley::SExp;
let parsed = "\"abcdefg\"".parse::<SExp>().unwrap();
assert_eq!(parsed, SExp::from("abcdefg"));
Variants§
Implementations§
Source§impl SExp
impl SExp
Source§impl SExp
impl SExp
Sourcepub fn cons(self, exp: Self) -> Self
pub fn cons(self, exp: Self) -> Self
The natural way to build up a list - from the end to the beginning.
§Example
use parsley::prelude::*;
use parsley::SExp::Null;
let macro_list = sexp![SExp::sym("quote"), ()];
let cons_list = Null.cons(Null).cons(SExp::sym("quote"));
assert_eq!(macro_list, cons_list);
Sourcepub fn sym(sym: &str) -> Self
pub fn sym(sym: &str) -> Self
Convenience method to build a symbolic atom.
§Example
use parsley::prelude::*;
let mut ctx = Context::base();
// A null list is an empty application
assert!(ctx.eval(SExp::Null).is_err());
// The symbol `null` (defined in `Context::base`) creates a null when evaluated
let result = ctx.run("null").unwrap();
assert_eq!(result, SExp::Null);
Trait Implementations§
Source§impl FromIterator<SExp> for SExp
impl FromIterator<SExp> for SExp
Source§impl IntoIterator for SExp
impl IntoIterator for SExp
impl StructuralPartialEq for SExp
Auto Trait Implementations§
impl Freeze for SExp
impl !RefUnwindSafe for SExp
impl !Send for SExp
impl !Sync for SExp
impl Unpin for SExp
impl !UnwindSafe for SExp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more