Skip to content

Commit d4f668e

Browse files
authored
Merge pull request #43 from purescript-contrib/compiler/0.12
Compiler/0.12
2 parents fa2cbbb + f3bdf50 commit d4f668e

File tree

8 files changed

+144
-120
lines changed

8 files changed

+144
-120
lines changed

.travis.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
12
language: node_js
2-
dist: trusty
33
sudo: required
4-
node_js: stable
4+
dist: trusty
5+
node_js: 8
6+
env:
7+
- PATH=$HOME/purescript:$PATH
58
install:
9+
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
10+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
11+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
12+
- chmod a+x $HOME/purescript
613
- npm install -g bower
714
- npm install
815
script:
9-
- bower install --production
10-
- npm run -s build
1116
- bower install
12-
- npm -s test
17+
- pulp test
1318
after_success:
1419
- >-
1520
test $TRAVIS_TAG &&
1621
echo $GITHUB_TOKEN | pulp login &&
17-
echo y | pulp publish --no-push
22+
echo y | pulp publish --no-push

bower.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
},
2323
"license": "MIT",
2424
"dependencies": {
25-
"purescript-argonaut-core": "^3.0.0",
26-
"purescript-generics": "^4.0.0",
27-
"purescript-integers": "^3.0.0",
28-
"purescript-maybe": "^3.0.0"
25+
"purescript-argonaut-core": "^4.0.0",
26+
"purescript-integers": "^4.0.0",
27+
"purescript-maybe": "^4.0.0",
28+
"purescript-ordered-collections": "^1.0.0",
29+
"purescript-foreign-object": "^1.0.0"
2930
},
3031
"devDependencies": {
31-
"purescript-strongcheck": "^3.1.0"
32+
"purescript-quickcheck": "^5.0.0"
3233
}
3334
}

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^11.0.0",
10-
"purescript-psa": "^0.5.0",
11-
"purescript": "^0.11.1",
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
1211
"rimraf": "^2.6.1"
1312
}
14-
}
13+
}

src/Data/Argonaut/Decode/Class.purs

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ module Data.Argonaut.Decode.Class
55

66
import Prelude
77

8-
import Data.Argonaut.Core (Json, JArray, JObject, isNull, foldJsonNull, foldJsonBoolean, foldJsonNumber, foldJsonString, toArray, toObject, toString)
8+
import Data.Argonaut.Core (Json, isNull, caseJsonNull, caseJsonBoolean, caseJsonNumber, caseJsonString, toArray, toObject, toString, stringify)
99
import Data.Bifunctor (lmap)
1010
import Data.Either (Either(..))
1111
import Data.Int (fromNumber)
1212
import Data.List (List(..), (:), fromFoldable)
1313
import Data.Map as M
1414
import Data.Maybe (maybe, Maybe(..))
15-
import Data.String (charAt)
16-
import Data.StrMap as SM
15+
import Data.String (CodePoint, codePointAt)
1716
import Data.Traversable (traverse)
1817
import Data.Tuple (Tuple(..))
18+
import Foreign.Object as FO
1919

