1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 17:05:33 +03:00

Move actualLines/actualLineRanges into the Source module.

This commit is contained in:
Rob Rix 2015-12-24 00:08:17 -05:00
parent d355f268e6
commit cfeb9e4ee8
2 changed files with 12 additions and 13 deletions

View File

@ -35,3 +35,15 @@ break predicate (Source vector) = let (start, remainder) = Vector.break predicat
(++) :: Source a -> Source a -> Source a (++) :: Source a -> Source a -> Source a
(++) (Source a) = Source . (a Vector.++) . getVector (++) (Source a) = Source . (a Vector.++) . getVector
actualLines :: Source Char -> [Source Char]
actualLines source | length source == 0 = [ source ]
actualLines source = case Source.break (== '\n') source of
(l, lines') -> case uncons lines' of
Nothing -> [ l ]
Just (_, lines') -> (l Source.++ fromList "\n") : actualLines lines'
-- | Compute the line ranges within a given range of a string.
actualLineRanges :: Range -> Source Char -> [Range]
actualLineRanges range = drop 1 . scanl toRange (Range (start range) (start range)) . actualLines . slice range
where toRange previous string = Range (end previous) $ end previous + length string

View File

@ -18,7 +18,6 @@ import Text.Blaze.Html.Renderer.Utf8
import Data.Monoid import Data.Monoid
import qualified Data.Set as Set import qualified Data.Set as Set
import Source hiding ((++)) import Source hiding ((++))
import qualified Source as Source ((++))
type ClassName = String type ClassName = String
@ -153,15 +152,3 @@ openDiff source diff@(Pure term) = const diff <$> openTerm source term
zipWithDefaults :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c] zipWithDefaults :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c]
zipWithDefaults f da db a b = take (max (length a) (length b)) $ zipWith f (a ++ repeat da) (b ++ repeat db) zipWithDefaults f da db a b = take (max (length a) (length b)) $ zipWith f (a ++ repeat da) (b ++ repeat db)
actualLines :: Source Char -> [Source Char]
actualLines source | length source == 0 = [ source ]
actualLines source = case Source.break (== '\n') source of
(l, lines') -> case uncons lines' of
Nothing -> [ l ]
Just (_, lines') -> (l Source.++ fromList "\n") : actualLines lines'
-- | Compute the line ranges within a given range of a string.
actualLineRanges :: Range -> Source Char -> [Range]
actualLineRanges range = drop 1 . scanl toRange (Range (start range) (start range)) . actualLines . slice range
where toRange previous string = Range (end previous) $ end previous + length string