Skip to content

optionMaybe doesn't propagate fail when used whiteSpace #236

@Hi-Angel

Description

@Hi-Angel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions