kdl-hs-1.1.1: KDL language parser and API
Safe HaskellNone
LanguageGHC2021

KDL.Decoder.Internal.DecodeM

Synopsis

Decoding errors

DecodeM monad

data DecodeM a Source #

The monad that returns either a DecodeError or a result of type a.

The odd structure here is because of our backtracking semantics. We want to collect all errors that may appear (even if a value is successfully parsed) so that if we get a failure later on, we can return the deepest error, even if it was in a successful branch.

Take this motivating example: a node takes an arbitrary number of string args. If you pass some strings then a number, it'll successfully parse up to the number and return success, only for the node to fail later with "unexpected argument: 123". But the true error was "unexpected number, expected string".

Instances

Instances details
Alternative DecodeM Source # 
Instance details

Defined in KDL.Decoder.Internal.DecodeM

Methods

empty :: DecodeM a #

(<|>) :: DecodeM a -> DecodeM a -> DecodeM a #

some :: DecodeM a -> DecodeM [a] #

many :: DecodeM a -> DecodeM [a] #

Applicative DecodeM Source # 
Instance details

Defined in KDL.Decoder.Internal.DecodeM

Methods

pure :: a -> DecodeM a #

(<*>) :: DecodeM (a -> b) -> DecodeM a -> DecodeM b #

liftA2 :: (a -> b -> c) -> DecodeM a -> DecodeM b -> DecodeM c #

(*>) :: DecodeM a -> DecodeM b -> DecodeM b #

(<*) :: DecodeM a -> DecodeM b -> DecodeM a #

Functor DecodeM Source # 
Instance details

Defined in KDL.Decoder.Internal.DecodeM

Methods

fmap :: (a -> b) -> DecodeM a -> DecodeM b #

(<$) :: a -> DecodeM b -> DecodeM a #

Monad DecodeM Source # 
Instance details

Defined in KDL.Decoder.Internal.DecodeM

Methods

(>>=) :: DecodeM a -> (a -> DecodeM b) -> DecodeM b #

(>>) :: DecodeM a -> DecodeM b -> DecodeM b #

return :: a -> DecodeM a #

runDecodeM :: DecodeM a -> Either DecodeError a Source #

Run a DecodeM action and return the result or the deepest error found.

decodeThrow :: DecodeErrorKind -> DecodeM a Source #

Throw an error.

addContext :: ContextItem -> DecodeM a -> DecodeM a Source #

Add context to all errors that occur in the given action.