@@ -9,12 +9,11 @@ import Prelude.Compat
99import Control.Arrow (first, (***))
1010import Control.Monad (when)
1111
12−import Data.Bifunctor (bimap)
1312import Data.Aeson ((.=))
1413import Data.Aeson.BetterErrors
1514import Data.ByteString.Lazy (ByteString)
1615import Data.Either (isLeft, isRight)
17−import Data.Maybe (mapMaybe)
16+import Data.Maybe (mapMaybe, fromMaybe)
1817import Data.Text (Text)
1918import Data.Version
2019import qualified Data.Vector as V
@@ -38,7 +37,7 @@ import Language.PureScript.Docs.RenderedCode as ReExports
3837data Package a = Package
3938 { pkgMeta :: PackageMeta
4039 , pkgVersion :: Version
41− , pkgVersionTag :: String
40+ , pkgVersionTag :: Text
4241 , pkgModules :: [Module]
4342 , pkgBookmarks :: [Bookmark]
4443 , pkgResolvedDependencies :: [(PackageName, Version)]
@@ -73,7 +72,7 @@ packageName = bowerName . pkgMeta
7372
7473data Module = Module
7574 { modName :: P.ModuleName
76− , modComments :: Maybe String
75+ , modComments :: Maybe Text
7776 , modDeclarations :: [Declaration]
7877 -- Re-exported values from other modules
7978 , modReExports :: [(P.ModuleName, [Declaration])]
@@ -81,8 +80,8 @@ data Module = Module
8180 deriving (Show, Eq, Ord)
8281
8382data Declaration = Declaration
84− { declTitle :: String
85− , declComments :: Maybe String
83+ { declTitle :: Text
84+ , declComments :: Maybe Text
8685 , declSourceSpan :: Maybe P.SourceSpan
8786 , declChildren :: [ChildDeclaration]
8887 , declInfo :: DeclarationInfo
@@ -109,7 +108,7 @@ data DeclarationInfo
109108 -- newtype) and its type arguments. Constructors are represented as child
110109 -- declarations.
111110 --
112− | DataDeclaration P.DataDeclType [(String, Maybe P.Kind)]
111+ | DataDeclaration P.DataDeclType [(Text, Maybe P.Kind)]
113112
114113 -- |
115114 -- A data type foreign import, with its kind.
@@ -119,13 +118,13 @@ data DeclarationInfo
119118 -- |
120119 -- A type synonym, with its type arguments and its type.
121120 --
122− | TypeSynonymDeclaration [(String, Maybe P.Kind)] P.Type
121+ | TypeSynonymDeclaration [(Text, Maybe P.Kind)] P.Type
123122
124123 -- |
125124 -- A type class, with its type arguments, its superclasses and functional
126125 -- dependencies. Instances and members are represented as child declarations.
127126 --
128− | TypeClassDeclaration [(String, Maybe P.Kind)] [P.Constraint] [([String], [String])]
127+ | TypeClassDeclaration [(Text, Maybe P.Kind)] [P.Constraint] [([Text], [Text])]
129128
130129 -- |
131130 -- An operator alias declaration, with the member the alias is for and the
@@ -134,14 +133,13 @@ data DeclarationInfo
134133 | AliasDeclaration P.Fixity FixityAlias
135134 deriving (Show, Eq, Ord)
136135
137−convertFundepsToStrings :: [(Text, Maybe P.Kind)] -> [P.FunctionalDependency] -> [([String], [String])]
136+convertFundepsToStrings :: [(Text, Maybe P.Kind)] -> [P.FunctionalDependency] -> [([Text], [Text])]
138137convertFundepsToStrings args fundeps =
139− map (bimap (map T.unpack) (map T.unpack)) fundeps'
138+ map (\(P.FunctionalDependency from to) -> toArgs from to) fundeps
140139 where
141− fundeps' = map (\(P.FunctionalDependency from to) -> toArgs from to) fundeps
142140 argsVec = V.fromList (map fst args)
143141 getArg i =
144− maybe
142+ fromMaybe
145143 (P.internalError $ unlines
146144 [ "convertDeclaration: Functional dependency index"
147145 , show i
@@ -150,12 +148,12 @@ convertFundepsToStrings args fundeps =
150148 , "Functional dependencies are"
151149 , show fundeps
152150 ]
153− ) id $ argsVec V.!? i
151+ ) $ argsVec V.!? i
154152 toArgs from to = (map getArg from, map getArg to)
155153
156154type FixityAlias = P.Qualified (Either (P.ProperName 'P.TypeName) (Either P.Ident (P.ProperName 'P.ConstructorName)))
157155
158−declInfoToString :: DeclarationInfo -> String
156+declInfoToString :: DeclarationInfo -> Text
159157declInfoToString (ValueDeclaration _) = "value"
160158declInfoToString (DataDeclaration _ _) = "data"
161159declInfoToString (ExternDataDeclaration _) = "externData"
@@ -201,8 +199,8 @@ filterChildren p decl =
201199 decl { declChildren = filter p (declChildren decl) }
202200
203201data ChildDeclaration = ChildDeclaration
204− { cdeclTitle :: String
205− , cdeclComments :: Maybe String
202+ { cdeclTitle :: Text
203+ , cdeclComments :: Maybe Text
206204 , cdeclSourceSpan :: Maybe P.SourceSpan
207205 , cdeclInfo :: ChildDeclarationInfo
208206 }
@@ -227,7 +225,7 @@ data ChildDeclarationInfo
227225 | ChildTypeClassMember P.Type
228226 deriving (Show, Eq, Ord)
229227
230−childDeclInfoToString :: ChildDeclarationInfo -> String
228+childDeclInfoToString :: ChildDeclarationInfo -> Text
231229childDeclInfoToString (ChildInstance _ _) = "instance"
232230childDeclInfoToString (ChildDataConstructor _) = "dataConstructor"
233231childDeclInfoToString (ChildTypeClassMember _) = "typeClassMember"
@@ -245,11 +243,11 @@ isDataConstructor ChildDeclaration{..} =
245243 _ -> False
246244
247245newtype GithubUser
248− = GithubUser { runGithubUser :: String }
246+ = GithubUser { runGithubUser :: Text }
249247 deriving (Show, Eq, Ord)
250248
251249newtype GithubRepo
252− = GithubRepo { runGithubRepo :: String }
250+ = GithubRepo { runGithubRepo :: Text }
253251 deriving (Show, Eq, Ord)
254252
255253data PackageError
@@ -258,14 +256,14 @@ data PackageError
258256 -- parser, and actual version used.
259257 | ErrorInPackageMeta BowerError
260258 | InvalidVersion
261− | InvalidDeclarationType String
262− | InvalidChildDeclarationType String
259+ | InvalidDeclarationType Text
260+ | InvalidChildDeclarationType Text
263261 | InvalidFixity
264− | InvalidKind String
265− | InvalidDataDeclType String
262+ | InvalidKind Text
263+ | InvalidDataDeclType Text
266264 deriving (Show, Eq, Ord)
267265
268−type Bookmark = InPackage (P.ModuleName, String)
266+type Bookmark = InPackage (P.ModuleName, Text)
269267
270268data InPackage a
271269 = Local a
@@ -307,7 +305,7 @@ asPackage minimumVersion uploader = do
307305
308306 Package <$> key "packageMeta" asPackageMeta .! ErrorInPackageMeta
309307 <*> key "version" asVersion
310− <*> key "versionTag" asString
308+ <*> key "versionTag" asText
311309 <*> key "modules" (eachInArray asModule)
312310 <*> key "bookmarks" asBookmarks .! ErrorInPackageMeta
313311 <*> key "resolvedDependencies" asResolvedDependencies
@@ -338,15 +336,15 @@ displayPackageError e = case e of
338336 InvalidVersion ->
339337 "Invalid version"
340338 InvalidDeclarationType str ->
341− "Invalid declaration type: \"" <> T.pack str <> "\""
339+ "Invalid declaration type: \"" <> str <> "\""
342340 InvalidChildDeclarationType str ->
343− "Invalid child declaration type: \"" <> T.pack str <> "\""
341+ "Invalid child declaration type: \"" <> str <> "\""
344342 InvalidFixity ->
345343 "Invalid fixity"
346344 InvalidKind str ->
347− "Invalid kind: \"" <> T.pack str <> "\""
345+ "Invalid kind: \"" <> str <> "\""
348346 InvalidDataDeclType str ->
349− "Invalid data declaration type: \"" <> T.pack str <> "\""
347+ "Invalid data declaration type: \"" <> str <> "\""
350348 where
351349 (<>) = T.append
352350
@@ -355,7 +353,7 @@ instance A.FromJSON a => A.FromJSON (Package a) where
355353 (asPackage (Version [0,0,0,0] []) fromAesonParser)
356354
357355asGithubUser :: Parse e GithubUser
358−asGithubUser = GithubUser <$> asString
356+asGithubUser = GithubUser <$> asText
359357
360358instance A.FromJSON GithubUser where
361359 parseJSON = toAesonParser' asGithubUser
@@ -372,14 +370,14 @@ parseVersion' str =
372370asModule :: Parse PackageError Module
373371asModule =
374372 Module <$> key "name" (P.moduleNameFromString <$> asText)
375− <*> key "comments" (perhaps asString)
373+ <*> key "comments" (perhaps asText)
376374 <*> key "declarations" (eachInArray asDeclaration)
377375 <*> key "reExports" (eachInArray asReExport)
378376
379377asDeclaration :: Parse PackageError Declaration
380378asDeclaration =
381− Declaration <$> key "title" asString
382− <*> key "comments" (perhaps asString)
379+ Declaration <$> key "title" asText
380+ <*> key "comments" (perhaps asText)
383381 <*> key "sourceSpan" (perhaps asSourceSpan)
384382 <*> key "children" (eachInArray asChildDeclaration)
385383 <*> key "info" asDeclarationInfo
@@ -417,7 +415,7 @@ asAssociativity = withString (maybe (Left InvalidFixity) Right . parseAssociativ
417415
418416asDeclarationInfo :: Parse PackageError DeclarationInfo
419417asDeclarationInfo = do
420− ty <- key "declType" asString
418+ ty <- key "declType" asText
421419 case ty of
422420 "value" ->
423421 ValueDeclaration <$> key "type" asType
@@ -439,10 +437,10 @@ asDeclarationInfo = do
439437 other ->
440438 throwCustomError (InvalidDeclarationType other)
441439
442−asTypeArguments :: Parse PackageError [(String, Maybe P.Kind)]
440+asTypeArguments :: Parse PackageError [(Text, Maybe P.Kind)]
443441asTypeArguments = eachInArray asTypeArgument
444442 where
445− asTypeArgument = (,) <$> nth 0 asString <*> nth 1 (perhaps asKind)
443+ asTypeArgument = (,) <$> nth 0 asText <*> nth 1 (perhaps asKind)
446444
447445asKind :: Parse e P.Kind
448446asKind = fromAesonParser
@@ -450,28 +448,28 @@ asKind = fromAesonParser
450448asType :: Parse e P.Type
451449asType = fromAesonParser
452450
453−asFunDeps :: Parse PackageError [([String], [String])]
451+asFunDeps :: Parse PackageError [([Text], [Text])]
454452asFunDeps = eachInArray asFunDep
455453 where
456− asFunDep = (,) <$> nth 0 (eachInArray asString) <*> nth 1 (eachInArray asString)
454+ asFunDep = (,) <$> nth 0 (eachInArray asText) <*> nth 1 (eachInArray asText)
457455
458456asDataDeclType :: Parse PackageError P.DataDeclType
459457asDataDeclType =
460− withString $ \s -> case s of
458+ withText $ \s -> case s of
461459 "data" -> Right P.Data
462460 "newtype" -> Right P.Newtype
463461 other -> Left (InvalidDataDeclType other)
464462
465463asChildDeclaration :: Parse PackageError ChildDeclaration
466464asChildDeclaration =
467− ChildDeclaration <$> key "title" asString
468− <*> key "comments" (perhaps asString)
465+ ChildDeclaration <$> key "title" asText
466+ <*> key "comments" (perhaps asText)
469467 <*> key "sourceSpan" (perhaps asSourceSpan)
470468 <*> key "info" asChildDeclarationInfo
471469
472470asChildDeclarationInfo :: Parse PackageError ChildDeclarationInfo
473471asChildDeclarationInfo = do
474− ty <- key "declType" asString
472+ ty <- key "declType" asText
475473 case ty of
476474 "instance" ->
477475 ChildInstance <$> key "dependencies" (eachInArray asConstraint)
@@ -504,7 +502,7 @@ asBookmarks = eachInArray asBookmark
504502asBookmark :: Parse BowerError Bookmark
505503asBookmark =
506504 asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asText)
507− <*> nth 1 asString)
505+ <*> nth 1 asText)
508506
509507asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
510508asResolvedDependencies =
@@ -514,8 +512,8 @@ asResolvedDependencies =
514512 mapLeft _ (Right x) = Right x
515513
516514asGithub :: Parse e (GithubUser, GithubRepo)
517−asGithub = (,) <$> nth 0 (GithubUser <$> asString)
518− <*> nth 1 (GithubRepo <$> asString)
515+asGithub = (,) <$> nth 0 (GithubUser <$> asText)
516+ <*> nth 1 (GithubRepo <$> asText)
519517
520518asSourceSpan :: Parse e P.SourceSpan
521519asSourceSpan = P.SourceSpan <$> key "name" asString