use std::collections::BTreeSet;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct OptimizationOptions {
pub(crate) entry_rules: BTreeSet<String>,
pub(crate) prune_unreachable: bool,
pub(crate) inline_trivial_rules: bool,
pub(crate) optimize_precedence_ladders: bool,
pub(crate) static_lexer_dfa: bool,
pub(crate) static_parser_dfa: bool,
pub(crate) static_dfa_only: bool,
pub(crate) dump_dfas: Option<String>,
pub(crate) profile_decisions: bool,
pub(crate) report_only: bool,
pub(crate) strict: bool,
}
impl OptimizationOptions {
pub fn new() -> Self {
Self::default()
}
pub fn entry_rule(&mut self, name: impl Into<String>) -> &mut Self {
self.entry_rules.insert(name.into());
self
}
pub const fn prune_unreachable_rules(&mut self, enabled: bool) -> &mut Self {
self.prune_unreachable = enabled;
self
}
pub const fn inline_trivial_rules(&mut self, enabled: bool) -> &mut Self {
self.inline_trivial_rules = enabled;
self
}
pub const fn optimize_precedence_ladders(&mut self, enabled: bool) -> &mut Self {
self.optimize_precedence_ladders = enabled;
self
}
pub const fn static_lexer_dfa(&mut self, enabled: bool) -> &mut Self {
self.static_lexer_dfa = enabled;
self
}
pub const fn static_parser_dfa(&mut self, enabled: bool) -> &mut Self {
self.static_parser_dfa = enabled;
self
}
pub const fn static_dfa_only(&mut self, enabled: bool) -> &mut Self {
self.static_dfa_only = enabled;
self
}
pub fn dump_dfas(&mut self, spec: impl Into<String>) -> &mut Self {
self.dump_dfas = Some(spec.into());
self
}
pub const fn profile_decisions(&mut self, enabled: bool) -> &mut Self {
self.profile_decisions = enabled;
self
}
pub const fn report_only(&mut self, enabled: bool) -> &mut Self {
self.report_only = enabled;
self
}
pub const fn strict(&mut self, enabled: bool) -> &mut Self {
self.strict = enabled;
self
}
pub(crate) const fn is_report_only(&self) -> bool {
self.report_only || self.has_parser_reports()
}
#[cfg(feature = "download")]
pub(crate) fn entry_rules(&self) -> impl Iterator<Item = &str> {
self.entry_rules.iter().map(String::as_str)
}
#[cfg(feature = "download")]
pub(crate) const fn prune_unreachable(&self) -> bool {
self.prune_unreachable
}
#[cfg(feature = "download")]
pub(crate) const fn inline_trivial(&self) -> bool {
self.inline_trivial_rules
}
#[cfg(feature = "download")]
pub(crate) const fn optimize_ladders(&self) -> bool {
self.optimize_precedence_ladders
}
#[cfg(feature = "download")]
pub(crate) const fn static_dfa(&self) -> bool {
self.static_lexer_dfa
}
#[cfg(feature = "download")]
pub(crate) const fn static_parser_dfa_enabled(&self) -> bool {
self.static_parser_dfa
}
#[cfg(feature = "download")]
pub(crate) const fn static_dfa_only_enabled(&self) -> bool {
self.static_dfa_only
}
#[cfg(feature = "download")]
pub(crate) const fn strict_enabled(&self) -> bool {
self.strict
}
pub(crate) const fn has_parser_reports(&self) -> bool {
self.dump_dfas.is_some() || self.profile_decisions
}
}