I have an attoparsec
parser, and tests for it, what annoys me is that if I comment part of the parser and run the tests, the parser doesn't return Left "parse error at line ..."
but instead I get Right []
.
Note that I'm using parseOnly
to make it clear that there'll be no more input.
Otherwise it's nice to get the partially parsed input, it can definitely be useful and I'm glad to have it. However I'd like to be informed that the whole input was not consumed. Maybe to get a character offset of the last consumed letter, or if that's what it takes, at least an option to be returned Left
.
If it's relevant, the parser can be found there.
If I comment for instance the line:
<|> PlainText <$> choice (string <$> ["[", "]", "*", "`"])
And run the tests, I get for instance:
1) notes parsing tests parses notes properly
simple test
expected: Right [NormalLine [PlainText "one line* # hello world"]]
but got: Right []
This is from that test.
Depending on if consuming the whole input should be the property of
parseNoteDocument
or just the tests, I'd extend one or the other withendOfInput
oratEnd
.I'd suggest to define a proper
Parser
for your documents, likeand then define
parseNoteDocument
in terms of it. Then you can useparseNoteDocument'
in the tests by defining a helper that parses a given piece of text usingto ensure that the whole input is consumed.