ANTLR4 + Python从字符串而不是路径解析

时间:2017-01-17 09:49:46

标签: python parsing antlr antlr4

我正在使用带有Python的ANTLR4,我目前正在使用以下代码进行解析:

lexer = MyGrammarLexer(a_given_string)

但是,我想更改此代码以直接从给定字符串而不是给定路径进行解析。因此将第一行更改为类似于

的内容
{{1}}

我该怎么做?

1 个答案:

答案 0 :(得分:5)

查看Pyhton2Python3运行时的来源,我要说使用InputStream代替:

lexer = MyGrammarLexer(InputStream(a_given_string))