-
Notifications
You must be signed in to change notification settings - Fork 34
Closed
Description
Hi, this is more a question than an issue. I can not find out how to get a nice failure message in case of an parse failure in an optional parser. Instead I get the message that the following non optional parser fails.
Example:
A string to parse:
line1 value
line2 !
line3 value
My parser definition:
def("start",
ref("line1")
.seq(ref("line2").optional)
.seq(ref("line3"))
.end()
def("line1", StringParser.of("line1 ")
.seq(CharacterParser.word().plusLazy(Token.NEWLINE_PARSER)
.seq(Token.NEWLINE_PARSER));
def("line2", StringParser.of("line2 ")
.seq(CharacterParser.word().plusLazy(Token.NEWLINE_PARSER)
.seq(Token.NEWLINE_PARSER));
def("line3", StringParser.of("line3 ")
.seq(CharacterParser.word().plusLazy(Token.NEWLINE_PARSER)
.seq(Token.NEWLINE_PARSER));
If I parse the string I get line3 expected at the beginning of line 2 from getMessages(). This is in principle correct, but it would be more usefull if I would get something like letter or digit expected at the end of the line 2.
Can someone give me an advice how to get better Messages in case of failure of an optional parser?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels