Skip to content

Commit

Permalink
Allow multiple command line arguments during parser generation
Browse files Browse the repository at this point in the history
Closes #180 How to pass multi CLI arguments to antlr?

Signed-off-by: Mike Lischke <mike@lischke-online.de>
  • Loading branch information
mike-lischke committed Nov 25, 2023
1 parent 6e09d40 commit 9bb3cb1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/extension-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/ExtensionHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ export class ExtensionHost {
listeners: false,
visitors: false,
alternativeJar: workspace.getConfiguration("antlr4.generation").get<string>("alternativeJar"),
additionalParameters: workspace.getConfiguration("antlr4.generation").get<string>("additionalParameters"),
additionalParameters: workspace.getConfiguration("antlr4.generation")
.get<string | string[]>("additionalParameters"),
language: workspace.getConfiguration("antlr4.generation").get<string>("language"),
package: workspace.getConfiguration("antlr4.generation").get<string>("package"),
};
Expand Down
6 changes: 5 additions & 1 deletion src/backend/SourceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/webviews/ATNGraphProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

/**
Expand Down

0 comments on commit 9bb3cb1

Please sign in to comment.