tunnelvisionlabs / antlr4ts

Optimized TypeScript target for ANTLR 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect code generation for lexer

HectorPeeters opened this issue · comments

When using antlr4ts (version 0.4.0-alpha.4) to generate a parser and lexer for the XQuery 3.1 language, the generated code includes some invalid typescript:
private int bracesInside = 0;

This can be fixed by changing it to:
private bracesInside: number = 0;

The command I used to generate the typescript code is:
antlr4ts src/parsing/XQueryLexer.g4 src/parsing/XQueryParser.g4 -visitor

And the g4 files can be found here: https://github.com/xqdoc/xqdoc/tree/master/src/main/antlr4/org/xqdoc

This is a snippet from the generated typescript code.

...
    ///
    /// FIELDS
    ///

    // for counting braces inside string literals
    private int bracesInside = 0;

constructor(input: CharStream) {
    super(input);
    this._interp = new LexerATNSimulator(XQueryLexer._ATN, this);
}
...

I tried to fixing the generation myself first but couldn't find the exact location in the codebase where bracesInside gets created.

I am experiencing the same problem.