pub enum Node<'ast> {
Show 19 variants
Null,
Bool(bool),
Number(&'ast Number),
String(&'ast str),
StringChunks(&'ast [StringChunk<Ast<'ast>>]),
Fun {
args: &'ast [Pattern<'ast>],
body: &'ast Ast<'ast>,
},
Let {
bindings: &'ast [LetBinding<'ast>],
body: &'ast Ast<'ast>,
rec: bool,
},
App {
head: &'ast Ast<'ast>,
args: &'ast [Ast<'ast>],
},
Var(LocIdent),
EnumVariant {
tag: LocIdent,
arg: Option<&'ast Ast<'ast>>,
},
Record(&'ast Record<'ast>),
IfThenElse {
cond: &'ast Ast<'ast>,
then_branch: &'ast Ast<'ast>,
else_branch: &'ast Ast<'ast>,
},
Match(Match<'ast>),
Array(&'ast [Ast<'ast>]),
PrimOpApp {
op: &'ast PrimOp,
args: &'ast [Ast<'ast>],
},
Annotated {
annot: &'ast Annotation<'ast>,
inner: &'ast Ast<'ast>,
},
Import(Import<'ast>),
Type(&'ast Type<'ast>),
ParseError(&'ast ParseError),
}Expand description
A node of the Nickel AST.
Nodes are built by the parser and then mostly traversed immutably. Such nodes are optimized for sharing (hence immutability) and for size, as the size of an enum can grow quite quickly in Rust. In particular, any data that is bigger than a few words isn’t usually owned but rather a reference to some arena-allocated data
Using an arena has another advantage: the data is allocated in the same order as the AST is built. This means that even if there are reference indirections, the children of a node are most likely close to the node itself in memory, which should be good for cache locality.
Variants§
Null
The null value.
Bool(bool)
A boolean value.
Number(&'ast Number)
A number.
A number is an arbitrary-precision rational in Nickel. It’s not small and thus we put it behind a reference to avoid size bloat.
String(&'ast str)
A string literal.
StringChunks(&'ast [StringChunk<Ast<'ast>>])
A string containing interpolated expressions, represented as a list of either literals or expressions.
As opposed to nickel_lang_core::term::Term::StrChunks, the chunks are stored in the original order:
"hello%{var}" will give ["hello", var].
Fun
A function.
Let
A let block.
App
An application to one or more arguments.
Var(LocIdent)
A variable.
EnumVariant
An enum variant (an algebraic datatype).
Variants have at most one argument: variants with no arguments are often called simply enum tags. Note that one can just use a record as an argument to emulate variants with multiple arguments.
Record(&'ast Record<'ast>)
A record.
IfThenElse
An if-then-else expression.
Match(Match<'ast>)
A match expression. This expression is still to be applied to an argument to match on.
Array(&'ast [Ast<'ast>])
An array.
PrimOpApp
An n-ary primitive operation application. As opposed to a traditional function application:
- The function part is necessarily a primitive operation.
- The arguments are forced before entering the
Annotated
A term with a type and/or contract annotation.
Import(Import<'ast>)
An import.
Type(&'ast Type<'ast>)
A type in term position, such as in let my_contract = Number -> Number in ....
During evaluation, this will get turned into a contract.
ParseError(&'ast ParseError)
A term that couldn’t be parsed properly. Used by the LSP to handle partially valid programs.
Implementations§
Source§impl<'ast> Node<'ast>
impl<'ast> Node<'ast>
Sourcepub fn try_str_chunk_as_static_str(&self) -> Option<String>
pub fn try_str_chunk_as_static_str(&self) -> Option<String>
Tries to extract a static literal from string chunks.
This methods returns a Some(..) when the term is a Node::StringChunks and all the
chunks are StringChunk::Literal
Trait Implementations§
Source§impl CloneTo for Node<'_>
impl CloneTo for Node<'_>
impl Allocable for Node<'_>
impl<'ast> Eq for Node<'ast>
impl<'ast> StructuralPartialEq for Node<'ast>
Auto Trait Implementations§
impl<'ast> Freeze for Node<'ast>
impl<'ast> RefUnwindSafe for Node<'ast>
impl<'ast> Send for Node<'ast>
impl<'ast> Sync for Node<'ast>
impl<'ast> Unpin for Node<'ast>
impl<'ast> UnsafeUnpin for Node<'ast>
impl<'ast> UnwindSafe for Node<'ast>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more