Safe Haskell | None |
---|---|
Language | GHC2021 |
Provides types for the legend functionality.
Synopsis
- linesToMap :: List KeyVal -> Either DuplicateKeyError LegendMap
- type LegendMap = HashMap Text (NESeq Text)
- newtype DuplicateKeyError = MkDuplicateKeyError Text
- translateCommands :: LegendMap -> NESeq Text -> Either CyclicKeyError (NESeq CommandP1)
- newtype CyclicKeyError = MkCyclicKeyError Text
Parsing
newtype DuplicateKeyError Source #
Errors when parsing the legend.
Instances
Exception DuplicateKeyError Source # | |
Defined in Shrun.Configuration.Legend | |
Show DuplicateKeyError Source # | |
Defined in Shrun.Configuration.Legend showsPrec :: Int -> DuplicateKeyError -> ShowS # show :: DuplicateKeyError -> String # showList :: [DuplicateKeyError] -> ShowS # | |
Eq DuplicateKeyError Source # | |
Defined in Shrun.Configuration.Legend (==) :: DuplicateKeyError -> DuplicateKeyError -> Bool # (/=) :: DuplicateKeyError -> DuplicateKeyError -> Bool # |
Translation
translateCommands :: LegendMap -> NESeq Text -> Either CyclicKeyError (NESeq CommandP1) 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" :<|| []), ("cmd2", "two" :<|| []), ("all", "cmd1" :<|| ["cmd2","other"]) ] cmds = translateCommands m ("all" :<|| ["blah"]) in (fmap . fmap) (view #command) cmds :} Right (fromList ("one" :| ["two","other","blah"]))
Note: If -- when looking up a line -- we detect a cycle, then a CyclicKeyError
will be returned.
>>>
:{
let m = Map.fromList [ ("a", "b" :<|| []), ("b", "c" :<|| []), ("c", "a" :<|| []) ] in translateCommands m ("a" :<|| []) :} Left (MkCyclicKeyError "a -> b -> c -> a")
newtype CyclicKeyError Source #
Instances
Exception CyclicKeyError Source # | |
Defined in Shrun.Configuration.Legend | |
Show CyclicKeyError Source # | |
Defined in Shrun.Configuration.Legend showsPrec :: Int -> CyclicKeyError -> ShowS # show :: CyclicKeyError -> String # showList :: [CyclicKeyError] -> ShowS # | |
Eq CyclicKeyError Source # | |
Defined in Shrun.Configuration.Legend (==) :: CyclicKeyError -> CyclicKeyError -> Bool # (/=) :: CyclicKeyError -> CyclicKeyError -> Bool # |