Struct ExprBuilder

Source
pub struct ExprBuilder<T> { /* private fields */ }
Expand description

Builder for constructing Expr objects annotated with some data (possibly taking default value) and optionally a source_loc.

Implementations§

Source§

impl<T> ExprBuilder<T>

Source

pub fn with_expr_kind(self, expr_kind: ExprKind<T>) -> Expr<T>

Construct an Expr containing the data and source_loc in this ExprBuilder and the given ExprKind.

Source

pub fn ite_arc( self, test_expr: Arc<Expr<T>>, then_expr: Arc<Expr<T>>, else_expr: Arc<Expr<T>>, ) -> Expr<T>

Create a ternary (if-then-else) Expr. Takes Arcs instead of owned Exprs. test_expr must evaluate to a Bool type

Source

pub fn record_arc(self, map: Arc<BTreeMap<SmolStr, Expr<T>>>) -> Expr<T>

Create an Expr which evaluates to a Record with the given key-value mapping.

If you have an iterator of pairs, generally prefer calling .record() instead of .collect()-ing yourself and calling this, potentially for efficiency reasons but also because .record() will properly handle duplicate keys but your own .collect() will not (by default).

Source§

impl<T: Clone + Default> ExprBuilder<T>

Source

pub fn with_same_source_loc<U>(self, expr: &Expr<U>) -> Self

Utility used the validator to get an expression with the same source location as an existing expression. This is done when reconstructing the Expr with type information.

Trait Implementations§

Source§

impl<T: Clone> Clone for ExprBuilder<T>

Source§

fn clone(&self) -> ExprBuilder<T>

Returns a copy 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<T: Debug> Debug for ExprBuilder<T>

Source§

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

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

impl<T: Default + Clone> ExprBuilder for ExprBuilder<T>

Source§

fn val(self, v: impl Into<Literal>) -> Expr<T>

Create an Expr that’s just a single Literal.

Note that you can pass this a Literal, an Integer, a String, etc.

Source§

fn unknown(self, u: Unknown) -> Expr<T>

Create an Unknown Expr

Source§

fn var(self, v: Var) -> Expr<T>

Create an Expr that’s just this literal Var

Source§

fn slot(self, s: SlotId) -> Expr<T>

Create an Expr that’s just this SlotId

Source§

fn ite( self, test_expr: Expr<T>, then_expr: Expr<T>, else_expr: Expr<T>, ) -> Expr<T>

Create a ternary (if-then-else) Expr.

test_expr must evaluate to a Bool type

Source§

fn not(self, e: Expr<T>) -> Expr<T>

Create a ‘not’ expression. e must evaluate to Bool type

Source§

fn is_eq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘==’ expression

Source§

