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: ValueCustom operator data, handed back to an evaluator as op.use.
key: boolA 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: boolA 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: ContentDefA paren operator’s content: see ContentDef.
separator: boolAn 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: boolA 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
impl OpDef
Sourcepub fn infix(src: impl Into<String>, left: i64, right: i64) -> Self
pub fn infix(src: impl Into<String>, left: i64, right: i64) -> Self
An infix operator with the given source and binding powers.
Sourcepub fn prefix(src: impl Into<String>, right: i64) -> Self
pub fn prefix(src: impl Into<String>, right: i64) -> Self
A prefix operator with the given source and right binding power.
Sourcepub fn suffix(src: impl Into<String>, left: i64) -> Self
pub fn suffix(src: impl Into<String>, left: i64) -> Self
A suffix operator with the given source and left binding power.
Sourcepub fn ternary(first: impl Into<String>, second: impl Into<String>) -> Self
pub fn ternary(first: impl Into<String>, second: impl Into<String>) -> Self
A ternary operator with its two source strings.
Sourcepub fn paren(osrc: impl Into<String>, csrc: impl Into<String>) -> Self
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.
Sourcepub fn key(src: impl Into<String>) -> Self
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.
Sourcepub fn dynamic_key(src: impl Into<String>) -> Self
pub fn dynamic_key(src: impl Into<String>) -> Self
A dynamic key operator: recognised and reported by a fold, never evaluated.
Sourcepub fn cast(
osrc: impl Into<String>,
csrc: impl Into<String>,
right: i64,
accept: impl Fn(&Value) -> bool + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn with_preval(self, preval: PrevalDef) -> Self
pub fn with_preval(self, preval: PrevalDef) -> Self
Give a paren operator a preval configuration.
Sourcepub fn with_left(self, left: i64) -> Self
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.
Sourcepub fn with_content(self, content: ContentDef) -> Self
pub fn with_content(self, content: ContentDef) -> Self
Give a paren operator a content configuration: see ContentDef.
Sourcepub fn with_separator(self) -> Self
pub fn with_separator(self) -> Self
Make an infix operator on , give way to separators: see
OpDef::separator.