Closed
Description
Describe the bug
Parsing is designed to distinguish between fail with and without data consumed. In particular, the combinators from Parsing.Combinators
as well as ones from Data.Array
propagate fail if it happens after data was consumed.
Unfortunately, this isn't the case for at least many*
combinators from Parsing.Combinators.Array
To Reproduce
Execute the following code:
module Main where
import Prelude
import Effect (Effect)
import Effect.Class.Console (logShow)
import Parsing (Parser, fail, runParser)
import Parsing.Combinators ((<|>))
import Parsing.Combinators as CombList
import Parsing.Combinators.Array as CombArray
import Parsing.String (anyChar, char)
failAfterConsuming :: ∀ a. Parser String a
failAfterConsuming = anyChar *> fail "failure"
main :: Effect Unit
main = do
logShow $ runParser "abc" $ CombArray.many (char 'a' <|> failAfterConsuming)
logShow $ runParser "abc" $ CombArray.many1 (char 'a' <|> failAfterConsuming)
logShow $ runParser "abc" $ CombList.many (char 'a' <|> failAfterConsuming)
logShow $ runParser "abc" $ CombList.many1 (char 'a' <|> failAfterConsuming)
Expected behavior
All 4 parses would return Left
Actual behavior
The Array
-based parses return successfully:
(Right ['a'])
(Right (NonEmptyArray ['a']))
(Left (ParseError "failure" (Position { column: 3, index: 2, line: 1 })))
(Left (ParseError "failure" (Position { column: 3, index: 2, line: 1 })))
Workarounds
many
from Data.Array
works as expected. However, there isn't analogous function for many1
.
Metadata
Metadata
Assignees
Labels
No labels