pomsky_syntax/exprs/
intersection.rs1use crate::Span;
5
6use super::Rule;
7
8#[derive(Debug, Clone)]
16#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
17pub struct Intersection {
18 pub rules: Vec<Rule>,
19 pub span: Span,
20}
21
22impl Intersection {
23 #[cfg(feature = "dbg")]
24 pub(super) fn pretty_print(&self, buf: &mut crate::PrettyPrinter, needs_parens: bool) {
25 if needs_parens {
26 buf.start_indentation("(");
27 }
28
29 let len = self.rules.len();
30 for (i, rule) in self.rules.iter().enumerate() {
31 let needs_parens = matches!(
32 rule,
33 Rule::Intersection(_)
34 | Rule::Alternation(_)
35 | Rule::Lookaround(_)
36 | Rule::StmtExpr(_)
37 );
38
39 buf.push_str("& ");
40 buf.increase_indentation(2);
41 rule.pretty_print(buf, needs_parens);
42 buf.decrease_indentation(2);
43 if i < len - 1 {
44 buf.write("\n");
45 }
46 }
47
48 if needs_parens {
49 buf.end_indentation(")");
50 }
51 }
52}