module Momo.Path
( Path(..)
, items
) where
import Data.Text (Text)
import Momo.Ident (Ident)
import Momo.Ident qualified as Ident
data Path
= Ident
{ Path -> Ident
ident :: Ident
}
| Dot
{ Path -> Path
path :: Path
, Path -> Text
field :: Text
}
deriving (Path -> Path -> Bool
(Path -> Path -> Bool) -> (Path -> Path -> Bool) -> Eq Path
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Path -> Path -> Bool
$c/= :: Path -> Path -> Bool
== :: Path -> Path -> Bool
$c== :: Path -> Path -> Bool
Eq, Eq Path
Eq Path
-> (Path -> Path -> Ordering)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Path)
-> (Path -> Path -> Path)
-> Ord Path
Path -> Path -> Bool
Path -> Path -> Ordering
Path -> Path -> Path
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Path -> Path -> Path
$cmin :: Path -> Path -> Path
max :: Path -> Path -> Path
$cmax :: Path -> Path -> Path
>= :: Path -> Path -> Bool
$c>= :: Path -> Path -> Bool
> :: Path -> Path -> Bool
$c> :: Path -> Path -> Bool
<= :: Path -> Path -> Bool
$c<= :: Path -> Path -> Bool
< :: Path -> Path -> Bool
$c< :: Path -> Path -> Bool
compare :: Path -> Path -> Ordering
$ccompare :: Path -> Path -> Ordering
Ord)
instance Show Path where
show :: Path -> String
show = [Text] -> String
forall a. Show a => a -> String
show ([Text] -> String) -> (Path -> [Text]) -> Path -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path -> [Text]
items
items :: Path -> [Text]
items :: Path -> [Text]
items = Path -> [Text]
go
where
go :: Path -> [Text]
go = \case
Ident{Ident
ident :: Ident
ident :: Path -> Ident
ident} ->
[Ident
ident.name]
Dot{Path
path :: Path
path :: Path -> Path
path, Text
field :: Text
field :: Path -> Text
field} ->
Path -> [Text]
go Path
path [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text
field]