1
1
mirror of https://github.com/github/semantic.git synced 2025-01-06 23:46:21 +03:00

Pattern match leaf in branches for correct use of 'the'

This commit is contained in:
Timothy Clem 2016-09-19 17:39:30 -07:00
parent 57271f30b7
commit 140bd7860b
2 changed files with 15 additions and 7 deletions

View File

@ -83,12 +83,9 @@ summaries patch = eitherErrorOrDoc <$> patchToDoc patch
-- or `ErrorInfo` it contains.
patchToDoc :: Patch DiffInfo -> [Doc]
patchToDoc = \case
p@(Replace i1 i2) -> zipWith (\a b -> (prefixWithPatch p) a <+> connector i1 <+> b) (toLeafInfos i1) (toLeafInfos i2)
p@(Replace i1 i2) -> zipWith (\a b -> prefixWithPatch p a <+> determiner "with" i1 <+> b) (toLeafInfos i1) (toLeafInfos i2)
p@(Insert info) -> prefixWithPatch p <$> toLeafInfos info
p@(Delete info) -> prefixWithPatch p <$> toLeafInfos info
where
connector (LeafInfo "number" _) = "with"
connector _ = "with the"
-- Prefixes a given doc with the type of patch it represents.
prefixWithPatch :: Patch DiffInfo -> Doc -> Doc
@ -100,8 +97,18 @@ prefixWithPatch patch = prefixWithThe (patchToPrefix patch)
(Insert _) -> "Added"
(Delete _) -> "Deleted"
connector = \case
(Replace (LeafInfo "number" _) _) -> ""
_ -> "the"
(Replace leaf _) -> determiner' leaf
(Insert leaf) -> determiner' leaf
(Delete leaf) -> determiner' leaf
-- Optional determiner (e.g. "the") to tie together summary statements.
determiner :: Doc -> DiffInfo -> Doc
determiner prefix (LeafInfo "number" _) = prefix <+> ""
determiner prefix (BranchInfo bs _ _) = determiner prefix (last bs)
determiner prefix _ = prefix <+> "the"
determiner' :: DiffInfo -> Doc
determiner' = determiner ""
toLeafInfos :: DiffInfo -> [Doc]
toLeafInfos (LeafInfo "number" termName) = pure (squotes (toDoc termName))

View File

@ -1,10 +1,11 @@
module Prologue
( module X
, lookup
, last
) where
import Protolude as X
import Data.List (lookup)
import Data.List (lookup, last)
import Control.Comonad.Trans.Cofree as X
import Control.Monad.Trans.Free as X