@@ -15,9 +15,11 @@ import Data.Argonaut (Json, JsonDecodeError(..), caseJson, decodeJson, isNull)
15import Data.Array as Array
15import Data.Array as Array
16import Data.Array.ST as STArray
16import Data.Array.ST as STArray
17import Data.Either (Either(..), note)
17import Data.Either (Either(..), note)
18+import Data.Enum (toEnum)
18import Data.Foldable (intercalate)
19import Data.Foldable (intercalate)
19import Data.Int as Int
20import Data.Int as Int
20import Data.Maybe (Maybe(..))
21import Data.Maybe (Maybe(..))
22+import Data.String.CodePoints (CodePoint, fromCodePointArray)
21import Data.String.CodeUnits as SCU
23import Data.String.CodeUnits as SCU
22import Data.Traversable (traverse)
24import Data.Traversable (traverse)
23import Data.Tuple (Tuple(..))
25import Data.Tuple (Tuple(..))
@@ -264,7 +266,7 @@ decodeLiteral dec json = do
264 "NumberLiteral" ->
266 "NumberLiteral" ->
265 LitNumber <$> getField decodeNumber obj "value"
267 LitNumber <$> getField decodeNumber obj "value"
266 "StringLiteral" ->
268 "StringLiteral" ->
267− LitString <$> getField decodeString obj "value"
269+ LitString <$> getField decodeStringLiteral obj "value"
268 "CharLiteral" -> do
270 "CharLiteral" -> do
269 str <- getField decodeString obj "value"
271 str <- getField decodeString obj "value"
270 LitChar <$> note (TypeMismatch "Char") do
272 LitChar <$> note (TypeMismatch "Char") do
@@ -358,12 +360,22 @@ decodeJArray = caseJson fail fail fail fail Right fail
358 fail :: forall a. a -> JsonDecode (Array Json)
360 fail :: forall a. a -> JsonDecode (Array Json)
359 fail _ = Left $ TypeMismatch "Array"
361 fail _ = Left $ TypeMismatch "Array"
363+decodeStringLiteral :: Json -> JsonDecode String
364+decodeStringLiteral json =
365+ decodeString json <|> \_ -> map fromCodePointArray (decodeCodePointArray json) <|> \_ -> throwError (TypeMismatch "StringLiteral")
361decodeString :: Json -> JsonDecode String
367decodeString :: Json -> JsonDecode String
362decodeString = caseJson fail fail fail Right fail fail
368decodeString = caseJson fail fail fail Right fail fail
364 fail :: forall a. a -> JsonDecode String
370 fail :: forall a. a -> JsonDecode String
365 fail _ = Left $ TypeMismatch "String"
371 fail _ = Left $ TypeMismatch "String"
373+decodeCodePointArray :: Json -> JsonDecode (Array CodePoint)
374+decodeCodePointArray = decodeArray decodeCodePoint
376+decodeCodePoint :: Json -> JsonDecode CodePoint
377+decodeCodePoint = note (TypeMismatch "CodePoint") <<< toEnum <=< decodeInt
367decodeNumber :: Json -> JsonDecode Number
379decodeNumber :: Json -> JsonDecode Number
368decodeNumber = caseJson fail fail Right fail fail fail
380decodeNumber = caseJson fail fail Right fail fail fail