IF Commons GitHub

grammar

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

Source: commons/lang-sql/src/grammar.ts

2 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

ANSI_GRAMMARconst
const ANSI_GRAMMAR: Grammar

The grammar of the common ground: nothing is added.

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

CustomOperatorinterfaceno test imports it
interface CustomOperator

An operator a dialect adds: its text as the lexer reads it and its binding power.

MemberTypeWhat it is
textstring
precnumber
Grammarinterfaceno test imports it
interface Grammar

How a dialect's grammar differs.

MemberTypeWhat it is
operatorsreadonly CustomOperator[]The binary operators it adds; each becomes an operator node.
castOperatorstring | undefinedThe operator that casts (::), or none.
likeWordsreadonly string[]The words that are LIKE for it (ILIKE, GLOB), upper case.
wordOperatorsreadonly CustomOperator[]The binary operators that are keywords (DIV, MOD, XOR in MySQL), upper case, each an operator node.
operatorRunsbooleanWhether 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.
emptySelectbooleanWhether a select may have no items (SELECT FROM t, PostgreSQL).
fromFirstbooleanWhether a query may begin with FROM (FROM t SELECT a, FROM t; DuckDB).
lambdasbooleanWhether x -> body and (x, y) -> body are lambdas and not operators.
colonPathsbooleanWhether x:a.b is a path into a value (Snowflake, Databricks).
tableIndexesbooleanWhether INDEX name ... and KEY name (...) are elements of CREATE TABLE (MySQL, ClickHouse).
queryTailreadonly 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.
parametricbooleanWhether a call may be followed by a second list of arguments, the first being its parameters (quantile(0.5)(x); ClickHouse).
selectTopbooleanWhether SELECT TOP n [PERCENT] [WITH TIES] is read (T-SQL).
unitsreadonly 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.
Precconst
const 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.

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

RESERVED_WORDSconstno test imports it
const RESERVED_WORDS: readonly string[]

The words the common grammar reserves: they are identifiers only after a . or where quoted.

UnitLiteralinterfaceno test imports it
interface UnitLiteral

A unit of number literals: its word (upper case) and the factor by which it scales the number before it.

MemberTypeWhat it is
unitstring
factornumber

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