generated from tpl/purs
Merge pull request #9 from archaeron/upgrade-ps-0.14
Upgrade for PureScript 0.14
This commit is contained in:
commit
627d1f3e95
56
package-lock.json
generated
56
package-lock.json
generated
@ -1,34 +1,46 @@
|
|||||||
{
|
{
|
||||||
"name": "purescript-yaml-next",
|
"name": "purescript-yaml-next",
|
||||||
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"lockfileVersion": 1,
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "SEE LICENSE FILE",
|
||||||
|
"dependencies": {
|
||||||
|
"js-yaml": "^4.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {}
|
||||||
|
},
|
||||||
|
"node_modules/argparse": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
|
||||||
|
},
|
||||||
|
"node_modules/js-yaml": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"argparse": "^2.0.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"js-yaml": "bin/js-yaml.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"argparse": {
|
"argparse": {
|
||||||
"version": "1.0.10",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||||
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
|
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
|
||||||
"requires": {
|
|
||||||
"sprintf-js": "~1.0.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"esprima": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
|
||||||
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
|
|
||||||
},
|
},
|
||||||
"js-yaml": {
|
"js-yaml": {
|
||||||
"version": "3.13.1",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.0.0.tgz",
|
||||||
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
|
"integrity": "sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"argparse": "^1.0.7",
|
"argparse": "^2.0.1"
|
||||||
"esprima": "^4.0.0"
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"sprintf-js": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
|
|
||||||
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,11 @@
|
|||||||
"contributors": [],
|
"contributors": [],
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"test": "spago test",
|
||||||
"postinstall": "spago build"
|
"postinstall": "spago build"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-yaml": "^3.13.1"
|
"js-yaml": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
let upstream =
|
let upstream =
|
||||||
https://github.com/purescript/package-sets/releases/download/psc-0.13.3-20191005/packages.dhall sha256:ba287d858ada09c4164792ad4e643013b742c208cbedf5de2e35ee27b64b6817
|
https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210317/packages.dhall sha256:e2e744972f9b60188dcf07f41418661b505c9ee2e9f91e57e67daefad3a5ae09
|
||||||
|
|
||||||
let overrides = {=}
|
let overrides = {=}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
, "console"
|
, "console"
|
||||||
, "effect"
|
, "effect"
|
||||||
, "foreign"
|
, "foreign"
|
||||||
, "foreign-generic"
|
|
||||||
, "functions"
|
, "functions"
|
||||||
, "ordered-collections"
|
, "ordered-collections"
|
||||||
, "psci-support"
|
, "psci-support"
|
||||||
|
@ -4,7 +4,7 @@ var yaml = require('js-yaml');
|
|||||||
|
|
||||||
exports.parseYAMLImpl = function(left, right, str) {
|
exports.parseYAMLImpl = function(left, right, str) {
|
||||||
try {
|
try {
|
||||||
return right(yaml.safeLoad(str));
|
return right(yaml.load(str));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return left(e.toString());
|
return left(e.toString());
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,23 @@
|
|||||||
module Data.YAML.Foreign.Decode (
|
module Data.YAML.Foreign.Decode (parseYAMLToJson)
|
||||||
readYAMLGeneric,
|
where
|
||||||
parseYAMLToJson
|
|
||||||
) where
|
|
||||||
|
|
||||||
import Foreign (F, Foreign, ForeignError(..), fail)
|
import Foreign (F, Foreign, ForeignError(..), fail)
|
||||||
import Foreign.Generic (genericDecode)
|
|
||||||
import Foreign.Generic.Class (class GenericDecode, Options)
|
|
||||||
import Data.Function.Uncurried (Fn3, runFn3)
|
import Data.Function.Uncurried (Fn3, runFn3)
|
||||||
import Data.Generic.Rep (class Generic)
|
import Prelude (pure, (<<<), (>>=))
|
||||||
import Prelude ((>=>), (<<<), pure, (>>=))
|
|
||||||
import Unsafe.Coerce (unsafeCoerce)
|
import Unsafe.Coerce (unsafeCoerce)
|
||||||
import Data.Argonaut.Core (Json)
|
import Data.Argonaut.Core (Json)
|
||||||
|
|
||||||
foreign import parseYAMLImpl :: forall r. Fn3 (String -> r) (Foreign -> r) String r
|
foreign import parseYAMLImpl :: forall r.
|
||||||
|
Fn3 (String -> r) (Foreign -> r) String r
|
||||||
|
|
||||||
|
|
||||||
-- | Attempt to parse a YAML string, returning the result as foreign data.
|
-- | Attempt to parse a YAML string, returning the result as foreign data.
|
||||||
parseYAML :: String -> F Foreign
|
parseYAML :: String -> F Foreign
|
||||||
parseYAML yaml = runFn3 parseYAMLImpl (fail <<< ForeignError) pure yaml
|
parseYAML yaml =
|
||||||
|
runFn3 parseYAMLImpl (fail <<< ForeignError) pure yaml
|
||||||
|
|
||||||
|
|
||||||
-- | Attempt to parse a YAML string, returning the result as Json
|
-- | Attempt to parse a YAML string, returning the result as Json
|
||||||
parseYAMLToJson :: String -> F Json
|
parseYAMLToJson :: String -> F Json
|
||||||
parseYAMLToJson yaml = parseYAML yaml >>= pure <<< unsafeCoerce
|
parseYAMLToJson yaml =
|
||||||
|
parseYAML yaml >>= pure <<< unsafeCoerce
|
||||||
-- | Automatically generate a YAML parser for your data from a generic instance.
|
|
||||||
readYAMLGeneric :: forall a rep. (Generic a rep) => (GenericDecode rep) => Options -> String -> F a
|
|
||||||
readYAMLGeneric opts = parseYAML >=> genericDecode opts
|
|
||||||
|
@ -14,5 +14,5 @@ exports.objToHash = function(valueToYAMLImpl, fst, snd, obj) {
|
|||||||
|
|
||||||
exports.toYAMLImpl = function(a) {
|
exports.toYAMLImpl = function(a) {
|
||||||
// noCompatMode does not support YAML 1.1
|
// noCompatMode does not support YAML 1.1
|
||||||
return yaml.safeDump(a, {noCompatMode : true});
|
return yaml.dump(a, {noCompatMode : true});
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
module Test.Instances where
|
module Test.Instances where
|
||||||
|
|
||||||
import Data.YAML.Foreign.Encode
|
import Data.YAML.Foreign.Encode
|
||||||
import Data.Argonaut.Core (toObject, toString)
|
import Data.Argonaut.Decode (decodeJson)
|
||||||
import Data.Argonaut.Decode.Combinators (getField)
|
import Data.Argonaut.Decode.Combinators (getField)
|
||||||
import Data.Argonaut.Decode.Class (class DecodeJson)
|
import Data.Argonaut.Decode.Class (class DecodeJson)
|
||||||
|
import Data.Argonaut.Decode.Error (JsonDecodeError(TypeMismatch))
|
||||||
import Data.Either (Either(..))
|
import Data.Either (Either(..))
|
||||||
import Data.Generic.Rep (class Generic)
|
import Data.Generic.Rep (class Generic)
|
||||||
import Data.Generic.Rep.Eq (genericEq)
|
import Data.Eq.Generic (genericEq)
|
||||||
import Data.Generic.Rep.Show (genericShow)
|
import Data.Show.Generic (genericShow)
|
||||||
import Data.Maybe (maybe)
|
|
||||||
import Prelude (class Eq, class Show, bind, pure, ($))
|
import Prelude (class Eq, class Show, bind, pure, ($))
|
||||||
|
|
||||||
data Point = Point Int Int
|
data Point = Point Int Int
|
||||||
@ -38,8 +38,8 @@ instance showMobility :: Show Mobility where show = genericShow
|
|||||||
instance eqMobility :: Eq Mobility where eq = genericEq
|
instance eqMobility :: Eq Mobility where eq = genericEq
|
||||||
|
|
||||||
instance geoJson :: DecodeJson GeoObject where
|
instance geoJson :: DecodeJson GeoObject where
|
||||||
decodeJson s = do
|
decodeJson json = do
|
||||||
obj <- maybe (Left "GeoObject is not an object.") Right (toObject s)
|
obj <- decodeJson json
|
||||||
name <- getField obj "Name"
|
name <- getField obj "Name"
|
||||||
scale <- getField obj "Scale"
|
scale <- getField obj "Scale"
|
||||||
points <- getField obj "Points"
|
points <- getField obj "Points"
|
||||||
@ -48,16 +48,17 @@ instance geoJson :: DecodeJson GeoObject where
|
|||||||
pure $ GeoObject { name, scale, points, mobility, coverage }
|
pure $ GeoObject { name, scale, points, mobility, coverage }
|
||||||
|
|
||||||
instance mobilityJson :: DecodeJson Mobility where
|
instance mobilityJson :: DecodeJson Mobility where
|
||||||
decodeJson s = do
|
decodeJson json = do
|
||||||
mob <- maybe (Left "Mobility is not a string.") Right (toString s)
|
mob <- decodeJson json
|
||||||
case mob of
|
case mob of
|
||||||
"Fix" -> pure Fix
|
"Fix" -> pure Fix
|
||||||
"Flex" -> pure Flex
|
"Flex" -> pure Flex
|
||||||
_ -> Left "Mobility must be either Flex or Fix"
|
_ -> Left $ TypeMismatch "Mobility must be either Flex or Fix"
|
||||||
|
|
||||||
|
|
||||||
instance pointJson :: DecodeJson Point where
|
instance pointJson :: DecodeJson Point where
|
||||||
decodeJson s = do
|
decodeJson json = do
|
||||||
obj <- maybe (Left "Point is not an object.") Right (toObject s)
|
obj <- decodeJson json
|
||||||
x <- getField obj "X"
|
x <- getField obj "X"
|
||||||
y <- getField obj "Y"
|
y <- getField obj "Y"
|
||||||
pure $ Point x y
|
pure $ Point x y
|
||||||
|
@ -2,6 +2,7 @@ module Test.Main where
|
|||||||
|
|
||||||
import Control.Monad.Except (runExcept)
|
import Control.Monad.Except (runExcept)
|
||||||
import Data.Argonaut.Decode (class DecodeJson, decodeJson)
|
import Data.Argonaut.Decode (class DecodeJson, decodeJson)
|
||||||
|
import Data.Argonaut.Decode.Error (printJsonDecodeError)
|
||||||
import Data.Either (Either(..))
|
import Data.Either (Either(..))
|
||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import Data.Map as Map
|
import Data.Map as Map
|
||||||
@ -103,8 +104,10 @@ Y: 1
|
|||||||
|
|
||||||
yamlToData :: forall a. (DecodeJson a) => String -> Either String a
|
yamlToData :: forall a. (DecodeJson a) => String -> Either String a
|
||||||
yamlToData s = case runExcept $ parseYAMLToJson s of
|
yamlToData s = case runExcept $ parseYAMLToJson s of
|
||||||
Left err -> Left "Could not parse yaml"
|
Left err -> Left "Could not parse YAML"
|
||||||
Right json -> decodeJson json
|
Right json -> case decodeJson json of
|
||||||
|
Left error -> Left $ printJsonDecodeError error
|
||||||
|
Right value -> Right value
|
||||||
|
|
||||||
|
|
||||||
testMap :: Map String (Array GeoObject)
|
testMap :: Map String (Array GeoObject)
|
||||||
|
Loading…
Reference in New Issue
Block a user