1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
module ParseMonad where
import ParseError
import ParseWarning
import ParsePos
type PM a = WM (PR a)
warnPM :: PR a -> [Warning] -> PM a
warnPM x w = returnWM x w
bindPM :: PM a -> (a -> PM b) -> PM b
bindPM m f = bindWM m $ \b -> case b of
Errors p -> cleanWM (Errors p)
OK x -> f x
liftPM :: (a -> b) -> PM a -> PM b
liftPM f m = bindPM m (cleanPM . f)
cleanPM :: a -> PM a
cleanPM x = warnOKPM x []
warnOKPM :: a -> [Warning] -> PM a
warnOKPM x = warnPM (okPR x)
throwPM :: Pos -> String -> PM _
throwPM p s = cleanWM (throwPMsg p s)
throwMultiPM :: Pos -> [String] -> PM _
throwMultiPM p strs = cleanWM (throwPR (map (\s -> (PError p s)) strs))
singlePM :: a -> Warning -> PM a
singlePM x w = warnOKPM x [w]
discardWarningsPM :: PM a -> PR a
discardWarningsPM = discardWarnings
getWarningsPM :: PM a -> [Warning]
getWarningsPM = getWarnings
mapWarnsPM :: (Warning -> Warning) -> PM a -> PM a
mapWarnsPM = mapWarns
crumplePM :: PM (PM a) -> PM a
crumplePM m = bindPM m id
swapIOPM :: PM (IO a) -> IO (PM a)
swapIOPM m = swapIOPR (discardWarningsPM m)
>>= return . flip warnPM (getWarningsPM m)
sequencePM :: [PM a] -> PM [a]
sequencePM ms = warnPM (sequencePR (map discardWarnings ms))
(foldr (++) [] (map getWarnings ms))
fstPM :: PM (a,b) -> PM a
fstPM = liftPM fst
sndPM :: PM (a,b) -> PM b
sndPM = liftPM snd
combinePMs :: (a -> b -> c) -> PM a -> PM b -> PM c
combinePMs f p1 p2 = warnPM (combinePRs f (discardWarningsPM p1)
(discardWarningsPM p2))
(concatWarns p1 p2)
where
concatWarns (WM _ w1) (WM _ w2) = w1 ++ w2
|