1
1
mirror of https://github.com/github/semantic.git synced 2024-12-18 12:21:57 +03:00

Only pass the start index around.

This commit is contained in:
Rob Rix 2015-12-14 12:37:07 -05:00
parent 774f731ab1
commit 6fc7632e93

View File

@ -62,13 +62,13 @@ parserForType mediaType = maybe P.lineByLineParser parseTreeSitterFile $ case me
_ -> Nothing _ -> Nothing
replaceLeavesWithWordBranches :: String -> Term String Info -> Term String Info replaceLeavesWithWordBranches :: String -> Term String Info -> Term String Info
replaceLeavesWithWordBranches source term@(Info range _ _ :< _) = replaceIn source range term replaceLeavesWithWordBranches source term = replaceIn source 0 term
where where
replaceIn source parentRange (info@(Info range lineRange categories) :< syntax) | range <- offsetRange (negate $ start parentRange) range = info :< case syntax of replaceIn source startIndex (info@(Info range lineRange categories) :< syntax) | range <- offsetRange (negate $ startIndex) range = info :< case syntax of
Leaf _ | ranges <- rangesOfWordsFrom (start range) (substring range source), length ranges > 1 -> Indexed $ makeLeaf source lineRange categories <$> ranges Leaf _ | ranges <- rangesOfWordsFrom (start range) (substring range source), length ranges > 1 -> Indexed $ makeLeaf source lineRange categories <$> ranges
Indexed i -> Indexed $ replaceIn (substring range source) range <$> i Indexed i -> Indexed $ replaceIn (substring range source) (start range) <$> i
Fixed f -> Fixed $ replaceIn (substring range source) range <$> f Fixed f -> Fixed $ replaceIn (substring range source) (start range) <$> f
Keyed k -> Keyed $ replaceIn (substring range source) range <$> k Keyed k -> Keyed $ replaceIn (substring range source) (start range) <$> k
_ -> syntax _ -> syntax
makeLeaf source lineRange categories range = Info range lineRange categories :< Leaf (substring range source) makeLeaf source lineRange categories range = Info range lineRange categories :< Leaf (substring range source)