Skip to main content

AstNode

Enum AstNode 

Source
pub enum AstNode {
Show 29 variants String(String), Name(String), Number(f64), Boolean(bool), Null, Undefined, Placeholder, Regex { pattern: String, flags: String, }, Variable(String), ParentVariable(String), Path { steps: Vec<PathStep>, }, Binary { op: BinaryOp, lhs: Box<AstNode>, rhs: Box<AstNode>, }, Unary { op: UnaryOp, operand: Box<AstNode>, }, Function { name: String, args: Vec<AstNode>, is_builtin: bool, }, Call { procedure: Box<AstNode>, args: Vec<AstNode>, }, Lambda { params: Vec<String>, body: Box<AstNode>, signature: Option<String>, thunk: bool, }, Array(Vec<AstNode>), Object(Vec<(AstNode, AstNode)>), ObjectTransform { input: Box<AstNode>, pattern: Vec<(AstNode, AstNode)>, }, Block(Vec<AstNode>), Conditional { condition: Box<AstNode>, then_branch: Box<AstNode>, else_branch: Option<Box<AstNode>>, }, Wildcard, Descendant, Predicate(Box<AstNode>), ArrayGroup(Vec<AstNode>), FunctionApplication(Box<AstNode>), Sort { input: Box<AstNode>, terms: Vec<(AstNode, bool)>, }, IndexBind { input: Box<AstNode>, variable: String, }, Transform { location: Box<AstNode>, update: Box<AstNode>, delete: Option<Box<AstNode>>, },
}
Expand description

AST Node types

This enum represents all possible node types in a JSONata expression AST. The structure closely mirrors the JavaScript implementation to facilitate maintenance and upstream synchronization.

Variants§

§

String(String)

String literal (e.g., “hello”, ‘world’)

§

Name(String)

Field/property name in path expressions (e.g., foo in foo.bar) This is distinct from String: Name is a field access, String is a literal value

§

Number(f64)

Number literal

§

Boolean(bool)

Boolean literal

§

Null

Null literal

§

Undefined

Undefined literal (distinct from null in JavaScript semantics) In JSONata, undefined represents “no value” and propagates through expressions

§

Placeholder

Placeholder for partial application (?) When used as a function argument, creates a partially applied function

§

Regex

Regex literal (e.g., /pattern/flags)

Fields

§pattern: String
§flags: String
§

Variable(String)

Variable reference (e.g., $var)

§

ParentVariable(String)

Parent variable reference (e.g., $$)

§

Path

Path expression (e.g., foo.bar) Each step can have stages (like predicates) attached

Fields

§steps: Vec<PathStep>
§

Binary

Binary operation

Fields

§

Unary

Unary operation

Fields

§operand: Box<AstNode>
§

Function

Function call by name

Fields

§name: String
§args: Vec<AstNode>
§is_builtin: bool

Whether this was called with $ prefix (built-in function) True for $string(x), false for string(x)

§

Call

Call an arbitrary expression as a function Used for IIFE patterns like (function($x){...})(5) or chained calls The procedure can be any expression that evaluates to a function

Fields

§procedure: Box<AstNode>
§args: Vec<AstNode>
§

Lambda

Lambda function definition

Fields

§params: Vec<String>
§body: Box<AstNode>
§signature: Option<String>

Optional signature for type checking (e.g., “n-n:n”)

§thunk: bool

Whether this lambda’s body is a thunk (contains tail call that should be optimized) A thunk wraps a tail-position function call for TCO

§

Array(Vec<AstNode>)

Array constructor

§

Object(Vec<(AstNode, AstNode)>)

Object constructor

§

ObjectTransform

Object transform (postfix object constructor): expr{key: value} Transforms the input using the object pattern

Fields

§input: Box<AstNode>
§pattern: Vec<(AstNode, AstNode)>
§

Block(Vec<AstNode>)

Block expression

§

Conditional

Conditional expression (? :)

Fields

§condition: Box<AstNode>
§then_branch: Box<AstNode>
§else_branch: Option<Box<AstNode>>
§

Wildcard

Wildcard operator (*) in path expressions

§

Descendant

Descendant operator (**) in path expressions

§

Predicate(Box<AstNode>)

Array filter/predicate [condition] Can be an index (number) or a predicate (boolean expression)

§

ArrayGroup(Vec<AstNode>)

Array grouping in path expression .[expr] Like Array but doesn’t flatten when used in paths

§

FunctionApplication(Box<AstNode>)

Function application in path expression .(expr) Maps expr over the current value, with $ referring to each element

§

Sort

Sort operator in path expression ^(expr) Sorts the current value by evaluating expr for each element expr can be prefixed with < (ascending, default) or > (descending)

Fields

§input: Box<AstNode>

The input expression to sort

§terms: Vec<(AstNode, bool)>

Sort terms - list of (expression, ascending) tuples

§

IndexBind

Index binding operator #$var Binds the current array index to the specified variable during path traversal For example: arr#$i.field binds the index to $i for each element

Fields

§input: Box<AstNode>

The input expression being indexed

§variable: String

The variable name to bind the index to (without the $ prefix)

§

Transform

Transform operator |location|update[,delete]| Creates a function that transforms objects by:

  1. Evaluating location to find objects to modify
  2. Applying update (object constructor) to each matched object
  3. Optionally deleting fields specified in delete array

Fields

§location: Box<AstNode>

Expression to locate objects to transform

§update: Box<AstNode>

Object constructor expression for updates

§delete: Option<Box<AstNode>>

Optional array of field names to delete

Implementations§

Source§

impl AstNode

Source

pub fn string(s: impl Into<String>) -> Self

Create a string literal node

Source

pub fn number(n: f64) -> Self

Create a number literal node

Source

pub fn boolean(b: bool) -> Self

Create a boolean literal node

Source

pub fn null() -> Self

Create a null literal node

Source

pub fn undefined() -> Self

Create an undefined literal node

Source

pub fn variable(name: impl Into<String>) -> Self

Create a variable reference node

Trait Implementations§

Source§

impl Clone for AstNode

Source§

fn clone(&self) -> AstNode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AstNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AstNode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for AstNode

Source§

fn eq(&self, other: &AstNode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AstNode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AstNode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,