mirror of
https://github.com/github/semantic.git
synced 2024-12-23 06:41:45 +03:00
Compute the set of free metavariables in a diff.
This commit is contained in:
parent
b4ca3be640
commit
8b1eb1e8be
10
src/Diff.hs
10
src/Diff.hs
@ -8,6 +8,7 @@ import Control.Monad.Effect.Reader
|
|||||||
import Data.Bifoldable
|
import Data.Bifoldable
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.Bitraversable
|
import Data.Bitraversable
|
||||||
|
import Data.Foldable (fold)
|
||||||
import Data.Functor.Both (Both, Join(..), liftShowsPrecBoth)
|
import Data.Functor.Both (Both, Join(..), liftShowsPrecBoth)
|
||||||
import qualified Data.Functor.Both as Both
|
import qualified Data.Functor.Both as Both
|
||||||
import Data.Functor.Classes
|
import Data.Functor.Classes
|
||||||
@ -17,6 +18,7 @@ import Data.JSON.Fields
|
|||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Mergeable
|
import Data.Mergeable
|
||||||
import Data.Record
|
import Data.Record
|
||||||
|
import qualified Data.Set as Set
|
||||||
import Data.Text (pack)
|
import Data.Text (pack)
|
||||||
import Data.Union
|
import Data.Union
|
||||||
import Patch
|
import Patch
|
||||||
@ -43,6 +45,14 @@ diffFBindings _ = []
|
|||||||
newtype Metavar = Metavar { unMetavar :: String }
|
newtype Metavar = Metavar { unMetavar :: String }
|
||||||
deriving (Eq, Ord, Show)
|
deriving (Eq, Ord, Show)
|
||||||
|
|
||||||
|
|
||||||
|
freeMetavariables :: (Foldable syntax, Functor syntax) => Diff syntax ann -> Set.Set Metavar
|
||||||
|
freeMetavariables = cata $ \ diff -> case diff of
|
||||||
|
Copy bindings _ body -> foldMap snd bindings <> foldr Set.delete (fold body) (fst <$> bindings)
|
||||||
|
Var v -> Set.singleton v
|
||||||
|
Patch patch -> foldMap fold patch
|
||||||
|
|
||||||
|
|
||||||
newtype Env a = Env { unEnv :: [(Metavar, a)] }
|
newtype Env a = Env { unEnv :: [(Metavar, a)] }
|
||||||
deriving (Eq, Foldable, Functor, Monoid, Ord, Show, Traversable)
|
deriving (Eq, Foldable, Functor, Monoid, Ord, Show, Traversable)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user