masaori335 opened a new pull request, #14038:
URL: https://github.com/apache/trafficserver/pull/14038
The last piece for #13680
# Motivation
#13857 added Sema, a front end that lowers the parse tree to an AST and
resolves it, and a parity test that holds
its `.conf` byte-identical to the CST visitor's. The CLI and the LSP still
ran the CST visitor, which reports some
errors badly:
- A procedure called with the wrong number of arguments is reported as a
visitor error at 0:0.
- An error inside a procedure comes without its source line.
`--output hrw4u` (flatten) had its own procedure expansion on the CST. It
pasted source slices and substituted
`$params` with a regex. It validated nothing, did not follow the compiler's
substitution rules, and crashed on
`SESSION_VARS`.
# Approach
All three paths run Sema:
- **`.conf`:** the CLI compiles through `compile_to_conf`, the path the
parity test covers.
- **`--output hrw4u`:** `Sema.expand` returns the program with every
procedure call replaced by the body Sema
inlined. `ast_unparse` renders the result. It moves from `tests/` to
`src/`, since it is now shipped code.
The output is the program as if each call were written out, so compiling
it needs no procedures path.
- **LSP:** diagnostics come from the same `ASTVisitor` + `Sema` run. Hover
and definition read the procedure table
from that run. The registry entry keeps the declaration's span, so
go-to-definition can open the declaration's
line.
The commits are kept separate so that each one makes a single decision.
# Behavior changes
- Procedure errors quote their source line. A wrong-arity call is reported
at the call.
- `--output hrw4u`:
- Formatting is re-rendered from the AST, so a trailing comment moves to
its own line.
- An empty section or `VARS` block is dropped.
- An invalid program writes nothing.
- `SESSION_VARS` no longer crashes.
- Its `.conf` differs from the source's `.conf` only where the emitter
frames an inlined body: comments, blank
lines and the hook line.
- LSP: an error-recovered parse tree cannot be lowered to an AST, so a
document with a syntax error shows only the
syntax error, as the CLI does. While it is there, hover and definition use
the last analysis without errors.
# Testing
- `make test` in `tools/hrw4u` passes at every commit (1475 tests at the
tip).
- New tests pin `--output hrw4u` (`test_cli.py`) and the LSP's procedure
hover and definition (`test_lsp.py`).
The LSP tests were written before the switch and pass on both front ends.
- I compared the CLI on the CST and on Sema over every test input. Every
config that compiles is byte-identical.
The only differences are procedure error the source line and give the
call'sposition.
- `conf(flatten(x)) == conf(x)` holds for iles, with the framing differences
above.
# Follow-ups
- `visitor.py` cannot be deleted yet. The CLI no longer uses it, but the
parity test, the test golden helpers and
`scripts/testcase.py` still do. `visitor_base.py` stays after that, since
`HRWInverseVisitor` shares it.
- Not addressed here; both front ends behave the same:
- A bare `$param` takes the argument as output hrw4u` can therefore write
sourcethat
does not parse, such as `X = a b;`.
- The LSP places an error inside an inlined procedure at the procedure
file's line and column on the caller's
document.
--
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]