git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' into 0.10.4-untested
commit0f8fc03a6eb7ae74bd12be416f4d06a32daae704 authorAndy Arvanitis <andyarvanitis@gmail.com> dateTue 3 Jan 2017, 21:32 (10 years ago) parent7088118068a019
9 files changed+96−30
purescript.cabal+1−1 src/Language/PureScript/Docs/Types.hs+6−7 src/Language/PureScript/Errors.hs+2 src/Language/PureScript/Kinds.hs+66−4 src/Language/PureScript/Publish.hs+6−7 src/Language/PureScript/Publish/BoxesHelpers.hs+5 src/Language/PureScript/Publish/ErrorsWarnings.hs+7−7 stack-ghc-8.0.yaml+1 stack.yaml+2−4
purescript.cabal+1−1
@@ -121,7 +121,7 @@ library
121121 aeson-better-errors >= 0.8,
122122 ansi-terminal >= 0.6.2 && < 0.7,
123123 base-compat >=0.6.0,
124− bower-json >= 0.8,
124+ bower-json >= 1.0.0.1 && < 1.1,
125125 boxes >= 0.1.4 && < 0.2.0,
126126 bytestring -any,
127127 containers -any,
src/Language/PureScript/Docs/Types.hs+6−7
@@ -10,6 +10,7 @@ import Control.Arrow (first, (***))
1010import Control.Monad (when)
1111import Control.Monad.Error.Class (catchError)
1212
13+import Data.Monoid ((<>))
1314import Data.Aeson ((.=))
1415import Data.Aeson.BetterErrors
1516import Data.ByteString.Lazy (ByteString)
@@ -358,8 +359,6 @@ displayPackageError e = case e of
358359 "Invalid kind: \"" <> str <> "\""
359360 InvalidDataDeclType str ->
360361 "Invalid data declaration type: \"" <> str <> "\""
361− where
362− (<>) = T.append
363362
364363instance A.FromJSON a => A.FromJSON (Package a) where
365364 parseJSON = toAesonParser displayPackageError
@@ -413,7 +412,7 @@ asReExport =
413412
414413asInPackage :: Parse BowerError a -> Parse BowerError (InPackage a)
415414asInPackage inner =
416− build <$> key "package" (perhaps (withString parsePackageName))
415+ build <$> key "package" (perhaps (withText parsePackageName))
417416 <*> key "item" inner
418417 where
419418 build Nothing = Local
@@ -468,8 +467,8 @@ asTypeArguments = eachInArray asTypeArgument
468467 where
469468 asTypeArgument = (,) <$> nth 0 asText <*> nth 1 (perhaps asKind)
470469
471−asKind :: Parse e P.Kind
472−asKind = fromAesonParser
470+asKind :: Parse PackageError P.Kind
471+asKind = P.kindFromJSON .! InvalidKind
473472
474473asType :: Parse e P.Type
475474asType = fromAesonParser
@@ -532,7 +531,7 @@ asBookmark =
532531
533532asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
534533asResolvedDependencies =
535− eachInObjectWithKey (mapLeft ErrorInPackageMeta . parsePackageName . T.unpack) asVersion
534+ eachInObjectWithKey (mapLeft ErrorInPackageMeta . parsePackageName) asVersion
536535 where
537536 mapLeft f (Left x) = Left (f x)
538537 mapLeft _ (Right x) = Right x
@@ -557,7 +556,7 @@ instance A.ToJSON a => A.ToJSON (Package a) where
557556 , "versionTag" .= pkgVersionTag
558557 , "modules" .= pkgModules
559558 , "bookmarks" .= map (fmap (first P.runModuleName)) pkgBookmarks
560− , "resolvedDependencies" .= assocListToJSON (T.pack . runPackageName)
559+ , "resolvedDependencies" .= assocListToJSON runPackageName
561560 (T.pack . showVersion)
562561 pkgResolvedDependencies
563562 , "github" .= pkgGithub
src/Language/PureScript/Errors.hs+2
@@ -498,6 +498,8 @@ prettyPrintSingleError (PPEOptions codeColor full level showDocs) e = flip evalS
498498 line $ "The type declaration for " <> markCode (showIdent nm) <> " should be followed by its definition."
499499 renderSimpleErrorMessage (RedefinedIdent name) =
500500 line $ "The value " <> markCode (showIdent name) <> " has been defined multiple times"
501+ renderSimpleErrorMessage (UnknownName name@(Qualified Nothing (IdentName (Ident "bind")))) =
502+ line $ "Unknown " <> printName name <> ". You're probably using do-notation, which the compiler replaces with calls to the " <> markCode "bind" <> " function. Please import " <> markCode "bind" <> " from module " <> markCode "Prelude"
501503 renderSimpleErrorMessage (UnknownName name) =
502504 line $ "Unknown " <> printName name
503505 renderSimpleErrorMessage (UnknownImport mn name) =
src/Language/PureScript/Kinds.hs+66−4
@@ -1,12 +1,15 @@
1−{-# LANGUAGE TemplateHaskell #-}
2−
31module Language.PureScript.Kinds where
42
53import Prelude.Compat
64
7−import qualified Data.Aeson.TH as A
5+import Data.Text (Text)
6+import qualified Data.Text as T
7+import Data.Aeson.BetterErrors (Parse, key, asText, asIntegral, nth, fromAesonParser, toAesonParser, throwCustomError)
8+import Data.Aeson ((.=))
9+import qualified Data.Aeson as A
810
911import Language.PureScript.Names
12+import qualified Language.PureScript.Constants as C
1013
1114-- | The data type of kinds
1215data Kind
@@ -20,7 +23,66 @@ data Kind
2023 | NamedKind (Qualified (ProperName 'KindName))
2124 deriving (Show, Eq, Ord)
2225
23−$(A.deriveJSON A.defaultOptions ''Kind)
26+-- This is equivalent to the derived Aeson ToJSON instance, except that we
27+-- write it out manually so that we can define a parser which is
28+-- backwards-compatible.
29+instance A.ToJSON Kind where
30+ toJSON kind = case kind of
31+ KUnknown i ->
32+ obj "KUnknown" i
33+ Row k ->
34+ obj "Row" k
35+ FunKind k1 k2 ->
36+ obj "FunKind" [k1, k2]
37+ NamedKind n ->
38+ obj "NamedKind" n
39+ where
40+ obj :: A.ToJSON a => Text -> a -> A.Value
41+ obj tag contents =
42+ A.object [ "tag" .= tag, "contents" .= contents ]
43+
44+-- This is equivalent to the derived Aeson FromJSON instance, except that it
45+-- also handles JSON generated by compilers up to 0.10.3 and maps them to the
46+-- new representations (i.e. NamedKinds which are defined in the Prim module).
47+kindFromJSON :: Parse Text Kind
48+kindFromJSON = do
49+ t <- key "tag" asText
50+ case t of
51+ "KUnknown" ->
52+ KUnknown <$> key "contents" (nth 0 asIntegral)
53+ "Star" ->
54+ pure kindType
55+ "Bang" ->
56+ pure kindEffect
57+ "Row" ->
58+ Row <$> key "contents" kindFromJSON
59+ "FunKind" ->
60+ let
61+ kindAt n = key "contents" (nth n kindFromJSON)
62+ in
63+ FunKind <$> kindAt 0 <*> kindAt 1
64+ "Symbol" ->
65+ pure kindSymbol
66+ "NamedKind" ->
67+ NamedKind <$> key "contents" fromAesonParser
68+ other ->
69+ throwCustomError (T.append "Unrecognised tag: " other)
70+
71+ where
72+ -- The following are copied from Environment and reimplemented to avoid
73+ -- circular dependencies.
74+ primName :: Text -> Qualified (ProperName a)
75+ primName = Qualified (Just $ ModuleName [ProperName C.prim]) . ProperName
76+
77+ primKind :: Text -> Kind
78+ primKind = NamedKind . primName
79+
80+ kindType = primKind "Type"
81+ kindEffect = primKind "Effect"
82+ kindSymbol = primKind "Symbol"
83+
84+instance A.FromJSON Kind where
85+ parseJSON = toAesonParser id kindFromJSON
2486
2587everywhereOnKinds :: (Kind -> Kind) -> Kind -> Kind
2688everywhereOnKinds f = go
src/Language/PureScript/Publish.hs+6−7
@@ -209,7 +209,7 @@ getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExt
209209 Just Repository{..} -> do
210210 unless (repositoryType == "git")
211211 (Left (BadRepositoryType repositoryType))
212− maybe (Left NotOnGithub) Right (extractGithub (T.pack repositoryUrl))
212+ maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
213213
214214checkLicense :: PackageMeta -> PrepareM ()
215215checkLicense pkgMeta =
@@ -217,7 +217,7 @@ checkLicense pkgMeta =
217217 [] ->
218218 userError NoLicenseSpecified
219219 ls ->
220− unless (any isValidSPDX ls)
220+ unless (any (isValidSPDX . T.unpack) ls)
221221 (userError InvalidLicense)
222222
223223-- |
@@ -320,8 +320,7 @@ asResolvedDependencies = nubBy ((==) `on` fst) <$> go
320320 go =
321321 fmap (fromMaybe []) $
322322 keyMay "dependencies" $
323− (++) <$> eachInObjectWithKey (parsePackageName . T.unpack)
324− asDependencyStatus
323+ (++) <$> eachInObjectWithKey parsePackageName asDependencyStatus
325324 <*> (concatMap snd <$> eachInObject asResolvedDependencies)
326325
327326-- | Extracts only the top level dependency names from the output of
@@ -330,7 +329,7 @@ asToplevelDependencies :: Parse BowerError [PackageName]
330329asToplevelDependencies =
331330 fmap (map fst) $
332331 key "dependencies" $
333− eachInObjectWithKey (parsePackageName . T.unpack) (return ())
332+ eachInObjectWithKey parsePackageName (return ())
334333
335334asDependencyStatus :: Parse e DependencyStatus
336335asDependencyStatus = do
@@ -371,7 +370,7 @@ handleDeps deps = do
371370 ResolvedOther _ -> (ms, pkgName : os, is)
372371 ResolvedVersion v -> (ms, os, (pkgName, v) : is)
373372
374− bowerDir pkgName = "bower_components/" ++ runPackageName pkgName
373+ bowerDir pkgName = T.unpack $ "bower_components/" <> runPackageName pkgName
375374
376375 -- Try to extract a version, and warn if unsuccessful.
377376 tryExtractVersion' :: (PackageName, Text) -> PrepareM (Maybe (PackageName, Version))
@@ -406,6 +405,6 @@ getPackageName fp = do
406405 let xs = splitOn [pathSeparator] fp
407406 ys <- stripPrefix ["bower_components"] xs
408407 y <- headMay ys
409− case Bower.mkPackageName y of
408+ case Bower.mkPackageName (T.pack y) of
410409 Right name -> Just name
411410 Left _ -> Nothing
src/Language/PureScript/Publish/BoxesHelpers.hs+5
@@ -6,6 +6,8 @@ module Language.PureScript.Publish.BoxesHelpers
66
77import Prelude.Compat
88
9+import Data.Text (Text)
10+import qualified Data.Text as T
911import System.IO (hPutStr, stderr)
1012
1113import qualified Text.PrettyPrint.Boxes as Boxes
@@ -37,6 +39,9 @@ spacer = Boxes.emptyBox 1 1
3739bulletedList :: (a -> String) -> [a] -> [Boxes.Box]
3840bulletedList f = map (indented . para . ("* " ++) . f)
3941
42+bulletedListT :: (a -> Text) -> [a] -> [Boxes.Box]
43+bulletedListT f = bulletedList (T.unpack . f)
44+
4045printToStderr :: Boxes.Box -> IO ()
4146printToStderr = hPutStr stderr . Boxes.render
4247
src/Language/PureScript/Publish/ErrorsWarnings.hs+7−7
@@ -65,7 +65,7 @@ data UserError
6565
6666data RepositoryFieldError
6767 = RepositoryFieldMissing
68− | BadRepositoryType String
68+ | BadRepositoryType Text
6969 | NotOnGithub
7070 deriving (Show)
7171
@@ -213,7 +213,7 @@ displayUserError e = case e of
213213 , "installed:"
214214 ])
215215 ] ++
216− bulletedList runPackageName (NonEmpty.toList pkgs)
216+ bulletedListT runPackageName (NonEmpty.toList pkgs)
217217 ++
218218 [ spacer
219219 , para (concat
@@ -263,7 +263,7 @@ displayRepositoryError err = case err of
263263 BadRepositoryType ty ->
264264 para (concat
265265 [ "In your bower.json file, the repository type is currently listed as "
266− , "\"" ++ ty ++ "\". Currently, only git repositories are supported. "
266+ , "\"" ++ T.unpack ty ++ "\". Currently, only git repositories are supported. "
267267 , "Please publish your code in a git repository, and then update the "
268268 , "repository type in your bower.json file to \"git\"."
269269 ])
@@ -361,7 +361,7 @@ warnNoResolvedVersions pkgNames =
361361 ["The following ", packages, " did not appear to have a resolved "
362362 , "version:"])
363363 ] ++
364− bulletedList runPackageName (NonEmpty.toList pkgNames)
364+ bulletedListT runPackageName (NonEmpty.toList pkgNames)
365365 ++
366366 [ spacer
367367 , para (concat
@@ -385,7 +385,7 @@ warnUndeclaredDependencies pkgNames =
385385 [ "The following Bower ", packages, " ", are, " installed, but not "
386386 , "declared as ", dependencies, " in your bower.json file:"
387387 ])
388− : bulletedList runPackageName (NonEmpty.toList pkgNames)
388+ : bulletedListT runPackageName (NonEmpty.toList pkgNames)
389389
390390warnUnacceptableVersions :: NonEmpty (PackageName, Text) -> Box
391391warnUnacceptableVersions pkgs =
@@ -403,7 +403,7 @@ warnUnacceptableVersions pkgs =
403403 , "not be parsed:"
404404 ])
405405 ] ++
406− bulletedList showTuple (NonEmpty.toList pkgs)
406+ bulletedListT showTuple (NonEmpty.toList pkgs)
407407 ++
408408 [ spacer
409409 , para (concat
@@ -414,7 +414,7 @@ warnUnacceptableVersions pkgs =
414414 ])
415415 ]
416416 where
417− showTuple (pkgName, tag) = runPackageName pkgName ++ "#" ++ T.unpack tag
417+ showTuple (pkgName, tag) = runPackageName pkgName <> "#" <> tag
418418
419419warnDirtyWorkingTree :: Box
420420warnDirtyWorkingTree =
stack-ghc-8.0.yaml+1
@@ -5,3 +5,4 @@ extra-deps:
55- pipes-http-1.0.2
66- wai-websockets-3.0.0.9
77- websockets-0.9.6.2
8+- bower-json-1.0.0.1
stack.yaml+2−4
@@ -1,7 +1,5 @@
1−resolver: lts-7.9
1+resolver: lts-6.25
22packages:
33- '.'
44extra-deps:
5−- pipes-http-1.0.2
6−- wai-websockets-3.0.0.9
7−- websockets-0.9.6.2
5+- bower-json-1.0.0.1