1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Assign leaf costs in breakDownLeavesByWord.

This commit is contained in:
Rob Rix 2016-06-03 12:48:54 -04:00
parent 33791e3ed6
commit 8dd124876d

View File

@ -54,7 +54,7 @@ breakDownLeavesByWord :: Source Char -> Term T.Text Info -> Term T.Text Info
breakDownLeavesByWord source = cata replaceIn
where
replaceIn :: TermF T.Text Info (Term T.Text Info) -> Term T.Text Info
replaceIn (info :< syntax) = cofree $ info { size = 1 + sum (size . extract <$> syntax') } :< syntax'
replaceIn (info :< syntax) = let size' = 1 + sum (size . extract <$> syntax') in cofree $ info { size = size', cost = size' } :< syntax'
where syntax' = case (ranges, syntax) of
(_:_:_, Leaf _) -> Indexed (makeLeaf info <$> ranges)
_ -> syntax