I have a parser parser:
a = optionMaybe $ do {try $ spaceornull *> string "hello";string "No"}
Where spaceornullis((:[]) <$> try space) <|> string ""
When I test a with the input "", I get:
Left (row 1, column 2):
unexpected end of input
waiting for "hello"
I don’t understand this, I spaceornull *> string "hello"have to fail because there is no “hello”, then with trybacktracks parse, and now there is no input consumed, but it tryfails anyway, therefore the parser switched to optionMaybe(inside inside do) does not work completely, it should not try to consume a newer input, so we get an unsuccessful parser without consuming any input, so I have to get it Right Nothing.
But the error message says this, space is consumed, so tryit doesn’t actually recede, does tryn’t return when part of the parser is completed successfully? and how to make it return using the above?
source
share