diff --git a/crates/plotnik-lib/src/compile/quantifier.rs b/crates/plotnik-lib/src/compile/quantifier.rs index 16ad9b57..a8af5e29 100644 --- a/crates/plotnik-lib/src/compile/quantifier.rs +++ b/crates/plotnik-lib/src/compile/quantifier.rs @@ -51,7 +51,35 @@ impl QuantifierKind { pub fn is_greedy(self) -> bool { matches!(self, Self::Optional | Self::Star | Self::Plus) } +} + +/// Result of parsing a quantified expression. +enum QuantifierParse { + /// No inner expression found. + Empty, + /// Inner expression exists but no valid quantifier operator. + Plain(Expr), + /// Valid quantified expression with inner and kind. + Quantified { inner: Expr, kind: QuantifierKind }, +} +/// Parse a quantified expression into its components. +/// +/// Returns `Empty` if no inner, `Plain` if inner but no quantifier, +/// `Quantified` if both inner and valid quantifier operator. +fn parse_quantifier(quant: &ast::QuantifiedExpr) -> QuantifierParse { + let Some(inner) = quant.inner() else { + return QuantifierParse::Empty; + }; + + let Some(op) = quant.operator() else { + return QuantifierParse::Plain(inner); + }; + + match QuantifierKind::from_syntax(op.kind()) { + Some(kind) => QuantifierParse::Quantified { inner, kind }, + None => QuantifierParse::Plain(inner), + } } /// Configuration for unified quantifier compilation. @@ -83,16 +111,12 @@ impl Compiler<'_> { nav_override: Option