Skip to content

Commit b9ce1ec

Browse files
committed
chore: migrate from pegjs to peggyjs, its successor
1 parent 34c33ac commit b9ce1ec

12 files changed

+269
-76
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build
22
node_modules
33
test
44
parser
5+
src/generated

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"globals": {
1212
"PARSER_NAME": true
1313
},
14+
"parser": "@babel/eslint-parser",
1415
"rules": {
1516
"comma-dangle": [
1617
2,
@@ -138,4 +139,4 @@
138139
"no-process-env": 0,
139140
"default-case": 0
140141
}
141-
}
142+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ bower_components/
88
umd/
99
output/
1010
.DS_Store
11+
src/generated/

ast/postgresql.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,16 @@ export interface drop_index_stmt_node {
299299

300300
export type drop_stmt = AstStatement<drop_stmt_node> | AstStatement<drop_index_stmt_node>;
301301

302+
export type truncate_table_name = table_name & { suffix?: string };
303+
304+
export type truncate_table_name_list = truncate_table_name[];
305+
302306
export interface truncate_stmt_node {
303307
type: 'trucate';
304308
keyword: 'table';
309+
prefix?: string;
305310
name: table_ref_list;
311+
suffix: string[];
306312
}
307313

308314
export type truncate_stmt = AstStatement<truncate_stmt_node>;
@@ -559,7 +565,7 @@ export type table_option = {
559565
keyword: 'auto_increment' | 'avg_row_length' | 'key_block_size' | 'max_rows' | 'min_rows' | 'stats_sample_pages';
560566
symbol: '=';
561567
value: number; // <== literal_numeric['value']
562-
} | create_option_character_set | { keyword: 'connection' | 'comment'; symbol: '='; value: string; } | { keyword: 'compression'; symbol: '='; value: "'ZLIB'" | "'LZ4'" | "'NONE'" } | { keyword: 'engine'; symbol: '='; value: string; };
568+
} | create_option_character_set | { keyword: 'connection' | 'comment'; symbol: '='; value: string; } | { keyword: 'compression'; symbol?: '='; value: "'ZLIB'" | "'LZ4'" | "'NONE'" } | { keyword: 'engine'; symbol?: '='; value: string; } | { keyword: 'partition by'; value: expr; };
563569

564570
export type ALTER_ADD_FULLETXT_SPARITAL_INDEX = create_fulltext_spatial_index_definition & { action: 'add'; type: 'alter' };
565571

@@ -770,6 +776,8 @@ export type column_clause = 'ALL' | '*' | column_list_item[] | column_list_item[
770776

771777
export type array_index = { brackets: boolean, number: number };
772778

779+
export type array_index_list = array_index[];
780+
773781
export type expr_item = binary_expr & { array_index: array_index };
774782

775783
export type cast_data_type = data_type & { quoted?: string };
@@ -1103,32 +1111,38 @@ export type column_ref = string_constants_escape | {
11031111
property?: (literal_string | literal_numeric)[];
11041112
};
11051113

1114+
export type column_ref_quoted = IGNORE;
1115+
11061116
export type column_list = column[];
11071117

1118+
export type ident_without_kw_type = { type: 'default', value: string } | quoted_ident_type;
1119+
1120+
export type ident_type = ident_name | quoted_ident_type;
1121+
11081122
export type ident = string;
11091123

11101124
export type ident_list = ident[];
11111125

11121126
export type alias_ident = string;
11131127

1114-
export type quoted_ident = double_quoted_ident | single_quoted_ident | backticks_quoted_ident;
1115-
1116-
1128+
export type quoted_ident_type = double_quoted_ident | single_quoted_ident | backticks_quoted_ident;
11171129

1118-
export type double_quoted_ident = string;
1130+
export type quoted_ident = string;
11191131

1132+
export type double_quoted_ident = { type: 'double_quote_string'; value: string; };
11201133

1134+
export type single_quoted_ident = { type: 'single_quote_string'; value: string; };
11211135

1122-
export type single_quoted_ident = string;
1123-
1124-
1125-
1126-
export type backticks_quoted_ident = string;
1136+
export type backticks_quoted_ident = { type: 'backticks_quote_string'; value: string; };
11271137

11281138
export type ident_without_kw = ident_name | quoted_ident;
11291139

11301140
export type column_without_kw = column_name | quoted_ident;
11311141

1142+
export type column_without_kw_type = { type: 'default', value: string } | quoted_ident_type;
1143+
1144+
export type column_type = { type: 'default', value: string } | quoted_ident_type;
1145+
11321146

11331147

11341148
export type column = string | quoted_ident;
@@ -1199,11 +1213,11 @@ export type trim_position = "BOTH" | "LEADING" | "TRAILING";
11991213

12001214
export type trim_rem = expr_list;
12011215

1202-
export type trim_func_clause = { type: 'function'; name: string; args: expr_list; };
1216+
export type trim_func_clause = { type: 'function'; name: proc_func_name; args: expr_list; };
12031217

1204-
export type tablefunc_clause = { type: 'tablefunc'; name: crosstab; args: expr_list; as: func_call };
1218+
export type tablefunc_clause = { type: 'tablefunc'; name: proc_func_name; args: expr_list; as: func_call };
12051219

1206-
export type func_call = trim_func_clause | tablefunc_clause | { type: 'function'; name: string; args: expr_list; suffix: literal_string; } | { type: 'function'; name: string; args: expr_list; over?: over_partition; } | extract_func | { type: 'function'; name: string; over?: on_update_current_timestamp; } | { type: 'function'; name: string; args: expr_list; };
1220+
export type func_call = trim_func_clause | tablefunc_clause | { type: 'function'; name: proc_func_name; args: expr_list; suffix: literal_string; } | { type: 'function'; name: proc_func_name; args: expr_list; over?: over_partition; } | extract_func | { type: 'function'; name: proc_func_name; over?: on_update_current_timestamp; } | { type: 'function'; name: proc_func_name; args: expr_list; };
12071221

12081222
export type extract_filed = 'string';
12091223

@@ -1262,7 +1276,9 @@ export type literal_not_null = { type: 'not null'; value: 'not null' };
12621276

12631277
export type literal_bool = { type: 'bool', value: true } | { type: 'bool', value: false };
12641278

1265-
export type literal_string = { type: 'single_quote_string'; value: string; } | { type: 'string'; value: string; };
1279+
export type literal_string = { type: 'single_quote_string'; value: string; } | literal_double_quoted_string;
1280+
1281+
export type literal_double_quoted_string = { type: 'string'; value: string; };
12661282

12671283
export type literal_datetime = { type: 'TIME' | 'DATE' | 'TIMESTAMP' | 'DATETIME', value: string };
12681284

@@ -1730,7 +1746,7 @@ export type proc_join = { type: 'join'; ltable: var_decl; rtable: var_decl; op:
17301746

17311747
export type proc_primary = literal | var_decl | proc_func_call | param | proc_additive_expr & { parentheses: true; } | { type: 'var'; prefix: null; name: number; members: []; quoted: null } | column_ref;
17321748

1733-
export type proc_func_name = string;
1749+
export type proc_func_name = { schema?: ident_without_kw_type, name: ident_without_kw_type };
17341750

17351751
export type proc_func_call = { type: 'function'; name: string; args: null | { type: expr_list; value: proc_primary_list; }};
17361752

@@ -1831,4 +1847,6 @@ export type uuid_type = data_type;
18311847

18321848

18331849

1834-
export type record_type = data_type;
1850+
export type record_type = data_type;
1851+
1852+
export type custom_types = data_type;

build.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
const fs = require('fs')
1+
/*const fs = require('fs')
22
const path = require('path')
3-
const peg = require('pegjs')
3+
const peg = require('peggy')
44
55
const parserFolder = path.join(__dirname, 'pegjs')
66
const PARSER_FILE = /(.*)\.pegjs$/
7+
*/
78

9+
// note: we don't actually need it anymore now that we're pre-building
10+
/*
811
fs.readdirSync(parserFolder)
912
.filter(file => PARSER_FILE.test(file))
1013
.forEach(file => {
@@ -18,4 +21,5 @@ fs.readdirSync(parserFolder)
1821
},
1922
})
2023
fs.writeFileSync(path.join(__dirname, `build/${name}.js`), parser)
21-
})
24+
})
25+
*/

0 commit comments

Comments
 (0)