git.iko.soy/typeable/pandoc
on commonmark-github help sign in
typeable/pandoc/lib/fonts/parseUnicodeMapping.hs
40 lines 1.1 kB history raw
1import System.FilePath
2import Text.Parsec
3import Data.Char
4import System.Environment
5import Control.Applicative hiding (many)
6import Data.List
8main :: IO ()
9main = (head <$> getArgs) >>= parseUnicodeMapping
12parseUnicodeMapping :: FilePath -> IO ()
13parseUnicodeMapping fname = do
14 fin <- readFile fname
15 let mapname = dropExtension . takeFileName $ fname
16 let res = runParse fin
17 let header = "-- Generated from " ++ fname ++ "\n" ++
18 mapname ++ " :: [(Char, Char)]\n" ++ mapname ++" =\n [ "
19 let footer = "]"
20 writeFile (replaceExtension fname ".hs")
21 (header ++ (concat $ intersperse "\n , " (map show res)) ++ footer)
23type Unicode = Char
25runParse :: String -> [(Char, Unicode)]
26runParse s= either (error . show) id (parse parseMap "" s)
28anyline = manyTill anyChar newline
30getHexChar :: Parsec String () Char
31getHexChar = do
32 [(c,_)] <- readLitChar . ("\\x" ++) <$> many1 hexDigit
33 return c
35parseMap :: Parsec String () [(Char, Unicode)]
36parseMap = do
37 skipMany (char '#' >> anyline)
38 many (flip (,) <$> getHexChar <* tab <*> getHexChar <* anyline)