mirror of
https://github.com/github/semantic.git
synced 2024-12-24 07:25:44 +03:00
Move rangesOfWordsFrom into Range.hs.
This commit is contained in:
parent
8acc962ad2
commit
bf9aa915a3
10
app/Main.hs
10
app/Main.hs
@ -11,7 +11,6 @@ import Term
|
||||
import TreeSitter
|
||||
import Unified
|
||||
import Control.Comonad.Cofree
|
||||
import qualified Data.Char as Char
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.ByteString.Char8 as B1
|
||||
import qualified Data.ByteString.Lazy as B2
|
||||
@ -71,12 +70,3 @@ replaceLeavesWithWordBranches source term = replaceIn source 0 term
|
||||
Keyed k -> Keyed $ replaceIn (substring range source) (start range) <$> k
|
||||
_ -> syntax
|
||||
makeLeaf source startIndex lineRange categories range = Info range lineRange categories :< Leaf (substring (offsetRange (negate startIndex) range) source)
|
||||
|
||||
rangesOfWordsFrom :: Int -> String -> [Range]
|
||||
rangesOfWordsFrom startIndex string = case break Char.isSpace string of
|
||||
([], []) -> []
|
||||
([], rest) -> rangesOfWordsAfterWhitespace startIndex rest
|
||||
(word, []) -> [ Range startIndex $ length word ]
|
||||
(word, rest) -> (Range startIndex $ length word) : rangesOfWordsAfterWhitespace (startIndex + length word) rest
|
||||
where
|
||||
rangesOfWordsAfterWhitespace startIndex string | (whitespace, rest) <- break (not . Char.isSpace) string = rangesOfWordsFrom (startIndex + length whitespace) rest
|
||||
|
11
src/Range.hs
11
src/Range.hs
@ -1,5 +1,7 @@
|
||||
module Range where
|
||||
|
||||
import qualified Data.Char as Char
|
||||
|
||||
data Range = Range { start :: Int, end :: Int }
|
||||
deriving (Eq, Show)
|
||||
|
||||
@ -12,5 +14,14 @@ totalRange list = Range 0 $ length list
|
||||
offsetRange :: Int -> Range -> Range
|
||||
offsetRange i (Range start end) = Range (i + start) (i + end)
|
||||
|
||||
rangesOfWordsFrom :: Int -> String -> [Range]
|
||||
rangesOfWordsFrom startIndex string = case break Char.isSpace string of
|
||||
([], []) -> []
|
||||
([], rest) -> rangesOfWordsAfterWhitespace startIndex rest
|
||||
(word, []) -> [ Range startIndex $ length word ]
|
||||
(word, rest) -> (Range startIndex $ length word) : rangesOfWordsAfterWhitespace (startIndex + length word) rest
|
||||
where
|
||||
rangesOfWordsAfterWhitespace startIndex string | (whitespace, rest) <- break (not . Char.isSpace) string = rangesOfWordsFrom (startIndex + length whitespace) rest
|
||||
|
||||
instance Ord Range where
|
||||
a <= b = start a <= start b
|
||||
|
Loading…
Reference in New Issue
Block a user