1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00
semantic/src/Diff.hs

28 lines
746 B
Haskell
Raw Normal View History

2015-11-18 00:25:36 +03:00
module Diff where
2015-11-18 00:35:55 +03:00
import Syntax
2015-11-19 23:02:53 +03:00
import Data.Set
2015-11-18 00:35:52 +03:00
import Control.Monad.Free
2015-11-18 05:23:53 +03:00
import Patch
import Term
2015-12-03 05:40:34 +03:00
import Range
2015-11-19 23:06:34 +03:00
import Categorizable
2015-11-18 00:25:36 +03:00
data Annotated a annotation f = Annotated !annotation !(Syntax a f)
2015-12-01 18:12:52 +03:00
deriving (Functor, Eq, Show, Foldable)
2015-11-19 03:13:33 +03:00
2015-11-20 01:35:46 +03:00
type Category = String
2015-12-24 01:51:52 +03:00
data Info = Info { characterRange :: !Range, categories :: !(Set Category) }
deriving (Eq, Show)
2015-11-18 00:25:36 +03:00
2015-11-19 23:06:34 +03:00
instance Categorizable Info where
2015-12-24 01:50:29 +03:00
categories = Diff.categories
2015-11-19 23:06:34 +03:00
2015-11-19 22:27:31 +03:00
type Diff a annotation = Free (Annotated a (annotation, annotation)) (Patch (Term a annotation))
2015-11-18 00:25:36 +03:00
2015-12-01 03:06:48 +03:00
diffSum :: (Patch (Term a annotation) -> Integer) -> Diff a annotation -> Integer
2015-12-01 18:13:05 +03:00
diffSum patchCost diff = sum $ fmap patchCost diff
2015-12-01 03:06:48 +03:00
2015-11-27 20:06:14 +03:00
diffCost :: Diff a annotation -> Integer
2015-12-01 03:16:22 +03:00
diffCost = diffSum $ patchSum termSize