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

pomsky-lang / pomsky / 12099739427

30 Nov 2024 09:51PM UTC coverage: 80.473% (-0.6%) from 81.072%
12099739427

push

github

Aloso
feat: character set intersections

200 of 274 new or added lines in 19 files covered. (72.99%)

3 existing lines in 3 files now uncovered.

4422 of 5495 relevant lines covered (80.47%)

391063.72 hits per line

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

33.33
/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
    pub(crate) fn new_expr(rules: Vec<Rule>, start_span: Span) -> Option<Rule> {
7✔
24
        rules
7✔
25
            .into_iter()
7✔
26
            .reduce(|a, b| match (a, b) {
7✔
NEW
27
                (Rule::Intersection(mut a), Rule::Intersection(b)) => {
×
NEW
28
                    a.span = a.span.join(b.span);
×
NEW
29
                    a.rules.extend(b.rules);
×
NEW
30
                    Rule::Intersection(a)
×
31
                }
NEW
32
                (Rule::Intersection(mut a), b) => {
×
NEW
33
                    a.span = a.span.join(b.span());
×
NEW
34
                    a.rules.push(b);
×
NEW
35
                    Rule::Intersection(a)
×
36
                }
37
                (a, b) => {
7✔
38
                    let span = a.span().join(b.span());
7✔
39
                    Rule::Intersection(Intersection { rules: vec![a, b], span })
7✔
40
                }
41
            })
7✔
42
            .map(|mut rule| {
7✔
43
                if let Rule::Intersection(i) = &mut rule {
7✔
44
                    i.span = i.span.join(start_span)
7✔
NEW
45
                }
×
46
                rule
7✔
47
            })
7✔
48
    }
7✔
49

50
    #[cfg(feature = "dbg")]
NEW
51
    pub(super) fn pretty_print(&self, buf: &mut crate::PrettyPrinter, needs_parens: bool) {
×
NEW
52
        if needs_parens {
×
NEW
53
            buf.start_indentation("(");
×
NEW
54
        }
×
55

NEW
56
        let len = self.rules.len();
×
NEW
57
        for (i, rule) in self.rules.iter().enumerate() {
×
NEW
58
            let needs_parens = matches!(
×
NEW
59
                rule,
×
60
                Rule::Intersection(_)
61
                    | Rule::Alternation(_)
62
                    | Rule::Lookaround(_)
63
                    | Rule::StmtExpr(_)
64
            );
65

NEW
66
            buf.push_str("& ");
×
NEW
67
            buf.increase_indentation(2);
×
NEW
68
            rule.pretty_print(buf, needs_parens);
×
NEW
69
            buf.decrease_indentation(2);
×
NEW
70
            if i < len - 1 {
×
NEW
71
                buf.write("\n");
×
NEW
72
            }
×
73
        }
74

NEW
75
        if needs_parens {
×
NEW
76
            buf.end_indentation(")");
×
NEW
77
        }
×
NEW
78
    }
×
79
}
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

© 2026 Coveralls, Inc