Relix reserves a fixed set of operator and keyword words (SELECT, SORT,
ORDER, GROUP, JOIN, …). A relation, column, or alias whose name collides with
one of them — or that is otherwise not identifier-shaped — cannot be written
bare: it must be wrapped in backticks so the lexer reads it as a plain name
rather than the operator, e.g. `order` references a relation named
order. render(String) applies that wrapping only when
needed and leaves ordinary names untouched, so canonical pretty-printer output
is byte-for-byte unchanged for the overwhelmingly common case.
The reserved-word set is intentionally duplicated here because
relix-ast is the base module and cannot depend on relix-parser
(which owns the lexer). A guard test in relix-parser
(DelimitedIdentifierLexerTest) asserts this set stays a superset of the
lexer's live keyword table (Lexer.reservedWords()), so a newly added
keyword can never silently start printing un-delimited.
A qualified name (Users.id) is delimited per dotted segment
(`Users`.id only if Users needs it) — the common case. The one
ambiguity this cannot recover is a single delimited name that itself contains a
literal dot (`weird.name`): the AST stores it as the bare string
weird.name, indistinguishable from a qualified reference, so it
re-renders as two segments. Such names are vanishingly rare.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisReserved(String word) Whetherwordis a reserved operator/keyword (case-insensitive).static booleanneedsDelimiting(String segment) Whether a single name segment cannot appear bare and must be backtick- delimited: it is empty, not identifier-shaped, or a reserved word.static StringRenders a (possibly dotted) name for pretty-printing, delimiting each segment that needs it and leaving ordinary names unchanged.
-
Method Details
-
isReserved
Whetherwordis a reserved operator/keyword (case-insensitive). -
needsDelimiting
Whether a single name segment cannot appear bare and must be backtick- delimited: it is empty, not identifier-shaped, or a reserved word. -
render
Renders a (possibly dotted) name for pretty-printing, delimiting each segment that needs it and leaving ordinary names unchanged.- Parameters:
name- the stored name (bare or dotted);nullrenders as``- Returns:
- the name, ready to parse back to the identical name
-