public final class ConservativeTokenRenderer extends Object implements RegionRenderer
Pp2TokenStream and emits each token's text with light spacing.
No clause-level layout, no recognition pipeline — pure token passthrough.
GuardedAstDelegate (S13) only fires on regions whose source
actually parses. Everything else — invalid SQL, partial scripts, vendor
fragments the parser doesn't yet support — needs a renderer that
guarantees every solid input token appears in the output, in order
without throwing or losing bytes. Until the lexical island pipeline
(S31) ships, the conservative renderer is the only safety net the engine
has. Even after S31 lands it stays as the last-resort renderer for
cases where the island pipeline itself throws.
Two operating modes, selected by
Pp2FormatOptions.commentPolicy:
CommentPolicy.PRESERVE (default): emit each token's
original preceding whitespace verbatim — the renderer is a
byte-exact passthrough modulo the inter-region leading trivia,
which is handed off to the region assembler (S15).CommentPolicy.REANCHOR / CommentPolicy.REFLOW:
a single space between consecutive tokens, with a "\n"
inserted after every ";". No other layout choices are
made — the renderer never reorders, never drops, never merges.Regardless of policy, tokens carrying the
TokenRole.NO_FORMAT_ZONE role are emitted with their original
preceding whitespace, so --BEGIN_NO_FORMAT/--END_NO_FORMAT
blocks survive byte-exact through any policy.
The renderer never emits leading whitespace for the first token of the range — that whitespace belongs to the inter-region gap handled by the assembler (S15). The renderer's output starts with the first token's text and ends with the last token's text. Trailing trivia after the last token is similarly the assembler's responsibility.
Every Pp2Token in the range contributes its text to the
output exactly once, in source order; nothing is dropped, reordered, or
collapsed. This guarantee is verified by
TokenEquivalence in
ConservativeTokenRendererTest.
Plan reference: §5.2, §7.3/S14, §7.4/S14.
| Constructor and Description |
|---|
ConservativeTokenRenderer() |
| Modifier and Type | Method and Description |
|---|---|
long |
getEmittedTokenCount()
Number of tokens emitted across all rendered regions.
|
long |
getRenderedRegionCount()
Number of regions
render(...) has produced output for. |
RendererId |
id()
Identifier mirrored on
RendererId so
Pp2FormatResult.Region.getRendererId() reflects which strategy
actually produced the text for the region. |
String |
render(RegionParseOutcome outcome,
Pp2TokenStream stream,
Pp2FormatOptions opts)
Render the outcome's region to its final text.
|
public ConservativeTokenRenderer()
public long getRenderedRegionCount()
render(...) has produced output for.public long getEmittedTokenCount()
public RendererId id()
RegionRendererRendererId so
Pp2FormatResult.Region.getRendererId() reflects which strategy
actually produced the text for the region.id in interface RegionRendererpublic String render(RegionParseOutcome outcome, Pp2TokenStream stream, Pp2FormatOptions opts)
RegionRendererrender in interface RegionRendereroutcome - non-null parse outcome for the region. Implementations
may assume RegionParseOutcome.getRange() and
RegionParseOutcome.getParsedSql() are non-null.
RegionParseOutcome.getParser() is non-null only
for AST_OK
outcomes.stream - the engine's full Pp2TokenStream for the whole
input script (token-based renderers slice into it via
the outcome's range token indices)opts - non-null pp2 optionsnull (the
only sentinel) to signal fall-through to the next renderer
in the chain. An empty string is a valid rendering, not a
fall-through.