From a5011772c5d0cf05e9407b5c937fdc046d4e8f59 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 14:55:37 -0700 Subject: [PATCH 01/19] ++js-test --- test/repos/js-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/repos/js-test b/test/repos/js-test index 719d74043..34f20c506 160000 --- a/test/repos/js-test +++ b/test/repos/js-test @@ -1 +1 @@ -Subproject commit 719d74043a87f458f83171d5a4273f33ee624dbb +Subproject commit 34f20c506948668395c1d5049d558881e1b30dd7 From 615871ac8f885b6f8a461f78cff54e884945b04a Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 14:58:48 -0700 Subject: [PATCH 02/19] docs --- src/Syntax.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Syntax.hs b/src/Syntax.hs index 88bf3f4d0..93bb5f227 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -32,6 +32,8 @@ data Syntax -- | The list of arguments to a method call. -- | TODO: It might be worth removing this and using Fixed instead. | Args [f] + -- | A variable declaration. e.g. var foo; | VarDecl f + -- | A variable assignment in a variable declaration. var foo = bar; | VarAssignment { varId :: f, varValue :: f } deriving (Functor, Show, Eq, Foldable, Traversable) From 2465fbe847b2fab26e304397217f2e8974b9f6aa Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:09:44 -0700 Subject: [PATCH 03/19] s/var declaration/variable --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 71f870a76..1746c085e 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -63,7 +63,7 @@ instance HasCategory Category where Category.MethodCall -> "method call" Category.Args -> "arguments" Category.VarAssignment -> "var assignment" - Category.VarDecl -> "var declaration" + Category.VarDecl -> "variable" Identifier -> "identifier" IntegerLiteral -> "integer" Other s -> s From 4d3678b024085a70816102cb9c45055e9c2361b6 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:10:11 -0700 Subject: [PATCH 04/19] Replace toVarDecl's child categories with VarDecl --- src/Parser.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parser.hs b/src/Parser.hs index 1a6cce911..1a68b18ce 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -66,7 +66,7 @@ termConstructor source info = cofree . construct construct children | VarDecl == category info = withDefaultInfo . S.Indexed $ toVarDecl <$> children where toVarDecl :: Term Text Info -> Term Text Info - toVarDecl child = cofree $ (extract child :< S.VarDecl child) + toVarDecl child = cofree $ ((extract child) { category = VarDecl } :< S.VarDecl child) construct children | isFixed (category info) = withDefaultInfo $ S.Fixed children construct children | isKeyed (category info) = withDefaultInfo . S.Keyed . Map.fromList $ assignKey <$> children From 4bcf6afcf38f7ba2ae026f0ba65132db1806a680 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:20:49 -0700 Subject: [PATCH 05/19] Add Switch/Case to Diff.Arbitrary --- src/Diff/Arbitrary.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Diff/Arbitrary.hs b/src/Diff/Arbitrary.hs index 79473e95c..4358b81ee 100644 --- a/src/Diff/Arbitrary.hs +++ b/src/Diff/Arbitrary.hs @@ -74,4 +74,6 @@ instance (Eq leaf, Eq annotation, Arbitrary leaf, Arbitrary annotation) => Arbit Syntax.MemberAccess memberId property -> Syntax.MemberAccess <$> shrink memberId <*> shrink property Syntax.VarDecl decl -> Syntax.VarDecl <$> shrink decl Syntax.VarAssignment varId value -> Syntax.VarAssignment <$> shrink varId <*> shrink value + Syntax.Switch switchExpr cases -> Syntax.Switch <$> shrink switchExpr <*> (List.subsequences cases >>= recursivelyShrink) + Syntax.Case expr statements -> Syntax.Case <$> shrink expr <*> shrink statements Pure patch -> ArbitraryDiff . Pure <$> shrink patch From 6e7c5eeb5a99d5a5a1c2921825c21335284638c9 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:20:58 -0700 Subject: [PATCH 06/19] Add Switch/Case to Syntax --- src/Syntax.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Syntax.hs b/src/Syntax.hs index 93bb5f227..ddd3d5c85 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -36,4 +36,6 @@ data Syntax | VarDecl f -- | A variable assignment in a variable declaration. var foo = bar; | VarAssignment { varId :: f, varValue :: f } + | Switch { switchExpr :: f, cases :: [f] } + | Case { caseExpr :: f, caseStatements :: f } deriving (Functor, Show, Eq, Foldable, Traversable) From e4e7168f3cf914c8119a043d93ee1630eb204342 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:23:58 -0700 Subject: [PATCH 07/19] Add Switch/Case to Term.Arbitrary --- src/Term/Arbitrary.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Term/Arbitrary.hs b/src/Term/Arbitrary.hs index 477ce2915..9ab502552 100644 --- a/src/Term/Arbitrary.hs +++ b/src/Term/Arbitrary.hs @@ -59,3 +59,5 @@ instance (Eq leaf, Eq annotation, Arbitrary leaf, Arbitrary annotation) => Arbit VarAssignment varId value -> VarAssignment <$> shrink varId <*> shrink value Assignment id value -> Assignment <$> shrink id <*> shrink value MemberAccess memberId property -> MemberAccess <$> shrink memberId <*> shrink property + Switch expr cases -> Switch <$> shrink expr <*> (List.subsequences cases >>= recursivelyShrink) + Case expr statements -> Case <$> shrink expr <*> shrink statements From 1875f0cbefaf27beb9611432a384fbeef32612ad Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:48:27 -0700 Subject: [PATCH 08/19] Add Switch and Case to Category --- src/Category.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Category.hs b/src/Category.hs index e4a1dc609..8ca6d48ac 100644 --- a/src/Category.hs +++ b/src/Category.hs @@ -49,6 +49,8 @@ data Category | VarAssignment -- | A variable declaration. | VarDecl + | Switch + | Case -- | A non-standard category, which can be used for comparability. | Other Text deriving (Eq, Show, Ord) From 6d2824475cc7da68d4bf10042c9b7accb7587e01 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:48:47 -0700 Subject: [PATCH 09/19] Add Switch/Case/VarDecl/VarAssignment to Renderer.JSON --- src/Renderer/JSON.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index 177eedb5b..f88e87fbc 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -77,6 +77,10 @@ termFields Info{..} syntax = "range" .= characterRange : "category" .= category Syntax.Args c -> childrenFields c Syntax.Assignment assignmentId property -> [ "assignmentIdentifier" .= assignmentId ] <> [ "property" .= property ] Syntax.MemberAccess memberId value -> [ "memberIdentifier" .= memberId ] <> [ "value" .= value ] + Syntax.Switch expr cases -> [ "switchExpression" .= expr ] <> [ "cases" .= cases ] + Syntax.Case expr body -> [ "caseExpression" .= expr ] <> [ "caseStatement" .= body ] + Syntax.VarDecl decl -> [ "variableDeclaration" .= decl ] + Syntax.VarAssignment id value -> [ "varIdentifier" .= id ] <> [ "value" .= value ] where childrenFields c = [ "children" .= c ] patchFields :: KeyValue kv => SplitPatch (Term leaf Info) -> [kv] From 69e5fca7cbfea49de2ea8be3016fc532f93b34b8 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:49:02 -0700 Subject: [PATCH 10/19] Add Switch/Case to styleName --- src/Renderer/Split.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Renderer/Split.hs b/src/Renderer/Split.hs index cc25536fc..9ef290b14 100644 --- a/src/Renderer/Split.hs +++ b/src/Renderer/Split.hs @@ -53,6 +53,8 @@ styleName category = "category-" <> case category of Category.MemberAccess -> "member_access" Category.VarDecl -> "var_declaration" Category.VarAssignment -> "var_assignment" + Category.Switch -> "switch" + Category.Case -> "case" TemplateString -> "template_string" Regex -> "regex" Identifier -> "identifier" From f28e50da8afff273a849a78e1fc8b255a903b26a Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:49:11 -0700 Subject: [PATCH 11/19] Add Switch/Case to Renderer.Split --- src/Renderer/Split.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Renderer/Split.hs b/src/Renderer/Split.hs index 9ef290b14..e3774cdd0 100644 --- a/src/Renderer/Split.hs +++ b/src/Renderer/Split.hs @@ -126,6 +126,8 @@ instance ToMarkup f => ToMarkup (Renderable (Source Char, Info, Syntax a (f, Ran Syntax.VarDecl decl -> ul . mconcat $ wrapIn li <$> contentElements source characterRange [decl] Syntax.VarAssignment varId value -> dl . mconcat $ (wrapIn dt <$> (contentElements source characterRange [varId])) <> (wrapIn dd <$> contentElements source characterRange [value]) + Syntax.Switch expr cases -> ul . mconcat $ wrapIn li <$> contentElements source characterRange (expr : cases) + Syntax.Case expr body -> ul . mconcat $ wrapIn li <$> contentElements source characterRange [expr, body] contentElements :: (Foldable t, ToMarkup f) => Source Char -> Range -> t (f, Range) -> [Markup] contentElements source range children = let (elements, next) = foldr' (markupForContextAndChild source) ([], end range) children in text (toText (slice (Range (start range) (max next (start range))) source)) : elements From 212c0cc1a85abd140bb3314e3a4b777b1cc7672f Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:51:17 -0700 Subject: [PATCH 12/19] Add Case/Switch to toTermName --- src/DiffSummary.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 1746c085e..10923e662 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -36,9 +36,13 @@ toTermName term = case unwrap term of _ -> "." Syntax.VarAssignment varId _ -> toTermName varId Syntax.VarDecl decl -> toTermName decl - -- TODO: We should remove Args from Syntax since I don't think we shouldn ever + -- TODO: We should remove Args from Syntax since I don't think we should ever -- evaluate Args as a single toTermName Text - joshvera Syntax.Args args -> mconcat $ toTermName <$> args + -- TODO: We should remove Case from Syntax since I don't think we should ever + -- evaluate Case as a single toTermName Text - joshvera + Syntax.Case expr _ -> toTermName expr + Syntax.Switch expr cases -> toTermName expr class HasCategory a where toCategoryName :: a -> Text From 8e32dea21c046ac262b66c447987c4094ad9456c Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:57:55 -0700 Subject: [PATCH 13/19] Not using this --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 10923e662..ba5be9707 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -42,7 +42,7 @@ toTermName term = case unwrap term of -- TODO: We should remove Case from Syntax since I don't think we should ever -- evaluate Case as a single toTermName Text - joshvera Syntax.Case expr _ -> toTermName expr - Syntax.Switch expr cases -> toTermName expr + Syntax.Switch expr _ -> toTermName expr class HasCategory a where toCategoryName :: a -> Text From 4fceda482d89d9c32b4ae790dfeab13b2c5ed7ae Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 15:58:08 -0700 Subject: [PATCH 14/19] Add a switch case to termToDiffInfo --- src/DiffSummary.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index ba5be9707..b9435fb85 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -133,6 +133,7 @@ termToDiffInfo term = case runCofree term of args@(info :< Syntax.Args{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree args) ] varDecl@(info :< Syntax.VarDecl{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree varDecl) ] varAssignment@(info :< Syntax.VarAssignment{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree varAssignment) ] + switch@(info :< Syntax.Switch{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree switch) ] prependSummary :: Category -> DiffSummary DiffInfo -> DiffSummary DiffInfo prependSummary annotation summary = summary { parentAnnotations = annotation : parentAnnotations summary } From 68e9a501bfbe2cae1614bb91f64fa7ac40d7740a Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 16:13:22 -0700 Subject: [PATCH 15/19] ++js-test --- test/repos/js-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/repos/js-test b/test/repos/js-test index 34f20c506..5339029f8 160000 --- a/test/repos/js-test +++ b/test/repos/js-test @@ -1 +1 @@ -Subproject commit 34f20c506948668395c1d5049d558881e1b30dd7 +Subproject commit 5339029f879a6c74f022be68d6c4ef1fd7c79a5f From 39d200ebdcf0c36053e9ad8c560c8a5dad8e0d40 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 16:51:48 -0700 Subject: [PATCH 16/19] Add Switch/Case to HasCategory Category instance --- src/DiffSummary.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index b9435fb85..b45a3ab93 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -68,6 +68,8 @@ instance HasCategory Category where Category.Args -> "arguments" Category.VarAssignment -> "var assignment" Category.VarDecl -> "variable" + Category.Switch -> "switch statement" + Category.Case -> "case statement" Identifier -> "identifier" IntegerLiteral -> "integer" Other s -> s From 243b3665557d3a3e819f0a79e73774466ecb18c1 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 16:52:05 -0700 Subject: [PATCH 17/19] Add Switch/Case cases to diffSummary --- src/DiffSummary.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index b45a3ab93..b9c52c124 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -115,6 +115,8 @@ diffSummary = cata $ \case (Free (infos :< Syntax.VarAssignment varId value)) -> prependSummary (category $ snd infos) <$> varId <> value (Free (infos :< Syntax.VarDecl decl)) -> prependSummary (category $ snd infos) <$> decl (Free (infos :< Syntax.Args args)) -> prependSummary (category $ snd infos) <$> join args + (Free (infos :< Syntax.Switch expr cases)) -> prependSummary (category $ snd infos) <$> expr <> join cases + (Free (infos :< Syntax.Case expr body)) -> prependSummary (category $ snd infos) <$> expr <> body (Pure (Insert term)) -> (\info -> DiffSummary (Insert info) []) <$> termToDiffInfo term (Pure (Delete term)) -> (\info -> DiffSummary (Delete info) []) <$> termToDiffInfo term (Pure (Replace t1 t2)) -> (\(info1, info2) -> DiffSummary (Replace info1 info2) []) <$> zip (termToDiffInfo t1) (termToDiffInfo t2) From f1fd404826c02944d37183b862355823f86cc72e Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 16:52:20 -0700 Subject: [PATCH 18/19] Map tree-sitter nodes to Switch/Case --- src/Parser.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Parser.hs b/src/Parser.hs index 1a68b18ce..f06d9c24f 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -68,6 +68,12 @@ termConstructor source info = cofree . construct toVarDecl :: Term Text Info -> Term Text Info toVarDecl child = cofree $ ((extract child) { category = VarDecl } :< S.VarDecl child) + construct children | Switch == category info , (expr:cases) <- children = + withDefaultInfo $ S.Switch expr children + + construct children | Case == category info , [expr, body] <- children = + withDefaultInfo $ S.Case expr body + construct children | isFixed (category info) = withDefaultInfo $ S.Fixed children construct children | isKeyed (category info) = withDefaultInfo . S.Keyed . Map.fromList $ assignKey <$> children construct children = withDefaultInfo $ S.Indexed children From 6fea8145e4731e95cc4ab72fc2fa961318437889 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 15 Jun 2016 16:52:39 -0700 Subject: [PATCH 19/19] Add Switch/Case to defaultCategoryForNodeName --- src/TreeSitter.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index e5128c724..35a322010 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -56,6 +56,8 @@ defaultCategoryForNodeName name = case name of "template_string" -> TemplateString "var_assignment" -> VarAssignment "var_declaration" -> VarDecl + "switch_statement" -> Switch + "case" -> Case _ -> Other name -- | Return a parser for a tree sitter language & document.