-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels