parser: lower matched regexes to typed ones

This commit is contained in:
Guillem L. Jara
2026-05-25 14:14:05 +02:00
parent 5b69891bcf
commit fa77cb8f44
2 changed files with 8 additions and 3 deletions
+7 -2
View File
@@ -301,9 +301,14 @@ impl<'a, 'b> Pratt<'a, 'b> {
if op.is_non_associative() && lhs.is_non_associative() {
return Err(ParsingError::NonAssociativeOperator(lex.span()));
}
self.typed_regex = matches!(op, BinaryOperator::Matches | BinaryOperator::MatchesNot);
let is_regex = matches!(op, BinaryOperator::Matches | BinaryOperator::MatchesNot);
self.typed_regex = is_regex;
let rhs = self.parse_expression(lex, op.binding_power().1)?;
let mut rhs = self.parse_expression(lex, op.binding_power().1)?;
if is_regex && let Expr::Leaf(Atom::Regex(r)) = rhs {
// Has interactions with pretty printing, but makes the interpreter easier.
rhs = Expr::Leaf(Atom::TypedRegex(r));
}
Ok(Expr::node(op.expr(lhs, rhs), self.parser.arena))
}
+1 -1
View File
@@ -347,7 +347,7 @@ fn test_parser_logical_operators() {
rules: [
(None, Some("(body (And (And awk::a awk::b) (Eq awk::c 3)))")),
(None, Some("(body (Or (Or awk::a (Gt awk::b 2)) awk::c))")),
(None, Some("(body (Or (Matches 1 /a/) (And awk::b awk::c)))")),
(None, Some("(body (Or (Matches 1 @/a/) (And awk::b awk::c)))")),
(None, Some("(body (Negation awk::a))")),
(None, Some("(body (Negation (And awk::a awk::b)))")),
],