[][src]Enum parsley::SExp

pub enum SExp {
    Null,
    Atom(Primitive),
    Pair {
        head: Box<SExp>,
        tail: Box<SExp>,
    },
}

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

NullAtom(Primitive)Pair

Fields of Pair

head: Box<SExp>tail: Box<SExp>

Methods

impl SExp
[src]

pub fn iter(&self) -> SExpRefIterator
[src]

Iterate over an S-Expression, by reference.

Example

use parsley::prelude::*;
assert_eq!(
    sexp![()].iter().next().unwrap(),
    &SExp::Null
);

pub fn is_empty(&self) -> bool
[src]

Easy way to check for Null if you're planning on iterating

pub fn len(&self) -> usize
[src]

Get the length of an S-Expression (vector or list)

Example

use parsley::prelude::*;
assert_eq!(
    sexp!['a', "bee", SExp::sym("sea")].len(),
    3
);

impl SExp
[src]

pub fn cons(self, exp: Self) -> Self
[src]

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);

pub fn sym(sym: &str) -> Self
[src]

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);

pub fn type_of(&self) -> &str
[src]

Printable type for an expression.

Example

use parsley::SExp;

assert_eq!(SExp::Null.type_of(), "null");
assert_eq!(SExp::from(3).type_of(), "number");
assert_eq!(SExp::from(true).type_of(), "bool");
assert_eq!(SExp::from((5,)).type_of(), "list");

Trait Implementations

impl Clone for SExp
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl IntoIterator for SExp
[src]

type Item = Self

The type of the elements being iterated over.

type IntoIter = SExpIterator

Which kind of iterator are we turning this into?

impl<T> From<T> for SExp where
    Primitive: From<T>, 
[src]

impl From<()> for SExp
[src]

impl<T> From<(T,)> for SExp where
    SExp: From<T>, 
[src]

impl<T, U> From<(T, U)> for SExp where
    SExp: From<T> + From<U>, 
[src]

impl<T, '_> From<&'_ [T]> for SExp where
    T: Into<SExp> + Clone
[src]

impl<T> From<Vec<T>> for SExp where
    T: Into<SExp>, 
[src]

impl PartialEq<SExp> for SExp
[src]

impl Display for SExp
[src]

impl Debug for SExp
[src]

impl Index<usize> for SExp
[src]

type Output = Self

The returned type after indexing.

impl FromIterator<SExp> for SExp
[src]

impl FromStr for SExp
[src]

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations

impl !Send for SExp

impl !Sync for SExp

Blanket Implementations

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]