Closed jpicau closed 6 years ago
Hi Not sure tree pattern matching was ever ported to Python If you need it may I suggest that you look into implementing it and submit a PR if you get it working?
Envoyé de mon iPhone
Le 1 mars 2018 à 22:23, jpicau notifications@github.com a écrit :
Dear ANTLR team,
I used
conda
to install theantlr-python-runtime 4.7.1
package. I compiled the Lua grammar as such:antlr4 -o lua -Dlanguage=Python3 -visitor Lua.g4
I'm parsing the
factorial.lua
example and would like to use the tree pattern matching capabilities. The first steps were as the described in many simple examples:from antlr4 import * from lua import * def main(): input = FileStream("factorial.lua") # antlr4 lexer = LuaLexer(input) stream = CommonTokenStream(lexer) # antlr4 parser = LuaParser(stream) tree = parser.chunk()
However, the next line:
p = parser.compileParseTreePattern("<ID>", LuaParser.RULE_exp)
gives me the following error:
AttributeError: 'ParseTreePatternMatcher' object has no attribute 'compile'
I looked into the
ParseTreePatternMatcher
class, but found onlycompileTreePattern
.Am I missing something?
Thanks, Jaroslaw
-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/antlr/antlr4/issues/2237 ----==_mimepart_5a9STLS 80cd8c1857_1cf72ae23ed12ec81065ec Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
Dear ANTLR team,
I used
conda
to install theantlr-python-runtime 4.7.1
package.
I compiled the Lua grammar as such:
antlr4 -o lua -Dlanguage=Python3 -visitor Lua.g4
I'm parsing the
factorial.lua
example and would like to use the tree pattern matching capabilities.
The first steps were as the described in many simple examples:from antlr4 import * from lua import * def main(): input = FileStream("factorial.lua") # antlr4 lexer = LuaLexer(input) stream = CommonTokenStream(lexer) # antlr4 parser = LuaParser(stream) tree = parser.chunk()
However, the next line:
p = parser.compileParseTreePattern("<ID>", LuaParser.RULE_exp)
gives me the following error:
AttributeError: 'ParseTreePatternMatcher' object has no attribute 'compile'
I looked into the
ParseTreePatternMatcher
class, but found onlycompileTreePattern
.Am I missing something?
Thanks,
Jaroslaw—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
:D Thanks. I'd love to. However, I'm still too new to ANTLR. I keep working/digging and come back later ... Thanks, again.
I also have the problem and find that the Method compile was not Implemented in the Class ParseTreePatternMatcher. And so far have you solved the problem?
Hi,
my intention was to find all function definitons. I used Trees.findAllRuleNodes(...)
instead. I don't know if this helps:
from antlr4 import *
from antlr4.tree.Trees import Trees
from lua import *
def main():
input = FileStream("factorial.lua") # antlr4
lexer = LuaLexer(input)
stream = CommonTokenStream(lexer) # antlr4
parser = LuaParser(stream)
tree = parser.chunk()
# find all function definitions
names = Trees.findAllRuleNodes(tree, LuaParser.RULE_funcname)
for name in names:
funcname = name.getPayload()
...
Bye, Jaroslaw
@jpicau Thanks a lot, your code has given me some good ideas.
Cool! You're welcome.
@jpicau Why was this closed ? It doesn't seem like the original issue of compileParseTreePattern
was ever resolved.
Dear ANTLR team,
I used
conda
to install theantlr-python-runtime 4.7.1
package. I compiled the Lua grammar as such:antlr4 -o lua -Dlanguage=Python3 -visitor Lua.g4
I'm parsing the
factorial.lua
example and would like to use the tree pattern matching capabilities. The first steps were as the described in many simple examples:However, the next line:
gives me the following error:
I looked into the
ParseTreePatternMatcher
class, but found onlycompileTreePattern
.Am I missing something?
Thanks, Jaroslaw