fn and(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘and’ expression. Arguments must evaluate to Bool type

Source§

fn or(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘or’ expression. Arguments must evaluate to Bool type

Source§

fn less(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘<’ expression. Arguments must evaluate to Long type

Source§

fn lesseq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘<=’ expression. Arguments must evaluate to Long type

Source§

fn add(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘add’ expression. Arguments must evaluate to Long type

Source§

fn sub(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘sub’ expression. Arguments must evaluate to Long type

Source§

fn mul(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘mul’ expression. Arguments must evaluate to Long type

Source§

fn neg(self, e: Expr<T>) -> Expr<T>

Create a ‘neg’ expression. e must evaluate to Long type.

Source§

fn is_in(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘in’ expression. First argument must evaluate to Entity type. Second argument must evaluate to either Entity type or Set type where all set elements have Entity type.

Source§

fn contains(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘contains’ expression. First argument must have Set type.

Source§

fn contains_all(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘contains_all’ expression. Arguments must evaluate to Set type

Source§

fn contains_any(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘contains_any’ expression. Arguments must evaluate to Set type

Source§

fn is_empty(self, expr: Expr<T>) -> Expr<T>

Create an ‘is_empty’ expression. Argument must evaluate to Set type

Source§

fn get_tag(self, expr: Expr<T>, tag: Expr<T>) -> Expr<T>

Create a ‘getTag’ expression. expr must evaluate to Entity type, tag must evaluate to String type.

Source§

fn has_tag(self, expr: Expr<T>, tag: Expr<T>) -> Expr<T>

Create a ‘hasTag’ expression. expr must evaluate to Entity type, tag must evaluate to String type.

Source§

fn set(self, exprs: impl IntoIterator<Item = Expr<T>>) -> Expr<T>

Create an Expr which evaluates to a Set of the given Exprs

Source§

fn record( self, pairs: impl IntoIterator<Item = (SmolStr, Expr<T>)>, ) -> Result<Expr<T>, ExpressionConstructionError>

Create an Expr which evaluates to a Record with the given (key, value) pairs.

Source§

fn call_extension_fn( self, fn_name: Name, args: impl IntoIterator<Item = Expr<T>>, ) -> Expr<T>

Create an Expr which calls the extension function with the given Name on args

Source§

fn unary_app(self, op: impl Into<UnaryOp>, arg: Expr<T>) -> Expr<T>

Create an application Expr which applies the given built-in unary operator to the given arg

Source§

fn binary_app( self, op: impl Into<BinaryOp>, arg1: Expr<T>, arg2: Expr<T>, ) -> Expr<T>

Create an application Expr which applies the given built-in binary operator to arg1 and arg2

Source§

fn get_attr(self, expr: Expr<T>, attr: SmolStr) -> Expr<T>

Create an Expr which gets a given attribute of a given Entity or record.

expr must evaluate to either Entity or Record type

Source§

fn has_attr(self, expr: Expr<T>, attr: SmolStr) -> Expr<T>

Create an Expr which tests for the existence of a given attribute on a given Entity or record.

expr must evaluate to either Entity or Record type

Source§

fn like(self, expr: Expr<T>, pattern: Pattern) -> Expr<T>

Create a ‘like’ expression.

expr must evaluate to a String type

Source§

fn is_entity_type(self, expr: Expr<T>, entity_type: EntityType) -> Expr<T>

Create an ‘is’ expression.

Source§

type Expr = Expr<T>

The type of expression constructed by this instance of ExprBuilder.
Source§

type Data = T

Type for extra information stored on nodes of the expression AST. This can be () if no data is stored.
Source§

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.
Source§

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.
Source§

fn with_data(data: T) -> Self

Build an expression storing this information
Source§

fn with_maybe_source_loc(self, maybe_source_loc: Option<&Loc>) -> Self

Build an expression located at l, if l is Some. An implementation may ignore this if it cannot store source information.
Source§

fn new() -> Self
where Self: Sized,

Construct a new expression builder for an expression that will not carry any data.
Source§

fn with_source_loc(self, l: &Loc) -> Self
where Self: Sized,

Build an expression located at l. An implementation may ignore this if it cannot store source information.
Source§

fn is_in_entity_type( self, e1: Self::Expr, entity_type: EntityType, e2: Self::Expr, ) -> Self::Expr
where Self: Sized,

Create an _ is _ in _ expression
Source§

fn noteq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
where Self: Sized,

Create a ‘!=’ expression.
Source§

fn greater(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
where Self: Sized,

Create a ‘>’ expression.
Source§

fn greatereq(self, e1: Self::Expr, e2: Self::Expr) -> Self::Expr
where Self: Sized,

Create a ‘>=’ expression.
Source§

fn and_nary( self, first: Self::Expr, others: impl IntoIterator<Item = Self::Expr>, ) -> Self::Expr
where 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. Read more
Source§

fn or_nary( self, first: Self::Expr, others: impl IntoIterator<Item = Self::Expr>, ) -> Self::Expr
where 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. Read more
Source§

fn add_nary( self, first: Self::Expr, other: impl IntoIterator<Item = (AddOp, Self::Expr)>, ) -> Self::Expr
where 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.
Source§

fn mul_nary( self, first: Self::Expr, other: impl IntoIterator<Item = Self::Expr>, ) -> Self::Expr
where 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.

Auto Trait Implementations§

§

impl<T> Freeze for ExprBuilder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ExprBuilder<T>
where T: RefUnwindSafe,

§

impl<T> Send for ExprBuilder<T>
where T: Send,

§

impl<T> Sync for ExprBuilder<T>
where T: Sync,

§

impl<T> Unpin for ExprBuilder<T>
where T: Unpin,

§

impl<T> UnwindSafe for ExprBuilder<T>
where T: UnwindSafe,

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.