1module Data.Schematic.Path where
3import Data.Foldable as F
5import Data.Singletons.Prelude
6import Data.Singletons.TypeLits
10data PathSegment = Key Symbol | Ix Nat
12data instance Sing (jp :: PathSegment) where
13 SKey :: (SingI k) => Sing (k :: Symbol) -> Sing ('Key k)
14 SIx :: (SingI n) => Sing (n :: Nat) -> Sing ('Ix n)
16data DemotedPathSegment = DKey Text | DIx Integer
19-- | Textual representation of json path.
20newtype JSONPath = JSONPath Text
23demotePath :: Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
26 go :: [DemotedPathSegment] -> Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
28 go acc (SCons p ps) = go (acc ++ [demotePathSeg p]) ps
29 demotePathSeg :: Sing (ps :: PathSegment) -> DemotedPathSegment
30 demotePathSeg (SKey s) = DKey $ T.pack $ withKnownSymbol s $ symbolVal s
31 demotePathSeg (SIx n) = DIx $ withKnownNat n $ fromIntegral $ natVal n
33demotedPathToText :: [DemotedPathSegment] -> JSONPath
34demotedPathToText = JSONPath . F.foldl' renderPathSegment ""
36 renderPathSegment acc (DKey t) = acc <> "." <> t
37 renderPathSegment acc (DIx n) = acc <> "[" <> T.pack (show n) <> "]"
39pathToText :: Sing (ps :: [PathSegment]) -> JSONPath
40pathToText = 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