mirror of
https://github.com/uutils/awk.git
synced 2026-06-10 16:15:04 -07:00
parser: lower matched regexes to typed ones
This commit is contained in:
+7
-2
@@ -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
@@ -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)))")),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user