Skip to content

Commit

Permalink
Separate data types from generic keywords (#677)
Browse files Browse the repository at this point in the history
Part of preparations for PR #673 

---

Copied from [my
comment](#673 (comment)):

I would want to then do a separate PR to separate out all of the data
type information in `src/languages/*/*.keywords.ts` in these flat arrays
in into a separate (optional) export in each file called `export const
dataTypes`, which would temporarily merged together with `keywords` to
keep compatibility before `reservedDataTypes` in the next step is
implemented
  • Loading branch information
nene authored Dec 1, 2023
2 parents 98d602c + 971fcd3 commit d9db4ca
Show file tree
Hide file tree
Showing 34 changed files with 444 additions and 412 deletions.
8 changes: 5 additions & 3 deletions src/languages/bigquery/bigquery.formatter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DialectOptions } from '../../dialect.js';
import { EOF_TOKEN, isToken, TokenType, Token } from '../../lexer/token.js';
import { expandPhrases } from '../../expandPhrases.js';
import { keywords } from './bigquery.keywords.js';
import { EOF_TOKEN, isToken, Token, TokenType } from '../../lexer/token.js';
import { functions } from './bigquery.functions.js';
import { dataTypes, keywords } from './bigquery.keywords.js';

const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]']);

Expand Down Expand Up @@ -163,7 +163,9 @@ export const bigquery: DialectOptions = {
reservedSetOperations,
reservedJoins,
reservedPhrases,
reservedKeywords: keywords,
reservedKeywords:
// Temporary, will be replaced by reservedDataTypes
[...new Set(keywords.concat(dataTypes))],
reservedFunctionNames: functions,
extraParens: ['[]'],
stringTypes: [
Expand Down
39 changes: 18 additions & 21 deletions src/languages/bigquery/bigquery.keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export const keywords: string[] = [
'ALL',
'AND',
'ANY',
'ARRAY',
'AS',
'ASC',
'ASSERT_ROWS_MODIFIED',
Expand Down Expand Up @@ -46,13 +45,11 @@ export const keywords: string[] = [
'IN',
'INNER',
'INTERSECT',
'INTERVAL',
'INTO',
'IS',
'JOIN',
'LATERAL',
'LEFT',
'LIKE',
'LIMIT',
'LOOKUP',
'MERGE',
Expand Down Expand Up @@ -80,7 +77,6 @@ export const keywords: string[] = [
'SELECT',
'SET',
'SOME',
'STRUCT',
'TABLE',
'TABLESAMPLE',
'THEN',
Expand All @@ -97,7 +93,24 @@ export const keywords: string[] = [
'WITH',
'WITHIN',

// datatypes
// misc
'SAFE',

// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
'LIKE', // CREATE TABLE LIKE
'COPY', // CREATE TABLE COPY
'CLONE', // CREATE TABLE CLONE
'IN',
'OUT',
'INOUT',
'RETURNS',
'LANGUAGE',
'CASCADE',
'RESTRICT',
'DETERMINISTIC',
];

export const dataTypes: string[] = [
'ARRAY', // parametric, ARRAY<T>
'BOOL',
'BYTES', // parameterised, BYTES(Length)
Expand Down Expand Up @@ -129,20 +142,4 @@ export const keywords: string[] = [
'ASCII',
'UTF-8',
'UTF8',

// misc
'SAFE',

// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
'LIKE', // CREATE TABLE LIKE
'COPY', // CREATE TABLE COPY
'CLONE', // CREATE TABLE CLONE
'IN',
'OUT',
'INOUT',
'RETURNS',
'LANGUAGE',
'CASCADE',
'RESTRICT',
'DETERMINISTIC',
];
6 changes: 4 additions & 2 deletions src/languages/db2/db2.formatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DialectOptions } from '../../dialect.js';
import { expandPhrases } from '../../expandPhrases.js';
import { functions } from './db2.functions.js';
import { keywords } from './db2.keywords.js';
import { dataTypes, keywords } from './db2.keywords.js';

const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']);

Expand Down Expand Up @@ -265,7 +265,9 @@ export const db2: DialectOptions = {
reservedSetOperations,
reservedJoins,
reservedPhrases,
reservedKeywords: keywords,
reservedKeywords:
// Temporary, will be replaced by reservedDataTypes
[...new Set(keywords.concat(dataTypes))],
reservedFunctionNames: functions,
extraParens: ['[]'],
stringTypes: [
Expand Down
20 changes: 12 additions & 8 deletions src/languages/db2/db2.keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export const keywords: string[] = [
'CASCADED',
'CASE',
'CAST',
'CCSID',
'CHAR',
'CHARACTER',
'CHECK',
'CLONE',
'CLOSE',
Expand Down Expand Up @@ -73,7 +70,6 @@ export const keywords: string[] = [
'DATABASE',
'DATAPARTITIONNAME',
'DATAPARTITIONNUM',
'DATE',
'DAY',
'DAYS',
'DB2GENERAL',
Expand All @@ -100,7 +96,6 @@ export const keywords: string[] = [
'DISTINCT',
'DO',
'DOCUMENT',
'DOUBLE',
'DROP',
'DSSIZE',
'DYNAMIC',
Expand Down Expand Up @@ -208,7 +203,6 @@ export const keywords: string[] = [
'LOCK',
'LOCKMAX',
'LOCKSIZE',
'LONG',
'LOOP',
'MAINTAINED',
'MATERIALIZED',
Expand Down Expand Up @@ -368,8 +362,6 @@ export const keywords: string[] = [
'TABLE',
'TABLESPACE',
'THEN',
'TIME',
'TIMESTAMP',
'TO',
'TRANSACTION',
'TRIGGER',
Expand Down Expand Up @@ -408,3 +400,15 @@ export const keywords: string[] = [
'YEAR',
'YEARS',
];

export const dataTypes: string[] = [
// https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
'CCSID',
'CHAR',
'CHARACTER',
'DATE',
'DOUBLE',
'LONG',
'TIME',
'TIMESTAMP',
];
6 changes: 4 additions & 2 deletions src/languages/db2i/db2i.formatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DialectOptions } from '../../dialect.js';
import { expandPhrases } from '../../expandPhrases.js';
import { functions } from './db2i.functions.js';
import { keywords } from './db2i.keywords.js';
import { dataTypes, keywords } from './db2i.keywords.js';

const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']);

Expand Down Expand Up @@ -161,7 +161,9 @@ export const db2i: DialectOptions = {
reservedSetOperations,
reservedJoins,
reservedPhrases,
reservedKeywords: keywords,
reservedKeywords:
// Temporary, will be replaced by reservedDataTypes
[...new Set(keywords.concat(dataTypes))],
reservedFunctionNames: functions,
nestedBlockComments: true,
extraParens: ['[]'],
Expand Down
47 changes: 34 additions & 13 deletions src/languages/db2i/db2i.keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export const keywords: string[] = [
'BEFORE',
'BEGIN',
'BETWEEN',
'BINARY',
'BIND',
'BIT',
'BOOLEAN',
'BSON',
'BUFFERPOOL',
'BY',
Expand All @@ -45,9 +42,6 @@ export const keywords: string[] = [
'CARDINALITY',
'CASE',
'CAST',
'CCSID',
'CHAR',
'CHARACTER',
'CHECK',
'CL',
'CLOSE',
Expand Down Expand Up @@ -90,11 +84,9 @@ export const keywords: string[] = [
'CURRENT_USER',
'CURSOR',
'CYCLE',
'DATA',
'DATABASE',
'DATAPARTITIONNAME',
'DATAPARTITIONNUM',
'DATE',
'DAY',
'DAYS',
'DB2GENERAL',
Expand Down Expand Up @@ -127,7 +119,6 @@ export const keywords: string[] = [
'DISTINCT',
'DO',
'DOCUMENT',
'DOUBLE',
'DROP',
'DYNAMIC',
'EACH',
Expand Down Expand Up @@ -177,7 +168,6 @@ export const keywords: string[] = [
'GO',
'GOTO',
'GRANT',
'GRAPHIC',
'GROUP',
'HANDLER',
'HASH',
Expand Down Expand Up @@ -256,7 +246,6 @@ export const keywords: string[] = [
'LOCKSIZE',
'LOG',
'LOGGED',
'LONG',
'LOOP',
'MAINTAINED',
'MASK',
Expand Down Expand Up @@ -436,8 +425,6 @@ export const keywords: string[] = [
'TAG',
'THEN',
'THREADSAFE',
'TIME',
'TIMESTAMP',
'TO',
'TRANSACTION',
'TRANSFER',
Expand Down Expand Up @@ -508,3 +495,37 @@ export const keywords: string[] = [
'YES',
'ZONE',
];

export const dataTypes: string[] = [
// https://www.ibm.com/docs/en/i/7.2?topic=iaodsd-odbc-data-types-how-they-correspond-db2-i-database-types
'BIGINT',
'BINARY',
'BIT',
'BLOB',
'BOOLEAN',
'CCSID',
'CHAR',
'CHARACTER',
'CLOB',
'DATA',
'DATALINK',
'DATE',
'DBCLOB',
'DECFLOAT',
'DECIMAL',
'DOUBLE',
'FLOAT',
'GRAPHIC',
'INTEGER',
'LONG',
'NUMERIC',
'REAL',
'ROWID',
'SMALLINT',
'TIME',
'TIMESTAMP',
'VARBINARY',
'VARCHAR',
'VARGRAPHIC',
'XML',
];
6 changes: 4 additions & 2 deletions src/languages/hive/hive.formatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DialectOptions } from '../../dialect.js';
import { expandPhrases } from '../../expandPhrases.js';
import { functions } from './hive.functions.js';
import { keywords } from './hive.keywords.js';
import { dataTypes, keywords } from './hive.keywords.js';

const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']);

Expand Down Expand Up @@ -90,7 +90,9 @@ export const hive: DialectOptions = {
reservedSetOperations,
reservedJoins,
reservedPhrases,
reservedKeywords: keywords,
reservedKeywords:
// Temporary, will be replaced by reservedDataTypes
[...new Set(keywords.concat(dataTypes))],
reservedFunctionNames: functions,
extraParens: ['[]'],
stringTypes: ['""-bs', "''-bs"],
Expand Down
Loading

0 comments on commit d9db4ca

Please sign in to comment.