use crate::Span;
use super::Rule;
#[derive(Debug, Clone)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct Alternation {
pub rules: Vec<Rule>,
pub(crate) span: Span,
}
impl Alternation {
#[cfg(feature = "dbg")]
pub(super) fn pretty_print(&self, buf: &mut crate::PrettyPrinter, needs_parens: bool) {
if needs_parens {
buf.start_indentation("(");
}
let len = self.rules.len();
for (i, rule) in self.rules.iter().enumerate() {
let needs_parens =
matches!(rule, Rule::Alternation(_) | Rule::Lookaround(_) | Rule::StmtExpr(_));
buf.push_str("| ");
buf.increase_indentation(2);
rule.pretty_print(buf, needs_parens);
buf.decrease_indentation(2);
if i < len - 1 {
buf.write("\n");
}
}
if needs_parens {
buf.end_indentation(")");
}
}
}