Skip to content

Commit 4a2bd58

Browse files
committed
Fix merge conflicts, remove dead code
1 parent bb8cbaf commit 4a2bd58

4 files changed

Lines changed: 97 additions & 46 deletions

File tree

doc/admin-guide/configuration/hrw4u.en.rst

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,86 @@ HRW4U aims to improve the following:
6060
Standalone Compiler
6161
-------------------
6262

63-
A standalone Python compiler is available in ``tools/hrw4u`` for development:
63+
A standalone Python compiler is available in ``tools/hrw4u`` for development,
64+
testing, and migration workflows. It provides additional features not available
65+
in the native C++ parser:
6466

6567
- Debug tracing (``--debug``)
6668
- IDE integration via LSP (``hrw4u-lsp``)
6769
- Reverse conversion (``u4wrh``) to convert header_rewrite to hrw4u
6870

69-
Build with Python 3.10+ using ``./bootstrap.sh && make package``.
71+
Building the Standalone Compiler
72+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73+
74+
Build with Python 3.10+ using the bootstrap script:
75+
76+
.. code-block:: none
77+
78+
cd tools/hrw4u
79+
./bootstrap.sh
80+
make package
81+
82+
This produces a PIP package in the ``dist`` directory. Install with:
83+
84+
.. code-block:: none
85+
86+
pipx install dist/hrw4u-1.4.0-py3-none-any.whl
87+
88+
Basic Usage
89+
^^^^^^^^^^^
90+
91+
Compile a single file to stdout:
92+
93+
.. code-block:: none
94+
95+
hrw4u some_file.hrw4u
96+
97+
Compile from stdin:
98+
99+
.. code-block:: none
100+
101+
cat some_file.hrw4u | hrw4u
102+
103+
Compile multiple files to stdout (separated by ``# ---``):
104+
105+
.. code-block:: none
106+
107+
hrw4u file1.hrw4u file2.hrw4u file3.hrw4u
108+
109+
Bulk Compilation
110+
^^^^^^^^^^^^^^^^
111+
112+
For bulk compilation, use the ``input:output`` format to compile multiple files
113+
to their respective output files in a single command:
114+
115+
.. code-block:: none
116+
117+
hrw4u file1.hrw4u:file1.conf file2.hrw4u:file2.conf file3.hrw4u:file3.conf
118+
119+
This is particularly useful for build systems or when processing many configuration
120+
files at once. All files are processed in a single invocation, improving performance
121+
for large batches of files.
122+
123+
Reverse Tool (u4wrh)
124+
^^^^^^^^^^^^^^^^^^^^
125+
126+
The reverse tool converts existing ``header_rewrite`` configurations to ``hrw4u``.
127+
It supports the same usage patterns:
128+
129+
.. code-block:: none
130+
131+
# Convert single file to stdout
132+
u4wrh existing_config.conf
133+
134+
# Bulk conversion
135+
u4wrh file1.conf:file1.hrw4u file2.conf:file2.hrw4u
136+
137+
IDE Support
138+
^^^^^^^^^^^
139+
140+
For IDE integration, the package provides an LSP server named ``hrw4u-lsp``.
141+
This enables syntax highlighting, error diagnostics, and auto-completion in
142+
editors that support the Language Server Protocol.
70143

71144
Syntax Differences
72145
==================
@@ -401,8 +474,19 @@ These can be used with both sets and equality checks, using the ``with`` keyword
401474
Debugging
402475
=========
403476

404-
Syntax errors are reported with filename, line, and column position. For development,
405-
the standalone compiler's ``--debug all`` option traces lexer, parser, and evaluation.
477+
Syntax errors are reported with filename, line, and column position. The native
478+
parser in ``header_rewrite`` provides clear error messages when parsing fails.
479+
480+
For development and debugging complex rules, use the standalone Python compiler
481+
with ``--debug`` to trace:
482+
483+
- Lexer and parser behavior
484+
- Condition evaluations
485+
- State and output emission
486+
487+
.. code-block:: none
488+
489+
hrw4u --debug /path/to/rules.hrw4u
406490
407491
Examples
408492
========

tools/hrw4u/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ build-backend = "setuptools.build_meta"
2020

2121
[project]
2222
name = "hrw4u"
23-
version = "1.4.2"
23+
version = "1.5.0"
2424
description = "HRW4U CLI tool for Apache Traffic Server header rewrite rules"
2525
authors = [
2626
{name = "Leif Hedstrom", email = "leif@apache.org"}

tools/hrw4u/scripts/u4wrh

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,14 @@ from u4wrh.u4wrhParser import u4wrhParser
2727

2828
def main() -> None:
2929
"""Main entry point for the u4wrh script."""
30-
parser, output_group = create_base_parser("Process header_rewrite (HRW) lines and reconstruct hrw4u source.")
31-
32-
# Argument parsing
33-
output_group.add_argument("--hrw4u", action="store_true", help="Produce reconstructed hrw4u output (default)")
34-
parser.add_argument("--no-comments", action="store_true", help="Skip comment preservation (ignore comments in output)")
35-
parser.add_argument(
36-
"--no-merge-sections",
37-
action="store_true",
38-
help="Disable section merging (create separate sections for each cond directive)")
39-
args = parser.parse_args()
40-
41-
# Default to hrw4u output if neither AST nor hrw4u specified
42-
if not (args.ast or args.hrw4u):
43-
args.hrw4u = True
44-
45-
content, filename = process_input(args.input_file)
46-
tree, parser_obj, error_collector = create_parse_tree(
47-
content, filename, u4wrhLexer, u4wrhParser, "u4wrh", not args.stop_on_error)
48-
49-
# Generate output
50-
generate_output(tree, parser_obj, HRWInverseVisitor, filename, args, error_collector)
30+
run_main(
31+
description="Process header_rewrite (HRW) lines and reconstruct hrw4u source.",
32+
lexer_class=u4wrhLexer,
33+
parser_class=u4wrhParser,
34+
visitor_class=HRWInverseVisitor,
35+
error_prefix="u4wrh",
36+
output_flag_name="hrw4u",
37+
output_flag_help="Produce reconstructed hrw4u output (default)")
5138

5239

5340
if __name__ == "__main__":

tools/hrw4u/src/common.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,6 @@ def fatal(message: str) -> NoReturn:
109109
sys.exit(1)
110110

111111

112-
def create_base_parser(description: str) -> tuple[argparse.ArgumentParser, argparse._MutuallyExclusiveGroup]:
113-
"""Create base argument parser with common options."""
114-
parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawDescriptionHelpFormatter)
115-
parser.add_argument(
116-
"input_file",
117-
help="The input file to parse (default: stdin)",
118-
nargs="?",
119-
type=argparse.FileType("r", encoding="utf-8"),
120-
default=sys.stdin)
121-
122-
output_group = parser.add_mutually_exclusive_group()
123-
output_group.add_argument("--ast", action="store_true", help="Produce the ANTLR parse tree only")
124-
125-
parser.add_argument("--debug", action="store_true", help="Enable debug output")
126-
parser.add_argument(
127-
"--stop-on-error", action="store_true", help="Stop processing on first error (default: collect and report multiple errors)")
128-
129-
return parser, output_group
130-
131-
132112
def process_input(input_file: TextIO) -> tuple[str, str]:
133113
"""Read input content and determine filename."""
134114
content = input_file.read()

0 commit comments

Comments
 (0)