git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1498 from senju/master
9d1e0a2Phil Freeman
CONTRIBUTORS.md+1
@@ -53,6 +53,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
53- [@utkarshkukreti](https://github.com/utkarshkukreti) (Utkarsh Kukreti) My existing contributions and all future contributions until further notice are Copyright Utkarsh Kukreti, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
53- [@utkarshkukreti](https://github.com/utkarshkukreti) (Utkarsh Kukreti) My existing contributions and all future contributions until further notice are Copyright Utkarsh Kukreti, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
54- [@vkorablin](https://github.com/vkorablin) (Vladimir Korablin) - My existing contributions and all future contributions until further notice are Copyright Vladimir Korablin, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
54- [@vkorablin](https://github.com/vkorablin) (Vladimir Korablin) - My existing contributions and all future contributions until further notice are Copyright Vladimir Korablin, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
55- [@zudov](https://github.com/zudov) (Konstantin Zudov) My existing contributions and all future contributions until further notice are Copyright Konstantin Zudov, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
55- [@zudov](https://github.com/zudov) (Konstantin Zudov) My existing contributions and all future contributions until further notice are Copyright Konstantin Zudov, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
56+- [@senju](https://github.com/senju) - My existing contributions and all future contributions until further notice are Copyright senju, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
56<http://opensource.org/licenses/MIT>.
57<http://opensource.org/licenses/MIT>.
57
58
58### Companies
59### Companies
examples/passing/UTF8Sourcefile.pursnew file+10
@@ -0,0 +1,10 @@
1+module Main where
2+
3+import Control.Monad.Eff.Console
4+
5+-- '→' is multibyte sequence \u2192.
6+utf8multibyte = "Hello λ→ world!!"
7+
8+main = do
9+ log "done"
10+
psc/Main.hs+4−2
@@ -32,6 +32,7 @@ import Options.Applicative as Opts
32
32
33import System.Exit (exitSuccess, exitFailure)
33import System.Exit (exitSuccess, exitFailure)
34import System.IO (hPutStrLn, stderr)
34import System.IO (hPutStrLn, stderr)
35+import System.IO.UTF8
35import System.FilePath.Glob (glob)
36import System.FilePath.Glob (glob)
36
37
37import qualified Language.PureScript as P
38import qualified Language.PureScript as P
@@ -60,7 +61,7 @@ compile (PSCMakeOptions inputGlob inputForeignGlob outputDir opts usePrefix) = d
60 let (jsFiles, pursFiles) = partition (isSuffixOf ".js") input
61 let (jsFiles, pursFiles) = partition (isSuffixOf ".js") input
61 moduleFiles <- readInput (InputOptions pursFiles)
62 moduleFiles <- readInput (InputOptions pursFiles)
62 inputForeign <- globWarningOnMisses warnFileTypeNotFound inputForeignGlob
63 inputForeign <- globWarningOnMisses warnFileTypeNotFound inputForeignGlob
63− foreignFiles <- forM (inputForeign ++ jsFiles) (\inFile -> (inFile,) <$> readFile inFile)
64+ foreignFiles <- forM (inputForeign ++ jsFiles) (\inFile -> (inFile,) <$> readUTF8File inFile)
64 case runWriterT (parseInputs moduleFiles foreignFiles) of
65 case runWriterT (parseInputs moduleFiles foreignFiles) of
65 Left errs -> do
66 Left errs -> do
66 hPutStrLn stderr (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
67 hPutStrLn stderr (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
@@ -93,7 +94,7 @@ globWarningOnMisses warn = concatMapM globWithWarning
93 concatMapM f = liftM concat . mapM f
94 concatMapM f = liftM concat . mapM f
94
95
95readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
96readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
96−readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readFile inFile
97+readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readUTF8File inFile
97
98
98parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
99parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
99 => [(Either P.RebuildPolicy FilePath, String)]
100 => [(Either P.RebuildPolicy FilePath, String)]
@@ -178,6 +179,7 @@ pscMakeOptions = PSCMakeOptions <$> many inputFile
178 <*> options
179 <*> options
179 <*> (not <$> noPrefix)
180 <*> (not <$> noPrefix)
180
181
182+
181main :: IO ()
183main :: IO ()
182main = execParser opts >>= compile
184main = execParser opts >>= compile
183 where
185 where
purescript.cabal+1
@@ -162,6 +162,7 @@ library
162 Control.Monad.Supply
162 Control.Monad.Supply
163 Control.Monad.Supply.Class
163 Control.Monad.Supply.Class
164
164
165+ System.IO.UTF8
165 exposed: True
166 exposed: True
166 buildable: True
167 buildable: True
167 hs-source-dirs: src
168 hs-source-dirs: src
src/System/IO/UTF8.hsnew file+9
@@ -0,0 +1,9 @@
1+module System.IO.UTF8
2+where
3+import System.IO (hGetContents, hSetEncoding, openFile, utf8, IOMode (..))
4+
5+readUTF8File :: FilePath -> IO String
6+readUTF8File inFile = do
7+ h <- openFile inFile ReadMode
8+ hSetEncoding h utf8
9+ hGetContents h
tests/Main.hs+4−3
@@ -66,6 +66,7 @@ import System.Exit
66import System.Process
66import System.Process
67import System.FilePath
67import System.FilePath
68import System.Directory
68import System.Directory
69+import System.IO.UTF8
69import qualified System.Info
70import qualified System.Info
70import qualified System.FilePath.Glob as Glob
71import qualified System.FilePath.Glob as Glob
71
72
@@ -97,7 +98,7 @@ makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input
97
98
98readInput :: [FilePath] -> IO [(FilePath, String)]
99readInput :: [FilePath] -> IO [(FilePath, String)]
99readInput inputFiles = forM inputFiles $ \inputFile -> do
100readInput inputFiles = forM inputFiles $ \inputFile -> do
100− text <- readFile inputFile
101+ text <- readUTF8File inputFile
101 return (inputFile, text)
102 return (inputFile, text)
102
103
103type TestM = WriterT [(FilePath, String)] IO
104type TestM = WriterT [(FilePath, String)] IO
@@ -157,7 +158,7 @@ assertDoesNotCompile inputFiles foreigns = do
157
158
158 where
159 where
159 getShouldFailWith =
160 getShouldFailWith =
160− readFile
161+ readUTF8File
161 >>> liftIO
162 >>> liftIO
162 >>> fmap ( lines
163 >>> fmap ( lines
163 >>> mapMaybe (stripPrefix "-- @shouldFailWith ")
164 >>> mapMaybe (stripPrefix "-- @shouldFailWith ")
@@ -184,7 +185,7 @@ main = do
184 supportPurs <- supportFiles "purs"
185 supportPurs <- supportFiles "purs"
185 supportJS <- supportFiles "js"
186 supportJS <- supportFiles "js"
186
187
187− foreignFiles <- forM supportJS (\f -> (f,) <$> readFile f)
188+ foreignFiles <- forM supportJS (\f -> (f,) <$> readUTF8File f)
188 Right (foreigns, _) <- runExceptT $ runWriterT $ P.parseForeignModulesFromFiles foreignFiles
189 Right (foreigns, _) <- runExceptT $ runWriterT $ P.parseForeignModulesFromFiles foreignFiles
189
190
190 let passing = cwd </> "examples" </> "passing"
191 let passing = cwd </> "examples" </> "passing"