antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.1k stars 3.69k forks source link

javascript grammer dont work with python #1246

Open 0x410c opened 5 years ago

0x410c commented 5 years ago

self explanatory question.

suggest what i can do to fix it?

zhunki commented 5 years ago

I have the same problem. generated python3 lexer doesn't work.

KvanTTT commented 5 years ago

You have to implement Python base lexer and parser classes similar to C# or Java ones.

Anoyomouse commented 5 years ago

Just found this

Unfortunately it's not a simple task of a 1-1 conversion for the base classes, however it's almsot that simple

YOu also need to change the references in the grammars to point to self instead of this

I've pushed a working example of this here: https://github.com/Anoyomouse/Antlr4-Grammar-JavaScript-Py

Because of the nature of the changes i don't think it's a simple case of making a PR and pushing here

KvanTTT commented 4 years ago

@Anoyomouse could you please suggest a pull request with Python files JavaScriptBaseLexer.py, JavaScriptBaseParer.py? I think it's enough.

Anoyomouse commented 4 years ago

@KvanTTT I've updated my parser (same repo) and unfortunately it's still not a trivial matter, the translation from Java/C# is not directly compatible with python because of how the rules in the lexer work (the lexer uses this. instead of self.), that being said, it's actually simple enough to transfrom the g4 before running Antlr, and that gives you a working parser (actually tested properly this time)

However, i've done a PR (#1675), but i'm almost totally sure it'll get killed off because of incompatibilities with all the other languages