Closed ForceBru closed 5 years ago
Can't edit the original post since I'm using a really old browser, but I wanted to add that subclassing from parser_module.Interpreter
solves this issue, so now I'm unsure if it's a bug or Visitor
isn't meant to be used like this, although the docs say it is...
A temporary fix would be to move the weird ###}
comment in tree.py
, line 59 to somewhere further down (outside a function, also at the start of the line, maybe at line 124. (Directly before the # XXX Deprecated
comment).
This tells the standalone program to include the iter_subtrees
function.
A temporary fix would be to move the weird ###}
It's not weird, it's ingenious! Learn to use the correct adjectives ;)
But yes, iter_subtrees isn't included, and moving the comment MegIng pointed out would solve it.
But this isn't a bug, it was a conscious decision (agree with it or not). After all, there's no point in making every standalone bigger, for features that are used very rarely.
@erezsh Yes, but then why is the Visitor class included?
That's a good point! Also, it's not a very long method
Decided to include iter_subtrees
, along with find_data
and find_predicate
.
Or, "Standalone
Tree
doesn't implement enough methods".I'm trying to convert a LALR parser to standalone and then visit the tree using the
Tree
included in the standalone version. I'm using the latest Lark from master: https://github.com/lark-parser/lark/commit/b6b95c3ff01896a45b7835a7375203969a8040e3I know the "standalonizer" script is supposed to be run from the command line. However, I don't really have access to a terminal since I'm running all this in Pythonista for iOS (yes, there's StaSh, but that's not really the point), so don't be surprised with the below code :D
The grammar is simple:
Output and traceback:
Indeed, the standalone
Tree
class doesn't have this method. Moreover, it doesn't seem to have many of the methods oflark.Tree
:Unfortunately, this doesn't allow me to visit a tree using the standalone version of the parser.