mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Use Alternative to combine our non-skipped parsers.
This commit is contained in:
parent
835a3a0245
commit
e9f21668a1
12
src/Range.hs
12
src/Range.hs
@ -1,5 +1,6 @@
|
||||
module Range where
|
||||
|
||||
import Control.Applicative ((<|>))
|
||||
import qualified Data.Char as Char
|
||||
|
||||
data Range = Range { start :: Int, end :: Int }
|
||||
@ -17,15 +18,12 @@ offsetRange i (Range start end) = Range (i + start) (i + end)
|
||||
rangesAndWordsFrom :: Int -> String -> [(Range, String)]
|
||||
rangesAndWordsFrom _ "" = []
|
||||
rangesAndWordsFrom startIndex string =
|
||||
case parse isWord string of
|
||||
case (parse isWord string <|> parse (not . isWordOrSeparator) string) of
|
||||
Just parsed -> takeAndContinue parsed
|
||||
Nothing ->
|
||||
case parse (not . isWordOrSeparator) string of
|
||||
Just parsed -> takeAndContinue parsed
|
||||
Nothing ->
|
||||
case parse Char.isSeparator string of
|
||||
Just (space, rest) -> rangesAndWordsFrom (startIndex + length space) rest
|
||||
Nothing -> []
|
||||
case parse Char.isSeparator string of
|
||||
Just (space, rest) -> rangesAndWordsFrom (startIndex + length space) rest
|
||||
Nothing -> []
|
||||
where
|
||||
takeAndContinue (parsed, rest) = (Range startIndex $ startIndex + length parsed, parsed) : rangesAndWordsFrom (startIndex + length parsed) rest
|
||||
parse predicate string = case span predicate string of
|
||||
|
Loading…
Reference in New Issue
Block a user