Skip to content
This repository was archived by the owner on Aug 23, 2018. It is now read-only.

Commit 2cf040a

Browse files
committed
Switch from String to Text, following changes in elm-compiler
1 parent 26f458f commit 2cf040a

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

src/BuildManager.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Control.Monad.Except (ExceptT, runExceptT)
55
import Control.Monad.State (StateT, liftIO, runStateT)
66
import qualified Control.Monad.State as State
77
import qualified Data.List as List
8+
import Data.Text (Text)
89
import qualified Data.Time.Clock.POSIX as Time
910
import qualified Elm.Compiler as Compiler
1011
import qualified Elm.Compiler.Module as Module
@@ -138,7 +139,7 @@ phaseToString overallDuration indent (Phase tag start subphases end) =
138139

139140

140141
data Error
141-
= CompilerErrors FilePath String [Compiler.Error]
142+
= CompilerErrors FilePath Text [Compiler.Error]
142143
| CorruptedArtifact FilePath
143144
| Cycle [TMP.CanonicalModule]
144145
| PackageProblem String

src/Pipeline/Compile.hs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import qualified Data.List as List
66
import qualified Data.Map as Map
77
import qualified Data.Maybe as Maybe
88
import qualified Data.Set as Set
9+
import qualified Data.Text as Text
10+
import qualified Data.Text.IO as Text
911
import qualified Data.Text.Lazy.IO as LazyTextIO
1012
import qualified Elm.Compiler as Compiler
1113
import qualified Elm.Compiler.Module as Module
@@ -253,7 +255,7 @@ buildModule env interfaces (modul, location) =
253255
context =
254256
Compiler.Context packageName isExposed deps
255257
in
256-
do source <- readFile path
258+
do source <- Text.readFile path
257259

258260
let (localizer, warnings, rawResult) =
259261
Compiler.compile context source ifaces
@@ -264,8 +266,9 @@ buildModule env interfaces (modul, location) =
264266
Chan.writeChan (resultChan env) result
265267

266268

