forked from bortzmeyer/GaBuZoMeu
33 lines
976 B
Haskell
33 lines
976 B
Haskell
module Parsers where
|
|
|
|
import Text.ParserCombinators.Parsec
|
|
import Data.Maybe (catMaybes)
|
|
import Data.Char (toUpper)
|
|
import Control.Monad (liftM)
|
|
|
|
-- Parsing functions not in Text.ParserCombinators.Parsec
|
|
|
|
-- There is also a good ine in hsemail, manyNtoM
|
|
countBetween m n p
|
|
| n < m = error "First bound must be lower or equal than second bound"
|
|
| otherwise = do
|
|
xs <- try (count m p)
|
|
ys <- try (count (n - m) ((option Nothing) (do
|
|
y <- p
|
|
return (Just y))))
|
|
return (xs ++ catMaybes ys)
|
|
|
|
facultative p = liftM Just p <|> return Nothing
|
|
|
|
-- Case-insensitive parsers stloen from hsemail
|
|
-- Case-insensitive variant of Parsec's 'char' function.
|
|
ichar :: Char -> CharParser st Char
|
|
ichar c = satisfy (\x -> toUpper x == toUpper c)
|
|
-- Case-insensitive variant of Parsec's 'string' function.
|
|
istring :: String -> CharParser st String
|
|
istring cs = mapM ichar cs <?> cs
|
|
|
|
--
|
|
-- End of parsing functions
|
|
|