From 51b55cc1b49c1285ecc2448cf8eaffb15ce911cd Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:19:15 -0400 Subject: [PATCH 1/8] Generalize toTermName over record annotations. --- src/DiffSummary.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 2efbe689f..9b86b02c7 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -12,11 +12,12 @@ import Category import Data.Functor.Foldable as Foldable import Data.Functor.Both import Data.OrderedMap +import Data.Record import Data.Text as Text (intercalate, unpack) data DiffInfo = DiffInfo { categoryName :: Text, termName :: Text } deriving (Eq, Show) -toTermName :: HasCategory leaf => Term leaf Info -> Text +toTermName :: (HasCategory leaf, HasField fields Category) => Term leaf (Record fields) -> Text toTermName term = case unwrap term of Fixed children -> fromMaybe "EmptyFixedNode" $ (toCategoryName . category) . extract <$> head children Indexed children -> fromMaybe "EmptyIndexedNode" $ (toCategoryName . category) . extract <$> head children From 63a37920ace682c265412526c525b4a5ce83dd01 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:19:47 -0400 Subject: [PATCH 2/8] Generalize HasCategory over categorizable terms. --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 9b86b02c7..567034852 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -99,7 +99,7 @@ instance HasCategory Category where TemplateString -> "template string" Category.Object -> "object" -instance HasCategory leaf => HasCategory (Term leaf Info) where +instance (HasCategory leaf, HasField fields Category) => HasCategory (Term leaf (Record fields)) where toCategoryName = toCategoryName . category . extract data DiffSummary a = DiffSummary { From 577ca768bbf929276dd548d67171e168e3be9ca1 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:23:44 -0400 Subject: [PATCH 3/8] Get the category name from the Term instance. --- src/DiffSummary.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 567034852..0e08e66d9 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -154,17 +154,17 @@ termToDiffInfo term = case runCofree term of (_ :< Indexed children) -> join $ termToDiffInfo <$> children (_ :< Fixed children) -> join $ termToDiffInfo <$> children (_ :< Keyed children) -> join $ termToDiffInfo <$> Prologue.toList children - (info :< Syntax.FunctionCall identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ] - (info :< Syntax.Ternary ternaryCondition _) -> [ DiffInfo (toCategoryName info) (toTermName ternaryCondition) ] - (info :< Syntax.Function identifier _ _) -> [ DiffInfo (toCategoryName info) (maybe "anonymous" toTermName identifier) ] - (info :< Syntax.Assignment identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ] - (info :< Syntax.MathAssignment identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ] + (_ :< Syntax.FunctionCall identifier _) -> [ DiffInfo (toCategoryName term) (toTermName identifier) ] + (_ :< Syntax.Ternary ternaryCondition _) -> [ DiffInfo (toCategoryName term) (toTermName ternaryCondition) ] + (_ :< Syntax.Function identifier _ _) -> [ DiffInfo (toCategoryName term) (maybe "anonymous" toTermName identifier) ] + (_ :< Syntax.Assignment identifier _) -> [ DiffInfo (toCategoryName term) (toTermName identifier) ] + (_ :< Syntax.MathAssignment identifier _) -> [ DiffInfo (toCategoryName term) (toTermName identifier) ] -- Currently we cannot express the operator for an operator production from TreeSitter. Eventually we should be able to -- use the term name of the operator identifier when we have that production value. Until then, I'm using a placeholder value -- to indicate where that value should be when constructing DiffInfos. - (info :< Syntax.Operator _) -> [DiffInfo (toCategoryName info) "x"] - (info :< Commented cs leaf) -> join (termToDiffInfo <$> cs) <> maybe [] (\leaf -> [ DiffInfo (toCategoryName info) (toTermName leaf) ]) leaf - (info :< _) -> [ DiffInfo (toCategoryName info) (toTermName term) ] + (_ :< Syntax.Operator _) -> [DiffInfo (toCategoryName term) "x"] + (_ :< Commented cs leaf) -> join (termToDiffInfo <$> cs) <> maybe [] (\leaf -> [ DiffInfo (toCategoryName term) (toTermName leaf) ]) leaf + _ -> [ DiffInfo (toCategoryName term) (toTermName term) ] prependSummary :: Category -> DiffSummary DiffInfo -> DiffSummary DiffInfo prependSummary annotation summary = summary { parentAnnotations = annotation : parentAnnotations summary } From fa44ef74d8e933da3f621b3b988fa00bde943ac4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:23:51 -0400 Subject: [PATCH 4/8] :fire: the HasCategory instance over Info. --- src/DiffSummary.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 0e08e66d9..10dbbd180 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -62,9 +62,6 @@ class HasCategory a where instance HasCategory Text where toCategoryName = identity -instance HasCategory Info where - toCategoryName = toCategoryName . category - instance HasCategory Category where toCategoryName = \case ArrayLiteral -> "array" From 13d2dfc24f50a20bfc1a53e4e2b8d6ce4b2fbc7f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:25:27 -0400 Subject: [PATCH 5/8] Generalize termToDiffInfo over records. --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 10dbbd180..5b7b8d570 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -145,7 +145,7 @@ diffSummary = cata $ \case (Pure (Delete term)) -> (\info -> DiffSummary (Delete info) []) <$> termToDiffInfo term (Pure (Replace t1 t2)) -> (\(info1, info2) -> DiffSummary (Replace info1 info2) []) <$> zip (termToDiffInfo t1) (termToDiffInfo t2) -termToDiffInfo :: HasCategory leaf => Term leaf Info -> [DiffInfo] +termToDiffInfo :: (HasCategory leaf, HasField fields Category) => Term leaf (Record fields) -> [DiffInfo] termToDiffInfo term = case runCofree term of (_ :< Leaf _) -> [ DiffInfo (toCategoryName term) (toTermName term) ] (_ :< Indexed children) -> join $ termToDiffInfo <$> children From f51b1724fe7ab09adcb0e5b396da4c568531fa87 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:25:37 -0400 Subject: [PATCH 6/8] Generalize diffSummary over records. --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 5b7b8d570..522bc2774 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -116,7 +116,7 @@ instance Show (DiffSummary DiffInfo) where then "" else " in the " <> intercalate "/" (toCategoryName <$> parentAnnotations) <> " context" -diffSummary :: HasCategory leaf => Diff leaf Info -> [DiffSummary DiffInfo] +diffSummary :: (HasCategory leaf, HasField fields Category) => Diff leaf (Record fields) -> [DiffSummary DiffInfo] diffSummary = cata $ \case -- Skip comments and leaves since they don't have any changes (Free (_ :< Leaf _)) -> [] From 7304d79e539371f85aceac27a45e4e24f6fa30c3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:25:43 -0400 Subject: [PATCH 7/8] =?UTF-8?q?Don=E2=80=99t=20import=20the=20`Info`=20typ?= =?UTF-8?q?e=20synonym.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 522bc2774..bad6b81da 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -4,7 +4,7 @@ module DiffSummary (DiffSummary(..), diffSummary, DiffInfo(..)) where import Prologue hiding (snd, intercalate) import Diff -import Info (Info, category) +import Info (category) import Patch import Term import Syntax From 9e9622ef10510c6d99044d0c319905959e142d39 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 14 Jul 2016 14:25:49 -0400 Subject: [PATCH 8/8] :fire: a redundant import. --- src/Term.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Term.hs b/src/Term.hs index 72a9a2027..0c71a52fb 100644 --- a/src/Term.hs +++ b/src/Term.hs @@ -8,7 +8,6 @@ import Data.Functor.Foldable as Foldable import Data.Functor.Both import Data.These import Syntax -import Unsafe -- | An annotated node (Syntax) in an abstract syntax tree. type TermF a annotation = CofreeF (Syntax a) annotation