hrw4u: More fixes for complex groups and logical operations#12907
hrw4u: More fixes for complex groups and logical operations#12907zwoop merged 2 commits intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issues with complex group handling and logical operations in the hrw4u transpiler (a DSL compiler for Apache Traffic Server's header_rewrite plugin). The changes eliminate redundant nested GROUP/GROUP:END pairs that were previously generated for parenthesized expressions and improve comment handling in the reverse compiler (u4wrh).
Changes:
- Fixed forward compiler (hrw4u) to prevent double-wrapping of grouped expressions by passing
grouped=Falseto nestedemit_expressioncalls when a GROUP is already open - Fixed section body emission to use
first_hook_emittedflag instead ofidx > 0for proper blank line handling between rules - Added comment deferral mechanism in reverse compiler (u4wrh) to properly handle comments inside if-blocks
- Updated test expectations to reflect simplified GROUP output (removed unnecessary nested GROUP pairs)
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/hrw4u/src/visitor.py | Fixed emit_factor to handle negated groups correctly and prevent double-wrapping by passing grouped=False; changed _emit_section_body to check first_hook_emitted instead of idx > 0 |
| tools/hrw4u/src/hrw_visitor.py | Added _deferred_comments list and _expecting_if_cond flag; implemented _flush_deferred_comments() and _close_if_chain_for_new_rule() for better comment and control flow handling |
| tools/hrw4u/tests/data/examples/all-nonsense.output.txt | Removed redundant nested GROUP pairs (lines 31-34, 38-41, 53-55) and extraneous blank lines |
| tools/hrw4u/tests/data/conds/group-*.{input,output,ast}.txt | Added new test cases for various group scenarios (OR, AND-NOT, nested, two groups, in-if) |
| tools/hrw4u/tests/data/conds/double-negation.output.txt | Updated to show correct GROUP/GROUP:END [NOT] pattern for double negation |
| tools/hrw4u/tests/data/conds/exceptions.txt | Updated comment explaining why double-negation test only works in forward direction |
bryancall
left a comment
There was a problem hiding this comment.
Good stuff — the core fix eliminating redundant double GROUP wrapping is correct and the new test cases are solid. A couple things to address:
Dead code: _close_if_chain_for_new_rule() and _expecting_if_cond
_close_if_chain_for_new_rule() is defined but never called, and _expecting_if_cond is initialized/reset but never set to True anywhere in this PR. Is this scaffolding for a follow-up? If so, I'd pull it out and include it when it's actually wired up.
Missing newline at EOF
double-negation.output.txt is missing its trailing newline — diff shows \ No newline at end of file.
|
Fixed the dead code. |
|
[approve ci autest] |
bryancall
left a comment
There was a problem hiding this comment.
Looks good — the double GROUP wrapping fix is clean and the test coverage is solid. Nice handling of the negated group case too.
One ask: can you add a PR description? The body is empty and it makes it harder for others to understand the changes at a glance (and the squash merge commit message will need something).
|
Cherry-picked to 10.2.x |
* hrw4u: More fixes for complex groups and logical operations * Fixes from reviews (cherry picked from commit 4955787)
This avoids the double wrapping of grouped expressions.