From eb1ba339bffcadff5a12d5e370f268d4943ac424 Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Sat, 9 Nov 2024 08:03:53 -0700 Subject: [PATCH 1/2] Allow for multiple start rules --- bin/abnf_gen.js | 8 +++++++- lib/ast.js | 9 ++++++--- test/parse.ava.js | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/abnf_gen.js b/bin/abnf_gen.js index 5523e55..70750b4 100755 --- a/bin/abnf_gen.js +++ b/bin/abnf_gen.js @@ -20,6 +20,11 @@ function genFormat(rules, opts) { } } +function append(v, p = []) { + p.push(v); + return p; +} + const program = new Command(); program .argument("[abnfFile...]", "ABNF files to turn into grammars.") @@ -31,7 +36,8 @@ program ) .option( "-s, --startRule ", - "Start rule for generated grammar. Defaults to first rule in ABNF grammar." + "Start rule for generated grammar. Defaults to first rule in ABNF grammar. Can be specified multiple times.", + append ) .option("--stubs", "Generate stubs for rules that do not exist, rather than failing.") .option( diff --git a/lib/ast.js b/lib/ast.js index d51a075..1a807cc 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -5,7 +5,7 @@ /** * @typedef {object} FormatOptions * @prop {string} [format='peggy'] - * @prop {string} [startRule] Defaults to first + * @prop {string|string[]} [startRule] Defaults to first * @prop {boolean} [stubs=false] * @prop {boolean} [unused=false] */ @@ -369,10 +369,13 @@ export class Rules extends Base { if (!["peggy", "pest"].includes(opts.format)) { badFormat(opts); } - if (!opts.startRule) { + if (opts.startRule === null) { return ""; } - const needed = [opts.startRule]; + if (typeof opts.startRule === "string") { + opts.startRule = [opts.startRule]; + } + const needed = [...opts.startRule]; const done = new Set(); let res = ""; while (needed.length > 0) { diff --git a/test/parse.ava.js b/test/parse.ava.js index 25e6263..d19a1e9 100644 --- a/test/parse.ava.js +++ b/test/parse.ava.js @@ -130,7 +130,7 @@ binarySep = %b1100001 %b1100010 %b1100011 test("parser edges", t => { t.throws(() => parse("", { - startRule: "___INVALID____", + startRule: ["___INVALID____"], })); parse("foo = %x20\n", { From 63884a74b834f6ccb7e5a9d943de1f73a61018b2 Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Sat, 9 Nov 2024 08:06:38 -0700 Subject: [PATCH 2/2] Overrides to audit clean --- package.json | 6 ++++++ pnpm-lock.yaml | 31 +++++-------------------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 74143d1..2862294 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,12 @@ "typescript": "^5.6.3" }, "packageManager": "pnpm@9.12.3", + "pnpm": { + "overrides": { + "braces": "^3.0.3", + "micromatch": "^4.0.8" + } + }, "engines": { "node": ">=18" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43961f7..83d9512 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,10 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + braces: ^3.0.3 + micromatch: ^4.0.8 + importers: .: @@ -369,10 +373,6 @@ packages: brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} - braces@3.0.2: - resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} - engines: {node: '>=8'} - braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -636,10 +636,6 @@ packages: file-uri-to-path@1.0.0: resolution: {integrity: sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==} - fill-range@7.0.1: - resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} - engines: {node: '>=8'} - fill-range@7.1.1: resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} engines: {node: '>=8'} @@ -1010,10 +1006,6 @@ packages: micromark@4.0.0: resolution: {integrity: sha512-o/sd0nMof8kYff+TqcDx3VSrgBTcZpSvYcAHIfHhv5VAuNmisCxjhx6YmxS8PFEpb9z5WKWKPdzf0jM23ro3RQ==} - micromatch@4.0.5: - resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} - engines: {node: '>=8.6'} - micromatch@4.0.8: resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==} engines: {node: '>=8.6'} @@ -1837,10 +1829,6 @@ snapshots: dependencies: balanced-match: 1.0.2 - braces@3.0.2: - dependencies: - fill-range: 7.0.1 - braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -2069,7 +2057,7 @@ snapshots: '@nodelib/fs.walk': 1.2.8 glob-parent: 5.1.2 merge2: 1.4.1 - micromatch: 4.0.5 + micromatch: 4.0.8 fast-json-stable-stringify@2.1.0: {} @@ -2089,10 +2077,6 @@ snapshots: file-uri-to-path@1.0.0: {} - fill-range@7.0.1: - dependencies: - to-regex-range: 5.0.1 - fill-range@7.1.1: dependencies: to-regex-range: 5.0.1 @@ -2615,11 +2599,6 @@ snapshots: transitivePeerDependencies: - supports-color - micromatch@4.0.5: - dependencies: - braces: 3.0.2 - picomatch: 2.3.1 - micromatch@4.0.8: dependencies: braces: 3.0.3