Skip to content

optionMaybe doesn't propagate fail when used whiteSpace #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Hi-Angel opened this issue Mar 1, 2025 · 0 comments · Fixed by #237
Closed

optionMaybe doesn't propagate fail when used whiteSpace #236

Hi-Angel opened this issue Mar 1, 2025 · 0 comments · Fixed by #237

Comments

@Hi-Angel
Copy link
Contributor

Hi-Angel commented Mar 1, 2025

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.

Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Hi-Angel added a commit to Hi-Angel/purescript-parsing that referenced this issue Mar 1, 2025
The Parsing design implies that if input was consumed, it must
propagate further unless `try` is used to reset that.

Fixes: purescript-contrib#236
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant