use crate::arm::{ARM_SEPARATOR, CONTENT_SEPARATOR_0, CONTENT_SEPARATOR_1, WILDCARD_ARM, MODIFIER_ACTIVATE, MODIFIER_DEACTIVATE, MODIFIER_PANIC};
pub enum NSCFGError {
MissingOperator,
EmptyNode,
InvalidCharacter(String),
AliasNotFound(String),
InvalidConfigurationPredicate(String),
EmptyArm,
WildcardArmNotLast,
ArmSeparatorMissing,
ContentSeparatorError,
WildcardArmMissing,
WildcardArmOnTarget,
TargetInFunction,
LegacySyntaxError,
MixedSyntaxError,
ContentSeparatorMissing,
ModifierNotFirst,
#[allow(dead_code)]
ModifierPanicRelease,
MatchModifierMoreThanOneActivate,
MatchDeactivatedWildArm,
}
impl NSCFGError {
pub fn message(&self, tokens : &str) -> String {
match self {
NSCFGError::MissingOperator => format!("Operator `&` or '|' missing for `{:?}`. Target must not contain space.", tokens),
NSCFGError::EmptyNode => format!("Empty node generated from attributes. Are you missing a statement between separator?"),
NSCFGError::InvalidCharacter(c) => format!("Invalid character `{}` for `{:?}`.", c, tokens),
NSCFGError::AliasNotFound(alias) => format!("Alias `{}` has no match! Is it added in config.toml as `target_cfg-{}`?", alias, alias),
NSCFGError::InvalidConfigurationPredicate(cfg_prd) => format!("Configuration predicate `{}` has no match! Is it added in config.toml as `target_cfg_predicate-{}`?", cfg_prd, cfg_prd),
NSCFGError::EmptyArm => format!("Empty arm with no attributes detected!"),
NSCFGError::WildcardArmNotLast => format!("Wildcard branch `_` must ALWAYS be the last branch."),
NSCFGError::ArmSeparatorMissing => format!("Arm syntax incorrect. Are you missing a separator `{}` between arms?", ARM_SEPARATOR),
NSCFGError::ContentSeparatorError => format!("Arm syntax incorrect. Is your arm separator `{}{}` syntax Ok?", CONTENT_SEPARATOR_0, CONTENT_SEPARATOR_1),
NSCFGError::WildcardArmMissing => format!("Ensure that all possible cases are being handled by adding a match arm with a `{}` wildcard pattern.", WILDCARD_ARM),
NSCFGError::WildcardArmOnTarget => format!("target_cfg! macro cannot have a `{}` wildcard pattern.", WILDCARD_ARM),
NSCFGError::TargetInFunction => format!("target_cfg! macro cannot be used inside a function. Use match_cfg! instead."),
NSCFGError::LegacySyntaxError => format!("Legacy syntax error in `{}`.", tokens),
NSCFGError::MixedSyntaxError => format!("Legacy syntax and simplified syntax can't be mixed on same arm!"),
NSCFGError::ContentSeparatorMissing => format!("Arm content separator `{}{}` missing!", CONTENT_SEPARATOR_0, CONTENT_SEPARATOR_1),
NSCFGError::ModifierNotFirst => format!("Arm modifiers `{}`, `{}` and `{}` must be the first character of arm!", MODIFIER_ACTIVATE, MODIFIER_DEACTIVATE, MODIFIER_PANIC),
NSCFGError::ModifierPanicRelease => format!("Arm modifiers `{}` and `{}` will panic during release compilation by default! This behaviour can be changed. See https://github.com/NickelAngeStudio/nscfg/wiki/Syntax#six-modifiers", MODIFIER_ACTIVATE, MODIFIER_DEACTIVATE),
NSCFGError::MatchModifierMoreThanOneActivate => format!("match_cfg! cannot have more than one `{}` modifier!", MODIFIER_ACTIVATE),
NSCFGError::MatchDeactivatedWildArm => format!("match_cfg! cannot deactivate wildcard arm with `{}` modifier!", MODIFIER_DEACTIVATE),
}
}
}