You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parser.desc causes loss of error information on failure of the original parser. So when a component parser (say in a generate) with a desc fails, the super-parser will not show the correct position or expected message in the result. I can give an example if you like, but it's easier just to look at the code because the problem is fixed with a small change: aggregate the original parser's failed result into the return value.
In Parser.desc, the original wrapped function looks like
@Parser
def desc_parser(stream, index):
result = self(stream, index)
if result.status:
return result
else:
return Result.failure(index, description)
In the case of failure, the error information in result is lost because it is not used, giving the unexpected behavior. Instead, just change the last line as follows:
@Parser
def desc_parser(stream, index):
result = self(stream, index)
if result.status:
return result
else:
return Result.failure(index, description).aggregate(result)
and the error information is correct.
Thanks. I'm enjoying using parsy.
The text was updated successfully, but these errors were encountered:
I think the original intent (the description supplanting the automatically generated one) has a use case, when applying .desc() at the "leaf" level. For example, in regex(r'horrible regex').desc('a thing'), we do not want the horrible regex in the expected output. But when applying desc() on a combined parser, we don't want to lose the index. The latter is a real problem because the error message becomes insensitive to component failures; I think that strongly motivates the fix above.
Still, these two cases are in conflict. Perhaps there needs to be two ideas here: the label for the thing and where the expected label comes from?
Hi @genovese I think your analysis is correct. I haven't looked into it yet - how easy is it to get both accurate location information and the desired specified description in the error message?
Some test cases would be helpful to see exactly the issue. Thanks!
Parser.desc
causes loss of error information on failure of the original parser. So when a component parser (say in a generate) with a desc fails, the super-parser will not show the correct position or expected message in the result. I can give an example if you like, but it's easier just to look at the code because the problem is fixed with a small change: aggregate the original parser's failed result into the return value.In
Parser.desc
, the original wrapped function looks likeIn the case of failure, the error information in result is lost because it is not used, giving the unexpected behavior. Instead, just change the last line as follows:
and the error information is correct.
Thanks. I'm enjoying using
parsy
.The text was updated successfully, but these errors were encountered: