on master help sign in
Switch Elm.Package to use Data.Name for author and project
5fbf3b1Evan Czaplicki
compiler/src/Elm/Package.hs+13−13
@@ -29,6 +29,7 @@ import Data.Binary (Binary, get, getWord8, put, putWord8)
29import qualified Data.Char as Char
29import qualified Data.Char as Char
30import Data.Function (on)
30import Data.Function (on)
31import qualified Data.List as List
31import qualified Data.List as List
32+import qualified Data.Name as Name
32import qualified Data.Map as Map
33import qualified Data.Map as Map
33import Data.Monoid ((<>))
34import Data.Monoid ((<>))
34import qualified Data.Text as Text
35import qualified Data.Text as Text
@@ -40,7 +41,6 @@ import Data.Text (Text)
40import Data.Word (Word16)
41import Data.Word (Word16)
41import System.FilePath ((</>))
42import System.FilePath ((</>))
42
43
43−import qualified Elm.Name as N
44import qualified Json.Decode.Internals as Decode
44import qualified Json.Decode.Internals as Decode
45import qualified Json.Encode as Encode
45import qualified Json.Encode as Encode
46
46
@@ -51,8 +51,8 @@ import qualified Json.Encode as Encode
51
51
52data Name =
52data Name =
53 Name
53 Name
54− { _author :: !Text
54+ { _author :: !Name.Name
55− , _project :: !Text
55+ , _project :: !Name.Name
56 }
56 }
57 deriving (Eq, Ord)
57 deriving (Eq, Ord)
58
58
@@ -75,30 +75,30 @@ isKernel (Name author _) =
75
75
76
76
77toString :: Name -> String
77toString :: Name -> String
78−toString name =
78+toString (Name author project) =
79− Text.unpack (toText name)
79+ Name.toString author <> "/" <> Name.toString project
80
80
81
81
82toText :: Name -> Text
82toText :: Name -> Text
83−toText (Name author project) =
83+toText name =
84− author <> "/" <> project
84+ Text.pack (toString name)
85
85
86
86
87toUrl :: Name -> String
87toUrl :: Name -> String
88toUrl (Name author project) =
88toUrl (Name author project) =
89− Text.unpack author ++ "/" ++ Text.unpack project
89+ Name.toString author ++ "/" ++ Name.toString project
90
90
91
91
92toFilePath :: Name -> FilePath
92toFilePath :: Name -> FilePath
93toFilePath (Name author project) =
93toFilePath (Name author project) =
94− Text.unpack author </> Text.unpack project
94+ Name.toString author </> Name.toString project
95
95
96
96
97fromText :: Text -> Either (String, [String]) Name
97fromText :: Text -> Either (String, [String]) Name
98fromText text =
98fromText text =
99 case Text.splitOn "/" text of
99 case Text.splitOn "/" text of
100 [ author, project ] | not (Text.null author || Text.null project) ->
100 [ author, project ] | not (Text.null author || Text.null project) ->
101− Name author <$> validateProjectName project
101+ Name (Name.fromString (Text.unpack author)) <$> validateProjectName project
102
102
103 _ ->
103 _ ->
104 Left
104 Left
@@ -107,7 +107,7 @@ fromText text =
107 )
107 )
108
108
109
109
110−validateProjectName :: Text -> Either (String, [String]) Text
110+validateProjectName :: Text -> Either (String, [String]) Name.Name
111validateProjectName text =
111validateProjectName text =
112 if Text.isInfixOf "--" text then
112 if Text.isInfixOf "--" text then
113 Left $ thisCannot "have two dashes in a row" text (Text.replace "--" "-" text)
113 Left $ thisCannot "have two dashes in a row" text (Text.replace "--" "-" text)
@@ -131,7 +131,7 @@ validateProjectName text =
131 Left $ thisCannot "end with a dash" text (Text.dropEnd 1 text)
131 Left $ thisCannot "end with a dash" text (Text.dropEnd 1 text)
132
132
133 else
133 else
134− Right text
134+ Right (Name.fromString (Text.unpack text))
135
135
136
136
137thisCannot :: String -> Text -> Text -> (String, [String])
137thisCannot :: String -> Text -> Text -> (String, [String])
@@ -240,7 +240,7 @@ linearAlgebra =
240-- PACKAGE SUGGESTIONS
240-- PACKAGE SUGGESTIONS
241
241
242
242
243−suggestions :: Map.Map N.Name Name
243+suggestions :: Map.Map Name.Name Name
244suggestions =
244suggestions =
245 Map.fromList
245 Map.fromList
246 [ ("Browser", browser)
246 [ ("Browser", browser)