1+ import Data.List (stripPrefix )
2+ import Data.Maybe (fromJust )
13import System.Environment
24import System.IO
35
@@ -21,6 +23,7 @@ main = do
2123 h <- openFile oname WriteMode
2224 let comments = map (" --" ++ ) $
2325 take 2 (cfComments cfs) ++ take 2 (scComments scs)
26+ version = parseVersion (cfComments cfs)
2427 mapM_ (hPutStrLn h) $
2528 [" -- AUTOMATICALLY GENERATED - DO NOT EDIT"
2629 ," -- Generated by scripts/CaseMapping.hs" ] ++
@@ -31,6 +34,9 @@ main = do
3134 ," module Data.Text.Internal.Fusion.CaseMapping where"
3235 ," import GHC.Int"
3336 ," import GHC.Exts"
37+ ," import Data.Version (Version, makeVersion)"
38+ ," unicodeVersion :: Version"
39+ ," unicodeVersion = makeVersion " ++ version
3440 ," unI64 :: Int64 -> _ {- unboxed Int64 -}"
3541 ," unI64 (I64# n) = n"
3642 ," " ]
@@ -39,3 +45,14 @@ main = do
3945 mapM_ (hPutStrLn h) (mapSC " title" title toTitle scs)
4046 mapM_ (hPutStrLn h) (mapCF cfs)
4147 hClose h
48+
49+ -- Parse version from CaseFolding comments
50+ -- and render it as a list (an argument of makeVersion)
51+ parseVersion :: [String ] -> String
52+ parseVersion comments = fromJust $ do
53+ line' : _ <- pure comments
54+ line'' <- stripPrefix " CaseFolding-" line'
55+ let (v1, line1) = span isDigit line''
56+ (v2, line2) = span isDigit (drop 1 line1)
57+ (v3, _) = span isDigit (drop 1 line2)
58+ pure $ " [" ++ v1 ++ " , " ++ v2 ++ " , " ++ v3 ++ " ]"
0 commit comments