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

How to use "atStartOfInput()" #3789

Open Roise-yue opened 11 months ago

Roise-yue commented 11 months ago

I'm reading a python file processed by python3 grammar in "grammars-v4",and as my code is written in python ,there is an error in this line:“with AlternationContext(self, [1, 0],, [this.atStartOfInput(), 1]) as weights0” The context of this code is as follows: def NEWLINE(self, parent=None): with RuleContext(self, UnlexerRule(name='NEWLINE', parent=parent)) as current: with AlternationContext(self, [1, 0],, [this.atStartOfInput(), 1]) as weights0: choice0 = self._model.choice(current, 0, weights0) if choice0 == 0: self.SPACES(parent=current) elif choice0 == 1: So I want to ask how to use "atStartOfInput" or how to modify thiscode.Thank you .

kaby76 commented 11 months ago

Copy the files from python/python3/Python3/ to python/python3/, run python transformGrammar.py to modify the .g4's, run `antlr4 -Dlanguage=Python3 .g4to generate the Python3 source code for the parser, then you can run the parser (though I don't know what driver you have in place). TheatStartOfInput()` function is defined in the file python/python3/Python3/Python3LexerBase.py.