pub struct OperDefs { /* private fields */ }Expand description
Central registry of all operator definitions.
OperDefs maps operator names to a table of definitions by fixity.
Provides fast lookup of operator behavior and metadata.
Implementations§
Source§impl OperDefs
impl OperDefs
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty OperDefs registry.
Initializes an operator definition map with no entries.
Sourcepub fn try_from_ops(arena: &Arena, ops: Term) -> Result<Self>
pub fn try_from_ops(arena: &Arena, ops: Term) -> Result<Self>
Builds an OperDefs table from a parsed term representation.
This helper reads operator specifications encoded as arena_terms::Term values
and populates the operator definition registry accordingly.
§Parameters
arena: TheArenaused to allocate or access term data.ops: The rootTermcontaining operator definitions.
§Errors
Returns an error if operator parsing or validation fails.
Sourcepub fn get(&self, index: Option<usize>) -> &OperDefTab
pub fn get(&self, index: Option<usize>) -> &OperDefTab
Retrieves an operator definition table by index.
Returns a reference to the corresponding OperDefTab,
or [EMPTY_OPER_DEF_TAB] if the index is None or out of bounds.
Sourcepub fn define_oper(&mut self, arena: &Arena, op: Term) -> Result<()>
pub fn define_oper(&mut self, arena: &Arena, op: Term) -> Result<()>
Defines a single operator entry from a parsed arena_terms::Term structure.
This function ingests a Prolog-style operator definition term of the form:
op(
oper: atom | func(arg: atom | '='(name: atom, default: term)), ...,
type: 'fun' | 'prefix' | 'infix' | 'postfix',
prec: 0..1200, % must be 0 for fixity = 'fun'
assoc: 'none' | 'left' | 'right',
rename_to: 'none' | some(new_name: atom),
embed_type: 'false' | 'true'
).Each op/1 term specifies one operator, including its name, fixity, precedence,
associativity, optional renaming target, and embedding behavior.
§Parameters
arena: TheArenaproviding term access and allocation.op: TheTermdescribing the operator declaration.
§Returns
Ok(())if the operator was successfully parsed and registered.
§Errors
Returns an error if the operator definition is invalid, malformed, or violates fixity/precedence/associativity constraints.
Sourcepub fn define_opers(&mut self, arena: &Arena, term: Term) -> Result<()>
pub fn define_opers(&mut self, arena: &Arena, term: Term) -> Result<()>
Defines one or more operators from a parsed arena_terms::Term structure.
This method accepts either:
- A list of operator terms (each of which is passed to [
define_oper]), or - A single operator term (
op(...)) to be defined directly.
Each term is ingested and registered according to its fixity, precedence, associativity, and optional metadata.
§Parameters
arena: TheArenaproviding term access and allocation.term: Either a list of operator definitions or a single operator term.
§Returns
Ok(())if all operator definitions were successfully processed.
§Errors
Returns an error if any individual operator definition is invalid, malformed, or violates fixity/precedence/associativity constraints.