@@ -21,13 +21,12 @@ module Elm.Compiler.Module
23import qualified Data.Char as Char
23import qualified Data.Char as Char
24−import qualified Data.List as List
24+import qualified Data.Name as Name
25import qualified Data.Text as Text
25import qualified Data.Text as Text
26−import System.FilePath ((</>))
26+import qualified System.FilePath as FP
28import qualified AST.Module.Name as ModuleName
28import qualified AST.Module.Name as ModuleName
29import qualified Elm.Interface as I
29import qualified Elm.Interface as I
30−import qualified Elm.Name as N
31import qualified Json.Decode as Decode
30import qualified Json.Decode as Decode
32import qualified Json.Encode as Encode
31import qualified Json.Encode as Encode
@@ -36,28 +35,29 @@ import qualified Json.Encode as Encode
39−type Raw = N.Name
38+type Raw = Name.Name
42nameToString :: Raw -> String
41nameToString :: Raw -> String
43nameToString =
42nameToString =
44− N.toString
43+ Name.toString
47nameToSlashPath :: Raw -> FilePath
46nameToSlashPath :: Raw -> FilePath
48nameToSlashPath name =
47nameToSlashPath name =
49− List.foldl1 (</>) (map Text.unpack (Text.splitOn "." (N.toText name)))
48+ map (\c -> if c == '.' then FP.pathSeparator else c) (Name.toString name)
52nameToHyphenPath :: Raw -> FilePath
51nameToHyphenPath :: Raw -> FilePath
53nameToHyphenPath name =
52nameToHyphenPath name =
54− Text.unpack (Text.replace "." "-" (N.toText name))
53+ map (\c -> if c == '.' then '-' else c) (Name.toString name)
57fromHyphenPath :: Text.Text -> Maybe Raw
56fromHyphenPath :: Text.Text -> Maybe Raw
58fromHyphenPath txt =
57fromHyphenPath txt =
58+ let str = Text.unpack txt in
59− if all isGoodChunk (Text.splitOn "-" txt)
59+ if all isGoodChunk (splitOn '-' str)
60− then Just (N.fromText (Text.replace "-" "." txt))
60+ then Just (Name.fromString (map (\c -> if c == '-' then '.' else c) str))
61 else Nothing
61 else Nothing
@@ -73,20 +73,20 @@ encode =
73decoder :: Decode.Decoder Text.Text Raw
73decoder :: Decode.Decoder Text.Text Raw
75 do txt <- Decode.text
75 do txt <- Decode.text
76− let chunks = Text.splitOn "." txt
76+ let str = Text.unpack txt
77− if all isGoodChunk chunks
77+ if all isGoodChunk (splitOn '.' str)
78− then Decode.succeed (N.fromText txt)
78+ then Decode.succeed (Name.fromString str)
79 else Decode.fail txt
79 else Decode.fail txt
82−isGoodChunk :: Text.Text -> Bool
82+isGoodChunk :: String -> Bool
83isGoodChunk chunk =
83isGoodChunk chunk =
84− case Text.uncons chunk of
84+ case chunk of
88− Just (first, rest) ->
88+ first : rest ->
89− Char.isUpper first && Text.all isGoodChar rest
89+ Char.isUpper first && all isGoodChar rest
92isGoodChar :: Char -> Bool
92isGoodChar :: Char -> Bool
@@ -94,3 +94,23 @@ isGoodChar char =
94 Char.isAlphaNum char || char == '_'
94 Char.isAlphaNum char || char == '_'
97+splitOn :: Char -> String -> [String]
99+ uncurry (:) (splitOnHelp sep string)
102+splitOnHelp :: Char -> String -> (String, [String])
103+splitOnHelp sep string =
110+ (chunk,chunks) = splitOnHelp sep rest
115+ (char:chunk, chunks)