Skip to content

hrw4u: More fixes for complex groups and logical operations#12907

Merged
zwoop merged 2 commits intoapache:masterfrom
zwoop:Hrw4uMoreGroupFixes
Mar 3, 2026
Merged

hrw4u: More fixes for complex groups and logical operations#12907
zwoop merged 2 commits intoapache:masterfrom
zwoop:Hrw4uMoreGroupFixes

Conversation

@zwoop
Copy link
Copy Markdown
Contributor

@zwoop zwoop commented Feb 23, 2026

This avoids the double wrapping of grouped expressions.

@zwoop zwoop added this to the 10.2.0 milestone Feb 23, 2026
@zwoop zwoop requested a review from Copilot February 23, 2026 16:28
@zwoop zwoop self-assigned this Feb 23, 2026
@zwoop zwoop added the hrw4u label Feb 23, 2026
@bryancall bryancall self-requested a review February 23, 2026 16:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=False to nested emit_expression calls when a GROUP is already open
  • Fixed section body emission to use first_hook_emitted flag instead of idx > 0 for 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

Copy link
Copy Markdown
Contributor

@bryancall bryancall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zwoop zwoop requested a review from bryancall February 23, 2026 23:18
@zwoop
Copy link
Copy Markdown
Contributor Author

zwoop commented Feb 23, 2026

Fixed the dead code.

@zwoop
Copy link
Copy Markdown
Contributor Author

zwoop commented Feb 24, 2026

[approve ci autest]

@zwoop zwoop dismissed bryancall’s stale review February 27, 2026 22:26

Addressed concerns.

Copy link
Copy Markdown
Contributor

@bryancall bryancall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@zwoop zwoop merged commit 4955787 into apache:master Mar 3, 2026
15 checks passed
@zwoop zwoop deleted the Hrw4uMoreGroupFixes branch March 3, 2026 18:43
@github-project-automation github-project-automation Bot moved this to For v10.2.0 in ATS v10.2.x Mar 3, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.0 to Picked v10.2.0 in ATS v10.2.x Mar 18, 2026
@cmcfarlen
Copy link
Copy Markdown
Contributor

Cherry-picked to 10.2.x

cmcfarlen pushed a commit that referenced this pull request Mar 18, 2026
* hrw4u: More fixes for complex groups and logical operations

* Fixes from reviews

(cherry picked from commit 4955787)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Picked v10.2.0

Development

Successfully merging this pull request may close these issues.

4 participants