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.
Parser.desccauses 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.