Changeset 12
- Timestamp:
- 07/12/08 01:31:33 (2 years ago)
- Files:
-
- fort/Parser.hs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fort/Parser.hs
r11 r12 3 3 -- but went into slightly more than that. 4 4 -- I don't mind it, I'll deal with it later. 5 -- BTW, it is quite buggy and unfriendly. Again, I'll sort it later.5 -- BTW, it is quite buggy and unfriendly. Again, I'll sort that later. 6 6 7 7 module Parser where … … 23 23 24 24 ------------------------------------------------------------------------------- 25 -- A parser monad.25 -- Position type. 26 26 27 27 data Pos = Pos { … … 36 36 type PosString = [PosChar] 37 37 38 data SP i o =39 N40 | O o (SP i o)41 | I (i -> SP i o)42 43 spPar N b = b44 spPar (O o a) b = O o $ spPar a b45 spPar a N = a46 spPar a (O o b) = O o $ spPar a b47 spPar (I f) (I g) = I $ \x -> spPar (f x) (g x)48 49 instance Monad (SP i) where50 return x = O x N51 52 N >>= _ = N53 (O o a) >>= q = (a >>= q) `spPar` q o54 (I f) >>= q = I $ \x -> f x >>= q55 56 38 ------------------------------------------------------------------------------- 57 -- Parser .39 -- Parser monad. 58 40 59 41 data P s a = P { unP :: ((s,String) -> [(a,(s,String))]) }
