Commit 1cd64eb
Refactor dialect front ends behind a PlxSurface.parse_body vtable
The transpiler put every dialect's lexer, parser, and emitter inside the
single ~11k-line src/plx_transpile.c and dispatched them with a hardcoded
`block_style` if-ladder. This inverts SOLID responsibility: the "general"
transpiler owned each language. This commit restructures it to mirror the
precomp design — a dialect-neutral engine plus per-dialect front ends selected
through a function pointer on the per-dialect descriptor.
Architecture:
- PlxSurface (the per-dialect descriptor already threaded as cx->surf) gains a
vtable method `void (*parse_body)(struct PlxCtx *cx)` and a
`self_contained_block` flag. plx_transpile() now calls
`cx.surf->parse_body(&cx)` and runs one assemble tail (conditional on
self_contained_block for PL/SQL, which emits its own DECLARE/BEGIN/END) —
the block_style if-ladder is gone. block_style survives only as a lexer hint.
- New src/plx_engine.h exposes the shared engine: the Ctx (now `struct PlxCtx`),
Tok/PlxLocal2 types, PLX_MAX_DEPTH/PLX_DIAG_* macros, and the plx_*-prefixed
entry points (plx_lex, plx_rewrite_expr, plx_emit_core/leaf, plx_span_text,
plx_local_add/find, plx_skip_seps, plx_is_ident[_start], ...). The engine
(lexer, expression rewriter, leaf emitter, symbol table, interpolation,
assemble) stays in plx_transpile.c, now ~2.6k lines.
- Each dialect's tokenizer/parser/emitter moves into its own translation unit:
COBOL/PL-SQL/T-SQL/Go/Ruby/Python into their plx_dialect_*.c, and the shared
PHP/JS/TS brace parser (+ TypeScript preprocessing) into a new
src/plx_parse_brace.c. php/js/ts become thin config stubs whose parse_body
points at plx_brace_parse_body.
No functional change. The generated plpgsql (pg_proc.prosrc) is byte-identical
across all 209 regression functions before and after; the move was verified at
every step against that golden set. All 13 installcheck tests pass and the tree
builds with zero compiler warnings.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 0beaa36 commit 1cd64eb
14 files changed
Lines changed: 8988 additions & 8829 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
0 commit comments