juanthropic opened a new pull request, #13126:
URL: https://github.com/apache/trafficserver/pull/13126

   ## Summary
   
   Adds a semantic AST and visitor for the hrw4u tool, converting
   the ANTLR parse tree into typed, immutable Python dataclasses
   that downstream visitors can operate on, including static
   analysis, code generation, and a future user-configurable
   policy linter.
   
   The ANTLR parse tree mirrors the grammar structure, not the
   domain, so every consumer must navigate intermediate rule nodes,
   punctuation tokens, and context wrappers. The AST strips that
   away and exposes typed, semantic nodes (e.g. `Comparison.operator`,
   `IfBlock.body`). Only `ASTVisitor` needs to understand the parse
   tree, so grammar changes are isolated to one file and all
   downstream visitors stay insulated.
   
   - `ast_nodes.py` — Frozen dataclasses for all hrw4u constructs:
     assignments, function calls, comparisons, logical/negation
     operators, if/elif/else blocks, var/use/procedure declarations,
     and sections. Includes `Target` decomposition and type aliases
     (`ConditionExpr`, `BodyNode`, `TopLevelNode`).
   - `ast_visitor.py` — `ASTVisitor` that walks the ANTLR parse tree
     and produces an `HRW4UAST`. Only `visitProgram` is overridden
     from the ANTLR base; all other dispatch is internal. Raises
     `ValueError` on unhandled grammar alternatives to catch
     visitor-grammar drift early.
   
   ## Test plan
   
   - `test_ast_nodes.py` — Unit tests for `Target.from_dotted`
     parsing, node construction, and immutability.
   - `test_ast_visitor.py` — Integration tests covering the full
     source-to-AST pipeline: sections, all statement types, every
     condition operator, if/elif/else nesting, real config patterns
     (IP ranges, set membership, WITH modifiers, boolean coercion),
     line number tracking across all 17 node types, and error
     handling.


-- 
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]

Reply via email to