pub struct DirectiveOptions {
pub name: String,
pub open: String,
pub close: Option<String>,
pub action: DirectiveAction,
pub rules: Option<RulesOption>,
pub custom: Option<CustomFn>,
}Expand description
Configuration for one directive.
Built with DirectiveOptions::new plus the with_* methods, then
handed to apply or plugin.
Fields§
§name: StringThe directive name, used as the rule name and token-name suffix. It must be non-empty and contain no whitespace — registration rejects anything else, because the serialized grammar could not name the token.
open: StringThe character sequence that starts the directive. It must be unique — re-registering an existing fixed token is an error.
close: Option<String>The optional character sequence that ends the directive. Without one the directive consumes a single value after the open token.
action: DirectiveActionHow the parsed body is transformed.
rules: Option<RulesOption>Which existing grammar rules are modified. None selects the
defaults (open val, close list,elem,map,pair); Some(value)
is a complete override, so Some(RulesOption::new()) modifies no
rules.
TypeScript deep-merges its defaults into whatever rules is
passed, so a partial rules there keeps the default of the
direction it omits. Rust, like Go, cannot express that merge over a
typed option and treats any Some as complete. This is an
intentional divergence — see docs/reference.md.
custom: Option<CustomFn>Extra parser customization once the directive rule exists.
Implementations§
Source§impl DirectiveOptions
impl DirectiveOptions
Sourcepub fn new(name: impl Into<String>, open: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, open: impl Into<String>) -> Self
A directive named name, opened by the token source open.
Sourcepub fn with_close(self, close: impl Into<String>) -> Self
pub fn with_close(self, close: impl Into<String>) -> Self
Give the directive a close token.
Sourcepub fn with_action(
self,
action: impl Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Send + Sync + 'static,
) -> Self
pub fn with_action( self, action: impl Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Send + Sync + 'static, ) -> Self
Set a classic action: write the result to rule.node.
Sourcepub fn with_token_action(
self,
action: impl Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Send + Sync + 'static,
) -> Self
pub fn with_token_action( self, action: impl Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Send + Sync + 'static, ) -> Self
Set an action that may return a token for the close hook to forward.
Sourcepub fn with_action_path(self, path: impl Into<String>) -> Self
pub fn with_action_path(self, path: impl Into<String>) -> Self
Set a dotted-path action resolved against the plugin options when
the directive fires. See DirectiveAction::Path.
Sourcepub fn with_rules(self, rules: RulesOption) -> Self
pub fn with_rules(self, rules: RulesOption) -> Self
Override which host rules are modified.
Sourcepub fn with_custom(
self,
custom: impl Fn(&mut Tabnas, &DirectiveConfig) + Send + Sync + 'static,
) -> Self
pub fn with_custom( self, custom: impl Fn(&mut Tabnas, &DirectiveConfig) + Send + Sync + 'static, ) -> Self
Run custom once the directive rule exists.