1module Data.Schematic.Path where
3import Data.Foldable as F
4import Data.Singletons.Prelude
5import Data.Singletons.TypeLits
7import Data.Aeson.Internal
10newtype JSONPathText = JSONPathText Text
13data PathSegment = PathKey Symbol | PathIx Nat
15data instance Sing (jp :: PathSegment) where
16 SKey :: (SingI k) => Sing (k :: Symbol) -> Sing ('PathKey k)
17 SIx :: (SingI n) => Sing (n :: Nat) -> Sing ('PathIx n)
19demotePath :: Sing (ps :: [PathSegment]) -> JSONPath
22 go :: JSONPath -> Sing (ps :: [PathSegment]) -> JSONPath
24 go acc (SCons p ps) = go (acc ++ [demotePathSeg p]) ps
25 demotePathSeg :: Sing (ps :: PathSegment) -> JSONPathElement
26 demotePathSeg (SKey s) = Key $ T.pack $ withKnownSymbol s $ symbolVal s
27 demotePathSeg (SIx n) = Index $ withKnownNat n $ fromIntegral $ natVal n
29demotedPathToText :: JSONPath -> JSONPathText
30demotedPathToText = JSONPathText . F.foldl' renderPathSegment ""
32 renderPathSegment acc (Key t) = acc <> "." <> t
33 renderPathSegment acc (Index n) = acc <> "[" <> T.pack (show n) <> "]"
35pathToText :: Sing (ps :: [PathSegment]) -> JSONPathText
36pathToText = 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