1module Data.Schematic.Path where
3import Data.Foldable as F
4import Data.Singletons.Prelude
5import Data.Singletons.TypeLits
9data PathSegment = Key Symbol | Ix Nat
11data instance Sing (jp :: PathSegment) where
12 SKey :: (SingI k) => Sing (k :: Symbol) -> Sing ('Key k)
13 SIx :: (SingI n) => Sing (n :: Nat) -> Sing ('Ix n)
15data DemotedPathSegment = DKey Text | DIx Integer
18-- | Textual representation of json path.
19newtype JSONPath = JSONPath Text
22demotePath :: Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
25 go :: [DemotedPathSegment] -> Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
27 go acc (SCons p ps) = go (acc ++ [demotePathSeg p]) ps
28 demotePathSeg :: Sing (ps :: PathSegment) -> DemotedPathSegment
29 demotePathSeg (SKey s) = DKey $ T.pack $ withKnownSymbol s $ symbolVal s
30 demotePathSeg (SIx n) = DIx $ withKnownNat n $ fromIntegral $ natVal n
32demotedPathToText :: [DemotedPathSegment] -> JSONPath
33demotedPathToText = JSONPath . F.foldl' renderPathSegment ""
35 renderPathSegment acc (DKey t) = acc <> "." <> t
36 renderPathSegment acc (DIx n) = acc <> "[" <> T.pack (show n) <> "]"
38pathToText :: Sing (ps :: [PathSegment]) -> JSONPath
39pathToText = demotedPathToText . demotePath
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list