mirror of
https://github.com/github/semantic.git
synced 2024-11-24 00:42:33 +03:00
Add a function computing the ranges of non-whitespace substrings within a string.
This commit is contained in:
parent
75d76afeb5
commit
0944591fab
10
app/Main.hs
10
app/Main.hs
@ -11,6 +11,7 @@ import Term
|
|||||||
import TreeSitter
|
import TreeSitter
|
||||||
import Unified
|
import Unified
|
||||||
import Control.Comonad.Cofree
|
import Control.Comonad.Cofree
|
||||||
|
import qualified Data.Char as Char
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.ByteString.Char8 as B1
|
import qualified Data.ByteString.Char8 as B1
|
||||||
import qualified Data.ByteString.Lazy as B2
|
import qualified Data.ByteString.Lazy as B2
|
||||||
@ -59,3 +60,12 @@ parserForType mediaType = maybe P.lineByLineParser parseTreeSitterFile $ case me
|
|||||||
".c" -> Just ts_language_c
|
".c" -> Just ts_language_c
|
||||||
".js" -> Just ts_language_javascript
|
".js" -> Just ts_language_javascript
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user