public final class Pp2Engine extends Object
Each format(String, EDbVendor, Pp2FormatOptions) call runs the
following stages in order:
TGSqlParser.tokenizeSqltext() produces a
raw TSourceTokenList.Pp2TokenStreamBuilder adapts the token
list into a Pp2TokenStream: folds whitespace into
precedingBlanks / precedingLinebreaks counts,
preserves comments as first-class tokens.SourceSpanLedger records every byte of the
original input so the assembler can restore inter-region trivia
verbatim.ProtectedZoneDetector annotates
NO_FORMAT_ZONE, COMMENT_LINE, COMMENT_BLOCK,
and template-placeholder roles onto the token stream.StatementBoundaryDetector walks
the annotated stream and emits one StatementRange per
statement.ParseRecoveryEngine.parseAll(List)
attempts per-region parsing. Each outcome is tagged
AST_OK | AST_ERROR | TRIVIA.EngineDispatch routes each outcome to the
appropriate renderer (plan §5.2 three-tier strategy):
AST_OK → GuardedAstDelegate (fallback to
conservative on guard failure); AST_ERROR →
ConservativeTokenRenderer; TRIVIA → passthrough.
Each rendered text is wrapped in a RenderedRegion.RegionAssembler interleaves the rendered
texts with the original inter-region trivia from the ledger,
producing the final output string.Pp2FormatResult carrying the assembled
text, FormatStatus, per-region Pp2FormatResult.Region
records, and all diagnostics accumulated across the pipeline.The engine never throws for non-null inputs. Any Throwable that
escapes the pipeline — from the tokenizer, ledger builder, boundary
detector, or assembler — is caught, logged via PPLogger, and the
engine falls back to returning the original SQL unchanged with
FormatStatus.FAILED and a FormatDiagnostic.Severity#FATAL
diagnostic.
The engine instance is stateless (all mutable objects are allocated per
format call). Concurrent calls with different inputs are safe. The
inner ParseRecoveryEngine allocates a fresh
ParserPool per call.
Plan reference: §5.1, §7.3/S16, §7.4/S16, §10.4.
| Constructor and Description |
|---|
Pp2Engine() |
| Modifier and Type | Method and Description |
|---|---|
Pp2FormatResult |
format(String sql,
EDbVendor vendor,
Pp2FormatOptions opts)
Format the given SQL string using the supplied database vendor and
options.
|
public Pp2Engine()
public Pp2FormatResult format(String sql, EDbVendor vendor, Pp2FormatOptions opts)
sql - the raw SQL to format; must not be nullvendor - the database dialect; governs tokenization, keyword
recognition, and boundary detectionopts - formatting options; must not be nullPp2FormatResult carrying the formatted text and
per-region metadata; never nullNullPointerException - if any argument is null