Skip to main content

OpDef

Struct OpDef 

Source
pub struct OpDef {
Show 18 fields pub src: Vec<String>, pub osrc: String, pub csrc: String, pub left: Option<i64>, pub right: Option<i64>, pub prefix: bool, pub suffix: bool, pub infix: bool, pub ternary: bool, pub paren: bool, pub preval: Option<PrevalDef>, pub use_data: Value, pub key: bool, pub dynamic: bool, pub content: ContentDef, pub separator: bool, pub cast: bool, pub accept: Option<Accept>,
}
Expand description

One entry of the op option map: the definition of an operator.

src carries one source string for a prefix, suffix or infix operator and two for a ternary (["?", ":"]); a paren operator uses osrc and csrc instead. A key operator’s src is the member name that marks a site, $ref say.

Fields§

§src: Vec<String>§osrc: String§csrc: String§left: Option<i64>§right: Option<i64>§prefix: bool§suffix: bool§infix: bool§ternary: bool§paren: bool§preval: Option<PrevalDef>§use_data: Value

Custom operator data, handed back to an evaluator as op.use.

§key: bool

A STRUCTURAL operator: an occurrence is a map that owns the member named by src, recognised by its shape when a tree is folded (fold), never by a token. No fixed token is registered for it, so the base grammar keeps the key position, and no binding power applies: its two terms are fixed by the shape, the member’s value and the map of the other members.

§dynamic: bool

A key operator a fold recognises and reports but never evaluates, such as $dynamicRef, whose meaning depends on a scope the parser does not have. Its map folds as a plain map.

§content: ContentDef

A paren operator’s content: see ContentDef.

§separator: bool

An infix operator on , that gives way to the separator: wherever an enclosing context separates on , (a list, a map, or a paren whose content is separated) the comma separates, and only elsewhere is it this operator. A group is such an elsewhere, even inside a call.

§cast: bool

A CAST: a prefix operator whose token is a group ((int) in (int)a) that accept accepts. osrc and csrc name the group, which a paren operator of the table on the same opener and closer parses; right is the cast’s binding power, as a prefix’s; src, by default osrc and csrc together, is what simplify writes. The operation’s terms are the group’s content and the operand. A group accept refuses stays a group, or a call, and a cast without accept accepts nothing.

§accept: Option<Accept>

A cast’s test of the group’s content: see Accept.

Implementations§

Source§

impl OpDef

Source

pub fn infix(src: impl Into<String>, left: i64, right: i64) -> Self

An infix operator with the given source and binding powers.

Source

pub fn prefix(src: impl Into<String>, right: i64) -> Self

A prefix operator with the given source and right binding power.

Source

pub fn suffix(src: impl Into<String>, left: i64) -> Self

A suffix operator with the given source and left binding power.

Source

pub fn ternary(first: impl Into<String>, second: impl Into<String>) -> Self

A ternary operator with its two source strings.

A ternary with a binding power on its left (with_left) is placed as an infix operator is, its middle term between its two tokens and its last term an operand on its right (with_right): x = a ? b : c is x = (a ? b : c) where the ternary binds tighter than =, and an operator after the last term binds into it, or takes the whole ternary, by the same comparison. The middle term is a whole expression of its own, in which a comma is the comma operator even where the context separates on commas. A ternary with no left takes the whole expression before it, and the whole one after it.

Source

pub fn paren(osrc: impl Into<String>, csrc: impl Into<String>) -> Self

A paren operator with its opening and closing source strings.

Two paren operators may share an opener: a group, whose preval is inactive, and a call or a subscript, whose preval is active. A value before the opener selects the preval operator and no value the group, so (e) and e() reach an evaluator as different operators. Of two of one kind on an opener the later declared applies, and an opener with no group uses an operator whose preval is active and not required for both forms. The default plain is left out of a table that has another paren operator on ( and ), unless the options change it.

Source

pub fn key(src: impl Into<String>) -> Self

A key operator: a map that owns the member src is an occurrence of it when a tree is folded.

Source

pub fn dynamic_key(src: impl Into<String>) -> Self

A dynamic key operator: recognised and reported by a fold, never evaluated.

Source

pub fn cast( osrc: impl Into<String>, csrc: impl Into<String>, right: i64, accept: impl Fn(&Value) -> bool + Send + Sync + 'static, ) -> Self

A cast on the group osrc csrc, with the binding power right, whose content accept tests: see OpDef::cast.

Source

pub fn with_preval(self, preval: PrevalDef) -> Self

Give a paren operator a preval configuration.

Source

pub fn with_left(self, left: i64) -> Self

Give a preval paren a binding power, compared like a suffix’s with the operator whose operand precedes it: where the paren binds no tighter, it takes that operator’s expression (a.b[1] is (a.b)[1]). Unset, the paren binds to the value just before it.

Source

pub fn with_right(self, right: i64) -> Self

Give an operator its right binding power: a ternary’s, which with a left one (with_left) places it as an infix operator is (see OpDef::ternary).

Source

pub fn with_content(self, content: ContentDef) -> Self

Give a paren operator a content configuration: see ContentDef.

Source

pub fn with_separator(self) -> Self

Make an infix operator on , give way to separators: see OpDef::separator.

Source

pub fn with_use(self, use_data: Value) -> Self

Attach custom operator data, handed back to an evaluator.

Trait Implementations§

Source§

impl Clone for OpDef

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 OpDef

Source§

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

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

impl Default for OpDef

Source§

fn default() -> Self

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

impl PartialEq for OpDef

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OpDef

Auto Trait Implementations§

§

impl !RefUnwindSafe for OpDef

§

impl !UnwindSafe for OpDef

§

impl Forget for OpDef

§

impl Freeze for OpDef

§

impl Move for OpDef

§

impl Send for OpDef

§

impl Sync for OpDef

§

impl Unpin for OpDef

§

impl UnsafeUnpin for OpDef

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.