diff --git a/semantic.cabal b/semantic.cabal index 54419649f..8c6ee65d4 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -41,7 +41,6 @@ library , Control.Abstract.Evaluator , Control.Abstract.Heap , Control.Abstract.Hole - , Control.Abstract.Matching , Control.Abstract.Modules , Control.Abstract.Primitive , Control.Abstract.PythonPackage @@ -51,7 +50,8 @@ library -- Effects , Control.Effect.Interpose , Control.Effect.REPL - -- Rewriting + -- Matching and rewriting DSLs + , Control.Matching , Control.Rewriting -- Datatypes for abstract interpretation , Data.Abstract.Address.Hole diff --git a/src/Control/Abstract/Matching.hs b/src/Control/Matching.hs similarity index 97% rename from src/Control/Abstract/Matching.hs rename to src/Control/Matching.hs index eeb4b8b4e..a25c2c23d 100644 --- a/src/Control/Abstract/Matching.hs +++ b/src/Control/Matching.hs @@ -1,6 +1,6 @@ {-# LANGUAGE GADTs, TypeOperators #-} -module Control.Abstract.Matching +module Control.Matching ( Matcher , TermMatcher , target @@ -9,6 +9,7 @@ module Control.Abstract.Matching , matchM , narrow , narrow' + , purely , succeeds , fails , runMatcher @@ -71,6 +72,10 @@ target = Target ensure :: (t -> Bool) -> Matcher t () ensure f = target >>= \c -> guard (f c) +-- | Promote a pure function to a 'Matcher'. +purely :: (a -> b) -> Matcher a b +purely f = fmap f target + -- | 'matchm' takes a modification function and a new matcher action the target parameter of which -- is the result of the modification function. If the modification function returns 'Just' when -- applied to the current 'target', the given matcher is executed with the result of that 'Just' diff --git a/src/Control/Rewriting.hs b/src/Control/Rewriting.hs index 65ed12286..2758028ea 100644 --- a/src/Control/Rewriting.hs +++ b/src/Control/Rewriting.hs @@ -74,7 +74,7 @@ import Data.Profunctor import qualified Data.Sum as Sum hiding (apply) import Data.Text (pack) -import Control.Abstract.Matching (Matcher, stepMatcher) +import Control.Matching (Matcher, stepMatcher) import Data.History as History import Data.Term diff --git a/src/Matching/Core.hs b/src/Matching/Core.hs index c0b08e747..8fb5b31af 100644 --- a/src/Matching/Core.hs +++ b/src/Matching/Core.hs @@ -8,7 +8,7 @@ module Matching.Core import Prologue -import Control.Abstract.Matching +import Control.Matching import qualified Data.Syntax.Literal as Literal import Data.Term diff --git a/src/Semantic/Util/Rewriting.hs b/src/Semantic/Util/Rewriting.hs index 0188d664b..6824c4d4f 100644 --- a/src/Semantic/Util/Rewriting.hs +++ b/src/Semantic/Util/Rewriting.hs @@ -9,7 +9,7 @@ import Control.Category import qualified Data.ByteString.Char8 as BC import Text.Show.Pretty (pPrint) -import Control.Abstract.Matching +import Control.Matching import Control.Rewriting hiding (fromMatcher, target) import Data.Blob import Data.File diff --git a/test/Control/Rewriting/Spec.hs b/test/Control/Rewriting/Spec.hs index 05b9b7d98..a7ff72ca5 100644 --- a/test/Control/Rewriting/Spec.hs +++ b/test/Control/Rewriting/Spec.hs @@ -8,7 +8,7 @@ import qualified Data.ByteString as B import Data.Either import Data.Text (Text) -import Control.Abstract.Matching as Matching +import Control.Matching as Matching import Control.Rewriting as Rewriting import Data.History as History import qualified Data.Source as Source @@ -21,7 +21,7 @@ import Reprinting.Pipeline onTrees :: ( Literal.TextElement :< syn , Literal.KeyValue :< syn , Apply Functor syn - , term ~ Term (Sum syn) History + , term ~ Term (Sum syn) History ) => Rewrite (env, term) (Literal.Hash term) onTrees = do Literal.Hash els <- Rewriting.target diff --git a/test/Matching/Go/Spec.hs b/test/Matching/Go/Spec.hs index a4fdc1e68..76e7fa6ef 100644 --- a/test/Matching/Go/Spec.hs +++ b/test/Matching/Go/Spec.hs @@ -2,7 +2,7 @@ module Matching.Go.Spec (spec) where -import Control.Abstract.Matching +import Control.Matching import Data.Abstract.Module import Data.List import Data.Sum