1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Move Source & its API to the Source module.

This commit is contained in:
Rob Rix 2015-12-23 22:38:20 -05:00
parent cc9dee5704
commit e9449fccb8
3 changed files with 21 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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