Writing, templates and diagnostics (commons lang-sql 0010-aide FR-009): transpile reads a text in one dialect and writes it in another with the constructs the other does not read, sql is a tagged template that puts a parameter for each value and never a value into the text, renderDiagnostic writes a diagnostic with its line and a caret under its span, and highlight says what each token of a text is, for a page that colours SQL (0010-aide FR-011).
Spec: 0010-aide FR-009, FR-011
Source: commons/lang-sql/src/aide/text/mod.ts
5 of 7 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.
Transpiledinterfaceno test imports itinterface Transpiled
What a transpile gives.
| Member | Type | What it is |
|---|
text | string | |
unsupported | readonly { readonly statement: number; readonly message: string; }[] | The statements, from 0, that the other dialect does not read as written, with why. |
function transpile(text: string, from: Dialect, to: Dialect): Result<Transpiled, readonly string[]>
A text read in one dialect and written in another; an error value where it does not read in the first.
Imported by 8 tests of the run (8 passed, 0 failed): the library's results
function sql(dialect: Dialect): (strings: TemplateStringsArray, ...values: readonly (string | number | boolean | null)[]) => Result<Statement, EmitError>
A tag for a template of a statement in a dialect: each ${value} becomes a parameter in the dialect's style, and the value is given beside the text.
Imported by 8 tests of the run (8 passed, 0 failed): the library's results
Renderableinterfaceno test imports itinterface Renderable
What can be rendered.
| Member | Type | What it is |
|---|
start | number | |
end | number | |
message | string | |
severity? | string | |
function renderDiagnostic(text: string, d: Renderable): string
A diagnostic with its line, the text of the line and a caret under its span.
Imported by 8 tests of the run (8 passed, 0 failed): the library's results
type SpanKind = "keyword" | "function" | "name" | "quoted-name" | "number" | "string" | "param" | "operator" | "punctuation" | "comment" | "error";
What a stretch of a text is, for colouring it.
Imported by 3 tests of the run (3 passed, 0 failed): the library's results
function highlight(text: string, dialect: Dialect): readonly Span[]
The stretches of a text and what each is, by the lexer of the dialect (not by a pattern, so a word is a keyword where the dialect says so, a word in a string or a comment is not one, and a dollar quote or a doubled quote is read as the dialect reads it): in the order of the text, never overlapping, with the white space between them left out. A word that is not a keyword and is followed by ( is a function; a keyword followed by ( (COUNT() is a function too, a keyword otherwise. A character the lexer cannot read is an error. Nothing throws for any text.
Imported by 3 tests of the run (3 passed, 0 failed): the library's results