Skip to main content

RuleScopedContext

Struct RuleScopedContext 

Source
pub struct RuleScopedContext<'cx, 'ctx> { /* private fields */ }
Expand description

A read-only scoped context bound to a rule key for diagnostics and slot extraction.

Implementations§

Source§

impl RuleScopedContext<'_, '_>

Source

pub fn invalid_shape(&self, message: impl Into<String>) -> RuleError

Creates an InvalidNodeShape error for the bound rule.

Source

pub fn missing_metadata(&self, name: impl Into<String>) -> RuleError

Creates a MissingMetadata error for the bound rule.

Source

pub fn ensure_shape( &self, condition: bool, message: impl Into<String>, ) -> Result<(), RuleError>

Returns Ok(()) when condition is true, or an invalid-shape error otherwise.

Source

pub fn expect_arg_len( &self, args: &[ArgumentSlot], expected: usize, subject: &str, ) -> Result<(), RuleError>

Asserts that args has exactly expected slots, returning an error that names subject on mismatch.

Source

pub fn expect_no_args( &self, args: &[ArgumentSlot], subject: &str, ) -> Result<(), RuleError>

Shorthand for expect_arg_len with expected = 0.

Source

pub fn star_arg_value( &self, slot: &ArgumentSlot, subject: &str, ) -> Result<bool, RuleError>

Extracts a boolean star argument from a parsed star slot.

Source

pub fn optional_math_content( &self, slot: &ArgumentSlot, subject: &str, label: &str, ) -> Result<Option<NodeId>, RuleError>

Extracts an optional math-content argument.

Source

pub fn optional_group_math_content( &self, slot: &ArgumentSlot, subject: &str, label: &str, ) -> Result<Option<NodeId>, RuleError>

Extracts an optional braced-group math-content argument.

Source

pub fn mandatory_math_content( &self, slot: &ArgumentSlot, subject: &str, label: &str, ) -> Result<NodeId, RuleError>

Extracts a mandatory math-content argument.

Source

pub fn mandatory_or_group_math_content( &self, slot: &ArgumentSlot, subject: &str, label: &str, ) -> Result<NodeId, RuleError>

Extracts a math-content argument that may be either mandatory or a braced group.

Methods from Deref<Target = RuleContext<'ctx>>§

Source

pub fn for_rule(&self, rule: RuleKey) -> RuleScopedContext<'_, 'a>

Returns a lightweight context that binds diagnostics and slot extraction to one rule.

Source

pub fn knows_command_name(&self, name: &str) -> bool

Source

pub fn knows_env_name(&self, name: &str) -> bool

Source

pub fn command_has_tag(&self, name: &str, tag: &str) -> bool

Source

pub fn env_has_tag(&self, name: &str, tag: &str) -> bool

Source

pub fn active_command(&self, node_id: NodeId) -> Option<&ActiveCommandRecord>

Looks up the active command record for the node at node_id by extracting its name from the AST.

Source

pub fn active_env(&self, node_id: NodeId) -> Option<&ActiveEnvironmentRecord>

Looks up the active environment record for the node at node_id by extracting its name from the AST.

Source

pub fn lookup_command( &self, name: &str, mode: ContentMode, ) -> Option<&ActiveCommandRecord>

Looks up a command record by name directly in the selected knowledge-base lane.

Source

pub fn lookup_character( &self, name: &str, mode: ContentMode, ) -> Option<&ActiveCharacterRecord>

Looks up a character record by name directly in the selected knowledge-base lane.

Source

pub fn lookup_env( &self, name: &str, mode: ContentMode, ) -> Option<&ActiveEnvironmentRecord>

Looks up an environment record by name directly in the selected knowledge-base lane.

Source

pub fn node(&self, node_id: NodeId) -> &Node

Returns the AST node for the given identifier.

Source

pub fn invalid_shape( &self, _rule: RuleKey, message: impl Into<String>, ) -> RuleError

Creates an InvalidNodeShape error for the given rule.

Source

pub fn missing_metadata( &self, _rule: RuleKey, name: impl Into<String>, ) -> RuleError

Creates a MissingMetadata error for the given rule.

Source

pub fn ensure_shape( &self, condition: bool, rule: RuleKey, message: impl Into<String>, ) -> Result<(), RuleError>

Returns Ok(()) when condition is true, or an InvalidNodeShape error otherwise.

Source

pub fn expect_arg_len( &self, rule: RuleKey, args: &[ArgumentSlot], expected: usize, subject: &str, ) -> Result<(), RuleError>

Asserts that args has exactly expected slots, returning an error that names subject on mismatch.

Source

pub fn expect_no_args( &self, rule: RuleKey, args: &[ArgumentSlot], subject: &str, ) -> Result<(), RuleError>

Shorthand for expect_arg_len with expected = 0.

Source

pub fn match_command( &self, node_id: NodeId, record: &'static BuiltinCommandRecord, ) -> Option<CommandView<'_>>

Tries to extract a CommandView from the node, returning None if it is not a matching prefix command.

Source

pub fn match_infix( &self, node_id: NodeId, record: &'static BuiltinCommandRecord, ) -> Option<InfixView<'_>>

Tries to extract an InfixView from the node, returning None if it is not a matching infix command.

Source

pub fn match_declarative( &self, node_id: NodeId, record: &'static BuiltinCommandRecord, ) -> Option<DeclarativeView<'_>>

Tries to extract a DeclarativeView from the node, returning None if it is not a matching declarative command.

Source

pub fn match_environment( &self, node_id: NodeId, record: &'static BuiltinEnvironmentRecord, ) -> Option<EnvironmentView<'_>>

Tries to extract an EnvironmentView from the node, returning None if it is not a matching environment.

Trait Implementations§

Source§

impl<'cx, 'ctx> Deref for RuleScopedContext<'cx, 'ctx>

Source§

type Target = RuleContext<'ctx>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'cx, 'ctx> Freeze for RuleScopedContext<'cx, 'ctx>

§

impl<'cx, 'ctx> RefUnwindSafe for RuleScopedContext<'cx, 'ctx>

§

impl<'cx, 'ctx> Send for RuleScopedContext<'cx, 'ctx>

§

impl<'cx, 'ctx> Sync for RuleScopedContext<'cx, 'ctx>

§

impl<'cx, 'ctx> Unpin for RuleScopedContext<'cx, 'ctx>

§

impl<'cx, 'ctx> UnsafeUnpin for RuleScopedContext<'cx, 'ctx>

§

impl<'cx, 'ctx> UnwindSafe for RuleScopedContext<'cx, 'ctx>

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> 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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.