From 9bb3cb189f30ea7ddb9c17b373e869ca6968bb56 Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Sat, 25 Nov 2023 19:57:53 +0100 Subject: [PATCH] Allow multiple command line arguments during parser generation Closes #180 How to pass multi CLI arguments to antlr? Signed-off-by: Mike Lischke --- doc/extension-settings.md | 2 +- package.json | 7 +++++-- src/ExtensionHost.ts | 3 ++- src/backend/SourceContext.ts | 6 +++++- src/frontend/webviews/ATNGraphProvider.ts | 4 ++-- src/types.ts | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/extension-settings.md b/doc/extension-settings.md index 87195ab..99ab9d6 100644 --- a/doc/extension-settings.md +++ b/doc/extension-settings.md @@ -25,7 +25,7 @@ This is a settings object named **antlr4.generation** with the following members * **listeners**, boolean (default: true), also create listeners on code generation (used only in external mode) * **visitors**, boolean (default: false), also create visitors on code generation (used only in external mode) * **alternativeJar**, string (default: undefined), specifies the ANTLR4 jar to use for generation, instead of the ones shipping with this extension. -* **additionalParameters**, string (default: undefined), specifies additional parameters to be passed on to the ANTLR4 jar (built-in or custom) during parser generation. +* **additionalParameters**, string | string[] (default: undefined), specifies additional parameters to be passed on to the ANTLR4 jar (built-in or custom) during parser generation. ## Grammar Formatting diff --git a/package.json b/package.json index 5094809..53f87db 100644 --- a/package.json +++ b/package.json @@ -180,8 +180,11 @@ "description": "Path to a Java jar file to be used for parser generation" }, "additionalParameters": { - "type": "string", - "description": "Any other command line parameters you want to send to the ANTLR4 jar" + "type": [ + "string", + "array" + ], + "description": "Additional command line parameters you want to send to the ANTLR4 jar. Either a single string or a list of strings." } } }, diff --git a/src/ExtensionHost.ts b/src/ExtensionHost.ts index bd64762..60086fd 100644 --- a/src/ExtensionHost.ts +++ b/src/ExtensionHost.ts @@ -395,7 +395,8 @@ export class ExtensionHost { listeners: false, visitors: false, alternativeJar: workspace.getConfiguration("antlr4.generation").get("alternativeJar"), - additionalParameters: workspace.getConfiguration("antlr4.generation").get("additionalParameters"), + additionalParameters: workspace.getConfiguration("antlr4.generation") + .get("additionalParameters"), language: workspace.getConfiguration("antlr4.generation").get("language"), package: workspace.getConfiguration("antlr4.generation").get("package"), }; diff --git a/src/backend/SourceContext.ts b/src/backend/SourceContext.ts index 6c0b674..bb0f2b0 100644 --- a/src/backend/SourceContext.ts +++ b/src/backend/SourceContext.ts @@ -1104,7 +1104,11 @@ export class SourceContext { parameters.push("-Xexact-output-dir"); // Available starting with 4.7.2. if (options.additionalParameters) { - parameters.push(options.additionalParameters); + if (Array.isArray(options.additionalParameters)) { + parameters.push(...options.additionalParameters); + } else { + parameters.push(options.additionalParameters); + } } dependencies.add(this); // Needs this also in the error parser. diff --git a/src/frontend/webviews/ATNGraphProvider.ts b/src/frontend/webviews/ATNGraphProvider.ts index 4b46ed5..c0cf0c3 100644 --- a/src/frontend/webviews/ATNGraphProvider.ts +++ b/src/frontend/webviews/ATNGraphProvider.ts @@ -197,8 +197,8 @@ export class ATNGraphProvider extends WebviewProvider { for (const node of saveMessage.nodes) { ruleEntry.statePositions[node.id] = { - fx: node.fx === null ? undefined : node.fx, - fy: node.fy === null ? undefined : node.fy, + fx: node.fx ?? undefined, + fy: node.fy ?? undefined, }; } diff --git a/src/types.ts b/src/types.ts index 1b237ec..627dcea 100644 --- a/src/types.ts +++ b/src/types.ts @@ -201,7 +201,7 @@ export interface IGenerationOptions { alternativeJar?: string; /** Any additional parameter you want to send to ANTLR4 for generation (e.g. "-XdbgST"). */ - additionalParameters?: string; + additionalParameters?: string | string[]; } /**