Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ignorePatterns": ["src/parser.ts"],
"ignorePatterns": ["src/parser.js", "src/parser.d.ts", "peggy-config.*"],
"env": {
"es2021": true
},
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
lib
src/parser.ts
src/parser.js
src/parser.d.ts
.claude
build
135 changes: 37 additions & 98 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
"pretty": "prettier --write .",
"add:keyword": "ts-node ./scripts/add-keyword.ts",
"add:template": "ts-node ./scripts/add-template.ts",
"generate": "ts-node ./scripts/generate.ts",
"generate:fast": "ts-node ./scripts/generate.ts --fast",
"generate": "npm run build:plugins && peggy -c peggy-config.mjs",
"generate:fast": "peggy -c peggy-config.fast.mjs",
"watch:generate": "npm-watch",
"clean": "rm -rf lib; rm -rf src/generated_parser.ts",
"build": "npm run clean && npm run generate && tsc -p tsconfig.build.json",
"clean": "rm -rf lib; rm -f src/parser.js src/parser.d.ts",
"build": "npm run clean && npm run generate && tsc -p tsconfig.build.json && cp src/parser.d.ts lib/parser.d.ts",
"build:plugins": "tsc -p tsconfig.plugins.json",
"test:bigquery": "jest --config test/config/bigquery.json",
"test:mysql": "jest --config test/config/mysql.json",
"test:mariadb": "jest --config test/config/mariadb.json",
Expand Down Expand Up @@ -57,11 +58,10 @@
"eslint-config-prettier": "^9.1.0",
"jest": "^30.3.0",
"npm-watch": "^0.11.0",
"peggy": "^3.0.2",
"peggy": "^4.2.0",
"prettier": "^2.7.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"ts-pegjs": "4.2.1",
"typescript": "^5.9.3"
},
"watch": {
Expand Down
10 changes: 10 additions & 0 deletions peggy-config.fast.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { moveImports } from "./build/plugins/move-imports.js";
import { ruleTemplates } from "./build/plugins/rule-templates.js";
import { disableRecursionCheck } from "./build/plugins/disable-recusion-check.js";

export default {
dts: true,
format: "es",
input: "src/parser.pegjs",
plugins: [moveImports, ruleTemplates, disableRecursionCheck],
};
9 changes: 9 additions & 0 deletions peggy-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { moveImports } from "./build/plugins/move-imports.js";
import { ruleTemplates } from "./build/plugins/rule-templates.js";

export default {
dts: true,
format: "es",
input: "src/parser.pegjs",
plugins: [moveImports, ruleTemplates],
};
10 changes: 4 additions & 6 deletions scripts/disable-recusion-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { Plugin } from "peggy";
* See: https://github.com/peggyjs/peggy/issues/457
*/
export const disableRecursionCheck: Plugin = {
use(config, options) {
if (options.disableRecursionCheck) {
config.passes.check = config.passes.check.filter(
(pass) => pass.name !== "reportInfiniteRecursion"
);
}
use(config) {
config.passes.check = config.passes.check.filter(
(pass) => pass.name !== "reportInfiniteRecursion"
);
},
};
28 changes: 0 additions & 28 deletions scripts/generate.ts

This file was deleted.

13 changes: 11 additions & 2 deletions scripts/move-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ const removeImportsPass: Pass = (ast) => {
if (!ast.initializer) {
return;
}
const code = ast.initializer.code;

const code =
ast.initializer instanceof Array
? ast.initializer[0].code
: ast.initializer.code;

imports = code.match(IMPORT_REGEX) || [];
const withoutImports = code.replace(IMPORT_REGEX, "");
ast.initializer.code = withoutImports;

if (ast.initializer instanceof Array) {
ast.initializer[0].code = withoutImports;
} else {
ast.initializer.code = withoutImports;
}
};

const addImportsPass: Pass = (ast) => {
Expand Down
14 changes: 6 additions & 8 deletions src/FormattedSyntaxError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Expectation, PeggySyntaxError } from "./parser";
import { Expectation, SyntaxError as PeggySyntaxError } from "./parser";

export class FormattedSyntaxError extends Error {
constructor(e: PeggySyntaxError, sql: string, filename?: string) {
Expand Down Expand Up @@ -29,11 +29,11 @@ ${indent} | ${"^".padStart(colNr)}`;

// When we stopped at a single letter, display the whole word instead
function expandFound(
found: string | null,
found: string | null | undefined,
colNr: number,
line: string
): string | null {
if (found !== null && /^\w$/.test(found)) {
): string | null | undefined {
if (found !== null && found !== undefined && /^\w$/.test(found)) {
const [word] = line.slice(colNr - 1).match(/\w+/) || [];
return word || null;
}
Expand All @@ -48,7 +48,7 @@ function expandFound(
/* eslint-disable no-control-regex */
/* eslint-disable no-case-declarations */

function describeFound(found1: string | null) {
function describeFound(found1: string | null | undefined) {
return found1 ? '"' + literalEscape(found1) + '"' : "end of input";
}

Expand Down Expand Up @@ -92,9 +92,7 @@ function describeExpectation(expectation: Expectation) {
case "class":
const escapedParts = expectation.parts.map((part) => {
return Array.isArray(part)
? classEscape(part[0] as string) +
"-" +
classEscape(part[1] as string)
? classEscape(part[0]) + "-" + classEscape(part[1])
: classEscape(part);
});

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export { type DialectName, type ParserOptions } from "./ParserOptions";
export { FormattedSyntaxError } from "./FormattedSyntaxError";

import { Node, Program } from "./cst/Node";
import { parse as parseSql, PeggySyntaxError } from "./parser";
import { parse as parseSql, SyntaxError as PeggySyntaxError } from "./parser";
import { show as showSql } from "./show";
import { ParserOptions, validDialectNames } from "./ParserOptions";
import { FormattedSyntaxError } from "./FormattedSyntaxError";
Expand Down
Loading
Loading