mirror of
https://github.com/github/semantic.git
synced 2024-12-18 04:11:48 +03:00
Only pass the start index around.
This commit is contained in:
parent
774f731ab1
commit
6fc7632e93
10
app/Main.hs
10
app/Main.hs
@ -62,13 +62,13 @@ parserForType mediaType = maybe P.lineByLineParser parseTreeSitterFile $ case me
|
||||
_ -> Nothing
|
||||
|
||||
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
|
||||
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
|
||||
Indexed i -> Indexed $ replaceIn (substring range source) range <$> i
|
||||
Fixed f -> Fixed $ replaceIn (substring range source) range <$> f
|
||||
Keyed k -> Keyed $ replaceIn (substring range source) range <$> k
|
||||
Indexed i -> Indexed $ replaceIn (substring range source) (start range) <$> i
|
||||
Fixed f -> Fixed $ replaceIn (substring range source) (start range) <$> f
|
||||
Keyed k -> Keyed $ replaceIn (substring range source) (start range) <$> k
|
||||
_ -> syntax
|
||||
makeLeaf source lineRange categories range = Info range lineRange categories :< Leaf (substring range source)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user