diff --git a/parser/src/pratt.rs b/parser/src/pratt.rs index d235cbd..0fdb176 100644 --- a/parser/src/pratt.rs +++ b/parser/src/pratt.rs @@ -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)) } diff --git a/parser/src/tests.rs b/parser/src/tests.rs index 79fc2e9..f8045a3 100644 --- a/parser/src/tests.rs +++ b/parser/src/tests.rs @@ -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)))")), ],