New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"No visitor method was defined" message unhelpful for unnamed expressions #110
Comments
You should use https://gist.github.com for pasting code - it makes it easier to view, comment, and fix. Here's your code as a gist: hello.py I find it useful to run my code under the Python debugger, so that I can investigate what is going on:
That An implicit, unnamed node is being created by the zero-or-more rule around spacing:
One way to work around this is to name the implicit node:
And now declare a Another way is to define a |
This is definitely something I've found really confusing as well. |
Humm https://gist.github.com, good to know about it! Thank you for the debug information, I did not know about it. Right on the spot! I have fixed using your explanation, thank you very much!! |
…r message. This was confusing people, as in #110. I also did an audit of the rest of the %s occurrences in the codebase, and no other obviously beneficial quotes are missing.
There, that should help for the moment. When somebody (or I) have a few more minutes, we could make the message more helpful in the case of an unnamed rule by having it suggest you define a generic_visitor or name the subexpression (which we can also call out into the error message by using its repr). |
@erikrose - I think there's a bug lurking here. Take the following example:
This blows up as follows:
How can I give a name to the subexpression here? |
It looks like the nameless top-level expression in the traceback is |
In fact, that's what #59 is about: a great first patch for somebody! |
Okay, but still, how can I give a name to that ZeroOrMore here, so that I can define a visitor method for it? |
Oh! I didn't understand your question. All you should have to do is…
And then say…
|
Have you tried your suggestion? My experience is that |
I just tried it, and generic_visit does not appear to be called for me in the presence of a from parsimonious import Grammar, NodeVisitor
class Query(NodeVisitor):
grammar = Grammar("""
expression = field clauses
clauses = clause*
clause = op field
field = ~"[a-z_]+"
op = "+"
""")
def visit_op(self, node, children):
return ' plus '
def visit_field(self, node, children):
return node.match.group(0)
def visit_clause(self, node, children):
return ' '.join(children)
def visit_expression(self, node, children):
return ' '.join(children)
def visit_clauses(self, node, children):
return "ha"
print Query().parse("x+y")
|
Hmm, well, without being able to reproduce myself, I'll retract my assertion that there's a bug lurking there until such time as I can reproduce it again ;-) |
I'm getting the same empty node name error with this peg. grammar = Grammar(r"""
sexp = lp ( atom / sexp )* rp
atom = num
num = ~"[0-9]+" delim
delim = &lp / &rp / ws
lp = "("
rp = ")"
ws = ~"[\r\a\t\n ]+"
""")
tree = grammar.parse('(1 2 3 (4 5))')
print LispFormatter().visit(tree)
|
issue #59 is long closed, and I think that means all the desired remediation for this is done. Please file a new issue or reopen this one if I'm mistaken |
I have downloaded the framework parsimonious yesterday (version 0.7.0) and created the following code.
hello.py.txt
The problem is that when I run the code I get the error msg:
"parsimonious.exceptions.VisitationError: NotImplementedError: No visitor method was defined for ."
Is it a bug? There is no rule called "."!
The full error: error.txt
The text was updated successfully, but these errors were encountered: