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

pomsky-lang / pomsky / 9142134100

18 May 2024 07:23PM UTC coverage: 82.949% (-1.3%) from 84.258%
9142134100

push

github

Aloso
fix e2e tests

1 of 1 new or added line in 1 file covered. (100.0%)

271 existing lines in 24 files now uncovered.

4242 of 5114 relevant lines covered (82.95%)

420176.26 hits per line

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

86.05
/pomsky-syntax/src/exprs/group.rs
1
use crate::Span;
2

3
use super::Rule;
4

5
/// A group, i.e. sequence of rules. A group is either capturing or
6
/// non-capturing.
7
///
8
/// If it is capturing, it must be wrapped in parentheses, and can have a name.
9
/// If it is non-capturing, the parentheses can be omitted in same cases.
10
#[derive(Debug, Clone)]
11
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
12
pub struct Group {
13
    pub parts: Vec<Rule>,
14
    pub kind: GroupKind,
15
    pub span: Span,
16
}
17

18
impl Group {
19
    pub fn new(parts: Vec<Rule>, kind: GroupKind, span: Span) -> Self {
302✔
20
        Group { parts, kind, span }
302✔
21
    }
302✔
22

23
    #[cfg(feature = "dbg")]
24
    pub(super) fn pretty_print(&self, buf: &mut crate::PrettyPrinter, needs_parens: bool) {
4✔
25
        let use_parens =
4✔
26
            matches!(self.kind, GroupKind::Capturing(_) | GroupKind::Atomic) || needs_parens;
4✔
27

28
        match &self.kind {
4✔
29
            GroupKind::Capturing(capture) => {
1✔
30
                buf.push(':');
1✔
31
                if let Some(name) = &capture.name {
1✔
32
                    buf.push_str(name);
1✔
33
                }
1✔
34
            }
35
            GroupKind::Atomic => {
×
36
                buf.push_str("atomic ");
×
UNCOV
37
            }
×
38
            GroupKind::Normal | GroupKind::Implicit => {}
3✔
39
        }
40

41
        if self.parts.is_empty() {
4✔
42
            buf.push_str("()");
×
UNCOV
43
        } else {
×
44
            if self.kind != GroupKind::Implicit {
4✔
45
                buf.start_indentation("(");
2✔
46
            }
2✔
47

48
            let len = self.parts.len();
4✔
49
            for (i, part) in self.parts.iter().enumerate() {
8✔
50
                let child_needs_parens = if len == 1 {
8✔
51
                    if use_parens {
2✔
52
                        false
2✔
53
                    } else {
UNCOV
54
                        needs_parens
×
55
                    }
56
                } else {
57
                    use Rule::*;
58
                    matches!(part, Lookaround(_) | StmtExpr(_) | Alternation(_) | Group(_))
6✔
59
                };
60
                part.pretty_print(buf, child_needs_parens);
8✔
61
                if i < len - 1 {
8✔
62
                    buf.write("\n");
4✔
63
                }
4✔
64
            }
65

66
            if self.kind != GroupKind::Implicit {
4✔
67
                buf.end_indentation(")");
2✔
68
            }
2✔
69
        }
70
    }
4✔
71
}
72

73
#[derive(Debug, Clone, PartialEq, Eq)]
74
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
75
pub enum GroupKind {
76
    /// A (possibly named) capturing group e.g. `:foo`
77
    Capturing(Capture),
78
    /// An atomic group
79
    Atomic,
80
    /// A normal group with a set of parentheses
81
    Normal,
82
    /// An implicit group, with no parentheses
83
    Implicit,
84
}
85

86
impl GroupKind {
87
    pub fn is_normal(&self) -> bool {
1,863✔
88
        matches!(self, GroupKind::Normal)
1,863✔
89
    }
1,863✔
90
}
91

92
#[derive(Debug, Clone, PartialEq, Eq)]
93
pub struct Capture {
94
    pub name: Option<String>,
95
}
96

97
impl Capture {
98
    pub fn new(name: Option<&str>) -> Self {
85✔
99
        Capture { name: name.map(str::to_string) }
85✔
100
    }
85✔
101
}
102

103
#[cfg(feature = "arbitrary")]
104
impl arbitrary::Arbitrary<'_> for Capture {
105
    fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
106
        if u.arbitrary()? {
107
            Ok(Capture { name: Some(super::arbitrary::Ident::create(u)?) })
108
        } else {
109
            Ok(Capture { name: None })
110
        }
111
    }
112

113
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
114
        (1, None)
115
    }
116
}
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