grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

Python Runtime incompatibilities with PHP Grammar

Open dkazantzas opened this issue 3 years ago • 3 comments

There are multiple occurences of actions and predicates such as the following: https://github.com/antlr/grammars-v4/blob/0c9a11ea096dd182862dac03f25766cd5546ff95/php/PhpLexer.g4#L47 https://github.com/antlr/grammars-v4/blob/0c9a11ea096dd182862dac03f25766cd5546ff95/php/PhpLexer.g4#L63

When the Python files are generated, they result in cases such as the following:

def Shebang_sempred(self, localctx:RuleContext, predIndex:int):                                                                                                                     
    if predIndex == 0:                                                                                                                                                          
        return  this.IsNewLineOrStart(-2)   

However, as the self keyword is used instead of this, the result is Python throwing a name error.

Not sure what the correct solution to this issue would be. At the very least, a warning should be added to the README.md, so that people that wish to use the Python runtimes don't have this issue.

dkazantzas avatar Jul 27 '22 11:07 dkazantzas

This PHP grammar is kind of a mess. We should have an automated way to modify the grammar to make it work with Python3, and fit it into the build. A good solution is to follow exactly what I did here: https://github.com/antlr/grammars-v4/commit/4794c0c5371ce6b0711a306256f8f7706394ec6d , adding transformGrammar.py, a new Readme.md, etc. In that PR, I added instructions to run "python3 transformGrammar.py", and just noted so in the readme. The Python script modifies the grammar for Python3. The file "transformGrammar.py" is automatically run in the build, and then the parser tested. I was hoping, could you add this code please? It would be very much appreciated.

kaby76 avatar Jul 27 '22 13:07 kaby76

Good idea. I've added the file. This will save help users automate the whole process

dkazantzas avatar Jul 28 '22 12:07 dkazantzas

@dkazantzas Thank you so much! I'll peek at the PR to make sure it's working.

kaby76 avatar Jul 28 '22 13:07 kaby76