Skip to content

Commit 4f410f3

Browse files
committed
Separate data types from generic keywords
1 parent 08d9a09 commit 4f410f3

File tree

10 files changed

+57
-35
lines changed

10 files changed

+57
-35
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ export const keywords: string[] = [
9696
'WINDOW',
9797
'WITH',
9898
'WITHIN',
99+
];
99100

100-
// datatypes
101+
export const dataTypes: string[] = [
101102
'ARRAY', // parametric, ARRAY<T>
102103
'BOOL',
103104
'BYTES', // parameterised, BYTES(Length)

src/languages/postgresql/postgresql.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 './postgresql.functions.js';
4-
import { keywords } from './postgresql.keywords.js';
4+
import { dataTypes, keywords } from './postgresql.keywords.js';
55

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

@@ -260,7 +260,9 @@ export const postgresql: DialectOptions = {
260260
reservedSetOperations,
261261
reservedJoins,
262262
reservedPhrases,
263-
reservedKeywords: keywords,
263+
reservedKeywords:
264+
// Temporary, will be replaced by reservedDataTypes
265+
[...new Set(keywords.concat(dataTypes))],
264266
reservedFunctionNames: functions,
265267
nestedBlockComments: true,
266268
extraParens: ['[]'],

src/languages/postgresql/postgresql.keywords.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const keywords: string[] = [
1+
export const keywords = [
22
// https://www.postgresql.org/docs/14/sql-keywords-appendix.html
33
'ABORT',
44
'ABSOLUTE',
@@ -32,10 +32,7 @@ export const keywords: string[] = [
3232
'BEFORE',
3333
'BEGIN',
3434
'BETWEEN', // (cannot be function or type)
35-
'BIGINT', // (cannot be function or type)
3635
'BINARY', // reserved (can be function or type)
37-
'BIT', // (cannot be function or type)
38-
'BOOLEAN', // (cannot be function or type)
3936
'BOTH', // reserved
4037
'BREADTH',
4138
'BY',
@@ -48,8 +45,6 @@ export const keywords: string[] = [
4845
'CAST', // reserved
4946
'CATALOG',
5047
'CHAIN',
51-
'CHAR', // (cannot be function or type), requires AS
52-
'CHARACTER', // (cannot be function or type), requires AS
5348
'CHARACTERISTICS',
5449
'CHECK', // reserved
5550
'CHECKPOINT',
@@ -96,7 +91,6 @@ export const keywords: string[] = [
9691
'DAY', // requires AS
9792
'DEALLOCATE',
9893
'DEC', // (cannot be function or type)
99-
'DECIMAL', // (cannot be function or type)
10094
'DECLARE',
10195
'DEFAULT', // reserved
10296
'DEFAULTS',
@@ -117,7 +111,6 @@ export const keywords: string[] = [
117111
'DO', // reserved
118112
'DOCUMENT',
119113
'DOMAIN',
120-
'DOUBLE',
121114
'DROP',
122115
'EACH',
123116
'ELSE', // reserved
@@ -145,7 +138,6 @@ export const keywords: string[] = [
145138
'FILTER', // requires AS
146139
'FINALIZE',
147140
'FIRST',
148-
'FLOAT', // (cannot be function or type)
149141
'FOLLOWING',
150142
'FOR', // reserved, requires AS
151143
'FORCE',
@@ -192,10 +184,7 @@ export const keywords: string[] = [
192184
'INSENSITIVE',
193185
'INSERT',
194186
'INSTEAD',
195-
'INT', // (cannot be function or type)
196-
'INTEGER', // (cannot be function or type)
197187
'INTERSECT', // reserved, requires AS
198-
'INTERVAL', // (cannot be function or type)
199188
'INTO', // reserved, requires AS
200189
'INVOKER',
201190
'IS', // reserved (can be function or type)
@@ -257,7 +246,6 @@ export const keywords: string[] = [
257246
'NULL', // reserved
258247
'NULLIF', // (cannot be function or type)
259248
'NULLS',
260-
'NUMERIC', // (cannot be function or type)
261249
'OBJECT',
262250
'OF',
263251
'OFF',
@@ -292,7 +280,6 @@ export const keywords: string[] = [
292280
'POLICY',
293281
'POSITION', // (cannot be function or type)
294282
'PRECEDING',
295-
'PRECISION', // (cannot be function or type), requires AS
296283
'PREPARE',
297284
'PREPARED',
298285
'PRESERVE',
@@ -307,7 +294,6 @@ export const keywords: string[] = [
307294
'QUOTE',
308295
'RANGE',
309296
'READ',
310-
'REAL', // (cannot be function or type)
311297
'REASSIGN',
312298
'RECHECK',
313299
'RECURSIVE',
@@ -360,7 +346,6 @@ export const keywords: string[] = [
360346
'SIMILAR', // reserved (can be function or type)
361347
'SIMPLE',
362348
'SKIP',
363-
'SMALLINT', // (cannot be function or type)
364349
'SNAPSHOT',
365350
'SOME', // reserved
366351
'SQL',
@@ -388,11 +373,8 @@ export const keywords: string[] = [
388373
'TEMP',
389374
'TEMPLATE',
390375
'TEMPORARY',
391-
'TEXT',
392376
'THEN', // reserved
393377
'TIES',
394-
'TIME', // (cannot be function or type)
395-
'TIMESTAMP', // (cannot be function or type)
396378
'TO', // reserved, requires AS
397379
'TRAILING', // reserved
398380
'TRANSACTION',
@@ -424,9 +406,7 @@ export const keywords: string[] = [
424406
'VALIDATOR',
425407
'VALUE',
426408
'VALUES', // (cannot be function or type)
427-
'VARCHAR', // (cannot be function or type)
428409
'VARIADIC', // reserved
429-
'VARYING', // requires AS
430410
'VERBOSE', // reserved (can be function or type)
431411
'VERSION',
432412
'VIEW',
@@ -442,7 +422,6 @@ export const keywords: string[] = [
442422
'WORK',
443423
'WRAPPER',
444424
'WRITE',
445-
'XML',
446425
'XMLATTRIBUTES', // (cannot be function or type)
447426
'XMLCONCAT', // (cannot be function or type)
448427
'XMLELEMENT', // (cannot be function or type)
@@ -456,5 +435,32 @@ export const keywords: string[] = [
456435
'XMLTABLE', // (cannot be function or type)
457436
'YEAR', // requires AS
458437
'YES',
438+
];
439+
440+
export const dataTypes: string[] = [
441+
// https://www.postgresql.org/docs/current/datatype.html
442+
'BIGINT', // (cannot be function or type)
443+
'BIT', // (cannot be function or type)
444+
'BOOL', // (cannot be function or type)
445+
'BOOLEAN', // (cannot be function or type)
446+
'CHAR', // (cannot be function or type), requires AS
447+
'CHARACTER', // (cannot be function or type), requires AS
448+
'DECIMAL', // (cannot be function or type)
449+
'DOUBLE',
450+
'FLOAT', // (cannot be function or type)
451+
'INT', // (cannot be function or type)
452+
'INTEGER', // (cannot be function or type)
453+
'INTERVAL', // (cannot be function or type)
454+
'NUMERIC', // (cannot be function or type)
455+
'PRECISION', // (cannot be function or type), requires AS
456+
'REAL', // (cannot be function or type)
457+
'SMALLINT', // (cannot be function or type)
458+
'TEXT',
459+
'TIME', // (cannot be function or type)
460+
'TIMESTAMP', // (cannot be function or type)
461+
'TIMESTAMPTZ', // (cannot be function or type)
462+
'VARCHAR', // (cannot be function or type)
463+
'VARYING', // requires AS
464+
'XML',
459465
'ZONE',
460466
];

src/languages/redshift/redshift.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 './redshift.functions.js';
4-
import { keywords } from './redshift.keywords.js';
4+
import { dataTypes, keywords } from './redshift.keywords.js';
55

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

@@ -147,7 +147,9 @@ export const redshift: DialectOptions = {
147147
reservedSetOperations,
148148
reservedJoins,
149149
reservedPhrases,
150-
reservedKeywords: keywords,
150+
reservedKeywords:
151+
// Temporary, will be replaced by reservedDataTypes
152+
[...new Set(keywords.concat(dataTypes))],
151153
reservedFunctionNames: functions,
152154
stringTypes: ["''-qq"],
153155
identTypes: [`""-qq`],

src/languages/redshift/redshift.keywords.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ export const keywords: string[] = [
197197
* SVL: https://docs.aws.amazon.com/redshift/latest/dg/svl_views.html
198198
* SVV: https://docs.aws.amazon.com/redshift/latest/dg/svv_views.html
199199
*/
200+
];
200201

202+
export const dataTypes: string[] = [
201203
// https://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html#r_Character_types-text-and-bpchar-types
202204
'BPCHAR',
203205
'TEXT',

src/languages/snowflake/snowflake.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 './snowflake.functions.js';
4-
import { keywords } from './snowflake.keywords.js';
4+
import { dataTypes, keywords } from './snowflake.keywords.js';
55

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

@@ -303,7 +303,9 @@ export const snowflake: DialectOptions = {
303303
reservedSetOperations,
304304
reservedJoins,
305305
reservedPhrases,
306-
reservedKeywords: keywords,
306+
reservedKeywords:
307+
// Temporary, will be replaced by reservedDataTypes
308+
[...new Set(keywords.concat(dataTypes))],
307309
reservedFunctionNames: functions,
308310
stringTypes: ['$$', `''-qq-bs`],
309311
identTypes: ['""-qq'],

src/languages/snowflake/snowflake.keywords.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ export const keywords: string[] = [
9696

9797
// These are definitely keywords, but haven't found a definite list in the docs
9898
'COMMENT',
99+
];
99100

100-
// datatypes
101+
export const dataTypes: string[] = [
101102
'NUMBER',
102103
'DECIMAL',
103104
'NUMERIC',

src/languages/trino/trino.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 './trino.functions.js';
4-
import { keywords } from './trino.keywords.js';
4+
import { dataTypes, keywords } from './trino.keywords.js';
55

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

@@ -132,7 +132,9 @@ export const trino: DialectOptions = {
132132
reservedSetOperations,
133133
reservedJoins,
134134
reservedPhrases,
135-
reservedKeywords: keywords,
135+
reservedKeywords:
136+
// Temporary, will be replaced by reservedDataTypes
137+
[...new Set(keywords.concat(dataTypes))],
136138
reservedFunctionNames: functions,
137139
// Trino also supports {- ... -} parenthesis.
138140
// The formatting of these currently works out as a result of { and -

src/languages/trino/trino.keywords.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ export const keywords: string[] = [
236236
'WRAPPER',
237237
'WRITE',
238238
'ZONE',
239+
];
239240

241+
export const dataTypes: string[] = [
240242
// https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-main/src/main/java/io/trino/metadata/TypeRegistry.java#L131-L168
241243
// or https://trino.io/docs/current/language/types.html
242244
'BIGINT',

0 commit comments

Comments
 (0)