shrun
Safe HaskellNone
LanguageGHC2021

Shrun.Configuration.Legend

Description

Provides types for the legend functionality.

Synopsis

Parsing

linesToMap :: (HasCallStack, MonadThrow m) => Seq KeyVal -> m LegendMap Source #

Attempts to parse the given [KeyVal] into LegendMap. Duplicate keys are not allowed.

type LegendMap = HashMap Text (NESeq Text, Maybe EdgeArgs) Source #

Alias for our legend map.

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

Expand
>>> :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")