Skip to main content

ExprOptions

Struct ExprOptions 

Source
pub struct ExprOptions {
    pub op: IndexMap<String, Option<OpDef>>,
    pub evaluate: Option<Evaluate>,
    pub juxtapose: Option<bool>,
    pub values: Vec<String>,
    pub node_limit: Option<usize>,
}
Expand description

Options for the plugin.

op is an insertion-ordered map, and the order matters: two operators claiming the same source string resolve to the same token, and the later entry wins, exactly as it does in the canonical TypeScript. A None entry deletes an operator the defaults provide.

Fields§

§op: IndexMap<String, Option<OpDef>>§evaluate: Option<Evaluate>§juxtapose: Option<bool>

Values side by side, with nothing between them, inside an expression or a paren group make an implicit list, as jsonic makes one (f(a b) is a call of [a, b]). With Some(false) they are refused, with the engine’s unexpected. A document’s own implicit list, outside any expression, and the items of a list or a map are unchanged. None reads as true.

§values: Vec<String>

The value tokens of a host grammar that lexes its own (an identifier, a number), by name, beside jsonic’s text, number, string and keyword values. With juxtapose false, one of them after a value or an expression is refused, with the engine’s unexpected, wherever it stands: an expression never ends at one, and the rule the expression is in never sees it. The items of a list or a map are not exempt.

§node_limit: Option<usize>

The most nodes one expression may hold, NODE_LIMIT when None. An expression past it is refused with the engine’s cancel code.

The limit keeps a realized tree shallow enough for the engine’s recursive walks of a value (display, JSON, drop), which abort the process past the stack where TypeScript and Go fail or go on. A host that raises it reduces every expression with an evaluator into values of its own, whose depth it bounds itself, and never realizes or simplifies a tree past NODE_LIMIT: the parse, the placing of an operator and the evaluation walk no deeper on the call stack however large an expression grows.

Implementations§

Source§

impl ExprOptions

Source

pub fn new() -> Self

Options carrying no operators of their own; the defaults still apply.

Source

pub fn with_op(self, name: impl Into<String>, def: OpDef) -> Self

Add or replace one operator definition.

Source

pub fn without_op(self, name: impl Into<String>) -> Self

Delete a default operator, the Rust spelling of plain: null.

Source

pub fn with_juxtapose(self, juxtapose: bool) -> Self

Whether values side by side make an implicit list: see ExprOptions::juxtapose.

Source

pub fn with_values<I, S>(self, values: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Name a host grammar’s own value tokens: see ExprOptions::values.

Source

pub fn with_node_limit(self, limit: usize) -> Self

Set the most nodes one expression may hold: see ExprOptions::node_limit.

Source

pub fn with_evaluate( self, evaluate: impl Fn(&mut EvalSite<'_>, &Op, &[Value]) -> Value + Send + Sync + 'static, ) -> Self

Set the evaluator that reduces each expression as it closes.

Source

pub fn from_value(options: &Value) -> Self

Read the operator table, and juxtapose, out of a serialized option bag, as the engine hands it to a plugin. Unreadable entries are ignored, the way the canonical plugin ignores what it cannot use.

Trait Implementations§

Source§

impl Clone for ExprOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ExprOptions

Source§

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

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

impl Default for ExprOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.