purescript-contrib/purescript-parsing

option description

Closed this issue · 1 comments

Is this description correct?

-- | Provide a default result in the case where a parser fails without consuming input.
option :: forall m s a. Monad m => a -> ParserT s m a -> ParserT s m a
option a p = p <|> pure a

The way I read the Alt instance,

instance altParserT :: Monad m => Alt (ParserT s m) where
alt p1 p2 = (ParserT <<< ExceptT <<< StateT) \(s@(ParseState i p _)) -> do
Tuple e s'@(ParseState _ _ c') <- runStateT (runExceptT (unwrap p1)) (ParseState i p false)
case e of
Left _
| not c' -> runStateT (runExceptT (unwrap p2)) s
_ -> pure (Tuple e s')

I think this description should be

-- | Provide a default result in the case where a parser fails or consumes no input.

I don't see anything in the test suite which clarifies this. Need to test.

This description is correct.