diff --git a/.eslintignore b/.eslintignore index 4bab032b..d41c1400 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,3 +2,4 @@ build node_modules test parser +src/generated diff --git a/.eslintrc b/.eslintrc index be1f758d..7541513b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,6 +11,7 @@ "globals": { "PARSER_NAME": true }, + "parser": "@babel/eslint-parser", "rules": { "comma-dangle": [ 2, @@ -138,4 +139,4 @@ "no-process-env": 0, "default-case": 0 } -} \ No newline at end of file +} diff --git a/.gitignore b/.gitignore index d0753058..5a3ab7a1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ bower_components/ umd/ output/ .DS_Store +src/generated/ diff --git a/ast/postgresql.ts b/ast/postgresql.ts index 2f659f49..68bac0ee 100644 --- a/ast/postgresql.ts +++ b/ast/postgresql.ts @@ -299,10 +299,16 @@ export interface drop_index_stmt_node { export type drop_stmt = AstStatement | AstStatement; +export type truncate_table_name = table_name & { suffix?: string }; + +export type truncate_table_name_list = truncate_table_name[]; + export interface truncate_stmt_node { type: 'trucate'; keyword: 'table'; + prefix?: string; name: table_ref_list; + suffix: string[]; } export type truncate_stmt = AstStatement; @@ -559,7 +565,7 @@ export type table_option = { keyword: 'auto_increment' | 'avg_row_length' | 'key_block_size' | 'max_rows' | 'min_rows' | 'stats_sample_pages'; symbol: '='; value: number; // <== literal_numeric['value'] - } | create_option_character_set | { keyword: 'connection' | 'comment'; symbol: '='; value: string; } | { keyword: 'compression'; symbol: '='; value: "'ZLIB'" | "'LZ4'" | "'NONE'" } | { keyword: 'engine'; symbol: '='; value: string; }; + } | 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; }; export type ALTER_ADD_FULLETXT_SPARITAL_INDEX = create_fulltext_spatial_index_definition & { action: 'add'; type: 'alter' }; @@ -770,6 +776,8 @@ export type column_clause = 'ALL' | '*' | column_list_item[] | column_list_item[ export type array_index = { brackets: boolean, number: number }; +export type array_index_list = array_index[]; + export type expr_item = binary_expr & { array_index: array_index }; export type cast_data_type = data_type & { quoted?: string }; @@ -1103,32 +1111,38 @@ export type column_ref = string_constants_escape | { property?: (literal_string | literal_numeric)[]; }; +export type column_ref_quoted = IGNORE; + export type column_list = column[]; +export type ident_without_kw_type = { type: 'default', value: string } | quoted_ident_type; + +export type ident_type = ident_name | quoted_ident_type; + export type ident = string; export type ident_list = ident[]; export type alias_ident = string; -export type quoted_ident = double_quoted_ident | single_quoted_ident | backticks_quoted_ident; - - +export type quoted_ident_type = double_quoted_ident | single_quoted_ident | backticks_quoted_ident; -export type double_quoted_ident = string; +export type quoted_ident = string; +export type double_quoted_ident = { type: 'double_quote_string'; value: string; }; +export type single_quoted_ident = { type: 'single_quote_string'; value: string; }; -export type single_quoted_ident = string; - - - -export type backticks_quoted_ident = string; +export type backticks_quoted_ident = { type: 'backticks_quote_string'; value: string; }; export type ident_without_kw = ident_name | quoted_ident; export type column_without_kw = column_name | quoted_ident; +export type column_without_kw_type = { type: 'default', value: string } | quoted_ident_type; + +export type column_type = { type: 'default', value: string } | quoted_ident_type; + export type column = string | quoted_ident; @@ -1199,11 +1213,11 @@ export type trim_position = "BOTH" | "LEADING" | "TRAILING"; export type trim_rem = expr_list; -export type trim_func_clause = { type: 'function'; name: string; args: expr_list; }; +export type trim_func_clause = { type: 'function'; name: proc_func_name; args: expr_list; }; -export type tablefunc_clause = { type: 'tablefunc'; name: crosstab; args: expr_list; as: func_call }; +export type tablefunc_clause = { type: 'tablefunc'; name: proc_func_name; args: expr_list; as: func_call }; -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; }; +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; }; export type extract_filed = 'string'; @@ -1262,7 +1276,9 @@ export type literal_not_null = { type: 'not null'; value: 'not null' }; export type literal_bool = { type: 'bool', value: true } | { type: 'bool', value: false }; -export type literal_string = { type: 'single_quote_string'; value: string; } | { type: 'string'; value: string; }; +export type literal_string = { type: 'single_quote_string'; value: string; } | literal_double_quoted_string; + +export type literal_double_quoted_string = { type: 'string'; value: string; }; export type literal_datetime = { type: 'TIME' | 'DATE' | 'TIMESTAMP' | 'DATETIME', value: string }; @@ -1730,7 +1746,7 @@ export type proc_join = { type: 'join'; ltable: var_decl; rtable: var_decl; op: 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; -export type proc_func_name = string; +export type proc_func_name = { schema?: ident_without_kw_type, name: ident_without_kw_type }; export type proc_func_call = { type: 'function'; name: string; args: null | { type: expr_list; value: proc_primary_list; }}; @@ -1831,4 +1847,6 @@ export type uuid_type = data_type; -export type record_type = data_type; \ No newline at end of file +export type record_type = data_type; + +export type custom_types = data_type; \ No newline at end of file diff --git a/build.js b/build.js index 8aa10e70..6558ef65 100644 --- a/build.js +++ b/build.js @@ -1,10 +1,13 @@ -const fs = require('fs') +/*const fs = require('fs') const path = require('path') -const peg = require('pegjs') +const peg = require('peggy') const parserFolder = path.join(__dirname, 'pegjs') const PARSER_FILE = /(.*)\.pegjs$/ +*/ +// note: we don't actually need it anymore now that we're pre-building +/* fs.readdirSync(parserFolder) .filter(file => PARSER_FILE.test(file)) .forEach(file => { @@ -18,4 +21,5 @@ fs.readdirSync(parserFolder) }, }) fs.writeFileSync(path.join(__dirname, `build/${name}.js`), parser) - }) \ No newline at end of file + }) +*/ diff --git a/package-lock.json b/package-lock.json index 29de3aab..2bcaf55b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "devDependencies": { "@babel/cli": "^7.5.5", "@babel/core": "^7.10.5", + "@babel/eslint-parser": "^7.23.10", "@babel/plugin-proposal-object-rest-spread": "^7.5.5", "@babel/preset-env": "^7.10.4", "@babel/register": "^7.10.5", @@ -25,7 +26,7 @@ "copy-webpack-plugin": "^6.0.3", "coveralls": "^3.0.13", "cross-env": "^7.0.2", - "eslint": "^8.3.0", + "eslint": "^8.57.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-strict": "^14.0.1", "eslint-plugin-filenames": "^1.3.2", @@ -35,8 +36,7 @@ "mocha": "^10.0.0", "mochapack": "^2.0.3", "nyc": "15.1.0", - "pegjs": "^0.10.0", - "pegjs-loader": "^0.5.6", + "peggy": "^4.0.2", "pre-commit": "^1.2.2", "rimraf": "^5.0.1", "source-map-support": "^0.5.19", @@ -345,6 +345,42 @@ "semver": "bin/semver.js" } }, + "node_modules/@babel/eslint-parser": { + "version": "7.23.10", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.23.10.tgz", + "integrity": "sha512-3wSYDPZVnhseRnxRJH6ZVTNknBz76AEnyC+AYYhasjP3Yy23qz0ERR7Fcd2SHmYuSFJ2kY9gaaDd3vyqU09eSw==", + "dev": true, + "dependencies": { + "@nicolo-ribaudo/eslint-scope-5-internals": "5.1.1-v1", + "eslint-visitor-keys": "^2.1.0", + "semver": "^6.3.1" + }, + "engines": { + "node": "^10.13.0 || ^12.13.0 || >=14.0.0" + }, + "peerDependencies": { + "@babel/core": "^7.11.0", + "eslint": "^7.5.0 || ^8.0.0" + } + }, + "node_modules/@babel/eslint-parser/node_modules/eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@babel/eslint-parser/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/generator": { "version": "7.23.6", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.6.tgz", @@ -2733,6 +2769,28 @@ "dev": true, "optional": true }, + "node_modules/@nicolo-ribaudo/eslint-scope-5-internals": { + "version": "5.1.1-v1", + "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", + "integrity": "sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==", + "dev": true, + "dependencies": { + "eslint-scope": "5.1.1" + } + }, + "node_modules/@nicolo-ribaudo/eslint-scope-5-internals/node_modules/eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2792,6 +2850,33 @@ "node": ">=10" } }, + "node_modules/@peggyjs/from-mem": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@peggyjs/from-mem/-/from-mem-1.2.1.tgz", + "integrity": "sha512-qh5zG8WKT36142/FqOYtpF0scRR3ZJ3H5XST1bJ/KV2FvyB5MvUB/tB9ZjihRe1iKjJD4PBOZczzwEx7hJtgMw==", + "dev": true, + "dependencies": { + "semver": "7.6.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@peggyjs/from-mem/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -12629,29 +12714,30 @@ "node": ">=0.12" } }, - "node_modules/pegjs": { - "version": "0.10.0", - "resolved": "http://registry.npmjs.org/pegjs/-/pegjs-0.10.0.tgz", - "integrity": "sha1-z4uvrm7d/0tafvsYUmnqr0YQ3b0=", + "node_modules/peggy": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/peggy/-/peggy-4.0.2.tgz", + "integrity": "sha512-j4cepPgB20V7honmTAI+7U022y/n/wVi7Rbbd2QrMl2nifFECpngvA6Zhrz/JdmZ5LIBoTdkgHcDzzaA6C4ABg==", "dev": true, + "dependencies": { + "@peggyjs/from-mem": "1.2.1", + "commander": "^12.0.0", + "source-map-generator": "0.8.0" + }, "bin": { - "pegjs": "bin/pegjs" + "peggy": "bin/peggy.js" }, "engines": { - "node": ">=0.10" + "node": ">=18" } }, - "node_modules/pegjs-loader": { - "version": "0.5.8", - "resolved": "https://registry.npmjs.org/pegjs-loader/-/pegjs-loader-0.5.8.tgz", - "integrity": "sha512-FcqC07tFiDN5kEOVcYw0wSJcHu3d6YrT2sCJM5xkNwOeTAEkk/gFcxnkJH4D/ZNfUaBLQ7fbCUwMWLFfJ/06Mg==", + "node_modules/peggy/node_modules/commander": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", + "integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==", "dev": true, - "dependencies": { - "loader-utils": "^1.4.2" - }, - "peerDependencies": { - "pegjs": "^0.10.0", - "webpack": ">=1" + "engines": { + "node": ">=18" } }, "node_modules/performance-now": { @@ -13933,6 +14019,15 @@ "node": ">=0.10.0" } }, + "node_modules/source-map-generator": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/source-map-generator/-/source-map-generator-0.8.0.tgz", + "integrity": "sha512-psgxdGMwl5MZM9S3FWee4EgsEaIjahYV5AzGnwUvPhWeITz/j6rKpysQHlQ4USdxvINlb8lKfWGIXwfkrgtqkA==", + "dev": true, + "engines": { + "node": ">= 10" + } + }, "node_modules/source-map-resolve": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.3.tgz", @@ -16364,6 +16459,31 @@ } } }, + "@babel/eslint-parser": { + "version": "7.23.10", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.23.10.tgz", + "integrity": "sha512-3wSYDPZVnhseRnxRJH6ZVTNknBz76AEnyC+AYYhasjP3Yy23qz0ERR7Fcd2SHmYuSFJ2kY9gaaDd3vyqU09eSw==", + "dev": true, + "requires": { + "@nicolo-ribaudo/eslint-scope-5-internals": "5.1.1-v1", + "eslint-visitor-keys": "^2.1.0", + "semver": "^6.3.1" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true + }, + "semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true + } + } + }, "@babel/generator": { "version": "7.23.6", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.6.tgz", @@ -18082,6 +18202,27 @@ "dev": true, "optional": true }, + "@nicolo-ribaudo/eslint-scope-5-internals": { + "version": "5.1.1-v1", + "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", + "integrity": "sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==", + "dev": true, + "requires": { + "eslint-scope": "5.1.1" + }, + "dependencies": { + "eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + } + } + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -18125,6 +18266,26 @@ } } }, + "@peggyjs/from-mem": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@peggyjs/from-mem/-/from-mem-1.2.1.tgz", + "integrity": "sha512-qh5zG8WKT36142/FqOYtpF0scRR3ZJ3H5XST1bJ/KV2FvyB5MvUB/tB9ZjihRe1iKjJD4PBOZczzwEx7hJtgMw==", + "dev": true, + "requires": { + "semver": "7.6.0" + }, + "dependencies": { + "semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -26110,19 +26271,23 @@ "sha.js": "^2.4.8" } }, - "pegjs": { - "version": "0.10.0", - "resolved": "http://registry.npmjs.org/pegjs/-/pegjs-0.10.0.tgz", - "integrity": "sha1-z4uvrm7d/0tafvsYUmnqr0YQ3b0=", - "dev": true - }, - "pegjs-loader": { - "version": "0.5.8", - "resolved": "https://registry.npmjs.org/pegjs-loader/-/pegjs-loader-0.5.8.tgz", - "integrity": "sha512-FcqC07tFiDN5kEOVcYw0wSJcHu3d6YrT2sCJM5xkNwOeTAEkk/gFcxnkJH4D/ZNfUaBLQ7fbCUwMWLFfJ/06Mg==", + "peggy": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/peggy/-/peggy-4.0.2.tgz", + "integrity": "sha512-j4cepPgB20V7honmTAI+7U022y/n/wVi7Rbbd2QrMl2nifFECpngvA6Zhrz/JdmZ5LIBoTdkgHcDzzaA6C4ABg==", "dev": true, "requires": { - "loader-utils": "^1.4.2" + "@peggyjs/from-mem": "1.2.1", + "commander": "^12.0.0", + "source-map-generator": "0.8.0" + }, + "dependencies": { + "commander": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", + "integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==", + "dev": true + } } }, "performance-now": { @@ -27146,6 +27311,12 @@ "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", "dev": true }, + "source-map-generator": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/source-map-generator/-/source-map-generator-0.8.0.tgz", + "integrity": "sha512-psgxdGMwl5MZM9S3FWee4EgsEaIjahYV5AzGnwUvPhWeITz/j6rKpysQHlQ4USdxvINlb8lKfWGIXwfkrgtqkA==", + "dev": true + }, "source-map-resolve": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.3.tgz", diff --git a/package.json b/package.json index b1a571c8..872c46de 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "types": "types.d.ts", "scripts": { "start": "webpack --config webpack.config.js", - "build": "npm run lint && npm run compile && webpack --config webpack.config.js --mode production", + "build:parsers": "mkdir -p src/generated ; for f in pegjs/*.pegjs ; do npx peggy -m -o src/generated/`basename $f .pegjs`.js $f ; done", + "build": "npm run build:parsers && npm run lint && npm run compile && webpack --config webpack.config.js --mode production", "test": "npm run lint && mochapack \"test/**/*.spec.js\"", "lint": "eslint src", "compile": "babel src -d lib", @@ -59,6 +60,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.5.5", "@babel/preset-env": "^7.10.4", "@babel/register": "^7.10.5", + "@babel/eslint-parser": "^7.23.10", "@types/chai": "^4.1.7", "@types/mocha": "^10.0.1", "babel-loader": "^8.1.0", @@ -67,7 +69,7 @@ "copy-webpack-plugin": "^6.0.3", "coveralls": "^3.0.13", "cross-env": "^7.0.2", - "eslint": "^8.3.0", + "eslint": "^8.57.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-strict": "^14.0.1", "eslint-plugin-filenames": "^1.3.2", @@ -77,8 +79,7 @@ "mocha": "^10.0.0", "mochapack": "^2.0.3", "nyc": "15.1.0", - "pegjs": "^0.10.0", - "pegjs-loader": "^0.5.6", + "peggy": "^4.0.2", "pre-commit": "^1.2.2", "rimraf": "^5.0.1", "source-map-support": "^0.5.19", diff --git a/src/parser.all.js b/src/parser.all.js index cc764027..3033fb89 100644 --- a/src/parser.all.js +++ b/src/parser.all.js @@ -1,16 +1,16 @@ -import { parse as athena } from '../pegjs/athena.pegjs' -import { parse as bigquery } from '../pegjs/bigquery.pegjs' -import { parse as db2 } from '../pegjs/db2.pegjs' -import { parse as flinksql } from '../pegjs/flinksql.pegjs' -import { parse as hive } from '../pegjs/hive.pegjs' -import { parse as mysql } from '../pegjs/mysql.pegjs' -import { parse as mariadb } from '../pegjs/mariadb.pegjs' -import { parse as noql } from '../pegjs/noql.pegjs' -import { parse as postgresql } from '../pegjs/postgresql.pegjs' -import { parse as redshift } from '../pegjs/redshift.pegjs' -import { parse as sqlite } from '../pegjs/sqlite.pegjs' -import { parse as transactsql } from '../pegjs/transactsql.pegjs' -import { parse as snowflake } from '../pegjs/snowflake.pegjs' +import { parse as athena } from './generated/athena' +import { parse as bigquery } from './generated/bigquery' +import { parse as db2 } from './generated/db2' +import { parse as flinksql } from './generated/flinksql' +import { parse as hive } from './generated/hive' +import { parse as mysql } from './generated/mysql' +import { parse as mariadb } from './generated/mariadb' +import { parse as noql } from './generated/noql' +import { parse as postgresql } from './generated/postgresql' +import { parse as redshift } from './generated/redshift' +import { parse as sqlite } from './generated/sqlite' +import { parse as transactsql } from './generated/transactsql' +import { parse as snowflake } from './generated/snowflake' export default { athena, diff --git a/src/parser.single.js b/src/parser.single.js index 9946ee31..d5347713 100644 --- a/src/parser.single.js +++ b/src/parser.single.js @@ -1,4 +1,4 @@ -import { parse } from '../pegjs/mysql.pegjs' +import { parse } from './generated/mysql' export default { [PARSER_NAME] : parse, diff --git a/test/mysql-mariadb.spec.js b/test/mysql-mariadb.spec.js index ba3df210..9219c4fa 100644 --- a/test/mysql-mariadb.spec.js +++ b/test/mysql-mariadb.spec.js @@ -963,10 +963,10 @@ describe('mysql', () => { it('should throw error when args is not right', () => { let sql = `select convert(json_unquote(json_extract('{"thing": "252"}', "$.thing")));` - expect(parser.astify.bind(parser, sql)).to.throw('Expected "!=", "#", "%", "&", "&&", "*", "+", ",", "-", "--", "/", "/*", "<", "<<", "<=", "<>", "=", ">", ">=", ">>", "AND", "BETWEEN", "IN", "IS", "LIKE", "NOT", "ON", "OR", "OVER", "REGEXP", "RLIKE", "USING", "XOR", "^", "div", "|", "||", or [ \\t\\n\\r] but ")" found.') - expect(parser.astify.bind(parser, 'select convert("");')).to.throw('Expected "!=", "#", "%", "&", "&&", "*", "+", ",", "-", "--", "/", "/*", "<", "<<", "<=", "<>", "=", ">", ">=", ">>", "AND", "BETWEEN", "COLLATE", "IN", "IS", "LIKE", "NOT", "OR", "REGEXP", "RLIKE", "USING", "XOR", "^", "div", "|", "||", or [ \\t\\n\\r] but ")" found.') + expect(parser.astify.bind(parser, sql)).to.throw('Expected "!=", "#", "&", "&&", ",", "--", "/*", "<<", "<=", "<>", ">", ">=", ">>", "AND", "BETWEEN", "IN", "IS", "LIKE", "NOT", "ON", "OR", "OVER", "REGEXP", "RLIKE", "USING", "XOR", "div", "||", [ \\t\\n\\r], [%*/], [+\\-], [<-=], or [\\^|] but ")" found.') + expect(parser.astify.bind(parser, 'select convert("");')).to.throw('Expected "!=", "#", "&", "&&", ",", "--", "/*", "<<", "<=", "<>", ">", ">=", ">>", "AND", "BETWEEN", "COLLATE", "IN", "IS", "LIKE", "NOT", "OR", "REGEXP", "RLIKE", "USING", "XOR", "div", "||", [ \\t\\n\\r], [%*/], [+\\-], [<-=], or [\\^|] but ")" found.') sql = 'SELECT AVG(Quantity,age) FROM table1;' - expect(parser.astify.bind(parser, sql)).to.throw('Expected "#", "%", "&", "(", ")", "*", "+", "-", "--", "->", "->>", ".", "/", "/*", "<<", ">>", "^", "div", "|", "||", [ \\t\\n\\r], [A-Za-z0-9_$\\x80-￿], or [A-Za-z0-9_:] but "," found.') + expect(parser.astify.bind(parser, sql)).to.throw('Expected "#", "&", "(", ")", "--", "->", "->>", ".", "/*", "<<", ">>", "div", "||", [ \\t\\n\\r], [%*/], [+\\-], [A-Za-z0-9_$\\x80-￿], [A-Za-z0-9_:], or [\\^|] but "," found.') }) it('should join multiple table with comma', () => { @@ -1099,4 +1099,4 @@ describe('mysql', () => { }) }) -}) \ No newline at end of file +}) diff --git a/typegen.js b/typegen.js index a167e456..e5dde816 100644 --- a/typegen.js +++ b/typegen.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -const peg = require('pegjs'); +const peg = require('peggy'); const syntax = fs.readFileSync(path.resolve(__dirname, './pegjs/postgresql.pegjs'), 'utf-8') const ast = peg.parser.parse(syntax); diff --git a/webpack.config.js b/webpack.config.js index dd8f17d6..09b241a9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -32,10 +32,6 @@ const moduleCfg = { } }, enforce: 'post', - }, - { - test: /\.pegjs$/, - loader: 'pegjs-loader?dependencies={"BigInt":"big-integer"}' } ], }