Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated code fails to compile #395

Closed
MartinJohns opened this issue Dec 14, 2018 · 3 comments
Closed

Generated code fails to compile #395

MartinJohns opened this issue Dec 14, 2018 · 3 comments

Comments

@MartinJohns
Copy link

MartinJohns commented Dec 14, 2018

Versions used:

Module Version
antlr4ts 0.5.0-alpha.1
antlr4ts-cli 0.5.0-alpha.1
TypeScript 3.2.2
Node 11.2.0
NPM 6.4.1
VS Code 1.30.0
Java 1.8.0_192-b12

Steps performed:

npm init -y
npm install typescript antlr4ts-cli --save-dev
npm install antlr4ts --save
node_modules/.bin/tsc --init
node_modules/.bin/antlr4ts -visitor Rule.g4

Issues:

The lexer, the listener and the visitor seem to compile fine, but the RuleParser.ts file contains several compilation errors.

  • this.match(argument) is called, but implementation does not accept any arguments.
  • Signatures of RuleParser.match() and base class Parser.match(..) do not match in arguments and return type.
  • this can't be passed as an argument to methods accepting a Parser (possibly because for the previous issue).
  • Context properties are not initialized.

The first two errors can be solved by renaming the match() method in the derived class to something like matchNoArgs() and replace all calls to the parameterless match method with the new name. I guess as part of some re-working the name got accidentally re-used (JavaScript does not support method overloading).

The last error can be solved by turning strictPropertyInitialization off in the TypeScript configuration.

After that I run into the same issue as #394 and hope for support of #311.

@sharwell
Copy link
Member

sharwell commented Dec 14, 2018

Signatures of RuleParser.match()

I can't figure out how this method is getting generated. Can you include a copy of Rule.g4?

Edit: This is probably caused by having a rule in the grammar itself named match. Currently this target doesn't have a hard-coded list of "bad words" (rule names that cause compilation errors), so if you hit one you'll need to rename the grammar rule to get it to compile.

Context properties are not initialized.

Can you provide an example of this? Edit: moved this item to #396

@MartinJohns
Copy link
Author

Can you include a copy of Rule.g4?

Unfortunately I can not, but as soon as I read your response I realized what the mistake is. The grammar is sports related and has a match rule, and that caused the match() method to be generated.

To prevent such occurances in the future you could consider adding a prefix to the base class methods, or to the derived class methods, or perhaps even use symbols to hide the base class implementation.

Regardless this issue is closed, as it was my own fault. :-) I've also added an example to #396.

@StarGazerM
Copy link

=. =, same problem appears to me, and after read this .........What fool am I.......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants