mike-lischke / vscode-antlr4

ANTLR4 language support for Visual Studio Code
http://www.soft-gems.net
MIT License
436 stars 61 forks source link

Generated TypeScript code contains errors #296

Open jpilgrim opened 2 months ago

jpilgrim commented 2 months ago

Versions.

I have defined a grammar (the expression example from https://github.com/mike-lischke/antlr4ng) and let the extension generate the code.

Here is my .vscode/settings.json:

{
    "antlr4.generation": {
        "language": "TypeScript",
        "mode": "internal",
    }
}

I also have generated the code via antlr4ng-cli, i.e.

npx antlr4ng -Dlanguage=TypeScript -o src/gen -nolistener -Xexact-output-dir src/Expression.g4

The generated parsers are different. The version generated with the script has no compile errors, the other one has errors. The errors actually stem from the differences: The version generated by the extension sets some (unknown) exception properties, e.g.

catch (re) {
            if (re instanceof antlr.RecognitionException) {
+                localContext.exception = re;
                this.errorHandler.reportError(this, re);
                this.errorHandler.recover(this, re);
            } else {
                throw re;
            }
        }
mike-lischke commented 2 months ago

Looks like an older version of the antlr jar is being used in the error case. That needs to be updated.