IF Commons GitHub

dialect

The dialect (commons lang-sql 0001-sql-lang FR-016, 0002-sql-ast-parser FR-013): a name, the dialect it extends, its Lexical and its Grammar, resolved once. A dialect says only what differs from its parent: it is given a function from its parent's lexical to its own, so that it can add, remove and replace what it inherits, and a chain of dialects (Redshift on PostgreSQL) is one lexical by the time the lexer reads it.

This is the lexical layer of a dialect; the grammar it will contribute to the parser is a later specification of the same folder, and a dialect value will gain it without changing how one is made.

const mine = defineDialect({ name: "mine", extends: ansi, lexical: (base) => ({ ...base, comments: [...base.comments, { kind: "line", marker: "#" }] }) });

Spec: 0001-sql-lang FR-015, FR-016; 0002-sql-ast-parser FR-013

Source: commons/lang-sql/src/dialect.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.

declareDialectfunction
function declareDialect(spec: DialectSpec): Dialect

Makes a dialect that a module declares at its top level from data of its own: where that data is wrong, it throws the error's sentence when the module is loaded, which the module's test catches; a dialect made at run time from data that arrives is made with defineDialect, which returns the error.

ParameterWhat it is
specits name, its parent and its lexical

Returns: the dialect

Imported by 35 tests of the run (35 passed, 0 failed): the library's results

defineDialectfunction
function defineDialect(spec: DialectSpec): Result<Dialect, DialectError>

Makes a dialect.

ParameterWhat it is
specits name, its parent and its lexical

Returns: the dialect, or what is wrong with it

Imported by 41 tests of the run (41 passed, 0 failed): the library's results

describeDialectErrorfunction
function describeDialectError(e: DialectError): string

One sentence for a dialect's error.

Imported by 25 tests of the run (25 passed, 0 failed): the library's results

Dialectinterface
interface Dialect

A dialect of SQL.

MemberTypeWhat it is
namestring
parentDialect | undefinedThe dialect it extends; none for the base.
lexicalLexicalHow it is written, whole.
compiledCompiledLexicalThe tables the lexer reads.
grammarGrammarHow its grammar differs from the common ground, whole.

Imported by 90 tests of the run (90 passed, 0 failed): the library's results

DialectErrortypeno test imports it
type DialectError =
  | { readonly kind: "no-name" }
  | { readonly kind: "lexical"; readonly dialect: string; readonly error: LexicalError }
  | { readonly kind: "grammar"; readonly dialect: string; readonly what: string };

What is wrong with a dialect.

DialectSpecinterfaceno test imports it
interface DialectSpec

What a dialect is made from.

MemberTypeWhat it is
namestring
extends?DialectThe dialect it extends.
lexical(parent: Lexical) => LexicalIts lexical, from its parent's (the empty lexical where it has no parent).
grammar?((parent: Grammar) => Grammar)Its grammar, from its parent's (the common ground where it has no parent); it stays its parent's where this is not given.
EMPTY_LEXICALconst
const EMPTY_LEXICAL: Lexical

The lexical a dialect with no parent starts from: nothing.

Imported by 3 tests of the run (3 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.