on master help sign in
text/scripts/Arsec.hs
44 lines 1.2 kB history raw
1module Arsec
2 (
3 Comment
4 , comment
5 , semi
6 , showC
7 , unichar
8 , unichars
9 , module Control.Applicative
10 , module Control.Monad
11 , module Data.Char
12 , module Text.ParserCombinators.Parsec.Char
13 , module Text.ParserCombinators.Parsec.Combinator
14 , module Text.ParserCombinators.Parsec.Error
15 , module Text.ParserCombinators.Parsec.Prim
16 ) where
18import Control.Monad
19import Control.Applicative
20import Data.Char
21import Numeric
22import Text.ParserCombinators.Parsec.Char hiding (lower, upper)
23import Text.ParserCombinators.Parsec.Combinator hiding (optional)
24import Text.ParserCombinators.Parsec.Error
25import Text.ParserCombinators.Parsec.Prim hiding ((<|>), many)
27type Comment = String
29unichar :: Parser Char
30unichar = chr . fst . head . readHex <$> many1 hexDigit
32unichars :: Parser [Char]
33unichars = manyTill (unichar <* spaces) semi
35semi :: Parser ()
36semi = char ';' *> spaces *> pure ()
38comment :: Parser Comment
39comment = (char '#' *> manyTill anyToken (char '\n')) <|> string "\n"
41showC :: Char -> String
42showC c = "'\\x" ++ d ++ "'"
43 where h = showHex (ord c) ""
44 d = replicate (4 - length h) '0' ++ h