pub enum Expr {
Show 13 variants
Path(Vec<Step>),
Literal(Value),
Neg(Box<Expr>),
Binary(BinOp, Box<Expr>, Box<Expr>),
Pipe(Box<Expr>, Box<Expr>),
Alternative(Box<Expr>, Box<Expr>),
Comma(Vec<Expr>),
Call(String, Vec<Expr>),
Collect(Option<Box<Expr>>),
ObjectConstruct(Vec<(String, Expr)>),
Assign(Box<Expr>, Box<Expr>),
UpdateAssign(Box<Expr>, Box<Expr>),
AddAssign(Box<Expr>, Box<Expr>),
}Expand description
An expression node.
Variants§
Path(Vec<Step>)
A path from the current input; an empty step list is identity (.).
Literal(Value)
A literal scalar value.
Neg(Box<Expr>)
Arithmetic negation.
Binary(BinOp, Box<Expr>, Box<Expr>)
A binary operation.
Pipe(Box<Expr>, Box<Expr>)
left | right - pipe each output of left into right.
Alternative(Box<Expr>, Box<Expr>)
left // right - jq’s alternative: left’s truthy outputs, or -
when there are none (a miss, null, false) - right’s.
Comma(Vec<Expr>)
a, b, c - concatenate output streams.
Call(String, Vec<Expr>)
A function call, e.g. length, select(.x == 1), ltrimstr("pre").
Collect(Option<Box<Expr>>)
[ expr ] - collect the inner stream into an array (None = []).
ObjectConstruct(Vec<(String, Expr)>)
{ key: expr, ... } - construct an object.
Assign(Box<Expr>, Box<Expr>)
path = rhs - assign; rhs is evaluated against the whole input.
UpdateAssign(Box<Expr>, Box<Expr>)
path |= rhs - update-assign; rhs sees the current value at path.
AddAssign(Box<Expr>, Box<Expr>)
path += rhs - add-assign; path = path + rhs (numeric add, string/array
concat). rhs is evaluated against the whole input.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn is_mutation(&self) -> bool
pub fn is_mutation(&self) -> bool
Does this expression mutate the document (contains an assignment or a
del(...))? The CLI uses this to pick mutation mode vs query mode.
Sourcepub fn as_path(&self) -> Option<&[Step]>
pub fn as_path(&self) -> Option<&[Step]>
The path steps if this expression is a plain path (the only valid left
side of an assignment), else None.
Sourcepub fn has_comment(&self) -> bool
pub fn has_comment(&self) -> bool
Does this expression address a comment (a # step) anywhere? The CLI
routes such queries through the comment-aware evaluator and rejects
comment mutation (a Phase-2 feature).