| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Shrun.Configuration.Legend
Contents
Description
Provides types for the legend functionality.
Synopsis
- linesToMap :: (HasCallStack, MonadThrow m) => Seq KeyVal -> m LegendMap
- type LegendMap = HashMap Text (NESeq Text, Maybe EdgeArgs)
- newtype DuplicateKeyError = MkDuplicateKeyError Text
- translateCommands :: (HasCallStack, MonadThrow m) => LegendMap -> NESeq Text -> Maybe EdgeArgs -> m (NESeq CommandP1, Edges)
- newtype CyclicKeyError = MkCyclicKeyError Text
Parsing
linesToMap :: (HasCallStack, MonadThrow m) => Seq KeyVal -> m LegendMap Source #
newtype DuplicateKeyError Source #
Errors when parsing the legend.
Constructors
| MkDuplicateKeyError Text |
Instances
| Exception DuplicateKeyError Source # | |
Defined in Shrun.Configuration.Legend Methods toException :: DuplicateKeyError -> SomeException # fromException :: SomeException -> Maybe DuplicateKeyError # | |
| Show DuplicateKeyError Source # | |
Defined in Shrun.Configuration.Legend Methods showsPrec :: Int -> DuplicateKeyError -> ShowS # show :: DuplicateKeyError -> String # showList :: [DuplicateKeyError] -> ShowS # | |
| Eq DuplicateKeyError Source # | |
Defined in Shrun.Configuration.Legend Methods (==) :: DuplicateKeyError -> DuplicateKeyError -> Bool # (/=) :: DuplicateKeyError -> DuplicateKeyError -> Bool # | |
Translation
translateCommands :: (HasCallStack, MonadThrow m) => LegendMap -> NESeq Text -> Maybe EdgeArgs -> m (NESeq CommandP1, Edges) Source #
Returns a list of Text commands, potentially transforming a
given string via the LegendMap legend.
Given a command string s, we first check if s exists as a key in
legend. If it does not, we return s. If there is a key matching
s, i.e.,
legend = fromList [...,(s, v),...]
where \(v = v_1,,\ldots,,v_n\), then we recursively search on each \(v_i\). We stop and return \(v_i\) when it does not exist as a key in the map.
Examples
>>>:set -XOverloadedLists>>>:{let m = Map.fromList [ ("cmd1", ("one" :<|| [], Nothing)), ("cmd2", ("two" :<|| [], Nothing)), ("all", ("cmd1" :<|| ["cmd2","other"], Nothing)) ] k = (fmap . first) (fmap (view #command)) in k $ translateCommands m ("all" :<|| ["blah"]) Nothing :} (fromList ("one" :| ["two","other","blah"]),MkEdges {unEdges = fromList []})
Note: If -- when looking up a line -- we detect a cycle, then a CyclicKeyError
will be returned.
>>>:{let m = Map.fromList [ ("a", ("b" :<|| [], Nothing)), ("b", ("c" :<|| [], Nothing)), ("c", ("a" :<|| [], Nothing)) ] in try @_ @CyclicKeyError $ translateCommands m ("a" :<|| []) Nothing :} Left (MkCyclicKeyError "a -> b -> c -> a")
newtype CyclicKeyError Source #
Constructors
| MkCyclicKeyError Text |
Instances
| Exception CyclicKeyError Source # | |
Defined in Shrun.Configuration.Legend Methods toException :: CyclicKeyError -> SomeException # fromException :: SomeException -> Maybe CyclicKeyError # displayException :: CyclicKeyError -> String # backtraceDesired :: CyclicKeyError -> Bool # | |
| Show CyclicKeyError Source # | |
Defined in Shrun.Configuration.Legend Methods showsPrec :: Int -> CyclicKeyError -> ShowS # show :: CyclicKeyError -> String # showList :: [CyclicKeyError] -> ShowS # | |
| Eq CyclicKeyError Source # | |
Defined in Shrun.Configuration.Legend Methods (==) :: CyclicKeyError -> CyclicKeyError -> Bool # (/=) :: CyclicKeyError -> CyclicKeyError -> Bool # | |