Skip to content

Commit 1066a8e

Browse files
committed
Add infix pattern synonym for Member
1 parent 4411534 commit 1066a8e

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for json-syntax
22

3+
## 0.1.2.0 -- 2020-??-??
4+
5+
* Add infix pattern synonym for `Member`.
6+
37
## 0.1.1.0 -- 2020-05-01
48

59
* Add `encode`.

json-syntax.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: json-syntax
3-
version: 0.1.1.0
3+
version: 0.1.2.0
44
synopsis: High-performance JSON parser and encoder
55
description:
66
This library parses JSON into a @Value@ type that is consistent with the

src/Json.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{-# language LambdaCase #-}
77
{-# language MagicHash #-}
88
{-# language NamedFieldPuns #-}
9+
{-# language PatternSynonyms #-}
910
{-# language TypeApplications #-}
1011
{-# language UnboxedTuples #-}
1112

@@ -17,6 +18,8 @@ module Json
1718
-- * Functions
1819
, decode
1920
, encode
21+
-- * Infix Synonyms
22+
, pattern (:->)
2023
) where
2124

2225
import Prelude hiding (Bool(True,False))
@@ -127,6 +130,7 @@ decode = P.parseBytesEither do
127130
P.endOfInput UnexpectedLeftovers
128131
pure result
129132

133+
-- | Encode a JSON syntax tree.
130134
encode :: Value -> BLDR.Builder
131135
encode = \case
132136
True -> BLDR.ascii4 't' 'r' 'u' 'e'
@@ -410,3 +414,7 @@ byteArrayToShortByteString (PM.ByteArray x) = BSS.SBS x
410414
-- Precondition: Not in the range [U+D800 .. U+DFFF]
411415
w16ToChar :: Word16 -> Char
412416
w16ToChar (W16# w) = C# (chr# (word2Int# w))
417+
418+
-- | Infix pattern synonym for 'Member'.
419+
pattern (:->) :: ShortText -> Value -> Member
420+
pattern key :-> value = Member{key,value}

0 commit comments

Comments
 (0)