Skip to content

Commit d9db4ca

Browse files
authored
Separate data types from generic keywords (#677)
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
2 parents 98d602c + 971fcd3 commit d9db4ca

34 files changed

+444
-412
lines changed

src/languages/bigquery/bigquery.formatter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { DialectOptions } from '../../dialect.js';
2-
import { EOF_TOKEN, isToken, TokenType, Token } from '../../lexer/token.js';
32
import { expandPhrases } from '../../expandPhrases.js';
4-
import { keywords } from './bigquery.keywords.js';
3+
import { EOF_TOKEN, isToken, Token, TokenType } from '../../lexer/token.js';
54
import { functions } from './bigquery.functions.js';
5+
import { dataTypes, keywords } from './bigquery.keywords.js';
66

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

@@ -163,7 +163,9 @@ export const bigquery: DialectOptions = {
163163
reservedSetOperations,
164164
reservedJoins,
165165
reservedPhrases,
166-
reservedKeywords: keywords,
166+
reservedKeywords:
167+
// Temporary, will be replaced by reservedDataTypes
168+
[...new Set(keywords.concat(dataTypes))],
167169
reservedFunctionNames: functions,
168170
extraParens: ['[]'],
169171
stringTypes: [

src/languages/bigquery/bigquery.keywords.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export const keywords: string[] = [
33
'ALL',
44
'AND',
55
'ANY',
6-
'ARRAY',
76
'AS',
87
'ASC',
98
'ASSERT_ROWS_MODIFIED',
@@ -46,13 +45,11 @@ export const keywords: string[] = [
4645
'IN',
4746
'INNER',
4847
'INTERSECT',
49-
'INTERVAL',
5048
'INTO',
5149
'IS',
5250
'JOIN',
5351
'LATERAL',
5452
'LEFT',
55-
'LIKE',
5653
'LIMIT',
5754
'LOOKUP',
5855
'MERGE',
@@ -80,7 +77,6 @@ export const keywords: string[] = [
8077
'SELECT',
8178
'SET',
8279
'SOME',
83-
'STRUCT',
8480
'TABLE',
8581
'TABLESAMPLE',
8682
'THEN',
@@ -97,7 +93,24 @@ export const keywords: string[] = [
9793
'WITH',
9894
'WITHIN',
9995

100-
// datatypes
96+
// misc
97+
'SAFE',
98+
99+
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
100+
'LIKE', // CREATE TABLE LIKE
101+
'COPY', // CREATE TABLE COPY
102+
'CLONE', // CREATE TABLE CLONE
103+
'IN',
104+
'OUT',
105+
'INOUT',
106+
'RETURNS',
107+
'LANGUAGE',
108+
'CASCADE',
109+
'RESTRICT',
110+
'DETERMINISTIC',
111+
];
112+
113+
export const dataTypes: string[] = [
101114
'ARRAY', // parametric, ARRAY<T>
102115
'BOOL',
103116
'BYTES', // parameterised, BYTES(Length)
@@ -129,20 +142,4 @@ export const keywords: string[] = [
129142
'ASCII',
130143
'UTF-8',
131144
'UTF8',
132-
133-
// misc
134-
'SAFE',
135-
136-
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
137-
'LIKE', // CREATE TABLE LIKE
138-
'COPY', // CREATE TABLE COPY
139-
'CLONE', // CREATE TABLE CLONE
140-
'IN',
141-
'OUT',
142-
'INOUT',
143-
'RETURNS',
144-
'LANGUAGE',
145-
'CASCADE',
146-
'RESTRICT',
147-
'DETERMINISTIC',
148145
];

src/languages/db2/db2.formatter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DialectOptions } from '../../dialect.js';
22
import { expandPhrases } from '../../expandPhrases.js';
33
import { functions } from './db2.functions.js';
4-
import { keywords } from './db2.keywords.js';
4+
import { dataTypes, keywords } from './db2.keywords.js';
55

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

@@ -265,7 +265,9 @@ export const db2: DialectOptions = {
265265
reservedSetOperations,
266266
reservedJoins,
267267
reservedPhrases,
268-
reservedKeywords: keywords,
268+
reservedKeywords:
269+
// Temporary, will be replaced by reservedDataTypes
270+
[...new Set(keywords.concat(dataTypes))],
269271
reservedFunctionNames: functions,
270272
extraParens: ['[]'],
271273
stringTypes: [

src/languages/db2/db2.keywords.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ export const keywords: string[] = [
3434
'CASCADED',
3535
'CASE',
3636
'CAST',
37-
'CCSID',
38-
'CHAR',
39-
'CHARACTER',
4037
'CHECK',
4138
'CLONE',
4239
'CLOSE',
@@ -73,7 +70,6 @@ export const keywords: string[] = [
7370
'DATABASE',
7471
'DATAPARTITIONNAME',
7572
'DATAPARTITIONNUM',
76-
'DATE',
7773
'DAY',
7874
'DAYS',
7975
'DB2GENERAL',
@@ -100,7 +96,6 @@ export const keywords: string[] = [
10096
'DISTINCT',
10197
'DO',
10298
'DOCUMENT',
103-
'DOUBLE',
10499
'DROP',
105100
'DSSIZE',
106101
'DYNAMIC',
@@ -208,7 +203,6 @@ export const keywords: string[] = [
208203
'LOCK',
209204
'LOCKMAX',
210205
'LOCKSIZE',
211-
'LONG',
212206
'LOOP',
213207
'MAINTAINED',
214208
'MATERIALIZED',
@@ -368,8 +362,6 @@ export const keywords: string[] = [
368362
'TABLE',
369363
'TABLESPACE',
370364
'THEN',
371-
'TIME',
372-
'TIMESTAMP',
373365
'TO',
374366
'TRANSACTION',
375367
'TRIGGER',
@@ -408,3 +400,15 @@ export const keywords: string[] = [
408400
'YEAR',
409401
'YEARS',
410402
];
403+
404+
export const dataTypes: string[] = [
405+
// https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
406+
'CCSID',
407+
'CHAR',
408+
'CHARACTER',
409+
'DATE',
410+
'DOUBLE',
411+
'LONG',
412+
'TIME',
413+
'TIMESTAMP',
414+
];

src/languages/db2i/db2i.formatter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DialectOptions } from '../../dialect.js';
22
import { expandPhrases } from '../../expandPhrases.js';
33
import { functions } from './db2i.functions.js';
4-
import { keywords } from './db2i.keywords.js';
4+
import { dataTypes, keywords } from './db2i.keywords.js';
55

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

@@ -161,7 +161,9 @@ export const db2i: DialectOptions = {
161161
reservedSetOperations,
162162
reservedJoins,
163163
reservedPhrases,
164-
reservedKeywords: keywords,
164+
reservedKeywords:
165+
// Temporary, will be replaced by reservedDataTypes
166+
[...new Set(keywords.concat(dataTypes))],
165167
reservedFunctionNames: functions,
166168
nestedBlockComments: true,
167169
extraParens: ['[]'],

src/languages/db2i/db2i.keywords.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ export const keywords: string[] = [
3232
'BEFORE',
3333
'BEGIN',
3434
'BETWEEN',
35-
'BINARY',
3635
'BIND',
37-
'BIT',
38-
'BOOLEAN',
3936
'BSON',
4037
'BUFFERPOOL',
4138
'BY',
@@ -45,9 +42,6 @@ export const keywords: string[] = [
4542
'CARDINALITY',
4643
'CASE',
4744
'CAST',
48-
'CCSID',
49-
'CHAR',
50-
'CHARACTER',
5145
'CHECK',
5246
'CL',
5347
'CLOSE',
@@ -90,11 +84,9 @@ export const keywords: string[] = [
9084
'CURRENT_USER',
9185
'CURSOR',
9286
'CYCLE',
93-
'DATA',
9487
'DATABASE',
9588
'DATAPARTITIONNAME',
9689
'DATAPARTITIONNUM',
97-
'DATE',
9890
'DAY',
9991
'DAYS',
10092
'DB2GENERAL',
@@ -127,7 +119,6 @@ export const keywords: string[] = [
127119
'DISTINCT',
128120
'DO',
129121
'DOCUMENT',
130-
'DOUBLE',
131122
'DROP',
132123
'DYNAMIC',
133124
'EACH',
@@ -177,7 +168,6 @@ export const keywords: string[] = [
177168
'GO',
178169
'GOTO',
179170
'GRANT',
180-
'GRAPHIC',
181171
'GROUP',
182172
'HANDLER',
183173
'HASH',
@@ -256,7 +246,6 @@ export const keywords: string[] = [
256246
'LOCKSIZE',
257247
'LOG',
258248
'LOGGED',
259-
'LONG',
260249
'LOOP',
261250
'MAINTAINED',
262251
'MASK',
@@ -436,8 +425,6 @@ export const keywords: string[] = [
436425
'TAG',
437426
'THEN',
438427
'THREADSAFE',
439-
'TIME',
440-
'TIMESTAMP',
441428
'TO',
442429
'TRANSACTION',
443430
'TRANSFER',
@@ -508,3 +495,37 @@ export const keywords: string[] = [
508495
'YES',
509496
'ZONE',
510497
];
498+
499+
export const dataTypes: string[] = [
500+
// https://www.ibm.com/docs/en/i/7.2?topic=iaodsd-odbc-data-types-how-they-correspond-db2-i-database-types
501+
'BIGINT',
502+
'BINARY',
503+
'BIT',
504+
'BLOB',
505+
'BOOLEAN',
506+
'CCSID',
507+
'CHAR',
508+
'CHARACTER',
509+
'CLOB',
510+
'DATA',
511+
'DATALINK',
512+
'DATE',
513+
'DBCLOB',
514+
'DECFLOAT',
515+
'DECIMAL',
516+
'DOUBLE',
517+
'FLOAT',
518+
'GRAPHIC',
519+
'INTEGER',
520+
'LONG',
521+
'NUMERIC',
522+
'REAL',
523+
'ROWID',
524+
'SMALLINT',
525+
'TIME',
526+
'TIMESTAMP',
527+
'VARBINARY',
528+
'VARCHAR',
529+
'VARGRAPHIC',
530+
'XML',
531+
];

src/languages/hive/hive.formatter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DialectOptions } from '../../dialect.js';
22
import { expandPhrases } from '../../expandPhrases.js';
33
import { functions } from './hive.functions.js';
4-
import { keywords } from './hive.keywords.js';
4+
import { dataTypes, keywords } from './hive.keywords.js';
55

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

@@ -90,7 +90,9 @@ export const hive: DialectOptions = {
9090
reservedSetOperations,
9191
reservedJoins,
9292
reservedPhrases,
93-
reservedKeywords: keywords,
93+
reservedKeywords:
94+
// Temporary, will be replaced by reservedDataTypes
95+
[...new Set(keywords.concat(dataTypes))],
9496
reservedFunctionNames: functions,
9597
extraParens: ['[]'],
9698
stringTypes: ['""-bs', "''-bs"],

0 commit comments

Comments
 (0)