1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 12:51:52 +03:00

Generalize breakDownLeavesByWord over extensible record annotations.

This commit is contained in:
Rob Rix 2016-07-14 16:35:49 -04:00
parent d1ed015446
commit 1e88543504

View File

@ -53,10 +53,9 @@ parserForFilepath :: FilePath -> Parser '[Range, Category, Size, Cost]
parserForFilepath = parserForType . T.pack . takeExtension
-- | Replace every string leaf with leaves of the words in the string.
breakDownLeavesByWord :: Source Char -> Term T.Text Info -> Term T.Text Info
breakDownLeavesByWord :: (HasField fields Cost, HasField fields Range, HasField fields Size) => Source Char -> Term T.Text (Record fields) -> Term T.Text (Record fields)
breakDownLeavesByWord source = cata replaceIn
where
replaceIn :: TermF T.Text Info (Term T.Text Info) -> Term T.Text Info
replaceIn (info :< syntax) = let size' = 1 + sum (size . extract <$> syntax') in cofree $ setCost (setSize info size') (Cost (unSize size')) :< syntax'
where syntax' = case (ranges, syntax) of
(_:_:_, Leaf _) -> Indexed (makeLeaf info <$> ranges)