ANSI_GRAMMARconstconst ANSI_GRAMMAR: GrammarThe grammar of the common ground: nothing is added.
How a dialect's grammar differs from the common ground (commons lang-sql 0002-sql-ast-parser FR-013): the operators it adds with their binding powers, its cast operator, and its like-words. A Grammar is data, made like a lexical by a function from the parent's, and checked against the dialect's lexical when the dialect is made.
The binding powers are those of Prec: an operator of the dialect binds as tightly as the level it is given, and associates to the left.
const g: Grammar = { ...ANSI_GRAMMAR, castOperator: "::", operators: [{ text: "->", prec: Prec.Other }] };Spec: 0002-sql-ast-parser FR-009, FR-013
ANSI_GRAMMARconstconst ANSI_GRAMMAR: GrammarThe grammar of the common ground: nothing is added.
CustomOperatorinterfaceno test imports itinterface CustomOperatorAn operator a dialect adds: its text as the lexer reads it and its binding power.
| Member | Type | What it is |
|---|---|---|
text | string | |
prec | number |
Grammarinterfaceno test imports itinterface GrammarHow a dialect's grammar differs.
| Member | Type | What it is |
|---|---|---|
operators | readonly CustomOperator[] | The binary operators it adds; each becomes an operator node. |
castOperator | string | undefined | The operator that casts (::), or none. |
likeWords | readonly string[] | The words that are LIKE for it (ILIKE, GLOB), upper case. |
wordOperators | readonly CustomOperator[] | The binary operators that are keywords (DIV, MOD, XOR in MySQL), upper case, each an operator node. |
operatorRuns | boolean | Whether any run of operator characters is an operator (PostgreSQL): a run the dialect does not list is read as one operator node of the loosest binding power, or as a prefix operator. |
emptySelect | boolean | Whether a select may have no items (SELECT FROM t, PostgreSQL). |
fromFirst | boolean | Whether a query may begin with FROM (FROM t SELECT a, FROM t; DuckDB). |
lambdas | boolean | Whether x -> body and (x, y) -> body are lambdas and not operators. |
colonPaths | boolean | Whether x:a.b is a path into a value (Snowflake, Databricks). |
tableIndexes | boolean | Whether INDEX name ... and KEY name (...) are elements of CREATE TABLE (MySQL, ClickHouse). |
queryTail | readonly string[] | The words that begin a clause after a query that is kept as text to the end of the query (SETTINGS, FORMAT of ClickHouse), upper case. |
parametric | boolean | Whether a call may be followed by a second list of arguments, the first being its parameters (quantile(0.5)(x); ClickHouse). |
selectTop | boolean | Whether SELECT TOP n [PERCENT] [WITH TIES] is read (T-SQL). |
units | readonly UnitLiteral[] | The units of number literals: a number followed by a word that is one of them (10 KB, 7d) is read as one number scaled by the unit's factor. |
Precconstconst Prec: { readonly Or: 10; readonly And: 20; readonly Not: 30; readonly Is: 40; readonly Compare: 50; readonly Like: 55; readonly Other: 60; readonly Additive: 70; readonly Multiplicative: 80; readonly Exponent: 85; readonly Unary: 90; readonly Cast: 100; }The binding powers of the operators, from the loosest; a higher number binds tighter.
RESERVED_WORDSconstno test imports itconst RESERVED_WORDS: readonly string[]The words the common grammar reserves: they are identifiers only after a . or where quoted.
UnitLiteralinterfaceno test imports itinterface UnitLiteralA unit of number literals: its word (upper case) and the factor by which it scales the number before it.
| Member | Type | What it is |
|---|---|---|
unit | string | |
factor | number |