plotnik_bytecode/type_system/
quantifier.rs

1//! Quantifier kinds for type inference.
2//!
3//! Quantifiers determine cardinality: how many times a pattern can match.
4
5/// Quantifier kind for pattern matching.
6#[derive(Copy, Clone, PartialEq, Eq, Debug)]
7pub enum QuantifierKind {
8    /// `?` or `??` - zero or one.
9    Optional,
10    /// `*` or `*?` - zero or more.
11    ZeroOrMore,
12    /// `+` or `+?` - one or more.
13    OneOrMore,
14}
15
16impl QuantifierKind {
17    /// Whether this quantifier requires strict dimensionality (row capture).
18    ///
19    /// `*` and `+` produce arrays, so internal captures need explicit row structure.
20    /// `?` produces at most one value, so no dimensionality issue.
21    pub fn requires_row_capture(self) -> bool {
22        matches!(self, Self::ZeroOrMore | Self::OneOrMore)
23    }
24
25    /// Whether this quantifier guarantees at least one match.
26    pub fn is_non_empty(self) -> bool {
27        matches!(self, Self::OneOrMore)
28    }
29
30    /// Whether this quantifier can match zero times.
31    pub fn can_be_empty(self) -> bool {
32        matches!(self, Self::Optional | Self::ZeroOrMore)
33    }
34}