on 0.7 help sign in
text/scripts/Arsec.hs
49 lines 1.3 kB history raw
1module Arsec
2 (
3 comment
4 , semi
5 , showC
6 , unichar
7 , unichars
8 , module Control.Applicative
9 , module Control.Monad
10 , module Data.Char
11 , module Text.ParserCombinators.Parsec.Char
12 , module Text.ParserCombinators.Parsec.Combinator
13 , module Text.ParserCombinators.Parsec.Error
14 , module Text.ParserCombinators.Parsec.Prim
15 ) where
17import Control.Monad
18import Control.Applicative
19import Data.Char
20import Numeric
21import Text.ParserCombinators.Parsec.Char hiding (lower, upper)
22import Text.ParserCombinators.Parsec.Combinator hiding (optional)
23import Text.ParserCombinators.Parsec.Error
24import Text.ParserCombinators.Parsec.Prim hiding ((<|>), many)
26instance Applicative (GenParser s a) where
27 pure = return
28 (<*>) = ap
30instance Alternative (GenParser s a) where
31 empty = mzero
32 (<|>) = mplus
34unichar :: Parser Char
35unichar = chr . fst . head . readHex <$> many1 hexDigit
37unichars :: Parser [Char]
38unichars = manyTill (unichar <* spaces) semi
40semi :: Parser ()
41semi = char ';' *> spaces *> pure ()
43comment :: Parser String
44comment = (char '#' *> manyTill anyToken (char '\n')) <|> string "\n"
46showC :: Char -> String
47showC c = "'\\x" ++ d ++ "'"
48 where h = showHex (ord c) ""
49 d = replicate (4 - length h) '0' ++ h