Copyright | (c) 2012--2021 The University of Kansas |
---|---|
License | BSD3 |
Maintainer | Neil Sculthorpe <neil.sculthorpe@ntu.ac.uk> |
Stability | beta |
Portability | ghc |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides combinators to find LocalPath
s sub-nodes specified by a predicate.
Synopsis
- type WithLocalPath c crumb = ExtendContext c (LocalPath crumb)
- withLocalPathT :: Transform (WithLocalPath c crumb) m a b -> Transform c m a b
- exposeLocalPathT :: Monad m => Transform (WithLocalPath c crumb) m a (LocalPath crumb)
- acceptLocalPathT :: MonadFail m => Transform c m u Bool -> Transform (WithLocalPath c crumb) m u (LocalPath crumb)
- pathsToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u [LocalPath crumb]
- onePathToT :: forall c crumb u m. (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb)
- oneNonEmptyPathToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb)
- prunePathsToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u [LocalPath crumb]
- uniquePathToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb)
- uniquePrunePathToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb)
Finding Local Paths
Context Transformers
To find a LocalPath
to a node that satisfies a predicate, use
,
where withLocalPathT
(tt (acceptLocalPathT
q))q
is a transformation returning Bool
, and tt
is a traversal strategy, such as collectT
or onetdT
.
This will handle the tracking of the local path.
See the example pathfinders below.
type WithLocalPath c crumb = ExtendContext c (LocalPath crumb) Source #
A context transformer that adds a LocalPath
(from the current node) to the context.
withLocalPathT :: Transform (WithLocalPath c crumb) m a b -> Transform c m a b Source #
Apply a transformation that stores a LocalPath
in the context (starting at the current node).
exposeLocalPathT :: Monad m => Transform (WithLocalPath c crumb) m a (LocalPath crumb) Source #
Extract the current LocalPath
from the context.
acceptLocalPathT :: MonadFail m => Transform c m u Bool -> Transform (WithLocalPath c crumb) m u (LocalPath crumb) Source #
Return the current LocalPath
if the predicate transformation succeeds.
Example Pathfinders
pathsToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u [LocalPath crumb] Source #
Find the LocalPath
s to every node that satisfies the predicate.
onePathToT :: forall c crumb u m. (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb) Source #
Find the LocalPath
to the first node that satisfies the predicate (in a pre-order traversal).
oneNonEmptyPathToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb) Source #
Find the LocalPath
to the first descendent node that satisfies the predicate (in a pre-order traversal).
prunePathsToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u [LocalPath crumb] Source #
Find the LocalPath
s to every node that satisfies the predicate, ignoring nodes below successes.
uniquePathToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb) Source #
Find the LocalPath
to the node that satisfies the predicate, failing if that does not uniquely identify a node.
uniquePrunePathToT :: (Walker (WithLocalPath c crumb) u, MonadCatch m) => Transform c m u Bool -> Transform c m u (LocalPath crumb) Source #
Build a LocalPath
to the node that satisfies the predicate, failing if that does not uniquely identify a node (ignoring nodes below successes).