1module Data.Schematic.Path where
3import Data.Foldable as F
6import Data.Singletons.Prelude
7import Data.Singletons.TypeLits
11data PathSegment = Key Symbol | Ix Nat
13data instance Sing (jp :: PathSegment) where
14 SKey :: (SingI k) => Sing (k :: Symbol) -> Sing ('Key k)
15 SIx :: (SingI n) => Sing (n :: Nat) -> Sing ('Ix n)
17data DemotedPathSegment = DKey Text | DIx Integer
20-- | Textual representation of json path.
21newtype JSONPath = JSONPath Text
24demotePath :: Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
27 go :: [DemotedPathSegment] -> Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
29 go acc (SCons p ps) = go (acc ++ [demote p]) ps
30 demote :: Sing (ps :: PathSegment) -> DemotedPathSegment
31 demote (SKey s) = DKey $ T.pack $ withKnownSymbol s $ symbolVal s
32 demote (SIx n) = DIx $ withKnownNat n $ natVal n
34demotedPathToText :: [DemotedPathSegment] -> JSONPath
35demotedPathToText = JSONPath . F.foldl' renderPathSegment ""
37 renderPathSegment acc (DKey t) = acc <> "." <> t
38 renderPathSegment acc (DIx n) = acc <> "[" <> T.pack (show n) <> "]"
40pathToText :: Sing (ps :: [PathSegment]) -> JSONPath
41pathToText = 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