juanthropic opened a new pull request, #13180:
URL: https://github.com/apache/trafficserver/pull/13180
Pulls the hrw4u AST out of "untyped strings built by something called a
visitor" into a typed, inspectable artifact, and adds a dev-only CLI to
look at it.
## AST contract
- Rename `ASTVisitor` to `ASTBuilder`. The class constructs an AST from
an ANTLR parse tree; it does not visit one.
- Replace raw-string fields on `Assignment`, `Comparison`, `LogicalOp`,
and `VarSection` with four AST-local enums (`AssignOp`, `CmpOp`,
`BoolOp`, `VarSectionKind`) that carry identity only. AST consumers
pattern-match against semantic names rather than grammar spellings,
so e.g. changing `==` to `eq` in the grammar would only touch the
builder.
- Wire the builder to actually emit the new enum values; the dataclass
annotations had been lying.
- Rename the shared `raw` value field to `text` / `name` / `pattern` on
the three node types where construction strips delimiters or sigils
(quotes, `$`, `/`); keep `raw` where nothing is stripped, so the
asymmetry encodes a real distinction.
- Promote `!` to a named `BANG` token so the negated `factor` and `in`
forms are discriminated via `ctx.BANG()` instead of fragile textual
scans of child nodes.
- Namespace `ast_nodes` imports in the builder (drop `import *`); tests
keep the wildcard since they read more naturally as the module's
public API consumer.
- Tidy `ast_nodes.py`: comment the enum `__repr__` alias so it doesn't
read as dead code, and switch the remaining `Union[...]` aliases to
`X | Y`.
- Note that `Target` is a value class, not an AST node, since it's
destructured from an `Assignment`'s IDENT lhs.
## Inspection tool
Adds an `hrw4u-ast` CLI that emits a chosen IR (`cst` or `ast`) from an
HRW4U source file. Stages are registered in a dict so future stages
(`ast-resolved`, `ast-validated`, ...) are one-line additions; `--stage`
defaults to `ast` since that's the common case.
The tool is dev-only: it's run from the source tree via
`uv run scripts/hrw4u-ast`, not shipped via `pip` or PyInstaller (each
`--onedir` bundle would add ~30–50 MB to release artifacts).
## Tests
Backfills tests for builder paths that the existing suite parsed but
never asserted on, so the enum/field renames don't silently regress
qualified function names, `!in` with an iprange RHS, lowercase `false`,
empty string assignment, `Target.from_dotted` with and without a
namespace, and a few other gaps surfaced along the way. Adds a smoke
test for the new CLI surface.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]