267-
data Result = Result
268-
{ _source :: String
269+
data Result =
270+
Result
271+
{ _source :: Text.Text
269272
, _path :: FilePath
270273
, _moduleID :: CanonicalModule
271274
, _localizer :: Compiler.Localizer

src/Pipeline/Crawl/Package.hs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{-# OPTIONS_GHC -Wall #-}
2+
{-# LANGUAGE OverloadedStrings #-}
23
module Pipeline.Crawl.Package where
34

45
import Control.Arrow (second)
56
import Control.Monad.Except (liftIO, throwError)
67
import qualified Data.Map as Map
8+
import qualified Data.Text as Text
79
import qualified Elm.Compiler as Compiler
810
import qualified Elm.Compiler.Module as Module
911
import qualified Elm.Package.Description as Desc
@@ -185,12 +187,10 @@ findHelp allowNatives locations moduleName (dir:srcDirs) =
185187
addJsPath locs =
186188
do let jsPath = dir </> Module.nameToPath moduleName <.> "js"
187189
jsExists <-
188-
case moduleName of
189-
"Native" : _ ->
190-
liftIO (doesFileExist jsPath)
191-
192-
_ ->
193-
return False
190+
if Text.isPrefixOf "Native." moduleName then
191+
liftIO (doesFileExist jsPath)
192+
else
193+
return False
194194

195195
return (consIf jsExists (JS jsPath) locs)
196196

@@ -205,15 +205,15 @@ readPackageData
205205
-> FilePath
206206
-> BM.Task (Module.Raw, (PackageData, [Unvisited]))
207207
readPackageData env maybeName filePath =
208-
do sourceCode <- liftIO (File.readStringUtf8 filePath)
208+
do sourceCode <- liftIO (File.readTextUtf8 filePath)
209209

210210
(tag, name, deps) <-
211211
case Compiler.parseDependencies (_packageName env) sourceCode of
212212
Right result ->
213213
return result
214214

215-
Left msgs ->
216-
throwError (BM.CompilerErrors filePath sourceCode msgs)
215+
Left msg ->
216+
throwError (BM.CompilerErrors filePath sourceCode [msg])
217217

218218
checkName filePath name maybeName
219219
checkTag filePath name (_permissions env) tag

src/Pipeline/Generate.hs

+8-5
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ getReachableObjectFiles debug moduleNames allNodes =
142142

143143
isVirtualDomDebug :: (fp, TMP.CanonicalModule, deps) -> Bool
144144
isVirtualDomDebug (_filePath, TMP.CanonicalModule (pkg, _vsn) name, _deps) =
145-
pkg == Pkg.virtualDom && name == ["VirtualDom","Debug"]
145+
pkg == Pkg.virtualDom && name == "VirtualDom.Debug"
146146

147147

148148

@@ -196,16 +196,19 @@ exportProgram
196196
-> Map.Map Module.Canonical Module.Interface
197197
-> Module.Canonical
198198
-> String
199-
exportProgram debugMode interfaces canonicalName@(Module.Canonical _ moduleName) =
199+
exportProgram debugMode interfaces canonicalName@(Module.Canonical _ rawName) =
200200
let
201201
program =
202-
Module.qualifiedVar canonicalName "main"
202+
Text.unpack (Module.qualifiedVar canonicalName "main")
203+
204+
moduleName =
205+
map Text.unpack (Text.splitOn "." rawName)
203206

204207
object =
205208
objectFor moduleName
206209

207210
name =
208-
Module.nameToString moduleName
211+
Module.nameToString rawName
209212

210213
debugArg =
211214
if debugMode then createDebugMetadata interfaces canonicalName else "undefined"
@@ -246,7 +249,7 @@ setup moduleName =
246249
unlines (map create paths)
247250

248251

249-
objectFor :: Module.Raw -> String
252+
objectFor :: [String] -> String
250253
objectFor names =
251254
let
252255
brackets :: String -> String

src/Pipeline/Plan.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
{-# LANGUAGE OverloadedStrings #-}
12
module Pipeline.Plan where
23

34
import Control.Monad (foldM)
45
import Control.Monad.Except (liftIO, throwError)
56
import qualified Data.Graph as Graph
67
import qualified Data.Set as Set
8+
import qualified Data.Text as Text
79
import Data.Time.Clock (UTCTime)
810
import Data.Map ((!))
911
import qualified Data.Map as Map
@@ -81,7 +83,7 @@ getFreshInterfaceInfo sourcePath interfacePath =
8183

8284
isMain :: CanonicalModule -> Bool
8385
isMain (CanonicalModule _ names) =
84-
names == ["Main"]
86+
names == "Main"
8587

8688

8789

@@ -192,13 +194,12 @@ filterCachedDeps interfaces name =
192194

193195

194196
filterNativeDeps :: CanonicalModule -> Maybe CanonicalModule
195-
filterNativeDeps name =
196-
case name of
197-
CanonicalModule _pkg ("Native" : _) ->
198-
Nothing
197+
filterNativeDeps moduleName@(CanonicalModule _ name) =
198+
if Text.isPrefixOf "Native." name then
199+
Nothing
199200

200-
_ ->
201-
Just name
201+
else
202+
Just moduleName
202203

203204

204205

src/Report.hs

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import qualified Control.Concurrent.Chan as Chan
44
import Control.Monad (when)
55
import qualified Data.Aeson as Json
66
import qualified Data.ByteString.Lazy.Char8 as BS
7+
import qualified Data.Text as Text
8+
import Data.Text (Text)
79
import qualified Elm.Compiler as Compiler
810
import qualified Elm.Package as Pkg
911
import qualified Elm.Package.Paths as Path
@@ -20,8 +22,8 @@ data Type = Normal | Json
2022

2123
data Message
2224
= Close
23-
| Complete CanonicalModule Compiler.Localizer FilePath String [Compiler.Warning]
24-
| Error CanonicalModule Compiler.Localizer FilePath String [Compiler.Warning] [Compiler.Error]
25+
| Complete CanonicalModule Compiler.Localizer FilePath Text [Compiler.Warning]
26+
| Error CanonicalModule Compiler.Localizer FilePath Text [Compiler.Warning] [Compiler.Error]
2527

2628

2729

@@ -157,15 +159,15 @@ printSeparator isTerminal color header =
157159
when isTerminal $ hSetSGR stderr [Reset]
158160

159161

160-
printError :: Bool -> Compiler.Localizer -> FilePath -> String -> Compiler.Error -> IO ()
162+
printError :: Bool -> Compiler.Localizer -> FilePath -> Text -> Compiler.Error -> IO ()
161163
printError isTerminal localizer path source err =
162164
if isTerminal then
163165
Compiler.printError stderr localizer path source err
164166
else
165167
hPutStr stderr (Compiler.errorToString localizer path source err)
166168

167169

168-
printWarning :: Bool -> Compiler.Localizer -> FilePath -> String -> Compiler.Warning -> IO ()
170+
printWarning :: Bool -> Compiler.Localizer -> FilePath -> Text -> Compiler.Warning -> IO ()
169171
printWarning isTerminal localizer path source err =
170172
if isTerminal then
171173
Compiler.printWarning stderr localizer path source err

0 commit comments

Comments
 (0)