{-# language BangPatterns #-}
module Json.Context
( Context(..)
, builderUtf8
, toPath
) where
import Json.Path (Path)
import Data.Text.Short (ShortText)
import Data.Bytes.Builder (Builder)
import qualified Json.Path as Path
data Context
= Top
| Key !ShortText !Context
| Index !Int !Context
deriving (Context -> Context -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Context -> Context -> Bool
$c/= :: Context -> Context -> Bool
== :: Context -> Context -> Bool
$c== :: Context -> Context -> Bool
Eq,Int -> Context -> ShowS
[Context] -> ShowS
Context -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Context] -> ShowS
$cshowList :: [Context] -> ShowS
show :: Context -> String
$cshow :: Context -> String
showsPrec :: Int -> Context -> ShowS
$cshowsPrec :: Int -> Context -> ShowS
Show)
toPath :: Context -> Path
toPath :: Context -> Path
toPath = Path -> Context -> Path
go Path
Path.Nil where
go :: Path -> Context -> Path
go !Path
acc Context
Top = Path
acc
go !Path
acc (Key ShortText
k Context
xs) = Path -> Context -> Path
go (ShortText -> Path -> Path
Path.Key ShortText
k Path
acc) Context
xs
go !Path
acc (Index Int
i Context
xs) = Path -> Context -> Path
go (Int -> Path -> Path
Path.Index Int
i Path
acc) Context
xs
builderUtf8 :: Context -> Builder
builderUtf8 :: Context -> Builder
builderUtf8 Context
ctx0 = Path -> Builder
Path.builderUtf8 (Context -> Path
toPath Context
ctx0)