@@ -9,12 +9,11 @@ import Prelude.Compat
9import Control.Arrow (first, (***))
9import Control.Arrow (first, (***))
10import Control.Monad (when)
10import Control.Monad (when)
12−import Data.Bifunctor (bimap)
13import Data.Aeson ((.=))
12import Data.Aeson ((.=))
14import Data.Aeson.BetterErrors
13import Data.Aeson.BetterErrors
15import Data.ByteString.Lazy (ByteString)
14import Data.ByteString.Lazy (ByteString)
16import Data.Either (isLeft, isRight)
15import Data.Either (isLeft, isRight)
17−import Data.Maybe (mapMaybe)
16+import Data.Maybe (mapMaybe, fromMaybe)
18import Data.Text (Text)
17import Data.Text (Text)
19import Data.Version
18import Data.Version
20import qualified Data.Vector as V
19import qualified Data.Vector as V
@@ -38,7 +37,7 @@ import Language.PureScript.Docs.RenderedCode as ReExports
38data Package a = Package
37data Package a = Package
39 { pkgMeta :: PackageMeta
38 { pkgMeta :: PackageMeta
40 , pkgVersion :: Version
39 , pkgVersion :: Version
41− , pkgVersionTag :: String
40+ , pkgVersionTag :: Text
42 , pkgModules :: [Module]
41 , pkgModules :: [Module]
43 , pkgBookmarks :: [Bookmark]
42 , pkgBookmarks :: [Bookmark]
44 , pkgResolvedDependencies :: [(PackageName, Version)]
43 , pkgResolvedDependencies :: [(PackageName, Version)]
@@ -73,7 +72,7 @@ packageName = bowerName . pkgMeta
74data Module = Module
73data Module = Module
75 { modName :: P.ModuleName
74 { modName :: P.ModuleName
76− , modComments :: Maybe String
75+ , modComments :: Maybe Text
77 , modDeclarations :: [Declaration]
76 , modDeclarations :: [Declaration]
78 -- Re-exported values from other modules
77 -- Re-exported values from other modules
79 , modReExports :: [(P.ModuleName, [Declaration])]
78 , modReExports :: [(P.ModuleName, [Declaration])]
@@ -81,8 +80,8 @@ data Module = Module
81 deriving (Show, Eq, Ord)
80 deriving (Show, Eq, Ord)
83data Declaration = Declaration
82data Declaration = Declaration
84− { declTitle :: String
83+ { declTitle :: Text
85− , declComments :: Maybe String
84+ , declComments :: Maybe Text
86 , declSourceSpan :: Maybe P.SourceSpan
85 , declSourceSpan :: Maybe P.SourceSpan
87 , declChildren :: [ChildDeclaration]
86 , declChildren :: [ChildDeclaration]
88 , declInfo :: DeclarationInfo
87 , declInfo :: DeclarationInfo
@@ -109,7 +108,7 @@ data DeclarationInfo
109 -- newtype) and its type arguments. Constructors are represented as child
108 -- newtype) and its type arguments. Constructors are represented as child
110 -- declarations.
109 -- declarations.
112− | DataDeclaration P.DataDeclType [(String, Maybe P.Kind)]
111+ | DataDeclaration P.DataDeclType [(Text, Maybe P.Kind)]
115 -- A data type foreign import, with its kind.
114 -- A data type foreign import, with its kind.
@@ -119,13 +118,13 @@ data DeclarationInfo
120 -- A type synonym, with its type arguments and its type.
119 -- A type synonym, with its type arguments and its type.
122− | TypeSynonymDeclaration [(String, Maybe P.Kind)] P.Type
121+ | TypeSynonymDeclaration [(Text, Maybe P.Kind)] P.Type
125 -- A type class, with its type arguments, its superclasses and functional
124 -- A type class, with its type arguments, its superclasses and functional
126 -- dependencies. Instances and members are represented as child declarations.
125 -- dependencies. Instances and members are represented as child declarations.
128− | TypeClassDeclaration [(String, Maybe P.Kind)] [P.Constraint] [([String], [String])]
127+ | TypeClassDeclaration [(Text, Maybe P.Kind)] [P.Constraint] [([Text], [Text])]
131 -- An operator alias declaration, with the member the alias is for and the
130 -- An operator alias declaration, with the member the alias is for and the
@@ -134,14 +133,13 @@ data DeclarationInfo
134 | AliasDeclaration P.Fixity FixityAlias
133 | AliasDeclaration P.Fixity FixityAlias
135 deriving (Show, Eq, Ord)
134 deriving (Show, Eq, Ord)
137−convertFundepsToStrings :: [(Text, Maybe P.Kind)] -> [P.FunctionalDependency] -> [([String], [String])]
136+convertFundepsToStrings :: [(Text, Maybe P.Kind)] -> [P.FunctionalDependency] -> [([Text], [Text])]
138convertFundepsToStrings args fundeps =
137convertFundepsToStrings args fundeps =
139− map (bimap (map T.unpack) (map T.unpack)) fundeps'
138+ map (\(P.FunctionalDependency from to) -> toArgs from to) fundeps
141− fundeps' = map (\(P.FunctionalDependency from to) -> toArgs from to) fundeps
142 argsVec = V.fromList (map fst args)
140 argsVec = V.fromList (map fst args)
143 getArg i =
141 getArg i =
145 (P.internalError $ unlines
143 (P.internalError $ unlines
146 [ "convertDeclaration: Functional dependency index"
144 [ "convertDeclaration: Functional dependency index"
@@ -150,12 +148,12 @@ convertFundepsToStrings args fundeps =
150 , "Functional dependencies are"
148 , "Functional dependencies are"
151 , show fundeps
149 , show fundeps
153− ) id $ argsVec V.!? i
151+ ) $ argsVec V.!? i
154 toArgs from to = (map getArg from, map getArg to)
152 toArgs from to = (map getArg from, map getArg to)
156type FixityAlias = P.Qualified (Either (P.ProperName 'P.TypeName) (Either P.Ident (P.ProperName 'P.ConstructorName)))
154type FixityAlias = P.Qualified (Either (P.ProperName 'P.TypeName) (Either P.Ident (P.ProperName 'P.ConstructorName)))
158−declInfoToString :: DeclarationInfo -> String
156+declInfoToString :: DeclarationInfo -> Text
159declInfoToString (ValueDeclaration _) = "value"
157declInfoToString (ValueDeclaration _) = "value"
160declInfoToString (DataDeclaration _ _) = "data"
158declInfoToString (DataDeclaration _ _) = "data"
161declInfoToString (ExternDataDeclaration _) = "externData"
159declInfoToString (ExternDataDeclaration _) = "externData"
@@ -201,8 +199,8 @@ filterChildren p decl =
201 decl { declChildren = filter p (declChildren decl) }
199 decl { declChildren = filter p (declChildren decl) }
203data ChildDeclaration = ChildDeclaration
201data ChildDeclaration = ChildDeclaration
204− { cdeclTitle :: String
202+ { cdeclTitle :: Text
205− , cdeclComments :: Maybe String
203+ , cdeclComments :: Maybe Text
206 , cdeclSourceSpan :: Maybe P.SourceSpan
204 , cdeclSourceSpan :: Maybe P.SourceSpan
207 , cdeclInfo :: ChildDeclarationInfo
205 , cdeclInfo :: ChildDeclarationInfo
@@ -227,7 +225,7 @@ data ChildDeclarationInfo
227 | ChildTypeClassMember P.Type
225 | ChildTypeClassMember P.Type
228 deriving (Show, Eq, Ord)
226 deriving (Show, Eq, Ord)
230−childDeclInfoToString :: ChildDeclarationInfo -> String
228+childDeclInfoToString :: ChildDeclarationInfo -> Text
231childDeclInfoToString (ChildInstance _ _) = "instance"
229childDeclInfoToString (ChildInstance _ _) = "instance"
232childDeclInfoToString (ChildDataConstructor _) = "dataConstructor"
230childDeclInfoToString (ChildDataConstructor _) = "dataConstructor"
233childDeclInfoToString (ChildTypeClassMember _) = "typeClassMember"
231childDeclInfoToString (ChildTypeClassMember _) = "typeClassMember"
@@ -245,11 +243,11 @@ isDataConstructor ChildDeclaration{..} =
245 _ -> False
243 _ -> False
247newtype GithubUser
245newtype GithubUser
248− = GithubUser { runGithubUser :: String }
246+ = GithubUser { runGithubUser :: Text }
249 deriving (Show, Eq, Ord)
247 deriving (Show, Eq, Ord)
251newtype GithubRepo
249newtype GithubRepo
252− = GithubRepo { runGithubRepo :: String }
250+ = GithubRepo { runGithubRepo :: Text }
253 deriving (Show, Eq, Ord)
251 deriving (Show, Eq, Ord)
255data PackageError
253data PackageError
@@ -258,14 +256,14 @@ data PackageError
258 -- parser, and actual version used.
256 -- parser, and actual version used.
259 | ErrorInPackageMeta BowerError
257 | ErrorInPackageMeta BowerError
260 | InvalidVersion
258 | InvalidVersion
261− | InvalidDeclarationType String
259+ | InvalidDeclarationType Text
262− | InvalidChildDeclarationType String
260+ | InvalidChildDeclarationType Text
263 | InvalidFixity
261 | InvalidFixity
264− | InvalidKind String
262+ | InvalidKind Text
265− | InvalidDataDeclType String
263+ | InvalidDataDeclType Text
266 deriving (Show, Eq, Ord)
264 deriving (Show, Eq, Ord)
268−type Bookmark = InPackage (P.ModuleName, String)
266+type Bookmark = InPackage (P.ModuleName, Text)
270data InPackage a
268data InPackage a
271 = Local a
269 = Local a
@@ -307,7 +305,7 @@ asPackage minimumVersion uploader = do
308 Package <$> key "packageMeta" asPackageMeta .! ErrorInPackageMeta
306 Package <$> key "packageMeta" asPackageMeta .! ErrorInPackageMeta
309 <*> key "version" asVersion
307 <*> key "version" asVersion
310− <*> key "versionTag" asString
308+ <*> key "versionTag" asText
311 <*> key "modules" (eachInArray asModule)
309 <*> key "modules" (eachInArray asModule)
312 <*> key "bookmarks" asBookmarks .! ErrorInPackageMeta
310 <*> key "bookmarks" asBookmarks .! ErrorInPackageMeta
313 <*> key "resolvedDependencies" asResolvedDependencies
311 <*> key "resolvedDependencies" asResolvedDependencies
@@ -338,15 +336,15 @@ displayPackageError e = case e of
338 InvalidVersion ->
336 InvalidVersion ->
339 "Invalid version"
337 "Invalid version"
340 InvalidDeclarationType str ->
338 InvalidDeclarationType str ->
341− "Invalid declaration type: \"" <> T.pack str <> "\""
339+ "Invalid declaration type: \"" <> str <> "\""
342 InvalidChildDeclarationType str ->
340 InvalidChildDeclarationType str ->
343− "Invalid child declaration type: \"" <> T.pack str <> "\""
341+ "Invalid child declaration type: \"" <> str <> "\""
344 InvalidFixity ->
342 InvalidFixity ->
345 "Invalid fixity"
343 "Invalid fixity"
346 InvalidKind str ->
344 InvalidKind str ->
347− "Invalid kind: \"" <> T.pack str <> "\""
345+ "Invalid kind: \"" <> str <> "\""
348 InvalidDataDeclType str ->
346 InvalidDataDeclType str ->
349− "Invalid data declaration type: \"" <> T.pack str <> "\""
347+ "Invalid data declaration type: \"" <> str <> "\""
351 (<>) = T.append
349 (<>) = T.append
@@ -355,7 +353,7 @@ instance A.FromJSON a => A.FromJSON (Package a) where
355 (asPackage (Version [0,0,0,0] []) fromAesonParser)
353 (asPackage (Version [0,0,0,0] []) fromAesonParser)
357asGithubUser :: Parse e GithubUser
355asGithubUser :: Parse e GithubUser
358−asGithubUser = GithubUser <$> asString
356+asGithubUser = GithubUser <$> asText
360instance A.FromJSON GithubUser where
358instance A.FromJSON GithubUser where
361 parseJSON = toAesonParser' asGithubUser
359 parseJSON = toAesonParser' asGithubUser
@@ -372,14 +370,14 @@ parseVersion' str =
372asModule :: Parse PackageError Module
370asModule :: Parse PackageError Module
373asModule =
371asModule =
374 Module <$> key "name" (P.moduleNameFromString <$> asText)
372 Module <$> key "name" (P.moduleNameFromString <$> asText)
375− <*> key "comments" (perhaps asString)
373+ <*> key "comments" (perhaps asText)
376 <*> key "declarations" (eachInArray asDeclaration)
374 <*> key "declarations" (eachInArray asDeclaration)
377 <*> key "reExports" (eachInArray asReExport)
375 <*> key "reExports" (eachInArray asReExport)
379asDeclaration :: Parse PackageError Declaration
377asDeclaration :: Parse PackageError Declaration
380asDeclaration =
378asDeclaration =
381− Declaration <$> key "title" asString
379+ Declaration <$> key "title" asText
382− <*> key "comments" (perhaps asString)
380+ <*> key "comments" (perhaps asText)
383 <*> key "sourceSpan" (perhaps asSourceSpan)
381 <*> key "sourceSpan" (perhaps asSourceSpan)
384 <*> key "children" (eachInArray asChildDeclaration)
382 <*> key "children" (eachInArray asChildDeclaration)
385 <*> key "info" asDeclarationInfo
383 <*> key "info" asDeclarationInfo
@@ -417,7 +415,7 @@ asAssociativity = withString (maybe (Left InvalidFixity) Right . parseAssociativ
418asDeclarationInfo :: Parse PackageError DeclarationInfo
416asDeclarationInfo :: Parse PackageError DeclarationInfo
419asDeclarationInfo = do
417asDeclarationInfo = do
420− ty <- key "declType" asString
418+ ty <- key "declType" asText
421 case ty of
419 case ty of
422 "value" ->
420 "value" ->
423 ValueDeclaration <$> key "type" asType
421 ValueDeclaration <$> key "type" asType
@@ -439,10 +437,10 @@ asDeclarationInfo = do
440 throwCustomError (InvalidDeclarationType other)
438 throwCustomError (InvalidDeclarationType other)
442−asTypeArguments :: Parse PackageError [(String, Maybe P.Kind)]
440+asTypeArguments :: Parse PackageError [(Text, Maybe P.Kind)]
443asTypeArguments = eachInArray asTypeArgument
441asTypeArguments = eachInArray asTypeArgument
445− asTypeArgument = (,) <$> nth 0 asString <*> nth 1 (perhaps asKind)
443+ asTypeArgument = (,) <$> nth 0 asText <*> nth 1 (perhaps asKind)
447asKind :: Parse e P.Kind
445asKind :: Parse e P.Kind
448asKind = fromAesonParser
446asKind = fromAesonParser
@@ -450,28 +448,28 @@ asKind = fromAesonParser
450asType :: Parse e P.Type
448asType :: Parse e P.Type
451asType = fromAesonParser
449asType = fromAesonParser
453−asFunDeps :: Parse PackageError [([String], [String])]
451+asFunDeps :: Parse PackageError [([Text], [Text])]
454asFunDeps = eachInArray asFunDep
452asFunDeps = eachInArray asFunDep
456− asFunDep = (,) <$> nth 0 (eachInArray asString) <*> nth 1 (eachInArray asString)
454+ asFunDep = (,) <$> nth 0 (eachInArray asText) <*> nth 1 (eachInArray asText)
458asDataDeclType :: Parse PackageError P.DataDeclType
456asDataDeclType :: Parse PackageError P.DataDeclType
459asDataDeclType =
457asDataDeclType =
460− withString $ \s -> case s of
458+ withText $ \s -> case s of
461 "data" -> Right P.Data
459 "data" -> Right P.Data
462 "newtype" -> Right P.Newtype
460 "newtype" -> Right P.Newtype
463 other -> Left (InvalidDataDeclType other)
461 other -> Left (InvalidDataDeclType other)
465asChildDeclaration :: Parse PackageError ChildDeclaration
463asChildDeclaration :: Parse PackageError ChildDeclaration
466asChildDeclaration =
464asChildDeclaration =
467− ChildDeclaration <$> key "title" asString
465+ ChildDeclaration <$> key "title" asText
468− <*> key "comments" (perhaps asString)
466+ <*> key "comments" (perhaps asText)
469 <*> key "sourceSpan" (perhaps asSourceSpan)
467 <*> key "sourceSpan" (perhaps asSourceSpan)
470 <*> key "info" asChildDeclarationInfo
468 <*> key "info" asChildDeclarationInfo
472asChildDeclarationInfo :: Parse PackageError ChildDeclarationInfo
470asChildDeclarationInfo :: Parse PackageError ChildDeclarationInfo
473asChildDeclarationInfo = do
471asChildDeclarationInfo = do
474− ty <- key "declType" asString
472+ ty <- key "declType" asText
475 case ty of
473 case ty of
476 "instance" ->
474 "instance" ->
477 ChildInstance <$> key "dependencies" (eachInArray asConstraint)
475 ChildInstance <$> key "dependencies" (eachInArray asConstraint)
@@ -504,7 +502,7 @@ asBookmarks = eachInArray asBookmark
504asBookmark :: Parse BowerError Bookmark
502asBookmark :: Parse BowerError Bookmark
505asBookmark =
503asBookmark =
506 asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asText)
504 asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asText)
507− <*> nth 1 asString)
505+ <*> nth 1 asText)
509asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
507asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
510asResolvedDependencies =
508asResolvedDependencies =
@@ -514,8 +512,8 @@ asResolvedDependencies =
514 mapLeft _ (Right x) = Right x
512 mapLeft _ (Right x) = Right x
516asGithub :: Parse e (GithubUser, GithubRepo)
514asGithub :: Parse e (GithubUser, GithubRepo)
517−asGithub = (,) <$> nth 0 (GithubUser <$> asString)
515+asGithub = (,) <$> nth 0 (GithubUser <$> asText)
518− <*> nth 1 (GithubRepo <$> asString)
516+ <*> nth 1 (GithubRepo <$> asText)
520asSourceSpan :: Parse e P.SourceSpan
518asSourceSpan :: Parse e P.SourceSpan
521asSourceSpan = P.SourceSpan <$> key "name" asString
519asSourceSpan = P.SourceSpan <$> key "name" asString