2020
class DecodeJson a where
2121
decodeJson :: Json -> Either String a
@@ -35,21 +35,21 @@ instance decodeJsonEither :: (DecodeJson a, DecodeJson b) => DecodeJson (Either
3535
decodeJson json =
3636
lmap ("Couldn't decode Either: " <> _) $
3737
decodeJObject json >>= \obj -> do
38-
tag <- maybe (Left "Expected field 'tag'") Right $ SM.lookup "tag" obj
39-
val <- maybe (Left "Expected field 'value'") Right $ SM.lookup "value" obj
38+
tag <- maybe (Left "Expected field 'tag'") Right $ FO.lookup "tag" obj
39+
val <- maybe (Left "Expected field 'value'") Right $ FO.lookup "value" obj
4040
case toString tag of
4141
Just "Right" -> Right <$> decodeJson val
4242
Just "Left" -> Left <$> decodeJson val
4343
_ -> Left "'tag' field was not \"Left\" or \"Right\""
4444

4545
instance decodeJsonNull :: DecodeJson Unit where
46-
decodeJson = foldJsonNull (Left "Value is not a null") (const $ Right unit)
46+
decodeJson = caseJsonNull (Left "Value is not a null") (const $ Right unit)
4747

4848
instance decodeJsonBoolean :: DecodeJson Boolean where
49-
decodeJson = foldJsonBoolean (Left "Value is not a Boolean") Right
49+
decodeJson = caseJsonBoolean (Left "Value is not a Boolean") Right
5050

5151
instance decodeJsonNumber :: DecodeJson Number where
52-
decodeJson = foldJsonNumber (Left "Value is not a Number") Right
52+
decodeJson = caseJsonNumber (Left "Value is not a Number") Right
5353

5454
instance decodeJsonInt :: DecodeJson Int where
5555
decodeJson
@@ -58,19 +58,19 @@ instance decodeJsonInt :: DecodeJson Int where
5858
<=< decodeJson
5959

6060
instance decodeJsonString :: DecodeJson String where
61-
decodeJson = foldJsonString (Left "Value is not a String") Right
61+
decodeJson = caseJsonString (Left "Value is not a String") Right
6262

6363
instance decodeJsonJson :: DecodeJson Json where
6464
decodeJson = Right
6565

66-
instance decodeJsonChar :: DecodeJson Char where
66+
instance decodeJsonChar :: DecodeJson CodePoint where
6767
decodeJson j =
68-
maybe (Left $ "Expected character but found: " <> show j) Right
69-
=<< charAt 0 <$> decodeJson j
68+
maybe (Left $ "Expected character but found: " <> stringify j) Right
69+
=<< codePointAt 0 <$> decodeJson j
7070

71-
instance decodeStrMap :: DecodeJson a => DecodeJson (SM.StrMap a) where
71+
instance decodeForeignObject :: DecodeJson a => DecodeJson (FO.Object a) where
7272
decodeJson
73-
= lmap ("Couldn't decode StrMap: " <> _)
73+
= lmap ("Couldn't decode ForeignObject: " <> _)
7474
<<< (traverse decodeJson <=< decodeJObject)
7575

7676
instance decodeArray :: DecodeJson a => DecodeJson (Array a) where
@@ -89,8 +89,8 @@ instance decodeMap :: (Ord a, DecodeJson a, DecodeJson b) => DecodeJson (M.Map a
8989
instance decodeVoid :: DecodeJson Void where
9090
decodeJson _ = Left "Value cannot be Void"
9191

92-
decodeJArray :: Json -> Either String JArray
92+
decodeJArray :: Json -> Either String (Array Json)
9393
decodeJArray = maybe (Left "Value is not an Array") Right <<< toArray
9494

95-
decodeJObject :: Json -> Either String JObject
95+
decodeJObject :: Json -> Either String (FO.Object Json)
9696
decodeJObject = maybe (Left "Value is not an Object") Right <<< toObject

src/Data/Argonaut/Decode/Combinators.purs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ module Data.Argonaut.Decode.Combinators where
22

33
import Prelude
44

5-
import Data.Argonaut.Core (JObject)
5+
import Data.Argonaut.Core (Json)
66
import Data.Argonaut.Decode.Class (class DecodeJson, decodeJson)
77
import Data.Either (Either(..))
88
import Data.Maybe (Maybe(..), fromMaybe, maybe)
9-
import Data.StrMap as SM
9+
import Foreign.Object as FO
1010

11-
getField :: forall a. DecodeJson a => JObject -> String -> Either String a
11+
getField :: forall a. DecodeJson a => FO.Object Json -> String -> Either String a
1212
getField o s =
1313
maybe
1414
(Left $ "Expected field " <> show s)
1515
decodeJson
16-
(SM.lookup s o)
16+
(FO.lookup s o)
1717

1818
infix 7 getField as .?
1919

20-
getFieldOptional :: forall a. DecodeJson a => JObject -> String -> Either String (Maybe a)
20+
getFieldOptional :: forall a. DecodeJson a => FO.Object Json -> String -> Either String (Maybe a)
2121
getFieldOptional o s =
2222
maybe
2323
(pure Nothing)
2424
decode
25-
(SM.lookup s o)
25+
(FO.lookup s o)
2626
where
2727
decode json = Just <$> decodeJson json
2828

src/Data/Argonaut/Encode/Class.purs

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import Data.Int (toNumber)
88
import Data.List (List(..), (:), toUnfoldable)
99
import Data.Map as M
1010
import Data.Maybe (Maybe(..))
11-
import Data.String (singleton)
12-
import Data.StrMap as SM
11+
import Data.String (CodePoint)
12+
import Data.String.CodePoints as CP
13+
import Data.String.CodeUnits as CU
1314
import Data.Tuple (Tuple(..))
15+
import Foreign.Object as FO
1416

1517
class EncodeJson a where
1618
encodeJson :: a -> Json
@@ -27,7 +29,7 @@ instance encodeJsonEither :: (EncodeJson a, EncodeJson b) => EncodeJson (Either
2729
where
2830
obj :: forall c. EncodeJson c => String -> c -> Json
2931
obj tag x =
30-
fromObject $ SM.fromFoldable $
32+
fromObject $ FO.fromFoldable $
3133
Tuple "tag" (fromString tag) : Tuple "value" (encodeJson x) : Nil
3234

3335
instance encodeJsonUnit :: EncodeJson Unit where
@@ -46,18 +48,21 @@ instance encodeJsonJString :: EncodeJson String where
4648
encodeJson = fromString
4749

4850
instance encodeJsonJson :: EncodeJson Json where
49-
encodeJson = id
51+
encodeJson = identity
52+
53+
instance encodeJsonCodePoint :: EncodeJson CodePoint where
54+
encodeJson = encodeJson <<< CP.singleton
5055

5156
instance encodeJsonChar :: EncodeJson Char where
52-
encodeJson = encodeJson <<< singleton
57+
encodeJson = encodeJson <<< CU.singleton
5358

5459
instance encodeJsonArray :: EncodeJson a => EncodeJson (Array a) where
5560
encodeJson json = fromArray (encodeJson <$> json)
5661

5762
instance encodeJsonList :: EncodeJson a => EncodeJson (List a) where
5863
encodeJson = fromArray <<< map encodeJson <<< toUnfoldable
5964

60-
instance encodeStrMap :: EncodeJson a => EncodeJson (SM.StrMap a) where
65+
instance encodeForeignObject :: EncodeJson a => EncodeJson (FO.Object a) where
6166
encodeJson = fromObject <<< map encodeJson
6267

6368
instance encodeMap :: (Ord a, EncodeJson a, EncodeJson b) => EncodeJson (M.Map a b) where

src/Data/Argonaut/Encode/Combinators.purs

+18-13
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,46 @@ module Data.Argonaut.Encode.Combinators where
1111

1212
import Prelude
1313

14-
import Data.Argonaut.Core (Json, JAssoc, foldJsonObject, fromObject, jsonSingletonObject)
14+
import Data.Argonaut.Core (Json, caseJsonObject, fromObject, jsonSingletonObject)
1515
import Data.Argonaut.Encode.Class (class EncodeJson, encodeJson)
1616
import Data.Maybe (Maybe(..))
17-
import Data.StrMap as SM
1817
import Data.Tuple (Tuple(..))
18+
import Foreign.Object as FO
1919

20-
-- | Creates a `JAssoc` entry, representing a key/value pair for an object.
20+
-- | Creates a `Tuple String Json` entry, representing a key/value pair for an object.
2121
infix 7 assoc as :=
2222

2323
-- | The named implementation of the `(:=)` operator.
24-
assoc :: forall a. EncodeJson a => String -> a -> JAssoc
24+
assoc :: forall a. EncodeJson a => String -> a -> Tuple String Json
2525
assoc k = Tuple k <<< encodeJson
2626

27-
-- | Creates an optional `JAssoc` entry, representing an optional key/value pair for an object.
27+
-- | Creates an optional `Tuple String Json` entry, representing an optional key/value pair for an object.
2828
infix 7 assocOptional as :=?
2929

3030
-- | The named implementation of the `(:=?)` operator.
31-
assocOptional :: forall a. EncodeJson a => String -> Maybe a -> Maybe JAssoc
31+
assocOptional
32+
:: forall a
33+
. EncodeJson a
34+
=> String
35+
-> Maybe a
36+
-> Maybe (Tuple String Json)
3237
assocOptional k = (<$>) (((:=) k) <<< encodeJson)
3338

34-
-- | Extends a Json object with a `JAssoc` property.
39+
-- | Extends a Json object with a `Tuple String Json` property.
3540
infixr 6 extend as ~>
3641

3742
-- | The named implementation of the `(~>)` operator.
38-
extend :: forall a. EncodeJson a => JAssoc -> a -> Json
43+
extend :: forall a. EncodeJson a => Tuple String Json -> a -> Json
3944
extend (Tuple k v) =
40-
foldJsonObject
45+
caseJsonObject
4146
(jsonSingletonObject k v)
42-
(SM.insert k v >>> fromObject)
47+
(FO.insert k v >>> fromObject)
4348
<<< encodeJson
4449

45-
-- | Optionally extends a Json object with an optional `JAssoc` property.
50+
-- | Optionally extends a Json object with an optional `Tuple String Json` property.
4651
infixr 6 extendOptional as ~>?
4752

4853
-- | The named implementation of the `(~>?)` operator.
49-
extendOptional :: forall a. EncodeJson a => Maybe JAssoc -> a -> Json
54+
extendOptional :: forall a. EncodeJson a => Maybe (Tuple String Json) -> a -> Json
5055
extendOptional (Just kv) = (~>) kv
51-
extendOptional Nothing = encodeJson
56+
extendOptional Nothing = encodeJson

0 commit comments

Comments
 (0)