purescript-contrib/purescript-parsing

`optionMaybe` doesn't propagate fail when used `whiteSpace`

Closed this issue · 0 comments

Describe the bug

Split from #235 (comment).

As discussed there, whiteSpace is declared as takeWhile isSpace and it doesn't check for consumed flag, which results in the failure.

To Reproduce

module Main where

import Prelude

import Effect (Effect)
import Effect.Console (logShow)
import Parsing (Parser, fail, runParser)
import Parsing.Combinators ((<|>))
import Parsing.String (string)
import Parsing.String.Basic (whiteSpace)

type TextParser = Parser String

parseTypes :: TextParser String
parseTypes = do
  _ <- string "foo" <* whiteSpace
  fail "test failure"

parseImpl :: TextParser String
parseImpl = parseTypes <|> pure ""

main :: Effect Unit
main = logShow $ runParser "foo" parseImpl

Expected behavior

Running this code should return Left with "test failure" (because it consumed the input before failing) instead of Right.