pub trait ExprBuilder: Clone {
type Expr: Clone + Display;
type Data: Default;
Show 45 methods
// Required methods
fn with_data(data: Self::Data) -> Self;
fn with_maybe_source_loc(self, l: Option<&Loc>) -> Self;
fn loc(&self) -> Option<&Loc>;
fn data(&self) -> &Self::Data;
fn val(self, v: impl Into<Literal>) -> Self::Expr;
fn var(self, v: Var) -> Self::Expr;
fn unknown(self, u: Unknown) -> Self::Expr;
fn slot(self, s: SlotId) -> Self::Expr;
fn ite(
self,
test_expr: Self::Expr,
then_expr: Self::Expr,
else_expr: Self::Expr,
) -> Self::Expr;
fn not(self, e: Self::Expr) -> Self::Expr;
fn is_eq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn and(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn or(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn less(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn lesseq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn add(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn sub(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn mul(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn neg(self, e: Self::Expr) -> Self::Expr;
fn is_in(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn contains(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn contains_all(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn contains_any(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr;
fn is_empty(self, expr: Self::Expr) -> Self::Expr;
fn get_tag(self, expr: Self::Expr, tag: Self::Expr) -> Self::Expr;
fn has_tag(self, expr: Self::Expr, tag: Self::Expr) -> Self::Expr;
fn set(self, exprs: impl IntoIterator<Item = Self::Expr>) -> Self::Expr;
fn record(
self,
pairs: impl IntoIterator<Item = (SmolStr, Self::Expr)>,
) -> Result<Self::Expr, ExpressionConstructionError>;
fn call_extension_fn(
self,
fn_name: Name,
args: impl IntoIterator<Item = Self::Expr>,
) -> Self::Expr;
fn get_attr(self, expr: Self::Expr, attr: SmolStr) -> Self::Expr;
fn has_attr(self, expr: Self::Expr, attr: SmolStr) -> Self::Expr;
fn like(self, expr: Self::Expr, pattern: Pattern) -> Self::Expr;
fn is_entity_type(
self,
expr: Self::Expr,
entity_type: EntityType,
) -> Self::Expr;
// Provided methods
fn new() -> Self
where Self: Sized { ... }
fn with_source_loc(self, l: &Loc) -> Self
where Self: Sized { ... }
fn is_in_entity_type(
self,
e1: Self::Expr,
entity_type: EntityType,
e2: Self::Expr,
) -> Self::Expr
where Self: Sized { ... }
fn unary_app(self, op: impl Into<UnaryOp>, arg: Self::Expr) -> Self::Expr
where Self: Sized { ... }
fn binary_app(
self,
op: impl Into<BinaryOp>,
arg1: Self::Expr,
arg2: Self::Expr,
) -> Self::Expr
where Self: Sized { ... }
fn noteq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
where Self: Sized { ... }
fn greater(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
where Self: Sized { ... }
fn greatereq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
where Self: Sized { ... }
fn and_nary(
self,
first: Self::Expr,
others: impl IntoIterator<Item = Self::Expr>,
) -> Self::Expr
where Self: Sized { ... }
fn or_nary(
self,
first: Self::Expr,
others: impl IntoIterator<Item = Self::Expr>,
) -> Self::Expr
where Self: Sized { ... }
fn add_nary(
self,
first: Self::Expr,
other: impl IntoIterator<Item = (AddOp, Self::Expr)>,
) -> Self::Expr
where Self: Sized { ... }
fn mul_nary(
self,
first: Self::Expr,
other: impl IntoIterator<Item = Self::Expr>,
) -> Self::Expr
where Self: Sized { ... }
}
Expand description
Defines a generic interface for building different expression data structures.
Required Associated Types§
Required Methods§
Sourcefn with_maybe_source_loc(self, l: Option<&Loc>) -> Self
fn with_maybe_source_loc(self, l: Option<&Loc>) -> Self
Build an expression located at l
, if l
is Some. An implementation
may ignore this if it cannot store source information.
Sourcefn loc(&self) -> Option<&Loc>
fn loc(&self) -> Option<&Loc>
Extract the location for this builder, if set. Used internally to provide utilities that construct multiple nodes which should all be reported as having the same source location.
Sourcefn data(&self) -> &Self::Data
fn data(&self) -> &Self::Data
Extract the data that will be stored on the constructed expression. Used internally to provide utilities that construct multiple nodes which will all have the same data.
Sourcefn val(self, v: impl Into<Literal>) -> Self::Expr
fn val(self, v: impl Into<Literal>) -> Self::Expr
Create an expression that’s just a single Literal
.
Note that you can pass this a Literal
, an Integer
, a String
, etc.
Sourcefn ite(
self,
test_expr: Self::Expr,
then_expr: Self::Expr,
else_expr: Self::Expr,
) -> Self::Expr
fn ite( self, test_expr: Self::Expr, then_expr: Self::Expr, else_expr: Self::Expr, ) -> Self::Expr
Create a ternary (if-then-else) Expr
.
Sourcefn is_in(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
fn is_in(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
Create an ‘in’ expression. First argument must evaluate to Entity type.
Sourcefn contains(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
fn contains(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
Create a ‘contains’ expression.
Sourcefn contains_all(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
fn contains_all(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
Create a ‘contains_all’ expression. Arguments must evaluate to Set type
Sourcefn contains_any(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
fn contains_any(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
Create an ‘contains_any’ expression. Arguments must evaluate to Set type
Sourcefn is_empty(self, expr: Self::Expr) -> Self::Expr
fn is_empty(self, expr: Self::Expr) -> Self::Expr
Create an ‘is_empty’ expression. Argument must evaluate to Set type
Sourcefn get_tag(self, expr: Self::Expr, tag: Self::Expr) -> Self::Expr
fn get_tag(self, expr: Self::Expr, tag: Self::Expr) -> Self::Expr
Create a ‘getTag’ expression.
Sourcefn has_tag(self, expr: Self::Expr, tag: Self::Expr) -> Self::Expr
fn has_tag(self, expr: Self::Expr, tag: Self::Expr) -> Self::Expr
Create a ‘hasTag’ expression.
Sourcefn set(self, exprs: impl IntoIterator<Item = Self::Expr>) -> Self::Expr
fn set(self, exprs: impl IntoIterator<Item = Self::Expr>) -> Self::Expr
Create an Expr
which evaluates to a Set of the given Expr
s
Sourcefn record(
self,
pairs: impl IntoIterator<Item = (SmolStr, Self::Expr)>,
) -> Result<Self::Expr, ExpressionConstructionError>
fn record( self, pairs: impl IntoIterator<Item = (SmolStr, Self::Expr)>, ) -> Result<Self::Expr, ExpressionConstructionError>
Create an Expr
which evaluates to a Record with the given (key, value) pairs.
Sourcefn call_extension_fn(
self,
fn_name: Name,
args: impl IntoIterator<Item = Self::Expr>,
) -> Self::Expr
fn call_extension_fn( self, fn_name: Name, args: impl IntoIterator<Item = Self::Expr>, ) -> Self::Expr
Create an Expr
which calls the extension function with the given
Name
on args
Sourcefn get_attr(self, expr: Self::Expr, attr: SmolStr) -> Self::Expr
fn get_attr(self, expr: Self::Expr, attr: SmolStr) -> Self::Expr
Create an Expr
which gets a given attribute of a given Entity
or record.
Sourcefn has_attr(self, expr: Self::Expr, attr: SmolStr) -> Self::Expr
fn has_attr(self, expr: Self::Expr, attr: SmolStr) -> Self::Expr
Create an Expr
which tests for the existence of a given
attribute on a given Entity
or record.
Sourcefn is_entity_type(self, expr: Self::Expr, entity_type: EntityType) -> Self::Expr
fn is_entity_type(self, expr: Self::Expr, entity_type: EntityType) -> Self::Expr
Create an ‘is’ expression.
Provided Methods§
Sourcefn new() -> Selfwhere
Self: Sized,
fn new() -> Selfwhere
Self: Sized,
Construct a new expression builder for an expression that will not carry any data.
Sourcefn with_source_loc(self, l: &Loc) -> Selfwhere
Self: Sized,
fn with_source_loc(self, l: &Loc) -> Selfwhere
Self: Sized,
Build an expression located at l
. An implementation may ignore this if
it cannot store source information.
Sourcefn is_in_entity_type(
self,
e1: Self::Expr,
entity_type: EntityType,
e2: Self::Expr,
) -> Self::Exprwhere
Self: Sized,
fn is_in_entity_type(
self,
e1: Self::Expr,
entity_type: EntityType,
e2: Self::Expr,
) -> Self::Exprwhere
Self: Sized,
Create an _ is _ in _
expression
Sourcefn unary_app(self, op: impl Into<UnaryOp>, arg: Self::Expr) -> Self::Exprwhere
Self: Sized,
fn unary_app(self, op: impl Into<UnaryOp>, arg: Self::Expr) -> Self::Exprwhere
Self: Sized,
Create an application Expr
which applies the given built-in unary
operator to the given arg
Sourcefn binary_app(
self,
op: impl Into<BinaryOp>,
arg1: Self::Expr,
arg2: Self::Expr,
) -> Self::Exprwhere
Self: Sized,
fn binary_app(
self,
op: impl Into<BinaryOp>,
arg1: Self::Expr,
arg2: Self::Expr,
) -> Self::Exprwhere
Self: Sized,
Create an application Expr
which applies the given built-in binary
operator to arg1
and arg2
Sourcefn noteq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Exprwhere
Self: Sized,
fn noteq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Exprwhere
Self: Sized,
Create a ‘!=’ expression.
Sourcefn greater(self, e1: Self::Expr, e2: Self::Expr) -> Self::Exprwhere
Self: Sized,
fn greater(self, e1: Self::Expr, e2: Self::Expr) -> Self::Exprwhere
Self: Sized,
Create a ‘>’ expression.
Sourcefn greatereq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Exprwhere
Self: Sized,
fn greatereq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Exprwhere
Self: Sized,
Create a ‘>=’ expression.
Sourcefn and_nary(
self,
first: Self::Expr,
others: impl IntoIterator<Item = Self::Expr>,
) -> Self::Exprwhere
Self: Sized,
fn and_nary(
self,
first: Self::Expr,
others: impl IntoIterator<Item = Self::Expr>,
) -> Self::Exprwhere
Self: Sized,
Create an and
expression that may have more than two subexpressions (A && B && C)
or may have only one subexpression, in which case no &&
is performed at all.
Arguments must evaluate to Bool type.
This may create multiple AST &&
nodes. If it does, all the nodes will have the same
source location and the same T
data (taken from this builder) unless overridden, e.g.,
with another call to with_source_loc()
.
Sourcefn or_nary(
self,
first: Self::Expr,
others: impl IntoIterator<Item = Self::Expr>,
) -> Self::Exprwhere
Self: Sized,
fn or_nary(
self,
first: Self::Expr,
others: impl IntoIterator<Item = Self::Expr>,
) -> Self::Exprwhere
Self: Sized,
Create an or
expression that may have more than two subexpressions (A || B || C)
or may have only one subexpression, in which case no ||
is performed at all.
Arguments must evaluate to Bool type.
This may create multiple AST ||
nodes. If it does, all the nodes will have the same
source location and the same T
data (taken from this builder) unless overridden, e.g.,
with another call to with_source_loc()
.
Sourcefn add_nary(
self,
first: Self::Expr,
other: impl IntoIterator<Item = (AddOp, Self::Expr)>,
) -> Self::Exprwhere
Self: Sized,
fn add_nary(
self,
first: Self::Expr,
other: impl IntoIterator<Item = (AddOp, Self::Expr)>,
) -> Self::Exprwhere
Self: Sized,
Create expression containing addition and subtraction that may have more than two subexpressions (A + B - C) or may have only one subexpression, in which case no operations are performed at all.
Sourcefn mul_nary(
self,
first: Self::Expr,
other: impl IntoIterator<Item = Self::Expr>,
) -> Self::Exprwhere
Self: Sized,
fn mul_nary(
self,
first: Self::Expr,
other: impl IntoIterator<Item = Self::Expr>,
) -> Self::Exprwhere
Self: Sized,
Create expression containing multiplication that may have more than two subexpressions (A * B * C) or may have only one subexpression, in which case no operations are performed at all.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.