mirror of
https://github.com/github/semantic.git
synced 2024-11-24 00:42:33 +03:00
Move Range to a module
This commit is contained in:
parent
d443f6f520
commit
2a063d3277
@ -5,6 +5,7 @@ import Diff
|
||||
import Interpreter
|
||||
import Patch
|
||||
import Syntax
|
||||
import Range
|
||||
import Split
|
||||
import Term
|
||||
import Unified
|
||||
|
@ -4,7 +4,7 @@ import Diff
|
||||
import Patch
|
||||
import Syntax
|
||||
import Term
|
||||
import Unified
|
||||
import Range
|
||||
import Control.Comonad.Cofree
|
||||
import Control.Monad.Free
|
||||
import qualified Data.Map as Map
|
||||
|
@ -4,6 +4,7 @@ import Diff
|
||||
import Patch
|
||||
import Syntax
|
||||
import Term
|
||||
import Range
|
||||
import Control.Arrow
|
||||
import Control.Monad.Free
|
||||
import Control.Comonad.Cofree
|
||||
@ -36,9 +37,6 @@ unified diff before after = do
|
||||
accumulateContext (out, previous) (child, Just range) = (mconcat [ out, pure . chunk $ substring Range { start = previous, end = start range } source, child ], end range)
|
||||
accumulateContext (out, previous) (child, _) = (out <> child, previous)
|
||||
|
||||
substring :: Range -> String -> String
|
||||
substring range = take (end range - start range) . drop (start range)
|
||||
|
||||
range :: Patch (Term a Info) -> Maybe Range
|
||||
range patch = range . extract <$> after patch where
|
||||
extract (annotation :< _) = annotation
|
||||
@ -47,5 +45,3 @@ range patch = range . extract <$> after patch where
|
||||
change :: String -> [Chunk String] -> [Chunk String]
|
||||
change bound content = [ chunk "{", chunk bound ] ++ content ++ [ chunk bound, chunk "}" ]
|
||||
|
||||
instance Ord Range where
|
||||
a <= b = start a <= start b
|
||||
|
@ -22,6 +22,7 @@ library
|
||||
, SES
|
||||
, Categorizable
|
||||
, Term
|
||||
, Range
|
||||
build-depends: base >= 4.8 && < 5
|
||||
, containers
|
||||
, free
|
||||
|
@ -5,14 +5,12 @@ import Data.Set
|
||||
import Control.Monad.Free
|
||||
import Patch
|
||||
import Term
|
||||
import Range
|
||||
import Categorizable
|
||||
|
||||
data Annotated a annotation f = Annotated annotation (Syntax a f)
|
||||
deriving (Functor, Eq, Show, Foldable)
|
||||
|
||||
data Range = Range { start :: Int, end :: Int }
|
||||
deriving (Eq, Show)
|
||||
|
||||
|
||||
type Category = String
|
||||
data Info = Info { characterRange :: Range, lineRange :: Range, categories :: (Set Category) }
|
||||
|
10
src/Range.hs
Normal file
10
src/Range.hs
Normal file
@ -0,0 +1,10 @@
|
||||
module Range where
|
||||
|
||||
data Range = Range { start :: Int, end :: Int }
|
||||
deriving (Eq, Show)
|
||||
|
||||
substring :: Range -> String -> String
|
||||
substring range = take (end range - start range) . drop (start range)
|
||||
|
||||
instance Ord Range where
|
||||
a <= b = start a <= start b
|
Loading…
Reference in New Issue
Block a user