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.
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"));
Fields of Pair
Iterate over an S-Expression, by reference.
use parsley::prelude::*;
assert_eq!(
sexp![()].iter().next().unwrap(),
&SExp::Null
);
Easy way to check for Null
if you're planning on iterating
Get the length of an S-Expression (vector or list)
use parsley::prelude::*;
assert_eq!(
sexp!['a', "bee", SExp::sym("sea")].len(),
3
);
The natural way to build up a list - from the end to the beginning.
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);
Convenience method to build a symbolic atom.
use parsley::prelude::*;
let mut ctx = Context::base();
assert!(ctx.eval(SExp::Null).is_err());
let result = ctx.run("null").unwrap();
assert_eq!(result, SExp::Null);
Printable type for an expression.
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");
Performs copy-assignment from source
. Read more
type Item = Self
The type of the elements being iterated over.
type IntoIter = SExpIterator
Which kind of iterator are we turning this into?
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The returned type after indexing.
Performs the indexing (container[index]
) operation.
The associated error which can be returned from parsing.
Parses a string s
to return a value of this type. Read more
Converts the given value to a String
. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static