on master help sign in
Convert Strings to Text in all the AST files
5e065deEvan Czaplicki
src/AST/Declaration.hs+3−2
@@ -1,4 +1,5 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
2module AST.Declaration where
3module AST.Declaration where
3
4
4import Data.Binary
5import Data.Binary
@@ -108,8 +109,8 @@ data Assoc = L | N | R
108 deriving (Eq)
109 deriving (Eq)
109
110
110
111
111−assocToString :: Assoc -> String
112+assocToText :: Assoc -> Text
112−assocToString assoc =
113+assocToText assoc =
113 case assoc of
114 case assoc of
114 L ->
115 L ->
115 "left"
116 "left"
src/AST/Effects.hs+7−5
@@ -1,5 +1,7 @@
1module AST.Effects where
1module AST.Effects where
2
2
3+import Data.Text (Text)
4+
3import qualified AST.Type as Type
5import qualified AST.Type as Type
4import qualified Elm.Package as Pkg
6import qualified Elm.Package as Pkg
5import qualified Reporting.Annotation as A
7import qualified Reporting.Annotation as A
@@ -39,9 +41,9 @@ data Info =
39
41
40
42
41data ManagerType
43data ManagerType
42− = CmdManager (A.Located String)
44+ = CmdManager (A.Located Text)
43− | SubManager (A.Located String)
45+ | SubManager (A.Located Text)
44− | FxManager (A.Located String) (A.Located String)
46+ | FxManager (A.Located Text) (A.Located Text)
45
47
46
48
47
49
@@ -50,14 +52,14 @@ data ManagerType
50
52
51data PortRaw =
53data PortRaw =
52 PortRaw
54 PortRaw
53− { _rawName :: String
55+ { _rawName :: Text
54 , _rawType :: Type.Raw
56 , _rawType :: Type.Raw
55 }
57 }
56
58
57
59
58data PortCanonical =
60data PortCanonical =
59 PortCanonical
61 PortCanonical
60− { _name :: String
62+ { _name :: Text
61 , _kind :: Kind
63 , _kind :: Kind
62 , _type :: Type.Canonical
64 , _type :: Type.Canonical
63 }
65 }
src/AST/Expression/Canonical.hs+2−2
@@ -42,7 +42,7 @@ data Expr'
42 | If [(Expr, Expr)] Expr
42 | If [(Expr, Expr)] Expr
43 | Let [Def] Expr
43 | Let [Def] Expr
44 | Case Expr [(Ptrn.Canonical, Expr)]
44 | Case Expr [(Ptrn.Canonical, Expr)]
45− | Ctor Text [Expr]
45+ | Ctor Var.Canonical [Expr]
46 | Access Expr Text
46 | Access Expr Text
47 | Update Expr [(Text, Expr)]
47 | Update Expr [(Text, Expr)]
48 | Record [(Text, Expr)]
48 | Record [(Text, Expr)]
@@ -53,7 +53,7 @@ data Expr'
53 | IncomingPort Text Type.Canonical
53 | IncomingPort Text Type.Canonical
54 | Program Main Expr
54 | Program Main Expr
55 | SaveEnv ModuleName.Canonical Effects.Canonical
55 | SaveEnv ModuleName.Canonical Effects.Canonical
56− | GLShader Text Text Literal.GLShaderTipe
56+ | GLShader Text Text Literal.Shader
57
57
58
58
59data Main
59data Main
src/AST/Expression/Optimized.hs+1−1
@@ -57,7 +57,7 @@ data Expr
57 | OutgoingPort Text Type.Canonical
57 | OutgoingPort Text Type.Canonical
58 | IncomingPort Text Type.Canonical
58 | IncomingPort Text Type.Canonical
59 | Program Can.Main Expr
59 | Program Can.Main Expr
60− | GLShader Text Text Literal.GLShaderTipe
60+ | GLShader Text Text Literal.Shader
61 | Crash ModuleName.Canonical R.Region (Maybe Expr)
61 | Crash ModuleName.Canonical R.Region (Maybe Expr)
62
62
63
63
src/AST/Expression/Source.hs+1−1
@@ -40,7 +40,7 @@ data Expr' def
40 | Access (Expr def) Text
40 | Access (Expr def) Text
41 | Update (Expr def) [(A.Located Text, Expr def)]
41 | Update (Expr def) [(A.Located Text, Expr def)]
42 | Record [(A.Located Text, Expr def)]
42 | Record [(A.Located Text, Expr def)]
43− | GLShader Text Text Literal.GLShaderTipe
43+ | GLShader Text Text Literal.Shader
44
44
45
45
46type RawExpr = Expr RawDef
46type RawExpr = Expr RawDef
src/AST/Helpers.hs+2−2
@@ -22,9 +22,9 @@ isTuple name =
22-- INFIX OPERATORS
22-- INFIX OPERATORS
23
23
24
24
25−isOp :: Text -> Bool
25+isOp :: String -> Bool
26isOp name =
26isOp name =
27− Text.all isSymbol name
27+ all isSymbol name
28
28
29
29
30isSymbol :: Char -> Bool
30isSymbol :: Char -> Bool
src/AST/Literal.hs+35−23
@@ -1,9 +1,16 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
2module AST.Literal where
3module AST.Literal where
3
4
4import qualified Data.Map as Map
5import qualified Data.Map as Map
5import Data.Text (Text)
6import Data.Text (Text)
6
7
8+import qualified AST.Variable as Var
9+
10+
11+
12+-- LITERALS
13+
7
14
8data Literal
15data Literal
9 = IntNum Int
16 = IntNum Int
@@ -24,32 +31,37 @@ toString literal =
24 Boolean bool -> show bool
31 Boolean bool -> show bool
25
32
26
33
34+
35+-- WebGL TYPES
36+
37+
27−data GLTipe
38+data GLType
28− = Int
39+ = Int
29− | Float
40+ | Float
30− | V2
41+ | V2
31− | V3
42+ | V3
32− | V4
43+ | V4
33− | M4
44+ | M4
34− | Texture
45+ | Texture
35− deriving (Eq)
46+ deriving (Eq)
36
47
37
48
38−glTipeName :: GLTipe -> String
49+glTypeToVar :: GLType -> Var.Canonical
39−glTipeName glTipe =
50+glTypeToVar glTipe =
40− case glTipe of
51+ case glTipe of
41− Int -> "Int"
42− Float -> "Float"
43− V2 -> "Math.Vector2.Vec2"
52+ V2 -> Var.inLinearAlgebra "Math.Vector2" "Vec2"
44− V3 -> "Math.Vector3.Vec3"
53+ V3 -> Var.inLinearAlgebra "Math.Vector3" "Vec3"
45− V4 -> "Math.Vector4.Vec4"
54+ V4 -> Var.inLinearAlgebra "Math.Vector4" "Vec4"
46− M4 -> "Math.Matrix4.Mat4"
55+ M4 -> Var.inLinearAlgebra "Math.Matrix4" "Mat4"
56+ Int -> Var.builtin "Int"
57+ Float -> Var.builtin "Float"
47− Texture -> "WebGL.Texture"
58+ Texture -> Var.inWebGL "WebGL" "Texture"
48
59
49
60
50−data GLShaderTipe = GLShaderTipe
61+data Shader =
62+ Shader
51− { attribute :: Map.Map String GLTipe
63+ { attribute :: Map.Map Text GLType
52− , uniform :: Map.Map String GLTipe
64+ , uniform :: Map.Map Text GLType
53− , varying :: Map.Map String GLTipe
65+ , varying :: Map.Map Text GLType
54 }
66 }
55 deriving (Eq)
67 deriving (Eq)
src/AST/Module.hs+24−11
@@ -1,5 +1,7 @@
1+{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
1module AST.Module
3module AST.Module
2− ( Header(..), Module(..)
4+ ( Header(..), defaultHeader, Module(..)
3
5
4 , Source, SourceInfo(..), SourceTag(..), SourceSettings, emptySettings
6 , Source, SourceInfo(..), SourceTag(..), SourceSettings, emptySettings
5 , Valid, ValidInfo(..)
7 , Valid, ValidInfo(..)
@@ -17,6 +19,7 @@ module AST.Module
17
19
18import Data.Binary
20import Data.Binary
19import qualified Data.Map as Map
21import qualified Data.Map as Map
22+import Data.Text (Text)
20
23
21import qualified AST.Declaration as Decl
24import qualified AST.Declaration as Decl
22import qualified AST.Effects as Effects
25import qualified AST.Effects as Effects
@@ -43,11 +46,21 @@ data Header imports =
43 , _name :: Name.Raw
46 , _name :: Name.Raw
44 , _exports :: Var.Listing (A.Located Var.Value)
47 , _exports :: Var.Listing (A.Located Var.Value)
45 , _settings :: SourceSettings
48 , _settings :: SourceSettings
46− , _docs :: A.Located (Maybe String)
49+ , _docs :: Maybe (A.Located Text)
47 , _imports :: imports
50 , _imports :: imports
48 }
51 }
49
52
50
53
54+instance Show (Header a) where
55+ show header =
56+ show (_name header)
57+
58+
59+defaultHeader :: imports -> Header imports
60+defaultHeader imports_ =
61+ Header Normal "Main" Var.openListing emptySettings Nothing imports_
62+
63+
51
64
52-- MODULES
65-- MODULES
53
66
@@ -68,7 +81,7 @@ data SourceInfo =
68 Source
81 Source
69 { srcTag :: SourceTag
82 { srcTag :: SourceTag
70 , srcSettings :: SourceSettings
83 , srcSettings :: SourceSettings
71− , srcDocs :: A.Located (Maybe String)
84+ , srcDocs :: Maybe (A.Located Text)
72 , srcExports :: Var.Listing (A.Located Var.Value)
85 , srcExports :: Var.Listing (A.Located Var.Value)
73 , srcImports :: [UserImport]
86 , srcImports :: [UserImport]
74 , srcDecls :: [Decl.Source]
87 , srcDecls :: [Decl.Source]
@@ -82,7 +95,7 @@ data SourceTag
82
95
83
96
84type SourceSettings =
97type SourceSettings =
85− A.Located [(A.Located String, A.Located String)]
98+ A.Located [(A.Located Text, A.Located Text)]
86
99
87
100
88emptySettings :: SourceSettings
101emptySettings :: SourceSettings
@@ -96,7 +109,7 @@ type Valid =
96
109
97data ValidInfo =
110data ValidInfo =
98 Valid
111 Valid
99− { validDocs :: A.Located (Maybe String)
112+ { validDocs :: Maybe (A.Located Text)
100 , validExports :: Var.Listing (A.Located Var.Value)
113 , validExports :: Var.Listing (A.Located Var.Value)
101 , validImports :: ([DefaultImport], [UserImport])
114 , validImports :: ([DefaultImport], [UserImport])
102 , validDecls :: Decl.Valid
115 , validDecls :: Decl.Valid
@@ -124,7 +137,7 @@ type DefaultImport = (Name.Raw, ImportMethod)
124
137
125data ImportMethod =
138data ImportMethod =
126 ImportMethod
139 ImportMethod
127− { alias :: Maybe String
140+ { alias :: Maybe Text
128 , exposedVars :: !(Var.Listing Var.Value)
141 , exposedVars :: !(Var.Listing Var.Value)
129 }
142 }
130
143
@@ -135,7 +148,7 @@ data ImportMethod =
135
148
136data Info program =
149data Info program =
137 Info
150 Info
138− { docs :: A.Located (Maybe Docs.Centralized)
151+ { docs :: Maybe (A.Located Docs.Centralized)
139 , exports :: [Var.Value]
152 , exports :: [Var.Value]
140 , imports :: [Name.Raw]
153 , imports :: [Name.Raw]
141 , program :: program
154 , program :: program
@@ -148,19 +161,19 @@ data Info program =
148
161
149
162
150type Types =
163type Types =
151− Map.Map String Type.Canonical
164+ Map.Map Text Type.Canonical
152
165
153
166
154type Aliases =
167type Aliases =
155− Map.Map String ([String], Type.Canonical)
168+ Map.Map Text ([Text], Type.Canonical)
156
169
157
170
158type Unions =
171type Unions =
159− Map.Map String (UnionInfo String)
172+ Map.Map Text (UnionInfo Text)
160
173
161
174
162type UnionInfo v =
175type UnionInfo v =
163− ( [String], [(v, [Type.Canonical])] )
176+ ( [Text], [(v, [Type.Canonical])] )
164
177
165
178
166type CanonicalUnion =
179type CanonicalUnion =
src/AST/Module/Name.hs+20−11
@@ -3,14 +3,13 @@
3module AST.Module.Name where
3module AST.Module.Name where
4
4
5import Data.Binary
5import Data.Binary
6−import qualified Data.List as List
7import qualified Data.Text as Text
6import qualified Data.Text as Text
8import Data.Text (Text)
7import Data.Text (Text)
9
8
10import qualified Elm.Package as Package
9import qualified Elm.Package as Package
11
10
12
11
13−type Raw = [Text] -- must be non-empty
12+type Raw = Text -- must be non-empty
14
13
15
14
16data Canonical = Canonical
15data Canonical = Canonical
@@ -35,24 +34,34 @@ inHtml raw =
35 Canonical Package.html raw
34 Canonical Package.html raw
36
35
37
36
37+inWebGL :: Raw -> Canonical
38+inWebGL raw =
39+ Canonical Package.webgl raw
40+
41+
42+inLinearAlgebra :: Raw -> Canonical
43+inLinearAlgebra raw =
44+ Canonical Package.linearAlgebra raw
45+
46+
38toString :: Raw -> String
47toString :: Raw -> String
39−toString rawName =
48+toString name =
40− List.intercalate "." (map Text.unpack rawName)
49+ Text.unpack name
41
50
42
51
43canonicalToString :: Canonical -> String
52canonicalToString :: Canonical -> String
44−canonicalToString (Canonical _ rawName) =
53+canonicalToString (Canonical _ name) =
45− toString rawName
54+ toString name
46
55
47
56
48isNative :: Raw -> Bool
57isNative :: Raw -> Bool
49isNative name =
58isNative name =
50− case name of
59+ Text.isPrefixOf "Native." name
51− "Native" : _ ->
60+
52− True
53
61
54− _ ->
62+canonicalIsNative :: Canonical -> Bool
55− False
63+canonicalIsNative (Canonical _ name) =
64+ isNative name
56
65
57
66
58instance Binary Canonical where
67instance Binary Canonical where
src/AST/Variable.hs+39−17
@@ -68,14 +68,24 @@ inHtml home name =
68 Canonical (Module (ModuleName.inHtml home)) name
68 Canonical (Module (ModuleName.inHtml home)) name
69
69
70
70
71+inWebGL :: ModuleName.Raw -> Text -> Canonical
72+inWebGL home name =
73+ Canonical (Module (ModuleName.inWebGL home)) name
74+
75+
76+inLinearAlgebra :: ModuleName.Raw -> Text -> Canonical
77+inLinearAlgebra home name =
78+ Canonical (Module (ModuleName.inLinearAlgebra home)) name
79+
80+
71cmd :: Canonical
81cmd :: Canonical
72cmd =
82cmd =
73− inCore ["Platform","Cmd"] "Cmd"
83+ inCore "Platform.Cmd" "Cmd"
74
84
75
85
76sub :: Canonical
86sub :: Canonical
77sub =
87sub =
78− inCore ["Platform","Sub"] "Sub"
88+ inCore "Platform.Sub" "Sub"
79
89
80
90
81
91
@@ -105,21 +115,21 @@ is home name var =
105
115
106isJson :: Canonical -> Bool
116isJson :: Canonical -> Bool
107isJson =
117isJson =
108− is ["Json", "Encode"] "Value"
118+ is "Json.Encode" "Value"
109
119
110
120
111isMaybe :: Canonical -> Bool
121isMaybe :: Canonical -> Bool
112isMaybe =
122isMaybe =
113− is ["Maybe"] "Maybe"
123+ is "Maybe" "Maybe"
114
124
115isArray :: Canonical -> Bool
125isArray :: Canonical -> Bool
116isArray =
126isArray =
117− is ["Array"] "Array"
127+ is "Array" "Array"
118
128
119
129
120isTask :: Canonical -> Bool
130isTask :: Canonical -> Bool
121isTask =
131isTask =
122− is ["Task"] "Task"
132+ is "Task" "Task"
123
133
124
134
125isList :: Canonical -> Bool
135isList :: Canonical -> Bool
@@ -127,6 +137,16 @@ isList v =
127 v == Canonical BuiltIn "List"
137 v == Canonical BuiltIn "List"
128
138
129
139
140+isNative :: Canonical -> Bool
141+isNative v =
142+ case v of
143+ Canonical (Module name) _ ->
144+ ModuleName.canonicalIsNative name
145+
146+ _ ->
147+ False
148+
149+
130isTuple :: Canonical -> Bool
150isTuple :: Canonical -> Bool
131isTuple v =
151isTuple v =
132 case v of
152 case v of
@@ -141,7 +161,8 @@ isPrimitive :: Canonical -> Bool
141isPrimitive v =
161isPrimitive v =
142 case v of
162 case v of
143 Canonical BuiltIn name ->
163 Canonical BuiltIn name ->
144− name `elem` ["Int","Float","String","Bool"]
164+ elem name ["Int","Float","String","Bool"]
165+
145 _ ->
166 _ ->
146 False
167 False
147
168
@@ -200,7 +221,8 @@ instance ToString Canonical where
200
221
201
222
202-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
223-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
203−data Listing a = Listing
224+data Listing a =
225+ Listing
204 { _explicits :: [a]
226 { _explicits :: [a]
205 , _open :: Bool
227 , _open :: Bool
206 }
228 }
@@ -224,9 +246,9 @@ listing xs =
224
246
225-- | A value that can be imported or exported
247-- | A value that can be imported or exported
226data Value
248data Value
227− = Value !String
249+ = Value !Text
228− | Alias !String
250+ | Alias !Text
229− | Union !String !(Listing String)
251+ | Union !Text !(Listing Text)
230 deriving (Eq, Ord)
252 deriving (Eq, Ord)
231
253
232
254
@@ -234,12 +256,12 @@ data Value
234-- CATEGORIZING VALUES
256-- CATEGORIZING VALUES
235
257
236
258
237−getValues :: [Value] -> [String]
259+getValues :: [Value] -> [Text]
238getValues values =
260getValues values =
239 Maybe.mapMaybe getValue values
261 Maybe.mapMaybe getValue values
240
262
241
263
242−getValue :: Value -> Maybe String
264+getValue :: Value -> Maybe Text
243getValue value =
265getValue value =
244 case value of
266 case value of
245 Value name -> Just name
267 Value name -> Just name
@@ -247,12 +269,12 @@ getValue value =
247 Union _ _ -> Nothing
269 Union _ _ -> Nothing
248
270
249
271
250−getAliases :: [Value] -> [String]
272+getAliases :: [Value] -> [Text]
251getAliases values =
273getAliases values =
252 Maybe.mapMaybe getAlias values
274 Maybe.mapMaybe getAlias values
253
275
254
276
255−getAlias :: Value -> Maybe String
277+getAlias :: Value -> Maybe Text
256getAlias value =
278getAlias value =
257 case value of
279 case value of
258 Value _-> Nothing
280 Value _-> Nothing
@@ -260,12 +282,12 @@ getAlias value =
260 Union _ _ -> Nothing
282 Union _ _ -> Nothing
261
283
262
284
263−getUnions :: [Value] -> [(String, Listing String)]
285+getUnions :: [Value] -> [(Text, Listing Text)]
264getUnions values =
286getUnions values =
265 Maybe.mapMaybe getUnion values
287 Maybe.mapMaybe getUnion values
266
288
267
289
268−getUnion :: Value -> Maybe (String, Listing String)
290+getUnion :: Value -> Maybe (Text, Listing Text)
269getUnion value =
291getUnion value =
270 case value of
292 case value of
271 Value _ -> Nothing
293 Value _ -> Nothing
src/Elm/Docs.hs+16−15
@@ -9,6 +9,7 @@ import qualified Data.Aeson.Encode.Pretty as Json
9import qualified Data.ByteString.Lazy.Char8 as BS
9import qualified Data.ByteString.Lazy.Char8 as BS
10import qualified Data.Map as Map
10import qualified Data.Map as Map
11import qualified Data.Text as Text
11import qualified Data.Text as Text
12+import Data.Text (Text)
12
13
13import qualified Docs.AST as Docs
14import qualified Docs.AST as Docs
14import qualified Elm.Compiler.Module as Module
15import qualified Elm.Compiler.Module as Module
@@ -24,7 +25,7 @@ import qualified Reporting.Annotation as A
24
25
25data Documentation = Documentation
26data Documentation = Documentation
26 { moduleName :: Module.Raw
27 { moduleName :: Module.Raw
27− , comment :: String
28+ , comment :: Text
28 , aliases :: [Alias]
29 , aliases :: [Alias]
29 , types :: [Union]
30 , types :: [Union]
30 , values :: [Value]
31 , values :: [Value]
@@ -33,30 +34,30 @@ data Documentation = Documentation
33
34
34
35
35data Alias = Alias
36data Alias = Alias
36− { aliasName :: String
37+ { aliasName :: Text
37− , aliasComment :: String
38+ , aliasComment :: Text
38− , aliasArgs :: [String]
39+ , aliasArgs :: [Text]
39 , aliasType :: Type.Type
40 , aliasType :: Type.Type
40 }
41 }
41
42
42
43
43data Union = Union
44data Union = Union
44− { unionName :: String
45+ { unionName :: Text
45− , unionComment :: String
46+ , unionComment :: Text
46− , unionArgs :: [String]
47+ , unionArgs :: [Text]
47− , unionCases :: [(String, [Type.Type])]
48+ , unionCases :: [(Text, [Type.Type])]
48 }
49 }
49
50
50
51
51data Value = Value
52data Value = Value
52− { valueName :: String
53+ { valueName :: Text
53− , valueComment :: String
54+ , valueComment :: Text
54 , valueType :: Type.Type
55 , valueType :: Type.Type
55− , valueFix :: Maybe (String,Int)
56+ , valueFix :: Maybe (Text,Int)
56 }
57 }
57
58
58
59
59−data Version = NonCanonicalTypes | Version String
60+data Version = NonCanonicalTypes | Version Text
60
61
61
62
62
63
@@ -84,7 +85,7 @@ fromCheckedDocs name (Docs.Docs comment aliases unions values) =
84 (map toAlias (Map.toList aliases))
85 (map toAlias (Map.toList aliases))
85 (map toUnion (Map.toList unions))
86 (map toUnion (Map.toList unions))
86 (map toValue (Map.toList values))
87 (map toValue (Map.toList values))
87− (Version $ (Pkg.versionToString Version.version))
88+ (Version (Text.pack (Pkg.versionToString Version.version)))
88
89
89
90
90
91
@@ -151,12 +152,12 @@ instance Json.ToJSON Version where
151 Json.String "old"
152 Json.String "old"
152
153
153 Version vsn ->
154 Version vsn ->
154− Json.String (Text.pack vsn)
155+ Json.String vsn
155
156
156
157
157instance Json.FromJSON Version where
158instance Json.FromJSON Version where
158 parseJSON (Json.String text) =
159 parseJSON (Json.String text) =
159− case Text.unpack text of
160+ case text of
160 "old" -> return NonCanonicalTypes
161 "old" -> return NonCanonicalTypes
161 vrsn -> return (Version vrsn)
162 vrsn -> return (Version vrsn)
162
163
src/Elm/Package.hs+29−14
@@ -1,3 +1,5 @@
1+{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
1module Elm.Package where
3module Elm.Package where
2
4
3import Data.Aeson
5import Data.Aeson
@@ -5,15 +7,18 @@ import Data.Binary
5import qualified Data.Char as Char
7import qualified Data.Char as Char
6import Data.Function (on)
8import Data.Function (on)
7import qualified Data.List as List
9import qualified Data.List as List
8−import qualified Data.Text as T
10+import qualified Data.Text as Text
11+import Data.Text (Text)
9import System.FilePath ((</>))
12import System.FilePath ((</>))
10
13
11
14
15+
12-- PACKGE NAMES
16-- PACKGE NAMES
13
17
18+
14data Name = Name
19data Name = Name
15− { user :: String
20+ { _user :: Text
16− , project :: String
21+ , _project :: Text
17 }
22 }
18 deriving (Eq, Ord, Show)
23 deriving (Eq, Ord, Show)
19
24
@@ -41,19 +46,29 @@ html =
41 Name "elm-lang" "html"
46 Name "elm-lang" "html"
42
47
43
48
49+webgl :: Name
50+webgl =
51+ Name "elm-community" "webgl"
52+
53+
54+linearAlgebra :: Name
55+linearAlgebra =
56+ Name "elm-community" "linear-algebra"
57+
58+
44toString :: Name -> String
59toString :: Name -> String
45−toString name =
60+toString (Name user project) =
46− user name ++ "/" ++ project name
61+ Text.unpack user ++ "/" ++ Text.unpack project
47
62
48
63
49toUrl :: Name -> String
64toUrl :: Name -> String
50−toUrl name =
65+toUrl (Name user project) =
51− user name ++ "/" ++ project name
66+ Text.unpack user ++ "/" ++ Text.unpack project
52
67
53
68
54toFilePath :: Name -> FilePath
69toFilePath :: Name -> FilePath
55−toFilePath name =
70+toFilePath (Name user project) =
56− user name </> project name
71+ Text.unpack user </> Text.unpack project
57
72
58
73
59fromString :: String -> Either String Name
74fromString :: String -> Either String Name
@@ -67,7 +82,7 @@ fromString string =
67 Left "You did not provide a project name (user/project)"
82 Left "You did not provide a project name (user/project)"
68
83
69 else if all (/='/') project then
84 else if all (/='/') project then
70− Name user <$> validateProjectName project
85+ Name (Text.pack user) <$> validateProjectName project
71
86
72 else
87 else
73 Left "Expecting only one slash, separating the user and project name (user/project)"
88 Left "Expecting only one slash, separating the user and project name (user/project)"
@@ -102,7 +117,7 @@ whitelistedUppercaseName name =
102 ]
117 ]
103
118
104
119
105−validateProjectName :: String -> Either String String
120+validateProjectName :: String -> Either String Text
106validateProjectName str =
121validateProjectName str =
107 if elem ('-','-') (zip str (tail str)) then
122 if elem ('-','-') (zip str (tail str)) then
108 Left "There is a double dash -- in your package name. It must be a single dash."
123 Left "There is a double dash -- in your package name. It must be a single dash."
@@ -117,7 +132,7 @@ validateProjectName str =
117 Left "Package names must start with a letter."
132 Left "Package names must start with a letter."
118
133
119 else
134 else
120− Right str
135+ Right (Text.pack str)
121
136
122
137
123instance Binary Name where
138instance Binary Name where
@@ -130,7 +145,7 @@ instance Binary Name where
130instance FromJSON Name where
145instance FromJSON Name where
131 parseJSON (String text) =
146 parseJSON (String text) =
132 let
147 let
133− string = T.unpack text
148+ string = Text.unpack text
134 in
149 in
135 case fromString string of
150 case fromString string of
136 Left msg ->
151 Left msg ->
@@ -233,7 +248,7 @@ instance Binary Version where
233
248
234instance FromJSON Version where
249instance FromJSON Version where
235 parseJSON (String text) =
250 parseJSON (String text) =
236− let string = T.unpack text in
251+ let string = Text.unpack text in
237 case versionFromString string of
252 case versionFromString string of
238 Right v ->
253 Right v ->
239 return v
254 return v