git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1498 from senju/master

fixed #1496.

commit9d1e0a2485e43f73fb14432ee9171589bc662051 authorPhil Freeman <paf31@cantab.net> dateFri 2 Oct 2015, 13:02 (11 years ago) parente7d1facae8cfaa
6 files changed+29−5
CONTRIBUTORS.md+1 examples/passing/UTF8Sourcefile.purs+10 psc/Main.hs+4−2 purescript.cabal+1 src/System/IO/UTF8.hs+9 tests/Main.hs+4−3
CONTRIBUTORS.md+1
@@ -53,6 +53,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
5353- [@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).
5454- [@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.
5555- [@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).
5657<http://opensource.org/licenses/MIT>.
5758
5859### 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
3232
3333import System.Exit (exitSuccess, exitFailure)
3434import System.IO (hPutStrLn, stderr)
35+import System.IO.UTF8
3536import System.FilePath.Glob (glob)
3637
3738import qualified Language.PureScript as P
@@ -60,7 +61,7 @@ compile (PSCMakeOptions inputGlob inputForeignGlob outputDir opts usePrefix) = d
6061 let (jsFiles, pursFiles) = partition (isSuffixOf ".js") input
6162 moduleFiles <- readInput (InputOptions pursFiles)
6263 inputForeign <- globWarningOnMisses warnFileTypeNotFound inputForeignGlob
63− foreignFiles <- forM (inputForeign ++ jsFiles) (\inFile -> (inFile,) <$> readFile inFile)
64+ foreignFiles <- forM (inputForeign ++ jsFiles) (\inFile -> (inFile,) <$> readUTF8File inFile)
6465 case runWriterT (parseInputs moduleFiles foreignFiles) of
6566 Left errs -> do
6667 hPutStrLn stderr (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
@@ -93,7 +94,7 @@ globWarningOnMisses warn = concatMapM globWithWarning
9394 concatMapM f = liftM concat . mapM f
9495
9596readInput :: 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
9798
9899parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
99100 => [(Either P.RebuildPolicy FilePath, String)]
@@ -178,6 +179,7 @@ pscMakeOptions = PSCMakeOptions <$> many inputFile
178179 <*> options
179180 <*> (not <$> noPrefix)
180181
182+
181183main :: IO ()
182184main = execParser opts >>= compile
183185 where
purescript.cabal+1
@@ -162,6 +162,7 @@ library
162162 Control.Monad.Supply
163163 Control.Monad.Supply.Class
164164
165+ System.IO.UTF8
165166 exposed: True
166167 buildable: True
167168 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
6666import System.Process
6767import System.FilePath
6868import System.Directory
69+import System.IO.UTF8
6970import qualified System.Info
7071import qualified System.FilePath.Glob as Glob
7172
@@ -97,7 +98,7 @@ makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input
9798
9899readInput :: [FilePath] -> IO [(FilePath, String)]
99100readInput inputFiles = forM inputFiles $ \inputFile -> do
100− text <- readFile inputFile
101+ text <- readUTF8File inputFile
101102 return (inputFile, text)
102103
103104type TestM = WriterT [(FilePath, String)] IO
@@ -157,7 +158,7 @@ assertDoesNotCompile inputFiles foreigns = do
157158
158159 where
159160 getShouldFailWith =
160− readFile
161+ readUTF8File
161162 >>> liftIO
162163 >>> fmap ( lines
163164 >>> mapMaybe (stripPrefix "-- @shouldFailWith ")
@@ -184,7 +185,7 @@ main = do
184185 supportPurs <- supportFiles "purs"
185186 supportJS <- supportFiles "js"
186187
187− foreignFiles <- forM supportJS (\f -> (f,) <$> readFile f)
188+ foreignFiles <- forM supportJS (\f -> (f,) <$> readUTF8File f)
188189 Right (foreigns, _) <- runExceptT $ runWriterT $ P.parseForeignModulesFromFiles foreignFiles
189190
190191 let passing = cwd </> "examples" </> "passing"