1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

s/runOnce/stepMatcher

This commit is contained in:
Timothy Clem 2018-08-23 15:53:29 -07:00
parent 17fbceb17a
commit 91210dbc42
2 changed files with 10 additions and 10 deletions

View File

@ -12,7 +12,7 @@ module Control.Abstract.Matching
, succeeds
, fails
, runMatcher
, runOnce
, stepMatcher
) where
import Data.Algebra
@ -114,14 +114,14 @@ runMatcher :: (Alternative m, Monad m, Corecursive t, Recursive t, Foldable (Bas
runMatcher m = para (paraMatcher m)
paraMatcher :: (Alternative m, Monad m, Corecursive t, Foldable (Base t)) => Matcher t a -> RAlgebra (Base t) t (m a)
paraMatcher m t = runOnce (embedTerm t) m <|> foldMapA snd t
paraMatcher m t = stepMatcher (embedTerm t) m <|> foldMapA snd t
-- | Run one step of a 'Matcher' computation. Look at 'runMatcher' if you want something
-- that folds over subterms.
runOnce :: (Alternative m, Monad m) => t -> Matcher t a -> m a
runOnce t (Choice a b) = runOnce t a <|> runOnce t b
runOnce t Target = pure t
runOnce t (Match f m) = foldMapA (`runOnce` m) (f t)
runOnce _ (Pure a) = pure a
runOnce _ Empty = empty
runOnce t (Then m f) = runOnce t m >>= runOnce t . f
stepMatcher :: (Alternative m, Monad m) => t -> Matcher t a -> m a
stepMatcher t (Choice a b) = stepMatcher t a <|> stepMatcher t b
stepMatcher t Target = pure t
stepMatcher t (Match f m) = foldMapA (`stepMatcher` m) (f t)
stepMatcher _ (Pure a) = pure a
stepMatcher _ Empty = empty
stepMatcher t (Then m f) = stepMatcher t m >>= stepMatcher t . f

View File

@ -296,7 +296,7 @@ testChangeKV = do
-- Temporary, until new KURE system lands.
fromMatcher :: Matcher from to -> ProcessT (Eff effs) from (Either from (from, to))
fromMatcher m = auto go where go x = maybe (Left x) (\y -> Right (x, y)) (runOnce x m)
fromMatcher m = auto go where go x = maybe (Left x) (\y -> Right (x, y)) (stepMatcher x m)
-- Turn a 'ProccessT' into an FAlgebra.
toAlgebra :: (Traversable (Base t), Corecursive t)