git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update tests
commit5264394477222e409a0fb68bc63c38cf58938e40 authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 19 Aug 2018, 17:48 (8 years ago) parent4eacd14
1 file changed+33−12
app/Main.hs+33−12
app/Main.hs+33−12
@@ -9,7 +9,7 @@ import Data.Aeson
99import Data.Aeson.Types
1010import Data.Char
1111import Data.FileEmbed (embedFile)
12−import Data.List (delete)
12+import Data.List (delete, isPrefixOf, partition)
1313import Data.Maybe
1414import Data.Monoid ((<>))
1515import Data.Version
@@ -55,14 +55,16 @@ main = do
5555 if null args
5656 then return ()
5757 else do
58− if head args == "tests"
58+ let (opts, files) = partition (isPrefixOf "--") args
59+ opts' = (map . map) toLower opts
60+ if "--tests" `elem` opts'
5961 then runTests
6062 else do
61− mapM (generateCode False) args
63+ mapM (generateCode opts') files
6264 return ()
6365
64−generateCode :: Bool -> FilePath -> IO ()
65−generateCode someOpt jsonFile = do
66+generateCode :: [String] -> FilePath -> IO ()
67+generateCode opts jsonFile = do
6668 jsonModTime <- getModificationTime jsonFile
6769 let filepath = takeDirectory jsonFile
6870 dirparts = splitDirectories $ filepath
@@ -74,11 +76,11 @@ generateCode someOpt jsonFile = do
7476 then do
7577 modTime <- getModificationTime possInterfaceFilename
7678 when (modTime < jsonModTime) $
77− transpile someOpt jsonFile
78− else transpile someOpt jsonFile
79+ transpile opts jsonFile
80+ else transpile opts jsonFile
7981
80−transpile :: Bool -> FilePath -> IO ()
81−transpile _ jsonFile = do
82+transpile :: [String] -> FilePath -> IO ()
83+transpile opts jsonFile = do
8284 jsonText <- T.readFile jsonFile
8385 let module' = jsonToModule $ parseJson jsonText
8486 ((interface, foreigns, asts, implHeader, implFooter), _) <- runSupplyT 5 (moduleToCpp module' Nothing)
@@ -91,13 +93,18 @@ transpile _ jsonFile = do
9193 implPath = outpath </> implFileName mn
9294 putStrLn interfacePath
9395 createDirectoryIfMissing True outpath
94− T.writeFile interfacePath interface
96+ T.writeFile interfacePath $ conv interface
9597 putStrLn implPath
96− T.writeFile implPath (implHeader <> implementation <> implFooter)
98+ T.writeFile implPath $ conv (implHeader <> implementation <> implFooter)
9799 let runtime = baseOutpath </> "purescript.h"
98100 runtimeExists <- doesFileExist runtime
99101 when (not runtimeExists) $ do
100− T.writeFile runtime $ T.decodeUtf8 $(embedFile "runtime/purescript.h")
102+ T.writeFile runtime . conv $ T.decodeUtf8 $(embedFile "runtime/purescript.h")
103+ where
104+ conv :: Text -> Text
105+ conv
106+ | "--ucns" `elem` opts = toUCNs . toDollars
107+ | otherwise = id
101108
102109outdir :: FilePath
103110outdir = "src"
@@ -114,3 +121,17 @@ escape = T.concatMap go
114121 go :: Char -> Text
115122 go c = T.pack $ printf "0x%04x," (ord c)
116123
124+
125+toUCNs :: Text -> Text
126+toUCNs = T.pack . concatMap toUCN . T.unpack
127+
128+toUCN :: Char -> String
129+toUCN c | isAscii c = [c]
130+toUCN c = printf "\\U%08x" $ ord c
131+
132+toDollars :: Text -> Text
133+toDollars = T.map toDollar
134+
135+toDollar :: Char -> Char
136+toDollar '_' = '$'
137+toDollar c = c