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<'_, '_>
impl RuleScopedContext<'_, '_>
Sourcepub fn invalid_shape(&self, message: impl Into<String>) -> RuleError
pub fn invalid_shape(&self, message: impl Into<String>) -> RuleError
Creates an InvalidNodeShape error for the bound rule.
Sourcepub fn missing_metadata(&self, name: impl Into<String>) -> RuleError
pub fn missing_metadata(&self, name: impl Into<String>) -> RuleError
Creates a MissingMetadata error for the bound rule.
Sourcepub fn ensure_shape(
&self,
condition: bool,
message: impl Into<String>,
) -> Result<(), RuleError>
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.
Sourcepub fn expect_arg_len(
&self,
args: &[ArgumentSlot],
expected: usize,
subject: &str,
) -> Result<(), RuleError>
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.
Sourcepub fn expect_no_args(
&self,
args: &[ArgumentSlot],
subject: &str,
) -> Result<(), RuleError>
pub fn expect_no_args( &self, args: &[ArgumentSlot], subject: &str, ) -> Result<(), RuleError>
Shorthand for expect_arg_len with expected = 0.
Sourcepub fn star_arg_value(
&self,
slot: &ArgumentSlot,
subject: &str,
) -> Result<bool, RuleError>
pub fn star_arg_value( &self, slot: &ArgumentSlot, subject: &str, ) -> Result<bool, RuleError>
Extracts a boolean star argument from a parsed star slot.
Sourcepub fn optional_math_content(
&self,
slot: &ArgumentSlot,
subject: &str,
label: &str,
) -> Result<Option<NodeId>, RuleError>
pub fn optional_math_content( &self, slot: &ArgumentSlot, subject: &str, label: &str, ) -> Result<Option<NodeId>, RuleError>
Extracts an optional math-content argument.
Sourcepub fn optional_group_math_content(
&self,
slot: &ArgumentSlot,
subject: &str,
label: &str,
) -> Result<Option<NodeId>, RuleError>
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.
Sourcepub fn mandatory_math_content(
&self,
slot: &ArgumentSlot,
subject: &str,
label: &str,
) -> Result<NodeId, RuleError>
pub fn mandatory_math_content( &self, slot: &ArgumentSlot, subject: &str, label: &str, ) -> Result<NodeId, RuleError>
Extracts a mandatory math-content argument.
Sourcepub fn mandatory_or_group_math_content(
&self,
slot: &ArgumentSlot,
subject: &str,
label: &str,
) -> Result<NodeId, RuleError>
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>>§
Sourcepub fn for_rule(&self, rule: RuleKey) -> RuleScopedContext<'_, 'a>
pub fn for_rule(&self, rule: RuleKey) -> RuleScopedContext<'_, 'a>
Returns a lightweight context that binds diagnostics and slot extraction to one rule.
pub fn knows_command_name(&self, name: &str) -> bool
pub fn knows_env_name(&self, name: &str) -> bool
pub fn command_has_tag(&self, name: &str, tag: &str) -> bool
pub fn env_has_tag(&self, name: &str, tag: &str) -> bool
Sourcepub fn active_command(&self, node_id: NodeId) -> Option<&ActiveCommandRecord>
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.
Sourcepub fn active_env(&self, node_id: NodeId) -> Option<&ActiveEnvironmentRecord>
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.
Sourcepub fn lookup_command(
&self,
name: &str,
mode: ContentMode,
) -> Option<&ActiveCommandRecord>
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.
Sourcepub fn lookup_character(
&self,
name: &str,
mode: ContentMode,
) -> Option<&ActiveCharacterRecord>
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.
Sourcepub fn lookup_env(
&self,
name: &str,
mode: ContentMode,
) -> Option<&ActiveEnvironmentRecord>
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.
Sourcepub fn invalid_shape(
&self,
_rule: RuleKey,
message: impl Into<String>,
) -> RuleError
pub fn invalid_shape( &self, _rule: RuleKey, message: impl Into<String>, ) -> RuleError
Creates an InvalidNodeShape error for the given rule.
Sourcepub fn missing_metadata(
&self,
_rule: RuleKey,
name: impl Into<String>,
) -> RuleError
pub fn missing_metadata( &self, _rule: RuleKey, name: impl Into<String>, ) -> RuleError
Creates a MissingMetadata error for the given rule.
Sourcepub fn ensure_shape(
&self,
condition: bool,
rule: RuleKey,
message: impl Into<String>,
) -> Result<(), RuleError>
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.
Sourcepub fn expect_arg_len(
&self,
rule: RuleKey,
args: &[ArgumentSlot],
expected: usize,
subject: &str,
) -> Result<(), RuleError>
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.
Sourcepub fn expect_no_args(
&self,
rule: RuleKey,
args: &[ArgumentSlot],
subject: &str,
) -> Result<(), RuleError>
pub fn expect_no_args( &self, rule: RuleKey, args: &[ArgumentSlot], subject: &str, ) -> Result<(), RuleError>
Shorthand for expect_arg_len with expected = 0.
Sourcepub fn match_command(
&self,
node_id: NodeId,
record: &'static BuiltinCommandRecord,
) -> Option<CommandView<'_>>
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.
Sourcepub fn match_infix(
&self,
node_id: NodeId,
record: &'static BuiltinCommandRecord,
) -> Option<InfixView<'_>>
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.
Sourcepub fn match_declarative(
&self,
node_id: NodeId,
record: &'static BuiltinCommandRecord,
) -> Option<DeclarativeView<'_>>
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.
Sourcepub fn match_environment(
&self,
node_id: NodeId,
record: &'static BuiltinEnvironmentRecord,
) -> Option<EnvironmentView<'_>>
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.