diff --git a/src/Source.hs b/src/Source.hs index 9ecc143e9..370522425 100644 --- a/src/Source.hs +++ b/src/Source.hs @@ -1,2 +1,21 @@ module Source where +import Range + +newtype Source a = Source (Int, [a]) + deriving (Eq, Show, Functor, Foldable) + +makeSource :: [a] -> Source a +makeSource list = Source (0, list) + +unSource :: Source a -> [a] +unSource (Source (_, list)) = list + +subsource :: Range -> Source a -> Source a +subsource range (Source (i, list)) = Source (start range, sublist (offsetRange (negate i) range) list) + +toString :: Source Char -> String +toString = unSource + +at :: Source a -> Int -> a +at = (!!) . unSource diff --git a/src/Split.hs b/src/Split.hs index ee1a3d7de..767aa61cb 100644 --- a/src/Split.hs +++ b/src/Split.hs @@ -17,25 +17,9 @@ import qualified Text.Blaze.Html5.Attributes as A import Text.Blaze.Html.Renderer.Utf8 import Data.Monoid import qualified Data.Set as Set +import Source type ClassName = String -newtype Source a = Source (Int, [a]) - deriving (Eq, Show, Functor, Foldable) - -makeSource :: [a] -> Source a -makeSource list = Source (0, list) - -unSource :: Source a -> [a] -unSource (Source (_, list)) = list - -subsource :: Range -> Source a -> Source a -subsource range (Source (i, list)) = Source (start range, sublist (offsetRange (negate i) range) list) - -toString :: Source Char -> String -toString = unSource - -at :: Source a -> Int -> a -at = (!!) . unSource classifyMarkup :: Foldable f => f String -> Markup -> Markup classifyMarkup categories element = maybe element ((element !) . A.class_ . stringValue . ("category-" ++)) $ maybeLast categories diff --git a/test/SplitSpec.hs b/test/SplitSpec.hs index 31b121280..88ef8eec9 100644 --- a/test/SplitSpec.hs +++ b/test/SplitSpec.hs @@ -10,6 +10,7 @@ import Test.QuickCheck hiding (Fixed) import Control.Comonad.Cofree import Control.Monad.Free hiding (unfold) import qualified Data.Maybe as Maybe +import Source import Line import Row import Patch