I am using ANTLR4 with Python and I am currently using the following code for parsing:
lexer = MyGrammarLexer(FileStream(path))
stream = CommonTokenStream(lexer)
parser = MyGrammarParser(stream)
return parser.start().object
However, I would like to change this code to parse directly from a given string instead of a given path. Thus changing the first line to something similar to
lexer = MyGrammarLexer(a_given_string)
How do I do this?
Looking at the sources of the Pyhton2 and Python3 runtimes, I'd say use an InputStream
instead:
lexer = MyGrammarLexer(InputStream(a_given_string))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With