use crate::parse::Token;
use crate::verdict::Verdict;
const RUNTIME_OPTIONS_LINE: &str =
"Any `+RTS`, `-RTS` or `--RTS` argument is refused (GHC runtime options can write statistics to a named file).";
#[derive(Debug, Clone, Copy)]
pub(in crate::registry) struct SpecHooks {
env_assignment_positionals: bool,
ghc_rts: bool,
}
impl SpecHooks {
pub(in crate::registry) fn lower(env_assignment_positionals: Option<bool>, ghc_rts: Option<bool>) -> Self {
Self { env_assignment_positionals: env_assignment_positionals.unwrap_or(false), ghc_rts: ghc_rts.unwrap_or(false) }
}
pub(in crate::registry) fn refuses(&self, tokens: &[Token]) -> bool {
self.ghc_rts && tokens.iter().any(|t| crate::ghc_rts::is_runtime_option(t.as_str()))
}
pub(in crate::registry) fn classify_exports(&self, tokens: &[Token], verdict: Verdict) -> Verdict {
if !self.env_assignment_positionals {
return verdict;
}
crate::envvars::exported_verdict(tokens[1..].iter().map(Token::as_str)).combine(verdict)
}
pub(in crate::registry) fn describe(&self, description: String) -> String {
if !self.ghc_rts {
description
} else if description.is_empty() {
RUNTIME_OPTIONS_LINE.to_string()
} else if description.starts_with("- ") {
format!("{description}\n- {RUNTIME_OPTIONS_LINE}")
} else {
format!("{description} {RUNTIME_OPTIONS_LINE}")
}
}
}