Steps to reproduce:
0) Install node v14.2.0
1) Download antlr 4.8
2) Create a basic grammar:
```
grammar Grammar;
main
: ('foo' | 'bar' | 'baz')* EOF ;
WS
: [ \t\r\n\u000C]+ -> skip ;
```
3) Generate javascript: java -jar antlr4.jar -Dlanguage=JavaScript Grammar.g4 -o src
4) cd src && npm install antlr4
5) Require the lexer file: node --trace-warnings -e 'require("./GrammarLexer")'
This does work, but shows a warning:
(node:20695) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency
at emitCircularRequireWarning (internal/modules/cjs/loader.js:817:11)
at Object.get (internal/modules/cjs/loader.js:831:5)
at Object.<anonymous> (node_modules/antlr4/RuleContext.js:30:46)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
at Module.load (internal/modules/cjs/loader.js:1040:32)
at Function.Module._load (internal/modules/cjs/loader.js:929:14)
at Module.require (internal/modules/cjs/loader.js:1080:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (node_modules/antlr4/PredictionContext.js:8:19)
(node:20695) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency
at emitCircularRequireWarning (internal/modules/cjs/loader.js:817:11)
at Object.get (internal/modules/cjs/loader.js:831:5)
at Object.<anonymous> (node_modules/antlr4/tree/Trees.js:13:49)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
at Module.load (internal/modules/cjs/loader.js:1040:32)
at Function.Module._load (internal/modules/cjs/loader.js:929:14)
at Module.require (internal/modules/cjs/loader.js:1080:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (node_modules/antlr4/RuleContext.js:122:13)
A similar error happens if you require RuleContext
directly: node --trace-warnings -e 'require("antlr4/RuleContext")'
I can confirm the issue. And, it is not just only a warning, node express stops serving. So, this is critical issue.
I believe this is already fixed in the latest master.
No release date yet.
Surely this error can be ignored using a node express setting until the fix is released?
https://github.com/antlr/antlr4/pull/2749 I think is the fix for this (specifically https://github.com/antlr/antlr4/commit/edf24eab3ff80961c82f12142c7ea1235d9b53d2), which is not released yet
Indeed this was fixed as part of the ES6 migration.
@parrt would suggest starting to plan a 4.9 release: Dart + ES6 + various bug fixes.... ?
Sure. Is ES6 is a big change?
created milestone. Closing. Fixed by #2749
Sure. Is ES6 is a big change?
Yes, it changes the generated code, and is a major step towards an official Typescript version
Hey folks, thanks for this!
I cloned the repo, built it locally from the master branch, and then used the generated JAR to re-generate my parser. But there were no changes at all. Am I missing something here?
I think this will be fixed with #2931 . PR #2749 only introduced a workaround to allow the runtime to compute the correct result but it didnt remove the cyclic dependency.
It is fixed with #2931
great! when's this going to be released? in 4.9 or before?
Hey folks, just as a data point for you: I tried this again and now it seems to work fine!
I had to do some changes:
Object.create
+ prototypesAnd some other things. But I guess all that will be documented in the release. Thanks for fixing this!