#[non_exhaustive]pub enum MacroError {
NoRules,
DuplicateBinding {
rule: usize,
name: Symbol,
},
UnboundVariable {
rule: usize,
name: Symbol,
},
StillRepeating {
rule: usize,
name: Symbol,
},
NoRepeatingVariable {
rule: usize,
},
EmptyRepetition {
rule: usize,
},
OptionalSeparator {
rule: usize,
},
}Expand description
Why Macro::new rejected a macro definition.
Every check that can be made without an invocation is made when the macro is
defined, so a macro that compiles can only fail to expand for reasons that
depend on the input. Each variant names the offending rule by its index in
the list passed to Macro::new; metavariable names are reported as the
Symbol the definition used, which the caller resolves through its own
interner.
The enum is #[non_exhaustive]: later releases may add checks.
§Examples
use macro_lang::{Macro, MacroError, Rule, Template};
use intern_lang::Interner;
let mut names = Interner::new();
let x = names.intern("x");
// The template uses `$x`, but the pattern never binds it.
let err = Macro::<char>::new(names.intern("m"), vec![Rule {
pattern: vec![],
template: vec![Template::Var(x)],
}]).unwrap_err();
assert_eq!(err, MacroError::UnboundVariable { rule: 0, name: x });Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NoRules
The macro has no rules, so no invocation could ever match it. Give it at least one rule.
DuplicateBinding
A pattern binds the same metavariable name twice, so a template use of it would be ambiguous. Rename one of the bindings.
UnboundVariable
A template uses a metavariable its rule’s pattern never binds. Bind it in the pattern, or write the token literally.
StillRepeating
A template uses a repeating metavariable outside enough repetitions to
expand it: the pattern captured it inside n repetitions, but the
template uses it inside fewer. Wrap the use in a Template::Repeat.
NoRepeatingVariable
A template repetition contains no metavariable that repeats at its depth, so there is no way to know how many times to write it. Use a repeating metavariable inside it, or remove the repetition.
EmptyRepetition
A pattern repetition can match without consuming anything, so it could repeat forever. Give its body at least one token, group, or binding that must be present.
OptionalSeparator
A pattern repetition uses Kleene::ZeroOrOne
together with a separator. An optional element never repeats, so the
separator could never appear. Remove the separator.
Trait Implementations§
Source§impl Clone for MacroError
impl Clone for MacroError
impl Copy for MacroError
Source§impl Debug for MacroError
impl Debug for MacroError
Source§impl Display for MacroError
impl Display for MacroError
impl Eq for MacroError
Source§impl Error for MacroError
impl Error for MacroError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()