Skip to content

Commit 1cd64eb

Browse files
Jonah H. Harrisclaude
andcommitted
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

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# plx - PGXS build
22
MODULE_big = plx
3-
OBJS = src/plx_core.o src/plx_transpile.o src/plx_strbuild.o src/plx_dialect_ruby.o src/plx_dialect_php.o src/plx_dialect_js.o src/plx_dialect_python.o src/plx_dialect_cobol.o src/plx_dialect_plsql.o src/plx_dialect_ts.o src/plx_dialect_tsql.o src/plx_dialect_go.o
3+
OBJS = src/plx_core.o src/plx_transpile.o src/plx_strbuild.o src/plx_dialect_ruby.o src/plx_dialect_php.o src/plx_dialect_js.o src/plx_dialect_python.o src/plx_dialect_cobol.o src/plx_dialect_plsql.o src/plx_dialect_ts.o src/plx_dialect_tsql.o src/plx_dialect_go.o src/plx_parse_brace.o
44

55
EXTENSION = plx
66
DATA = plx--1.0.sql plx--1.1.sql plx--1.1.1.sql plx--1.2.sql plx--1.2.1.sql plx--1.2.2.sql plx--1.3.0.sql plx--1.3.1.sql plx--1.0--1.1.sql plx--1.1--1.1.1.sql plx--1.1.1--1.2.sql plx--1.2--1.2.1.sql plx--1.2.1--1.2.2.sql plx--1.2.2--1.3.0.sql plx--1.3.0--1.3.1.sql
@@ -17,4 +17,4 @@ include $(PGXS)
1717

1818
# PGXS does not track header dependencies; declare them so a header change
1919
# rebuilds every object (the shared enum/struct layout must stay consistent).
20-
$(OBJS): src/plx.h src/plx_int.h
20+
$(OBJS): src/plx.h src/plx_int.h src/plx_engine.h

0 commit comments

Comments
 (0)