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
Null
Atom(Primitive)
Pair
Implementations
sourceimpl SExp
impl SExp
sourceimpl 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
sourceimpl FromIterator<SExp> for SExp
impl FromIterator<SExp> for SExp
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = SExp>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = SExp>,
Creates a value from an iterator. Read more
sourceimpl IntoIterator for SExp
impl IntoIterator for SExp
impl StructuralPartialEq for SExp
Auto Trait Implementations
impl !RefUnwindSafe for SExp
impl !Send for SExp
impl !Sync for SExp
impl Unpin for SExp
impl !UnwindSafe for SExp
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more