-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Currently, error messages always display the farthest that parsing got and the next token as the actual value that stopped parsing. This worked fine until the transformation parser, which can succeed in parsing input and then fail to accept that parsed value. The message the parsing failed on the token after the successful parse is not particularly correct. The error is the parsed token itself, which can be seen in this example:
from dataclasses import dataclass
from parsita import *
@dataclass
class Percent:
number: int
def to_percent(number: int):
if not 0 <= number <= 100:
return failure("a number between 0 and 100")
else:
return success(Percent(number))
class TestParsers(TextParsers):
percent = (reg(r"[0-9]+") > int) >= to_percent
TestParsers.percent.parse("150").or_die()This displays the error Expected a number between 0 and 100 but found end of source, when Expected a number between 0 and 100 but found 150 would be more sensible.
To fix this would require that the actual value and farthest point be configurable separately by the parser.
Metadata
Metadata
Assignees
Labels
No labels