Module ParseMonad

A Monad for Parsers

Author: Jasper Sikorra - jsi@informatik.uni-kiel.de

Version: January 2014

Summary of exported operations:

warnPM :: PR a -> [(Pos,String)] -> WM (PR a)   
Encapsulate an Error Monad with a Warning Monad creating a PM Monad
bindPM :: WM (PR a) -> (a -> WM (PR b)) -> WM (PR b)   
Bind
liftPM :: (a -> b) -> WM (PR a) -> WM (PR b)   
Lift
cleanPM :: a -> WM (PR a)   
Return without Warnings or Errors
warnOKPM :: a -> [(Pos,String)] -> WM (PR a)   
Return without Errors but with Warnings
throwPM :: Pos -> String -> WM (PR a)   
Return without Warnings but with Errors
throwMultiPM :: Pos -> [String] -> WM (PR a)   
singlePM :: a -> (Pos,String) -> WM (PR a)   
Return without Errors but with one Warning
discardWarningsPM :: WM (PR a) -> PR a   
Remove the Warning Monad from PM
getWarningsPM :: WM (PR a) -> [(Pos,String)]   
Extract the Warnings
mapWarnsPM :: ((Pos,String) -> (Pos,String)) -> WM (PR a) -> WM (PR a)   
Apply a function on each Warning
crumplePM :: WM (PR (WM (PR a))) -> WM (PR a)   
Crumple two Parser Monads
swapIOPM :: WM (PR (IO a)) -> IO (WM (PR a))   
Swap the PM and the IO Monad
sequencePM :: [WM (PR a)] -> WM (PR [a])   
Join multiple Parser Monads into one
fstPM :: WM (PR (a,b)) -> WM (PR a)   
fst defined on PM
sndPM :: WM (PR (a,b)) -> WM (PR b)   
snd defined on PM
combinePMs :: (a -> b -> c) -> WM (PR a) -> WM (PR b) -> WM (PR c)   
combines two PMs by function f, throws error if at least one of the two carries an error

Exported datatypes:


PM

Combining ParseResult and Warnings monads into a new monad

Type synonym: PM a = WM (PR a)


Exported operations:

warnPM :: PR a -> [(Pos,String)] -> WM (PR a)   

Encapsulate an Error Monad with a Warning Monad creating a PM Monad

Further infos:
  • solution complete, i.e., able to compute all solutions

bindPM :: WM (PR a) -> (a -> WM (PR b)) -> WM (PR b)   

Bind

liftPM :: (a -> b) -> WM (PR a) -> WM (PR b)   

Lift

cleanPM :: a -> WM (PR a)   

Return without Warnings or Errors

warnOKPM :: a -> [(Pos,String)] -> WM (PR a)   

Return without Errors but with Warnings

Further infos:
  • solution complete, i.e., able to compute all solutions

throwPM :: Pos -> String -> WM (PR a)   

Return without Warnings but with Errors

Further infos:
  • solution complete, i.e., able to compute all solutions

throwMultiPM :: Pos -> [String] -> WM (PR a)   

singlePM :: a -> (Pos,String) -> WM (PR a)   

Return without Errors but with one Warning

discardWarningsPM :: WM (PR a) -> PR a   

Remove the Warning Monad from PM

Further infos:
  • solution complete, i.e., able to compute all solutions

getWarningsPM :: WM (PR a) -> [(Pos,String)]   

Extract the Warnings

Further infos:
  • solution complete, i.e., able to compute all solutions

mapWarnsPM :: ((Pos,String) -> (Pos,String)) -> WM (PR a) -> WM (PR a)   

Apply a function on each Warning

crumplePM :: WM (PR (WM (PR a))) -> WM (PR a)   

Crumple two Parser Monads

swapIOPM :: WM (PR (IO a)) -> IO (WM (PR a))   

Swap the PM and the IO Monad

sequencePM :: [WM (PR a)] -> WM (PR [a])   

Join multiple Parser Monads into one

fstPM :: WM (PR (a,b)) -> WM (PR a)   

fst defined on PM

sndPM :: WM (PR (a,b)) -> WM (PR b)   

snd defined on PM

combinePMs :: (a -> b -> c) -> WM (PR a) -> WM (PR b) -> WM (PR c)   

combines two PMs by function f, throws error if at least one of the two carries an error