• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pomsky-lang / pomsky / 12166507628

04 Dec 2024 07:03PM UTC coverage: 80.471% (+0.009%) from 80.462%
12166507628

push

github

Aloso
refactor: improve parser

77 of 81 new or added lines in 3 files covered. (95.06%)

1 existing line in 1 file now uncovered.

4372 of 5433 relevant lines covered (80.47%)

395515.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pomsky-syntax/src/exprs/intersection.rs
1
//! Implements intersection: `'alt1' & 'alt2' & 'alt3'`. This is not a common feature,
2
//! and only makes sense in certain scenarios.
3

4
use crate::Span;
5

6
use super::Rule;
7

8
/// An [alternation](https://www.regular-expressions.info/alternation.html).
9
/// This is a list of alternatives. Each alternative is a [`Rule`].
10
///
11
/// If an alternative consists of multiple expressions (e.g. `'a' | 'b' 'c'`),
12
/// that alternative is a [`Rule::Group`]. Note that a group's parentheses are
13
/// removed when compiling to a regex if they aren't required. In other words,
14
/// `'a' | ('b' 'c')` compiles to `a|bc`.
15
#[derive(Debug, Clone)]
16
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
17
pub struct Intersection {
18
    pub rules: Vec<Rule>,
19
    pub span: Span,
20
}
21

22
impl Intersection {
23
    #[cfg(feature = "dbg")]
UNCOV
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
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc