From 5fbec01df24fdacde8175dde46ff8019e3adb128 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 19:49:28 -0400 Subject: [PATCH 01/39] Add freer-cofreer as a submodule. --- .gitmodules | 3 +++ vendor/freer-cofreer | 1 + 2 files changed, 4 insertions(+) create mode 160000 vendor/freer-cofreer diff --git a/.gitmodules b/.gitmodules index 0e9fd3c07..0088a413f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,3 +37,6 @@ [submodule "languages/json/vendor/tree-sitter-json"] path = languages/json/vendor/tree-sitter-json url = https://github.com/tree-sitter/tree-sitter-json +[submodule "vendor/freer-cofreer"] + path = vendor/freer-cofreer + url = https://github.com/robrix/freer-cofreer.git diff --git a/vendor/freer-cofreer b/vendor/freer-cofreer new file mode 160000 index 000000000..f18b72357 --- /dev/null +++ b/vendor/freer-cofreer @@ -0,0 +1 @@ +Subproject commit f18b723579f700674dda90ed1519f6e7298e2117 From bb6d3051ceddee7a80810991d7779a09f5c171c3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 19:54:52 -0400 Subject: [PATCH 02/39] Ignore local project files. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ae591ed76..149cf6917 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ xcuserdata profiles tags +cabal.project.local + tmp/ vendor/icu/tools From 2ba496fed43fa0b42678edbe3475e74570047fb8 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 19:54:57 -0400 Subject: [PATCH 03/39] Ignore dist-newstyle. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 149cf6917..7f56c5444 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ profiles tags cabal.project.local +dist-newstyle tmp/ From afb8f6c75444c84545a1c9ac2b2a9e7a8ed06ea6 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 20:03:03 -0400 Subject: [PATCH 04/39] Add a cabal.project file. --- cabal.project | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 cabal.project diff --git a/cabal.project b/cabal.project new file mode 100644 index 000000000..5c91849fb --- /dev/null +++ b/cabal.project @@ -0,0 +1,2 @@ +packages: semantic-diff.cabal languages/*/*.cabal vendor/effects/effects.cabal vendor/freer-cofreer/freer-cofreer.cabal vendor/haskell-tree-sitter/haskell-tree-sitter.cabal vendor/hspec-expectations-pretty-diff/hspec-expectations-pretty-diff.cabal +jobs: $ncpus From db54630e59ad342a7583e7f318942522138c47b9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 20:04:38 -0400 Subject: [PATCH 05/39] List the vendor packages in optional-packages. --- cabal.project | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index 5c91849fb..059bea068 100644 --- a/cabal.project +++ b/cabal.project @@ -1,2 +1,3 @@ -packages: semantic-diff.cabal languages/*/*.cabal vendor/effects/effects.cabal vendor/freer-cofreer/freer-cofreer.cabal vendor/haskell-tree-sitter/haskell-tree-sitter.cabal vendor/hspec-expectations-pretty-diff/hspec-expectations-pretty-diff.cabal +packages: semantic-diff.cabal languages/*/*.cabal +optional-packages: vendor/*/*.cabal jobs: $ncpus From 926fd1327d5c52af255d97ba5f07ac011cc3fb93 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 20:04:53 -0400 Subject: [PATCH 06/39] =?UTF-8?q?Hide=20Freer=E2=80=99s=20definition=20of?= =?UTF-8?q?=20cutoff.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Interpreter.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 59011e056..4e58a003d 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -9,7 +9,7 @@ module Interpreter ) where import Algorithm -import Control.Monad.Free.Freer +import Control.Monad.Free.Freer hiding (cutoff) import Data.Align.Generic import Data.Functor.Both import Data.Functor.Classes (Eq1) From 9983c1e5155493dcca96bce035ddda072847c775 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 20:07:17 -0400 Subject: [PATCH 07/39] Revert to simple setup. --- Setup.hs | 34 +--------------------------------- semantic-diff.cabal | 8 +------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/Setup.hs b/Setup.hs index 8f5b81328..9a994af67 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,34 +1,2 @@ -import Data.Maybe -import qualified Distribution.PackageDescription as P import Distribution.Simple -import Distribution.Simple.LocalBuildInfo -import Distribution.Simple.Setup -import System.Directory -import System.Process - -main = defaultMainWithHooks simpleUserHooks { confHook = conf } - -conf :: (P.GenericPackageDescription, P.HookedBuildInfo) -> ConfigFlags -> IO LocalBuildInfo -conf x flags = do - localBuildInfo <- confHook simpleUserHooks x flags - let packageDescription = localPkgDescr localBuildInfo - library = fromJust $ P.library packageDescription - libraryBuildInfo = P.libBuildInfo library - relativeIncludeDirs = [ "common", "i18n" ] in do - dir <- getCurrentDirectory - let icuLibDir = dir ++ "/vendor/icu/lib" - let icuSourceDir = dir ++ "/vendor/icu/source/" - icuLibDirExists <- doesDirectoryExist icuLibDir - icuSourceDirExists <- doesDirectoryExist icuSourceDir - let extraLibDirs = P.extraLibDirs libraryBuildInfo - let includeDirs = P.includeDirs libraryBuildInfo - return localBuildInfo { - localPkgDescr = packageDescription { - P.library = Just $ library { - P.libBuildInfo = libraryBuildInfo { - P.extraLibDirs = if icuLibDirExists then icuLibDir : extraLibDirs else extraLibDirs, - P.includeDirs = if icuSourceDirExists then ((icuSourceDir ++) <$> relativeIncludeDirs) ++ includeDirs else includeDirs - } - } - } - } +main = defaultMain diff --git a/semantic-diff.cabal b/semantic-diff.cabal index df043eb8b..c5704275a 100644 --- a/semantic-diff.cabal +++ b/semantic-diff.cabal @@ -7,7 +7,7 @@ author: Rob Rix, Josh Vera maintainer: rob.rix@github.com copyright: 2016 GitHub category: Web -build-type: Custom +build-type: Simple -- extra-source-files: cabal-version: >=1.10 @@ -181,12 +181,6 @@ test-suite test default-language: Haskell2010 default-extensions: DeriveFunctor, DeriveGeneric, FlexibleContexts, FlexibleInstances, OverloadedStrings, NoImplicitPrelude, RecordWildCards -custom-setup - setup-depends: base >= 4.8 && < 5 - , Cabal - , directory - , process - source-repository head type: git location: https://github.com/github/semantic-diff From ba1e043f259ab917defa3159d1eb8afb9496336d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 20:12:39 -0400 Subject: [PATCH 08/39] Bump haskell-tree-sitter to ignore some things. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 5607136d2..a5b69a1c5 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 5607136d25485b82159412948e7933f548381a12 +Subproject commit a5b69a1c52eb6b836b1c0027be4edc544c894482 From a889ded79cd59163508d304d775f1ab52b488129 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 10:33:08 -0400 Subject: [PATCH 09/39] Bump haskell-tree-sitter for template-haskell-2.12.0.0 support. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 5607136d2..b7ece8ec3 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 5607136d25485b82159412948e7933f548381a12 +Subproject commit b7ece8ec385b67856b29257a3c867759765b29b7 From 3ba14400f4403bd5b5e7791bea213ac3b9ccacd9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 10:34:30 -0400 Subject: [PATCH 10/39] Use the simple build type. --- Setup.hs | 34 +--------------------------------- semantic-diff.cabal | 8 +------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/Setup.hs b/Setup.hs index 8f5b81328..9a994af67 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,34 +1,2 @@ -import Data.Maybe -import qualified Distribution.PackageDescription as P import Distribution.Simple -import Distribution.Simple.LocalBuildInfo -import Distribution.Simple.Setup -import System.Directory -import System.Process - -main = defaultMainWithHooks simpleUserHooks { confHook = conf } - -conf :: (P.GenericPackageDescription, P.HookedBuildInfo) -> ConfigFlags -> IO LocalBuildInfo -conf x flags = do - localBuildInfo <- confHook simpleUserHooks x flags - let packageDescription = localPkgDescr localBuildInfo - library = fromJust $ P.library packageDescription - libraryBuildInfo = P.libBuildInfo library - relativeIncludeDirs = [ "common", "i18n" ] in do - dir <- getCurrentDirectory - let icuLibDir = dir ++ "/vendor/icu/lib" - let icuSourceDir = dir ++ "/vendor/icu/source/" - icuLibDirExists <- doesDirectoryExist icuLibDir - icuSourceDirExists <- doesDirectoryExist icuSourceDir - let extraLibDirs = P.extraLibDirs libraryBuildInfo - let includeDirs = P.includeDirs libraryBuildInfo - return localBuildInfo { - localPkgDescr = packageDescription { - P.library = Just $ library { - P.libBuildInfo = libraryBuildInfo { - P.extraLibDirs = if icuLibDirExists then icuLibDir : extraLibDirs else extraLibDirs, - P.includeDirs = if icuSourceDirExists then ((icuSourceDir ++) <$> relativeIncludeDirs) ++ includeDirs else includeDirs - } - } - } - } +main = defaultMain diff --git a/semantic-diff.cabal b/semantic-diff.cabal index df043eb8b..c5704275a 100644 --- a/semantic-diff.cabal +++ b/semantic-diff.cabal @@ -7,7 +7,7 @@ author: Rob Rix, Josh Vera maintainer: rob.rix@github.com copyright: 2016 GitHub category: Web -build-type: Custom +build-type: Simple -- extra-source-files: cabal-version: >=1.10 @@ -181,12 +181,6 @@ test-suite test default-language: Haskell2010 default-extensions: DeriveFunctor, DeriveGeneric, FlexibleContexts, FlexibleInstances, OverloadedStrings, NoImplicitPrelude, RecordWildCards -custom-setup - setup-depends: base >= 4.8 && < 5 - , Cabal - , directory - , process - source-repository head type: git location: https://github.com/github/semantic-diff From 754a02e2aec792f9945d6190b53774e58239d4f3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 10:46:20 -0400 Subject: [PATCH 11/39] Apparently Prologue exports Nat now. --- src/FDoc/NatExample.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FDoc/NatExample.hs b/src/FDoc/NatExample.hs index c94eeb414..da9ad4a19 100644 --- a/src/FDoc/NatExample.hs +++ b/src/FDoc/NatExample.hs @@ -1,6 +1,6 @@ module FDoc.NatExample where -import Prologue +import Prologue hiding (Nat) import Data.Functor.Foldable -- Our base Functor. The recursive bit is parameterized by r. From 05f43ebd99d047eecb0e1fddddb7a6102571f67b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 10:46:28 -0400 Subject: [PATCH 12/39] Make sure we export the Semigroup <>, not the Monoid <>. --- src/Prologue.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Prologue.hs b/src/Prologue.hs index 6f3735b8d..1b7f71ace 100644 --- a/src/Prologue.hs +++ b/src/Prologue.hs @@ -8,8 +8,9 @@ module Prologue , module Data.Hashable ) where -import Protolude as X +import Protolude as X hiding ((<>)) import Data.List (lookup) +import Data.Semigroup as X (Semigroup(..)) import Control.Comonad.Cofree as X hiding ((:<), unfold, unfoldM) import Control.Monad.Free as X (Free()) From ab40cce297bb87381e6466afb3f30ed7652cec84 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 11:01:34 -0400 Subject: [PATCH 13/39] :fire: the leaf type parameter from Syntax. --- src/Diff.hs | 2 +- src/FDoc/RecursionSchemes.hs | 11 +++++------ src/FDoc/Term.hs | 9 ++++----- src/Interpreter.hs | 14 +++++++------- src/Parser.hs | 8 ++++---- src/Renderer.hs | 6 +++--- src/Renderer/JSON.hs | 2 +- src/Renderer/TOC.hs | 2 +- src/SplitDiff.hs | 2 +- src/Syntax.hs | 24 +++++++++--------------- src/Term.hs | 4 ++-- test/InterpreterSpec.hs | 6 +++--- test/PatchOutputSpec.hs | 2 +- test/TOCSpec.hs | 18 +++++++++--------- 14 files changed, 51 insertions(+), 59 deletions(-) diff --git a/src/Diff.hs b/src/Diff.hs index e90011c17..3731bfb21 100644 --- a/src/Diff.hs +++ b/src/Diff.hs @@ -14,7 +14,7 @@ import Term type DiffF f annotation = FreeF (TermF f (Both annotation)) (Patch (Term f annotation)) type Diff f annotation = Free (TermF f (Both annotation)) (Patch (Term f annotation)) -type SyntaxDiff leaf fields = Diff (Syntax leaf) (Record fields) +type SyntaxDiff fields = Diff Syntax (Record fields) diffSum :: (Foldable f, Functor f) => (Patch (Term f annotation) -> Int) -> Diff f annotation -> Int diffSum patchCost diff = sum $ fmap patchCost diff diff --git a/src/FDoc/RecursionSchemes.hs b/src/FDoc/RecursionSchemes.hs index afb479273..1e39ffeec 100644 --- a/src/FDoc/RecursionSchemes.hs +++ b/src/FDoc/RecursionSchemes.hs @@ -5,7 +5,6 @@ import Data.Range import Data.Record import Category import Term -import Syntax import Prologue import Prelude import FDoc.Term @@ -25,7 +24,7 @@ structure. The example below adds a new field to the `Record` fields. -} -indexedTermAna :: [leaf] -> Term (Syntax leaf) (Record '[NewField, Range, Category]) +indexedTermAna :: [leaf] -> SyntaxTerm (Record '[NewField, Range, Category]) indexedTermAna childrenLeaves = ana coalgebra (indexedTerm childrenLeaves) where coalgebra term = (NewField :. (extract term)) :< unwrap term @@ -43,7 +42,7 @@ structure to a new shape. The example below adds a new field to the `Record` fields. -} -indexedTermCata :: [leaf] -> Term (Syntax leaf) (Record '[NewField, Range, Category]) +indexedTermCata :: [leaf] -> SyntaxTerm (Record '[NewField, Range, Category]) indexedTermCata childrenLeaves = cata algebra (indexedTerm childrenLeaves) where algebra :: Functor f => CofreeF f (Record t) (Cofree f (Record (NewField : t))) -> Cofree f (Record (NewField : t)) @@ -82,7 +81,7 @@ stringToTermAna "indexed" => the new cofree `Indexed` structure, resulting in a expansion of all possible string terms. -} -stringToTermAna :: String -> Term (Syntax String) (Record '[Range, Category]) +stringToTermAna :: String -> SyntaxTerm (Record '[Range, Category]) stringToTermAna = ana coalgebra where coalgebra representation = case representation of @@ -95,7 +94,7 @@ Catamorphism -- construct a list of Strings from a recursive Term structure. The example below shows how to tear down a recursive Term structure into a list of String representation. -} -termToStringCata :: Term (Syntax String) (Record '[Range, Category]) -> [String] +termToStringCata :: SyntaxTerm (Record '[Range, Category]) -> [String] termToStringCata = cata algebra where algebra term = case term of @@ -177,7 +176,7 @@ Final shape: ] -} -termPara :: Term (Syntax String) (Record '[Range, Category]) -> [(Term (Syntax String) (Record '[Range, Category]), String)] +termPara :: Syntaxterm (Record '[Range, Category]) -> [(SyntaxTerm (Record '[Range, Category]), String)] termPara = para algebra where algebra term = case term of diff --git a/src/FDoc/Term.hs b/src/FDoc/Term.hs index 0d90ebdcf..5a9764fe4 100644 --- a/src/FDoc/Term.hs +++ b/src/FDoc/Term.hs @@ -5,7 +5,6 @@ import Data.Range import Data.Record import Category import Term -import Syntax import Prologue {- @@ -32,7 +31,7 @@ Example (from GHCi): -} -leafTermF :: leaf -> TermF (Syntax leaf) (Record '[Range, Category]) b +leafTermF :: leaf -> SyntaxTermF (Record '[Range, Category]) b leafTermF leaf = (Range 1 10 :. Category.MethodCall :. Nil) :< Leaf leaf {- @@ -57,11 +56,11 @@ Example (from GHCi): > Leaf "example" -} -leafTerm :: leaf -> Cofree (Syntax leaf) (Record '[Range, Category]) +leafTerm :: leaf -> SyntaxTerm (Record '[Range, Category]) leafTerm = cofree . leafTermF -indexedTermF :: [leaf] -> TermF (Syntax leaf) (Record '[Range, Category]) (Term (Syntax leaf) (Record '[Range, Category])) +indexedTermF :: [leaf] -> SyntaxTermF (Record '[Range, Category]) (Term Syntax (Record '[Range, Category])) indexedTermF leaves = (Range 1 10 :. Category.MethodCall :. Nil) :< Indexed (leafTerm <$> leaves) -indexedTerm :: [leaf] -> Term (Syntax leaf) (Record '[Range, Category]) +indexedTerm :: [leaf] -> SyntaxTerm (Record '[Range, Category]) indexedTerm leaves = cofree $ indexedTermF leaves diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 59011e056..f468447af 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -25,9 +25,9 @@ import Term -- | Diff two terms recursively, given functions characterizing the diffing. -diffTerms :: (Eq leaf, Hashable leaf, HasField fields Category) - => Both (SyntaxTerm leaf fields) -- ^ A pair of terms representing the old and new state, respectively. - -> SyntaxDiff leaf fields +diffTerms :: HasField fields Category + => Both (SyntaxTerm fields) -- ^ A pair of terms representing the old and new state, respectively. + -> SyntaxDiff fields diffTerms = decoratingWith getLabel (diffTermsWith algorithmWithTerms comparableByCategory) -- | Diff two terms by decorating with feature vectors computed using the supplied labelling algebra, and stripping the feature vectors from the resulting diff. @@ -57,7 +57,7 @@ diffTermsWith refine comparable (Join (a, b)) = runAlgorithm decompose (diff a b Replace a b -> pure (replacing a b) -- | Compute the label for a given term, suitable for inclusion in a _p_,_q_-gram. -getLabel :: HasField fields Category => TermF (Syntax leaf) (Record fields) a -> (Category, Maybe leaf) +getLabel :: HasField fields Category => SyntaxTermF (Record fields) a -> (Category, Maybe Text) getLabel (h :< t) = (Info.category h, case t of Leaf s -> Just s _ -> Nothing) @@ -82,9 +82,9 @@ runAlgorithmSteps decompose = go -- | Construct an algorithm to diff a pair of terms. -algorithmWithTerms :: SyntaxTerm leaf fields - -> SyntaxTerm leaf fields - -> Algorithm (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) (SyntaxDiff leaf fields) +algorithmWithTerms :: SyntaxTerm fields + -> SyntaxTerm fields + -> Algorithm (SyntaxTerm fields) (SyntaxDiff fields) (SyntaxDiff fields) algorithmWithTerms t1 t2 = case (unwrap t1, unwrap t2) of (Indexed a, Indexed b) -> annotate . Indexed <$> byRWS a b diff --git a/src/Parser.hs b/src/Parser.hs index 658958b03..cf399cac0 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -50,14 +50,14 @@ data Parser term where -> Assignment ast grammar (Term (Union fs) (Record Location)) -- ^ An assignment from AST onto 'Term's. -> Parser (Term (Union fs) (Record Location)) -- ^ A parser producing 'Term's. -- | A tree-sitter parser. - TreeSitterParser :: Language -> Ptr TS.Language -> Parser (SyntaxTerm Text DefaultFields) + TreeSitterParser :: Language -> Ptr TS.Language -> Parser (SyntaxTerm DefaultFields) -- | A parser for 'Markdown' using cmark. MarkdownParser :: Parser (AST CMark.NodeType) -- | A parser which will parse any input 'Source' into a top-level 'Term' whose children are leaves consisting of the 'Source's lines. - LineByLineParser :: Parser (SyntaxTerm Text DefaultFields) + LineByLineParser :: Parser (SyntaxTerm DefaultFields) -- | Return a 'Language'-specific 'Parser', if one exists, falling back to the 'LineByLineParser'. -parserForLanguage :: Maybe Language -> Parser (SyntaxTerm Text DefaultFields) +parserForLanguage :: Maybe Language -> Parser (SyntaxTerm DefaultFields) parserForLanguage Nothing = LineByLineParser parserForLanguage (Just language) = case language of C -> TreeSitterParser C tree_sitter_c @@ -98,6 +98,6 @@ errorTerm :: Syntax.Error :< fs => Source -> Term (Union fs) (Record Location) errorTerm source = cofree ((totalRange source :. totalSpan source :. Nil) :< inj (Syntax.Error [])) -- | A fallback parser that treats a file simply as rows of strings. -lineByLineParser :: Source -> SyntaxTerm Text DefaultFields +lineByLineParser :: Source -> SyntaxTerm DefaultFields lineByLineParser source = cofree $ (totalRange source :. Program :. totalSpan source :. Nil) :< Indexed (zipWith toLine [1..] (sourceLineRanges source)) where toLine line range = cofree $ (range :. Program :. Span (Pos line 1) (Pos line (end range)) :. Nil) :< Leaf (toText (slice range source)) diff --git a/src/Renderer.hs b/src/Renderer.hs index 24c233840..ca691a852 100644 --- a/src/Renderer.hs +++ b/src/Renderer.hs @@ -42,7 +42,7 @@ data DiffRenderer output where -- | Render to a 'ByteString' formatted as nested s-expressions with patches indicated. SExpressionDiffRenderer :: DiffRenderer ByteString -- | “Render” by returning the computed 'SyntaxDiff'. This renderer is not surfaced in the command-line interface, and is intended strictly for tests. Further, as it cannot render à la carte terms, it should be regarded as a (very) short-term hack until such time as we have a better idea for TOCSpec.hs. - IdentityDiffRenderer :: DiffRenderer (Maybe (SyntaxDiff Text (Maybe Declaration ': DefaultFields))) + IdentityDiffRenderer :: DiffRenderer (Maybe (SyntaxDiff (Maybe Declaration ': DefaultFields))) deriving instance Eq (DiffRenderer output) deriving instance Show (DiffRenderer output) @@ -56,7 +56,7 @@ data TermRenderer output where -- | Render to a 'ByteString' formatted as nested s-expressions. SExpressionTermRenderer :: TermRenderer ByteString -- | “Render” by returning the computed 'SyntaxTerm'. This renderer is not surfaced in the command-line interface, and is intended strictly for tests. Further, as it cannot render à la carte terms, it should be regarded as a (very) short-term hack until such time as we have a better idea for SemanticSpec.hs. - IdentityTermRenderer :: TermRenderer (Maybe (SyntaxTerm Text DefaultFields)) + IdentityTermRenderer :: TermRenderer (Maybe (SyntaxTerm DefaultFields)) deriving instance Eq (TermRenderer output) deriving instance Show (TermRenderer output) @@ -70,7 +70,7 @@ data SomeRenderer f where deriving instance Show (SomeRenderer f) -identifierAlgebra :: RAlgebra (CofreeF (Syntax Text) a) (Cofree (Syntax Text) a) (Maybe Identifier) +identifierAlgebra :: RAlgebra (CofreeF Syntax a) (Cofree Syntax a) (Maybe Identifier) identifierAlgebra (_ :< syntax) = case syntax of S.Assignment f _ -> identifier f S.Class f _ _ -> identifier f diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index e25ff737e..92b9b3a35 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -100,7 +100,7 @@ instance ToJSON a => ToJSONFields (Patch a) where instance ToJSON a => ToJSONFields [a] where toJSONFields list = [ "children" .= list ] -instance ToJSON recur => ToJSONFields (Syntax leaf recur) where +instance ToJSON recur => ToJSONFields (Syntax recur) where toJSONFields syntax = [ "children" .= toList syntax ] instance (Foldable f, ToJSON a, ToJSONFields (Union fs a)) => ToJSONFields (Union (f ': fs) a) where diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index 62f5eb626..fb884f98c 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -93,7 +93,7 @@ declaration (annotation :< _) = annotation <$ (getField annotation :: Maybe Decl -- | Compute 'Declaration's for methods and functions in 'Syntax'. -syntaxDeclarationAlgebra :: HasField fields Range => Blob -> RAlgebra (SyntaxTermF Text fields) (SyntaxTerm Text fields) (Maybe Declaration) +syntaxDeclarationAlgebra :: HasField fields Range => Blob -> RAlgebra (SyntaxTermF fields) (SyntaxTerm fields) (Maybe Declaration) syntaxDeclarationAlgebra Blob{..} r = case tailF r of S.Function (identifier, _) _ _ -> Just $ FunctionDeclaration (getSource identifier) S.Method _ (identifier, _) Nothing _ _ -> Just $ MethodDeclaration (getSource identifier) diff --git a/src/SplitDiff.hs b/src/SplitDiff.hs index 79cc546b4..b069988ed 100644 --- a/src/SplitDiff.hs +++ b/src/SplitDiff.hs @@ -24,4 +24,4 @@ getRange diff = byteRange $ case runFree diff of -- | A diff with only one side’s annotations. type SplitDiff f annotation = Free (TermF f annotation) (SplitPatch (Term f annotation)) -type SplitSyntaxDiff leaf fields = SplitDiff (Syntax leaf) (Record fields) +type SplitSyntaxDiff fields = SplitDiff Syntax (Record fields) diff --git a/src/Syntax.hs b/src/Syntax.hs index c0e5bd058..301a5eeed 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -12,11 +12,10 @@ import Prologue -- | A node in an abstract syntax tree. -- --- 'a' is the type of leaves in the syntax tree, typically 'Text', but possibly some datatype representing different leaves more precisely. -- 'f' is the type representing another level of the tree, e.g. the children of branches. Often 'Cofree', 'Free' or similar. -data Syntax a f +data Syntax f -- | A terminal syntax node, e.g. an identifier, or atomic literal. - = Leaf a + = Leaf Text -- | An ordered branch of child nodes, expected to be variadic in the grammar, e.g. a list of statements or uncurried function parameters. | Indexed [f] -- | An ordered branch of child nodes, expected to be of fixed length in the grammar, e.g. a binary operator & its operands. @@ -57,7 +56,7 @@ data Syntax a f -- | A pair in an Object. e.g. foo: bar or foo => bar | Pair f f -- | A comment. - | Comment a + | Comment Text -- | A term preceded or followed by any number of comments. | Commented [f] (Maybe f) | ParseError [f] @@ -110,18 +109,18 @@ data Syntax a f | Ty [f] -- | A send statement has a channel and an expression in Go. | Send f f - deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON, NFData) + deriving (Eq, Foldable, Functor, GAlign, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON, NFData) -extractLeafValue :: Syntax leaf b -> Maybe leaf +extractLeafValue :: Syntax b -> Maybe Text extractLeafValue syntax = case syntax of Leaf a -> Just a _ -> Nothing -- Instances -instance Listable2 Syntax where - liftTiers2 leaf recur +instance Listable1 Syntax where + liftTiers recur = liftCons1 leaf Leaf \/ liftCons1 (liftTiers recur) Indexed \/ liftCons1 (liftTiers recur) Fixed @@ -177,13 +176,8 @@ instance Listable2 Syntax where \/ liftCons2 recur recur Send \/ liftCons1 (liftTiers recur) DefaultCase -instance Listable leaf => Listable1 (Syntax leaf) where - liftTiers = liftTiers2 tiers - -instance (Listable leaf, Listable recur) => Listable (Syntax leaf recur) where +instance Listable recur => Listable (Syntax recur) where tiers = tiers1 -instance Eq leaf => Eq1 (Syntax leaf) where +instance Eq1 Syntax where liftEq = genericLiftEq - -instance Eq leaf => GAlign (Syntax leaf) diff --git a/src/Term.hs b/src/Term.hs index 0ed7e35e8..05b896a8a 100644 --- a/src/Term.hs +++ b/src/Term.hs @@ -14,8 +14,8 @@ type Term f = Cofree f type TermF = CofreeF -- | A Term with a Syntax leaf and a record of fields. -type SyntaxTerm leaf fields = Term (Syntax leaf) (Record fields) -type SyntaxTermF leaf fields = TermF (Syntax leaf) (Record fields) +type SyntaxTerm fields = Term Syntax (Record fields) +type SyntaxTermF fields = TermF Syntax (Record fields) instance (NFData (f (Cofree f a)), NFData a, Functor f) => NFData (Cofree f a) where rnf = rnf . runCofree diff --git a/test/InterpreterSpec.hs b/test/InterpreterSpec.hs index f7017c61d..66288541f 100644 --- a/test/InterpreterSpec.hs +++ b/test/InterpreterSpec.hs @@ -26,15 +26,15 @@ spec = parallel $ do diffTerms (both termA termB) `shouldBe` replacing termA termB prop "produces correct diffs" $ - \ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm String '[Category])) in + \ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm '[Category])) in (beforeTerm diff, afterTerm diff) `shouldBe` (Just (unListableF a), Just (unListableF b)) prop "constructs zero-cost diffs of equal terms" $ - \ a -> let term = (unListableF a :: SyntaxTerm String '[Category]) + \ a -> let term = (unListableF a :: SyntaxTerm '[Category]) diff = diffTerms (pure term) in diffCost diff `shouldBe` 0 it "produces unbiased insertions within branches" $ - let term s = cofree ((StringLiteral :. Nil) :< Indexed [ cofree ((StringLiteral :. Nil) :< Leaf s) ]) :: SyntaxTerm String '[Category] + let term s = cofree ((StringLiteral :. Nil) :< Indexed [ cofree ((StringLiteral :. Nil) :< Leaf s) ]) :: SyntaxTerm '[Category] root = cofree . ((Program :. Nil) :<) . Indexed in diffTerms (both (root [ term "b" ]) (root [ term "a", term "b" ])) `shouldBe` wrap (pure (Program :. Nil) :< Indexed [ inserting (term "a"), cata wrap (fmap pure (term "b")) ]) diff --git a/test/PatchOutputSpec.hs b/test/PatchOutputSpec.hs index 65df22689..127a9d568 100644 --- a/test/PatchOutputSpec.hs +++ b/test/PatchOutputSpec.hs @@ -14,4 +14,4 @@ spec :: Spec spec = parallel $ do describe "hunks" $ do it "empty diffs have empty hunks" $ - hunks (wrap $ pure (Range 0 0 :. Nil) :< Leaf ("" :: Text)) (both (Blob mempty "abcde" "path2.txt" (Just defaultPlainBlob) Nothing) (Blob mempty "xyz" "path2.txt" (Just defaultPlainBlob) Nothing)) `shouldBe` [Hunk {offset = pure 0, changes = [], trailingContext = []}] + hunks (wrap $ pure (Range 0 0 :. Nil) :< Leaf "") (both (Blob mempty "abcde" "path2.txt" (Just defaultPlainBlob) Nothing) (Blob mempty "xyz" "path2.txt" (Just defaultPlainBlob) Nothing)) `shouldBe` [Hunk {offset = pure 0, changes = [], trailingContext = []}] diff --git a/test/TOCSpec.hs b/test/TOCSpec.hs index 90c9b6292..ac31a3af5 100644 --- a/test/TOCSpec.hs +++ b/test/TOCSpec.hs @@ -34,21 +34,21 @@ spec :: Spec spec = parallel $ do describe "tableOfContentsBy" $ do prop "drops all nodes with the constant Nothing function" $ - \ diff -> tableOfContentsBy (const Nothing :: a -> Maybe ()) (unListableDiff diff :: Diff (Syntax ()) ()) `shouldBe` [] + \ diff -> tableOfContentsBy (const Nothing :: a -> Maybe ()) (unListableDiff diff :: SyntaxDiff ()) `shouldBe` [] let diffSize = max 1 . sum . fmap (const 1) let lastValue a = fromMaybe (extract a) (getLast (foldMap (Last . Just) a)) prop "includes all nodes with a constant Just function" $ - \ diff -> let diff' = (unListableDiff diff :: Diff (Syntax ()) ()) in entryPayload <$> tableOfContentsBy (const (Just ())) diff' `shouldBe` replicate (diffSize diff') () + \ diff -> let diff' = (unListableDiff diff :: SyntaxDiff ()) in entryPayload <$> tableOfContentsBy (const (Just ())) diff' `shouldBe` replicate (diffSize diff') () prop "produces an unchanged entry for identity diffs" $ - \ term -> let term' = (unListableF term :: Term (Syntax ()) (Record '[Category])) in tableOfContentsBy (Just . headF) (diffTerms (pure term')) `shouldBe` [Unchanged (lastValue term')] + \ term -> let term' = (unListableF term :: SyntaxTerm (Record '[Category])) in tableOfContentsBy (Just . headF) (diffTerms (pure term')) `shouldBe` [Unchanged (lastValue term')] prop "produces inserted/deleted/replaced entries for relevant nodes within patches" $ - \ patch -> let patch' = (unListableF <$> patch :: Patch (Term (Syntax ()) Int)) in tableOfContentsBy (Just . headF) (pure patch') `shouldBe` these (pure . Deleted) (pure . Inserted) ((<>) `on` pure . Replaced) (unPatch (lastValue <$> patch')) + \ patch -> let patch' = (unListableF <$> patch :: Patch (SyntaxTerm Int)) in tableOfContentsBy (Just . headF) (pure patch') `shouldBe` these (pure . Deleted) (pure . Inserted) ((<>) `on` pure . Replaced) (unPatch (lastValue <$> patch')) prop "produces changed entries for relevant nodes containing irrelevant patches" $ - \ diff -> let diff' = fmap (1 <$) <$> mapAnnotations (const (0 :: Int)) (wrap (pure 0 :< Indexed [unListableDiff diff :: Diff (Syntax ()) Int])) in + \ diff -> let diff' = fmap (1 <$) <$> mapAnnotations (const (0 :: Int)) (wrap (pure 0 :< Indexed [unListableDiff diff :: SyntaxDiff Int])) in tableOfContentsBy (\ (n :< _) -> if n == 0 then Just n else Nothing) diff' `shouldBe` if Prologue.null diff' then [Unchanged 0] else replicate (length diff') (Changed 0) @@ -155,8 +155,8 @@ spec = parallel $ do toS output `shouldBe` ("{\"changes\":{\"test/fixtures/toc/markdown/headings.A.md -> test/fixtures/toc/markdown/headings.B.md\":[{\"span\":{\"start\":[5,1],\"end\":[5,7]},\"category\":\"Heading 2\",\"term\":\"## Two\",\"changeType\":\"added\"},{\"span\":{\"start\":[9,1],\"end\":[10,4]},\"category\":\"Heading 1\",\"term\":\"Final\",\"changeType\":\"added\"}]},\"errors\":{}}\n" :: ByteString) -type Diff' = SyntaxDiff Text (Maybe Declaration ': DefaultFields) -type Term' = SyntaxTerm Text (Maybe Declaration ': DefaultFields) +type Diff' = SyntaxDiff (Maybe Declaration ': DefaultFields) +type Term' = SyntaxTerm (Maybe Declaration ': DefaultFields) numTocSummaries :: Diff' -> Int numTocSummaries diff = length $ filter isValidSummary (diffTOC diff) @@ -200,7 +200,7 @@ functionInfo :: Record DefaultFields functionInfo = Range 0 0 :. C.Function :. sourceSpanBetween (0,0) (0,0) :. Nil -- Filter tiers for terms that we consider "meaniningful" in TOC summaries. -isMeaningfulTerm :: ListableF (Term (Syntax leaf)) a -> Bool +isMeaningfulTerm :: ListableF SyntaxTerm a -> Bool isMeaningfulTerm a = case runCofree (unListableF a) of (_ :< S.Indexed _) -> False (_ :< S.Fixed _) -> False @@ -209,7 +209,7 @@ isMeaningfulTerm a = case runCofree (unListableF a) of _ -> True -- Filter tiers for terms if the Syntax is a Method or a Function. -isMethodOrFunction :: HasField fields Category => ListableF (Term (Syntax leaf)) (Record fields) -> Bool +isMethodOrFunction :: HasField fields Category => ListableF SyntaxTerm (Record fields) -> Bool isMethodOrFunction a = case runCofree (unListableF a) of (_ :< S.Method{}) -> True (_ :< S.Function{}) -> True From 11860f29912cda7182d61d127ce2df621b650e24 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 11:07:25 -0400 Subject: [PATCH 14/39] Pack strings into Text. --- src/Syntax.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Syntax.hs b/src/Syntax.hs index 301a5eeed..6a4d7c9f2 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -7,6 +7,7 @@ import Data.Functor.Classes import Data.Functor.Classes.Eq.Generic import Data.Functor.Listable import Data.Mergeable +import Data.Text (pack) import GHC.Generics import Prologue @@ -121,7 +122,7 @@ extractLeafValue syntax = case syntax of instance Listable1 Syntax where liftTiers recur - = liftCons1 leaf Leaf + = liftCons1 (pack `mapT` tiers) Leaf \/ liftCons1 (liftTiers recur) Indexed \/ liftCons1 (liftTiers recur) Fixed \/ liftCons3 recur (liftTiers recur) (liftTiers recur) FunctionCall @@ -141,7 +142,7 @@ instance Listable1 Syntax where \/ liftCons1 (liftTiers recur) Select \/ liftCons2 (liftTiers recur) (liftTiers recur) Syntax.Object \/ liftCons2 recur recur Pair - \/ liftCons1 leaf Comment + \/ liftCons1 (pack `mapT` tiers) Comment \/ liftCons2 (liftTiers recur) (liftTiers recur) Commented \/ liftCons1 (liftTiers recur) Syntax.ParseError \/ liftCons2 (liftTiers recur) (liftTiers recur) For From b544e395cfac8cbad09a014245ed49ed6f0d16e2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 11:07:46 -0400 Subject: [PATCH 15/39] Remove record selectors from Syntax so we can derive ToJSON. --- src/Syntax.hs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Syntax.hs b/src/Syntax.hs index 6a4d7c9f2..0770bff3d 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -24,36 +24,36 @@ data Syntax f -- | A function call has an identifier where f is a (Leaf a) and a list of arguments. | FunctionCall f [f] [f] -- | A ternary has a condition, a true case and a false case - | Ternary { ternaryCondition :: f, ternaryCases :: [f] } + | Ternary f [f] -- | An anonymous function has a list of expressions and params. - | AnonymousFunction { params :: [f], expressions :: [f] } + | AnonymousFunction [f] [f] -- | A function has an identifier, possible type arguments, params, a possible type, and list of expressions. - | Function { id :: f, params :: [f], expressions :: [f] } + | Function f [f] [f] -- | An assignment has an identifier where f can be a member access, and the value is another syntax element (function call, leaf, etc.) - | Assignment { assignmentId :: f, value :: f } + | Assignment f f -- | An operator assignment represents expressions with operators like math (e.g x += 1) or conditional (e.g. x ||= 1) assignment. | OperatorAssignment f f -- | A member access contains a syntax, and another syntax that identifies a property or value in the first syntax. -- | e.g. in Javascript x.y represents a member access syntax. - | MemberAccess { memberId :: f, property :: f } + | MemberAccess f f -- | A method call consisting of its target, the method name, and the parameters passed to the method. -- | e.g. in Javascript console.log('hello') represents a method call. - | MethodCall { targetId :: f, methodId :: f, typeArgs :: [f], methodParams :: [f] } + | MethodCall f f [f] [f] -- | An operator can be applied to a list of syntaxes. | Operator [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 } + | VarAssignment [f] f -- | A subscript access contains a syntax, and another syntax that indefies a property or value in the first syntax. -- | e.g. in Javascript x["y"] represents a subscript access syntax. - | SubscriptAccess { subscriptId :: f, subscriptElement :: f } - | Switch { switchExpr :: [f], cases :: [f] } - | Case { caseExpr :: f, caseStatements :: [f] } + | SubscriptAccess f f + | Switch [f] [f] + | Case f [f] -- | A default case in a switch statement. | DefaultCase [f] - | Select { cases :: [f] } - | Object { objectTy :: Maybe f, keyValues :: [f] } + | Select [f] + | Object (Maybe f) [f] -- | A pair in an Object. e.g. foo: bar or foo => bar | Pair f f -- | A comment. @@ -63,13 +63,13 @@ data Syntax f | ParseError [f] -- | A for statement has a list of expressions to setup the iteration and then a list of expressions in the body. | For [f] [f] - | DoWhile { doWhileBody :: f, doWhileExpr :: f } - | While { whileExpr :: f, whileBody :: [f] } + | DoWhile f f + | While f [f] | Return [f] | Throw f | Constructor f -- | TODO: Is it a problem that in Ruby, this pattern can work for method def too? - | Try { tryBegin :: [f], catchRescue :: [f], beginElse :: Maybe f, finallyEnsure :: Maybe f } + | Try [f] [f] (Maybe f) (Maybe f) -- | An array literal with list of children. | Array (Maybe f) [f] -- | A class with an identifier, superclass, and a list of definitions. @@ -79,10 +79,10 @@ data Syntax f -- | An if statement with an expression and maybe more expression clauses. | If f [f] -- | A module with an identifier, and a list of syntaxes. - | Module { moduleId:: f, moduleBody :: [f] } + | Module f [f] -- | An interface with an identifier, a list of clauses, and a list of declarations.. | Interface f [f] [f] - | Namespace { namespaceId:: f, namespaceBody :: [f] } + | Namespace f [f] | Import f [f] | Export (Maybe f) [f] | Yield [f] From 9b04dee764e21a297cc8d71becdf170f26887a05 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 11:24:35 -0400 Subject: [PATCH 16/39] Fix up some references to Syntax. --- src/FDoc/RecursionSchemes.hs | 13 +++++++------ src/FDoc/Term.hs | 9 +++++---- src/Interpreter.hs | 2 +- src/Language.hs | 10 +++++----- src/Language/C.hs | 4 ++-- src/Language/Go.hs | 4 ++-- src/Language/Ruby.hs | 4 ++-- src/Language/TypeScript.hs | 4 ++-- src/TreeSitter.hs | 14 +++++++------- 9 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/FDoc/RecursionSchemes.hs b/src/FDoc/RecursionSchemes.hs index 1e39ffeec..40d18c053 100644 --- a/src/FDoc/RecursionSchemes.hs +++ b/src/FDoc/RecursionSchemes.hs @@ -7,6 +7,7 @@ import Category import Term import Prologue import Prelude +import Syntax import FDoc.Term data NewField = NewField deriving (Show) @@ -24,7 +25,7 @@ structure. The example below adds a new field to the `Record` fields. -} -indexedTermAna :: [leaf] -> SyntaxTerm (Record '[NewField, Range, Category]) +indexedTermAna :: [Text] -> SyntaxTerm '[NewField, Range, Category] indexedTermAna childrenLeaves = ana coalgebra (indexedTerm childrenLeaves) where coalgebra term = (NewField :. (extract term)) :< unwrap term @@ -42,7 +43,7 @@ structure to a new shape. The example below adds a new field to the `Record` fields. -} -indexedTermCata :: [leaf] -> SyntaxTerm (Record '[NewField, Range, Category]) +indexedTermCata :: [Text] -> SyntaxTerm '[NewField, Range, Category] indexedTermCata childrenLeaves = cata algebra (indexedTerm childrenLeaves) where algebra :: Functor f => CofreeF f (Record t) (Cofree f (Record (NewField : t))) -> Cofree f (Record (NewField : t)) @@ -81,7 +82,7 @@ stringToTermAna "indexed" => the new cofree `Indexed` structure, resulting in a expansion of all possible string terms. -} -stringToTermAna :: String -> SyntaxTerm (Record '[Range, Category]) +stringToTermAna :: Text -> SyntaxTerm '[Range, Category] stringToTermAna = ana coalgebra where coalgebra representation = case representation of @@ -94,7 +95,7 @@ Catamorphism -- construct a list of Strings from a recursive Term structure. The example below shows how to tear down a recursive Term structure into a list of String representation. -} -termToStringCata :: SyntaxTerm (Record '[Range, Category]) -> [String] +termToStringCata :: SyntaxTerm '[Range, Category] -> [Text] termToStringCata = cata algebra where algebra term = case term of @@ -122,7 +123,7 @@ Example Usage: stringTermHylo "indexed" => ["indexed", "leaf1", "leaf2", "leaf3"] -} -stringTermHylo :: String -> [String] +stringTermHylo :: Text -> [Text] stringTermHylo = hylo algebra coalgebra where algebra term = case term of @@ -176,7 +177,7 @@ Final shape: ] -} -termPara :: Syntaxterm (Record '[Range, Category]) -> [(SyntaxTerm (Record '[Range, Category]), String)] +termPara :: SyntaxTerm '[Range, Category] -> [(SyntaxTerm '[Range, Category], Text)] termPara = para algebra where algebra term = case term of diff --git a/src/FDoc/Term.hs b/src/FDoc/Term.hs index 5a9764fe4..bf2895f73 100644 --- a/src/FDoc/Term.hs +++ b/src/FDoc/Term.hs @@ -4,6 +4,7 @@ module FDoc.Term where import Data.Range import Data.Record import Category +import Syntax import Term import Prologue @@ -31,7 +32,7 @@ Example (from GHCi): -} -leafTermF :: leaf -> SyntaxTermF (Record '[Range, Category]) b +leafTermF :: Text -> SyntaxTermF '[Range, Category] b leafTermF leaf = (Range 1 10 :. Category.MethodCall :. Nil) :< Leaf leaf {- @@ -56,11 +57,11 @@ Example (from GHCi): > Leaf "example" -} -leafTerm :: leaf -> SyntaxTerm (Record '[Range, Category]) +leafTerm :: Text -> SyntaxTerm '[Range, Category] leafTerm = cofree . leafTermF -indexedTermF :: [leaf] -> SyntaxTermF (Record '[Range, Category]) (Term Syntax (Record '[Range, Category])) +indexedTermF :: [Text] -> SyntaxTermF '[Range, Category] (SyntaxTerm '[Range, Category]) indexedTermF leaves = (Range 1 10 :. Category.MethodCall :. Nil) :< Indexed (leafTerm <$> leaves) -indexedTerm :: [leaf] -> SyntaxTerm (Record '[Range, Category]) +indexedTerm :: [Text] -> SyntaxTerm '[Range, Category] indexedTerm leaves = cofree $ indexedTermF leaves diff --git a/src/Interpreter.hs b/src/Interpreter.hs index f468447af..67b79df18 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -57,7 +57,7 @@ diffTermsWith refine comparable (Join (a, b)) = runAlgorithm decompose (diff a b Replace a b -> pure (replacing a b) -- | Compute the label for a given term, suitable for inclusion in a _p_,_q_-gram. -getLabel :: HasField fields Category => SyntaxTermF (Record fields) a -> (Category, Maybe Text) +getLabel :: HasField fields Category => SyntaxTermF fields a -> (Category, Maybe Text) getLabel (h :< t) = (Info.category h, case t of Leaf s -> Just s _ -> Nothing) diff --git a/src/Language.hs b/src/Language.hs index e819e4e21..a72f3c5a9 100644 --- a/src/Language.hs +++ b/src/Language.hs @@ -36,7 +36,7 @@ languageForType mediaType = case mediaType of ".py" -> Just Python _ -> Nothing -toVarDeclOrAssignment :: HasField fields Category => Term (S.Syntax Text) (Record fields) -> Term (S.Syntax Text) (Record fields) +toVarDeclOrAssignment :: HasField fields Category => SyntaxTerm fields -> SyntaxTerm fields toVarDeclOrAssignment child = case unwrap child of S.Indexed [child', assignment] -> cofree $ setCategory (extract child) VarAssignment :< S.VarAssignment [child'] assignment S.Indexed [child'] -> cofree $ setCategory (extract child) VarDecl :< S.VarDecl [child'] @@ -44,22 +44,22 @@ toVarDeclOrAssignment child = case unwrap child of S.VarAssignment _ _ -> child _ -> toVarDecl child -toVarDecl :: HasField fields Category => Term (S.Syntax Text) (Record fields) -> Term (S.Syntax Text) (Record fields) +toVarDecl :: HasField fields Category => SyntaxTerm fields -> SyntaxTerm fields toVarDecl child = cofree $ setCategory (extract child) VarDecl :< S.VarDecl [child] -toTuple :: Term (S.Syntax Text) (Record fields) -> [Term (S.Syntax Text) (Record fields)] +toTuple :: SyntaxTerm fields -> [SyntaxTerm fields] toTuple child | S.Indexed [key,value] <- unwrap child = [cofree (extract child :< S.Pair key value)] toTuple child | S.Fixed [key,value] <- unwrap child = [cofree (extract child :< S.Pair key value)] toTuple child | S.Leaf c <- unwrap child = [cofree (extract child :< S.Comment c)] toTuple child = pure child -toPublicFieldDefinition :: HasField fields Category => [SyntaxTerm Text fields] -> Maybe (S.Syntax Text (SyntaxTerm Text fields)) +toPublicFieldDefinition :: HasField fields Category => [SyntaxTerm fields] -> Maybe (S.Syntax (SyntaxTerm fields)) toPublicFieldDefinition children = case break (\x -> category (extract x) == Identifier) children of (prev, [identifier, assignment]) -> Just $ S.VarAssignment (prev ++ [identifier]) assignment (_, [_]) -> Just $ S.VarDecl children _ -> Nothing -toInterface :: HasField fields Category => [SyntaxTerm Text fields] -> Maybe (S.Syntax Text (SyntaxTerm Text fields)) +toInterface :: HasField fields Category => [SyntaxTerm fields] -> Maybe (S.Syntax (SyntaxTerm fields)) toInterface (id : rest) = case break (\x -> category (extract x) == Other "object_type") rest of (clauses, [body]) -> Just $ S.Interface id clauses (toList (unwrap body)) _ -> Nothing diff --git a/src/Language/C.hs b/src/Language/C.hs index 6538af1d9..e39cec1f3 100644 --- a/src/Language/C.hs +++ b/src/Language/C.hs @@ -10,8 +10,8 @@ import Term termAssignment :: Source -- ^ The source of the term. -> Category -- ^ The category for the term. - -> [ SyntaxTerm Text DefaultFields ] -- ^ The child nodes of the term. - -> Maybe (S.Syntax Text (SyntaxTerm Text DefaultFields)) -- ^ The resulting term, in Maybe. + -> [ SyntaxTerm DefaultFields ] -- ^ The child nodes of the term. + -> Maybe (S.Syntax (SyntaxTerm DefaultFields)) -- ^ The resulting term, in Maybe. termAssignment _ _ _ = Nothing diff --git a/src/Language/Go.hs b/src/Language/Go.hs index e88946f7a..71257694e 100644 --- a/src/Language/Go.hs +++ b/src/Language/Go.hs @@ -10,8 +10,8 @@ import Term termAssignment :: Source -- ^ The source of the term. -> Category -- ^ The category for the term. - -> [ SyntaxTerm Text DefaultFields ] -- ^ The child nodes of the term. - -> Maybe (S.Syntax Text (SyntaxTerm Text DefaultFields)) -- ^ The resulting term, in Maybe. + -> [ SyntaxTerm DefaultFields ] -- ^ The child nodes of the term. + -> Maybe (S.Syntax (SyntaxTerm DefaultFields)) -- ^ The resulting term, in Maybe. termAssignment source category children = case (category, children) of (Module, [moduleName]) -> Just $ S.Module moduleName [] (Import, [importName]) -> Just $ S.Import importName [] diff --git a/src/Language/Ruby.hs b/src/Language/Ruby.hs index 739484749..d09936155 100644 --- a/src/Language/Ruby.hs +++ b/src/Language/Ruby.hs @@ -12,8 +12,8 @@ import Term termAssignment :: Source -- ^ The source of the term. -> Category -- ^ The category for the term. - -> [ SyntaxTerm Text DefaultFields ] -- ^ The child nodes of the term. - -> Maybe (S.Syntax Text (SyntaxTerm Text DefaultFields)) -- ^ The resulting term, in Maybe. + -> [ SyntaxTerm DefaultFields ] -- ^ The child nodes of the term. + -> Maybe (S.Syntax (SyntaxTerm DefaultFields)) -- ^ The resulting term, in Maybe. termAssignment _ category children = case (category, children) of (ArgumentPair, [ k, v ] ) -> Just $ S.Pair k v diff --git a/src/Language/TypeScript.hs b/src/Language/TypeScript.hs index 625268cb0..6b115e5e2 100644 --- a/src/Language/TypeScript.hs +++ b/src/Language/TypeScript.hs @@ -11,8 +11,8 @@ import Term termAssignment :: Source -- ^ The source of the term. -> Category -- ^ The category for the term. - -> [ SyntaxTerm Text DefaultFields ] -- ^ The child nodes of the term. - -> Maybe (S.Syntax Text (SyntaxTerm Text DefaultFields)) -- ^ The resulting term, in Maybe. + -> [ SyntaxTerm DefaultFields ] -- ^ The child nodes of the term. + -> Maybe (S.Syntax (SyntaxTerm DefaultFields)) -- ^ The resulting term, in Maybe. termAssignment _ category children = case (category, children) of (Assignment, [ identifier, value ]) -> Just $ S.Assignment identifier value diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 16106a0a7..f8d56075a 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -30,7 +30,7 @@ import qualified Text.Parser.TreeSitter as TS import Info -- | Returns a TreeSitter parser for the given language and TreeSitter grammar. -treeSitterParser :: Language -> Ptr TS.Language -> Source -> IO (Term (Syntax.Syntax Text) (Record DefaultFields)) +treeSitterParser :: Language -> Ptr TS.Language -> Source -> IO (SyntaxTerm DefaultFields) treeSitterParser language grammar source = bracket ts_document_new ts_document_free $ \ document -> do ts_document_set_language document grammar unsafeUseAsCStringLen (sourceBytes source) $ \ (sourceBytes, len) -> do @@ -66,13 +66,13 @@ anaM g = a where a = pure . embed <=< traverse a <=< g -- | Return a parser for a tree sitter language & document. -documentToTerm :: Language -> Ptr Document -> Source -> IO (Term (Syntax.Syntax Text) (Record DefaultFields)) +documentToTerm :: Language -> Ptr Document -> Source -> IO (SyntaxTerm DefaultFields) documentToTerm language document allSource = do root <- alloca (\ rootPtr -> do ts_document_root_node_p document rootPtr peek rootPtr) toTerm root (slice (nodeRange root) allSource) - where toTerm :: Node -> Source -> IO (Term (Syntax.Syntax Text) (Record DefaultFields)) + where toTerm :: Node -> Source -> IO (SyntaxTerm DefaultFields) toTerm node source = do name <- peekCString (nodeType node) @@ -91,7 +91,7 @@ documentToTerm language document allSource = do copyNamed = ts_node_copy_named_child_nodes document copyAll = ts_node_copy_child_nodes document -isNonEmpty :: HasField fields Category => SyntaxTerm Text fields -> Bool +isNonEmpty :: HasField fields Category => SyntaxTerm fields -> Bool isNonEmpty = (/= Empty) . category . extract nodeRange :: Node -> Range @@ -101,12 +101,12 @@ nodeSpan :: Node -> Span nodeSpan Node{..} = nodeStartPoint `seq` nodeEndPoint `seq` Span (pointPos nodeStartPoint) (pointPos nodeEndPoint) where pointPos TSPoint{..} = pointRow `seq` pointColumn `seq` Pos (1 + fromIntegral pointRow) (1 + fromIntegral pointColumn) -assignTerm :: Language -> Source -> Record DefaultFields -> [ SyntaxTerm Text DefaultFields ] -> IO [ SyntaxTerm Text DefaultFields ] -> IO (SyntaxTerm Text DefaultFields) +assignTerm :: Language -> Source -> Record DefaultFields -> [ SyntaxTerm DefaultFields ] -> IO [ SyntaxTerm DefaultFields ] -> IO (SyntaxTerm DefaultFields) assignTerm language source annotation children allChildren = cofree . (annotation :<) <$> case assignTermByLanguage language source (category annotation) children of Just a -> pure a _ -> defaultTermAssignment source (category annotation) children allChildren - where assignTermByLanguage :: Language -> Source -> Category -> [ SyntaxTerm Text DefaultFields ] -> Maybe (S.Syntax Text (SyntaxTerm Text DefaultFields)) + where assignTermByLanguage :: Language -> Source -> Category -> [ SyntaxTerm DefaultFields ] -> Maybe (S.Syntax (SyntaxTerm DefaultFields)) assignTermByLanguage language = case language of C -> C.termAssignment Language.Go -> Go.termAssignment @@ -114,7 +114,7 @@ assignTerm language source annotation children allChildren = TypeScript -> TS.termAssignment _ -> \ _ _ _ -> Nothing -defaultTermAssignment :: Source -> Category -> [ SyntaxTerm Text DefaultFields ] -> IO [ SyntaxTerm Text DefaultFields ] -> IO (S.Syntax Text (SyntaxTerm Text DefaultFields)) +defaultTermAssignment :: Source -> Category -> [ SyntaxTerm DefaultFields ] -> IO [ SyntaxTerm DefaultFields ] -> IO (S.Syntax (SyntaxTerm DefaultFields)) defaultTermAssignment source category children allChildren | category `elem` operatorCategories = S.Operator <$> allChildren | otherwise = pure $! case (category, children) of From 93456ff7d6eda9b5201aa01130caf4b2a131cddd Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 11:25:03 -0400 Subject: [PATCH 17/39] Fix up a bunch of symbols which protolude added. --- src/Algorithm.hs | 2 +- src/Data/Syntax/Assignment.hs | 2 +- src/Data/Syntax/Literal.hs | 2 +- src/Interpreter.hs | 2 +- src/Language/Markdown.hs | 2 +- src/Parser.hs | 2 +- src/RWS.hs | 2 +- src/Semantic.hs | 2 +- src/Semantic/Task.hs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Algorithm.hs b/src/Algorithm.hs index 0d3f8a690..c8c4b61b5 100644 --- a/src/Algorithm.hs +++ b/src/Algorithm.hs @@ -8,7 +8,7 @@ import Data.These import Data.Union import Diff import GHC.Generics -import Prologue hiding (liftF) +import Prologue hiding (diff, liftF) import Term import Text.Show diff --git a/src/Data/Syntax/Assignment.hs b/src/Data/Syntax/Assignment.hs index 171f22e54..a790176a7 100644 --- a/src/Data/Syntax/Assignment.hs +++ b/src/Data/Syntax/Assignment.hs @@ -99,7 +99,7 @@ import Data.Record import qualified Data.Source as Source (Source, fromBytes, slice, sourceBytes, sourceLines) import GHC.Stack import qualified Info -import Prologue hiding (Alt, get, Location, state) +import Prologue hiding (Alt, get, hPutStr, Location, Symbol, state) import System.Console.ANSI import Text.Parser.TreeSitter.Language import Text.Show hiding (show) diff --git a/src/Data/Syntax/Literal.hs b/src/Data/Syntax/Literal.hs index ca98ed42a..9750cb42b 100644 --- a/src/Data/Syntax/Literal.hs +++ b/src/Data/Syntax/Literal.hs @@ -6,7 +6,7 @@ import Data.Align.Generic import Data.Functor.Classes.Eq.Generic import Data.Functor.Classes.Show.Generic import GHC.Generics -import Prologue hiding (Set) +import Prologue hiding (Set, Symbol) -- Boolean diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 67b79df18..96494bc11 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -19,7 +19,7 @@ import Data.These import Diff import Info hiding (Return) import Patch (inserting, deleting, replacing, patchSum) -import Prologue hiding (lookup) +import Prologue hiding (diff, lookup) import Syntax as S hiding (Return) import Term diff --git a/src/Language/Markdown.hs b/src/Language/Markdown.hs index 2b01e2b3e..35d274e7d 100644 --- a/src/Language/Markdown.hs +++ b/src/Language/Markdown.hs @@ -9,7 +9,7 @@ import CMark import Data.Source import qualified Data.Syntax.Assignment as A (AST, Node(..)) import Info -import Prologue hiding (Location) +import Prologue hiding (Location, Symbol) import Text.Parser.TreeSitter.Language (Symbol(..), SymbolType(..)) data Grammar diff --git a/src/Parser.hs b/src/Parser.hs index cf399cac0..c6bcfe25e 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -26,7 +26,7 @@ import qualified Language.JSON.Syntax as JSON import qualified Language.Markdown.Syntax as Markdown import qualified Language.Python.Syntax as Python import qualified Language.Ruby.Syntax as Ruby -import Prologue hiding (Location) +import Prologue hiding (Location, Symbol) import Syntax hiding (Go) import Term import qualified Text.Parser.TreeSitter as TS diff --git a/src/RWS.hs b/src/RWS.hs index 3a60d9c38..5386f04af 100644 --- a/src/RWS.hs +++ b/src/RWS.hs @@ -290,7 +290,7 @@ pqGramDecorator getLabel p q = cata algebra unitVector :: Int -> Int -> FeatureVector unitVector d hash = listArray (0, d - 1) ((* invMagnitude) <$> components) where - invMagnitude = 1 / sqrtDouble (sum (fmap (** 2) components)) + invMagnitude = 1 / sqrt (sum (fmap (** 2) components)) components = evalRand (sequenceA (replicate d (liftRand randomDouble))) (pureMT (fromIntegral hash)) -- | Test the comparability of two root 'Term's in O(1). diff --git a/src/Semantic.hs b/src/Semantic.hs index bbd3dfbbe..ae095a66e 100644 --- a/src/Semantic.hs +++ b/src/Semantic.hs @@ -22,7 +22,7 @@ import Interpreter import qualified Language import Patch import Parser -import Prologue +import Prologue hiding (diff) import Renderer import Semantic.Task as Task import Term diff --git a/src/Semantic/Task.hs b/src/Semantic/Task.hs index d32f37142..fb2b00f2a 100644 --- a/src/Semantic/Task.hs +++ b/src/Semantic/Task.hs @@ -28,7 +28,7 @@ import Data.Syntax.Algebra (RAlgebra, decoratorWithAlgebra) import Diff import Language import Parser -import Prologue +import Prologue hiding (diff) import Term data TaskF output where From 71ce485347be05b60e14224e86dda17169e59aa4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 23 Jul 2017 11:36:08 -0400 Subject: [PATCH 18/39] Fix up the specs. --- test/AlignmentSpec.hs | 18 +++++++++--------- test/Data/Mergeable/Spec.hs | 4 ++-- test/Data/RandomWalkSimilarity/Spec.hs | 14 +++++++------- test/Data/Syntax/Assignment/Spec.hs | 2 +- test/DiffSpec.hs | 8 ++++---- test/InterpreterSpec.hs | 2 +- test/TOCSpec.hs | 14 +++++++------- test/TermSpec.hs | 2 +- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/test/AlignmentSpec.hs b/test/AlignmentSpec.hs index 3a84afe34..3df287283 100644 --- a/test/AlignmentSpec.hs +++ b/test/AlignmentSpec.hs @@ -31,7 +31,7 @@ spec :: Spec spec = parallel $ do describe "alignBranch" $ do it "produces symmetrical context" $ - alignBranch getRange ([] :: [Join These (SplitDiff (Syntax Text) (Record '[Range]))]) (both [Range 0 2, Range 2 4] [Range 0 2, Range 2 4]) `shouldBe` + alignBranch getRange ([] :: [Join These (SplitDiff Syntax (Record '[Range]))]) (both [Range 0 2, Range 2 4] [Range 0 2, Range 2 4]) `shouldBe` [ Join (These (Range 0 2, []) (Range 0 2, [])) , Join (These (Range 2 4, []) @@ -39,7 +39,7 @@ spec = parallel $ do ] it "produces asymmetrical context" $ - alignBranch getRange ([] :: [Join These (SplitDiff (Syntax Text) (Record '[Range]))]) (both [Range 0 2, Range 2 4] [Range 0 1]) `shouldBe` + alignBranch getRange ([] :: [Join These (SplitDiff Syntax (Record '[Range]))]) (both [Range 0 2, Range 2 4] [Range 0 1]) `shouldBe` [ Join (These (Range 0 2, []) (Range 0 1, [])) , Join (This (Range 2 4, [])) @@ -256,7 +256,7 @@ instance Listable BranchElement where counts :: [Join These (Int, a)] -> Both Int counts numbered = fromMaybe 0 . getLast . mconcat . fmap Last <$> Join (unalign (runJoin . fmap Prologue.fst <$> numbered)) -align :: Both Source.Source -> ConstructibleFree (Syntax Text) (Patch (Term (Syntax Text) (Record '[Range]))) (Both (Record '[Range])) -> PrettyDiff (SplitDiff [] (Record '[Range])) +align :: Both Source.Source -> ConstructibleFree Syntax (Patch (SyntaxTerm '[Range])) (Both (Record '[Range])) -> PrettyDiff (SplitDiff [] (Record '[Range])) align sources = PrettyDiff sources . fmap (fmap (getRange &&& identity)) . alignDiff sources . deconstruct info :: Int -> Int -> Record '[Range] @@ -281,14 +281,14 @@ newtype ConstructibleFree f patch annotation = ConstructibleFree { deconstruct : class PatchConstructible p where - insert :: Term (Syntax Text) (Record '[Range]) -> p - delete :: Term (Syntax Text) (Record '[Range]) -> p + insert :: SyntaxTerm '[Range] -> p + delete :: SyntaxTerm '[Range] -> p -instance PatchConstructible (Patch (Term (Syntax Text) (Record '[Range]))) where +instance PatchConstructible (Patch (SyntaxTerm '[Range])) where insert = Insert delete = Delete -instance PatchConstructible (SplitPatch (Term (Syntax Text) (Record '[Range]))) where +instance PatchConstructible (SplitPatch (SyntaxTerm '[Range])) where insert = SplitInsert delete = SplitDelete @@ -304,7 +304,7 @@ class SyntaxConstructible s where leaf :: annotation -> Text -> s annotation branch :: annotation -> [s annotation] -> s annotation -instance SyntaxConstructible (ConstructibleFree (Syntax Text) patch) where +instance SyntaxConstructible (ConstructibleFree Syntax patch) where leaf info = ConstructibleFree . free . Free . (info :<) . Leaf branch info = ConstructibleFree . free . Free . (info :<) . Indexed . fmap deconstruct @@ -312,7 +312,7 @@ instance SyntaxConstructible (ConstructibleFree [] patch) where leaf info = ConstructibleFree . free . Free . (info :<) . const [] branch info = ConstructibleFree . free . Free . (info :<) . fmap deconstruct -instance SyntaxConstructible (Cofree (Syntax Text)) where +instance SyntaxConstructible (Cofree Syntax) where info `leaf` value = cofree $ info :< Leaf value info `branch` children = cofree $ info :< Indexed children diff --git a/test/Data/Mergeable/Spec.hs b/test/Data/Mergeable/Spec.hs index 8aba89d5c..a1a657a8f 100644 --- a/test/Data/Mergeable/Spec.hs +++ b/test/Data/Mergeable/Spec.hs @@ -24,8 +24,8 @@ spec = parallel $ do withAlternativeInstances sequenceAltLaws (Identity `mapT` tiers :: [Tier (Identity Char)]) withAlternativeInstances mergeLaws (Identity `mapT` tiers :: [Tier (Identity Char)]) describe "Syntax" $ do - withAlternativeInstances sequenceAltLaws (tiers :: [Tier (Syntax Char Char)]) - withAlternativeInstances mergeLaws (tiers :: [Tier (Syntax Char Char)]) + withAlternativeInstances sequenceAltLaws (tiers :: [Tier (Syntax Char)]) + withAlternativeInstances mergeLaws (tiers :: [Tier (Syntax Char)]) prop "subsumes catMaybes/Just" $ \ a -> sequenceAlt a `shouldBe` pure (catMaybes (a :: [Maybe Char])) diff --git a/test/Data/RandomWalkSimilarity/Spec.hs b/test/Data/RandomWalkSimilarity/Spec.hs index b4537a84c..f0ef99eb5 100644 --- a/test/Data/RandomWalkSimilarity/Spec.hs +++ b/test/Data/RandomWalkSimilarity/Spec.hs @@ -23,30 +23,30 @@ spec = parallel $ do let positively = succ . abs describe "pqGramDecorator" $ do prop "produces grams with stems of the specified length" $ - \ (term, p, q) -> pqGramDecorator (rhead . headF) (positively p) (positively q) (unListableF term :: SyntaxTerm String '[Category]) `shouldSatisfy` all ((== positively p) . length . stem . rhead) + \ (term, p, q) -> pqGramDecorator (rhead . headF) (positively p) (positively q) (unListableF term :: SyntaxTerm '[Category]) `shouldSatisfy` all ((== positively p) . length . stem . rhead) prop "produces grams with bases of the specified width" $ - \ (term, p, q) -> pqGramDecorator (rhead . headF) (positively p) (positively q) (unListableF term :: SyntaxTerm String '[Category]) `shouldSatisfy` all ((== positively q) . length . base . rhead) + \ (term, p, q) -> pqGramDecorator (rhead . headF) (positively p) (positively q) (unListableF term :: SyntaxTerm '[Category]) `shouldSatisfy` all ((== positively q) . length . base . rhead) describe "featureVectorDecorator" $ do prop "produces a vector of the specified dimension" $ - \ (term, p, q, d) -> featureVectorDecorator (rhead . headF) (positively p) (positively q) (positively d) (unListableF term :: SyntaxTerm String '[Category]) `shouldSatisfy` all ((== (0, abs d)) . bounds . rhead) + \ (term, p, q, d) -> featureVectorDecorator (rhead . headF) (positively p) (positively q) (positively d) (unListableF term :: SyntaxTerm '[Category]) `shouldSatisfy` all ((== (0, abs d)) . bounds . rhead) describe "rws" $ do prop "produces correct diffs" $ - \ (as, bs) -> let tas = decorate <$> (unListableF <$> as :: [SyntaxTerm String '[Category]]) - tbs = decorate <$> (unListableF <$> bs :: [SyntaxTerm String '[Category]]) + \ (as, bs) -> let tas = decorate <$> (unListableF <$> as :: [SyntaxTerm '[Category]]) + tbs = decorate <$> (unListableF <$> bs :: [SyntaxTerm '[Category]]) root = cofree . ((Program :. Nil) :<) . Indexed diff = wrap (pure (Program :. Nil) :< Indexed (stripDiff . diffThese <$> rws editDistance canCompare tas tbs)) in (beforeTerm diff, afterTerm diff) `shouldBe` (Just (root (stripTerm <$> tas)), Just (root (stripTerm <$> tbs))) it "produces unbiased insertions within branches" $ - let (a, b) = (decorate (cofree ((StringLiteral :. Nil) :< Indexed [ cofree ((StringLiteral :. Nil) :< Leaf ("a" :: String)) ])), decorate (cofree ((StringLiteral :. Nil) :< Indexed [ cofree ((StringLiteral :. Nil) :< Leaf "b") ]))) in + let (a, b) = (decorate (cofree ((StringLiteral :. Nil) :< Indexed [ cofree ((StringLiteral :. Nil) :< Leaf "a") ])), decorate (cofree ((StringLiteral :. Nil) :< Indexed [ cofree ((StringLiteral :. Nil) :< Leaf "b") ]))) in fmap (bimap stripTerm stripTerm) (rws editDistance canCompare [ b ] [ a, b ]) `shouldBe` fmap (bimap stripTerm stripTerm) [ That a, These b b ] where canCompare a b = headF a == headF b - decorate :: SyntaxTerm leaf '[Category] -> SyntaxTerm leaf '[FeatureVector, Category] + decorate :: SyntaxTerm '[Category] -> SyntaxTerm '[FeatureVector, Category] decorate = defaultFeatureVectorDecorator (category . headF) diffThese = these deleting inserting replacing diff --git a/test/Data/Syntax/Assignment/Spec.hs b/test/Data/Syntax/Assignment/Spec.hs index 8f2d0083c..2e80e28e4 100644 --- a/test/Data/Syntax/Assignment/Spec.hs +++ b/test/Data/Syntax/Assignment/Spec.hs @@ -5,7 +5,7 @@ import Data.ByteString.Char8 as B (words, length) import Data.Source import Data.Syntax.Assignment import Info -import Prologue +import Prologue hiding (Symbol) import Test.Hspec import Text.Parser.TreeSitter.Language (Symbol(..), SymbolType(..)) diff --git a/test/DiffSpec.hs b/test/DiffSpec.hs index 77f2670ff..2c0cdd770 100644 --- a/test/DiffSpec.hs +++ b/test/DiffSpec.hs @@ -19,19 +19,19 @@ spec :: Spec spec = parallel $ do let decorate = defaultFeatureVectorDecorator (category . headF) prop "equality is reflexive" $ - \ a -> let diff = unListableDiff a :: SyntaxDiff String '[Category] in + \ a -> let diff = unListableDiff a :: SyntaxDiff '[Category] in diff `shouldBe` diff prop "equal terms produce identity diffs" $ - \ a -> let term = decorate (unListableF a :: SyntaxTerm String '[Category]) in + \ a -> let term = decorate (unListableF a :: SyntaxTerm '[Category]) in diffCost (diffTerms (pure term)) `shouldBe` 0 describe "beforeTerm" $ do prop "recovers the before term" $ - \ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm String '[Category])) in + \ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm '[Category])) in beforeTerm diff `shouldBe` Just (unListableF a) describe "afterTerm" $ do prop "recovers the after term" $ - \ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm String '[Category])) in + \ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm '[Category])) in afterTerm diff `shouldBe` Just (unListableF b) diff --git a/test/InterpreterSpec.hs b/test/InterpreterSpec.hs index 66288541f..c9f86efe7 100644 --- a/test/InterpreterSpec.hs +++ b/test/InterpreterSpec.hs @@ -21,7 +21,7 @@ spec :: Spec spec = parallel $ do describe "interpret" $ do it "returns a replacement when comparing two unicode equivalent terms" $ - let termA = cofree $ (StringLiteral :. Nil) :< Leaf ("t\776" :: String) + let termA = cofree $ (StringLiteral :. Nil) :< Leaf "t\776" termB = cofree $ (StringLiteral :. Nil) :< Leaf "\7831" in diffTerms (both termA termB) `shouldBe` replacing termA termB diff --git a/test/TOCSpec.hs b/test/TOCSpec.hs index ac31a3af5..c69c0833a 100644 --- a/test/TOCSpec.hs +++ b/test/TOCSpec.hs @@ -34,21 +34,21 @@ spec :: Spec spec = parallel $ do describe "tableOfContentsBy" $ do prop "drops all nodes with the constant Nothing function" $ - \ diff -> tableOfContentsBy (const Nothing :: a -> Maybe ()) (unListableDiff diff :: SyntaxDiff ()) `shouldBe` [] + \ diff -> tableOfContentsBy (const Nothing :: a -> Maybe ()) (unListableDiff diff :: Diff Syntax ()) `shouldBe` [] let diffSize = max 1 . sum . fmap (const 1) let lastValue a = fromMaybe (extract a) (getLast (foldMap (Last . Just) a)) prop "includes all nodes with a constant Just function" $ - \ diff -> let diff' = (unListableDiff diff :: SyntaxDiff ()) in entryPayload <$> tableOfContentsBy (const (Just ())) diff' `shouldBe` replicate (diffSize diff') () + \ diff -> let diff' = (unListableDiff diff :: Diff Syntax ()) in entryPayload <$> tableOfContentsBy (const (Just ())) diff' `shouldBe` replicate (diffSize diff') () prop "produces an unchanged entry for identity diffs" $ - \ term -> let term' = (unListableF term :: SyntaxTerm (Record '[Category])) in tableOfContentsBy (Just . headF) (diffTerms (pure term')) `shouldBe` [Unchanged (lastValue term')] + \ term -> let term' = (unListableF term :: SyntaxTerm '[Category]) in tableOfContentsBy (Just . headF) (diffTerms (pure term')) `shouldBe` [Unchanged (lastValue term')] prop "produces inserted/deleted/replaced entries for relevant nodes within patches" $ - \ patch -> let patch' = (unListableF <$> patch :: Patch (SyntaxTerm Int)) in tableOfContentsBy (Just . headF) (pure patch') `shouldBe` these (pure . Deleted) (pure . Inserted) ((<>) `on` pure . Replaced) (unPatch (lastValue <$> patch')) + \ patch -> let patch' = (unListableF <$> patch :: Patch (Term Syntax Int)) in tableOfContentsBy (Just . headF) (pure patch') `shouldBe` these (pure . Deleted) (pure . Inserted) ((<>) `on` pure . Replaced) (unPatch (lastValue <$> patch')) prop "produces changed entries for relevant nodes containing irrelevant patches" $ - \ diff -> let diff' = fmap (1 <$) <$> mapAnnotations (const (0 :: Int)) (wrap (pure 0 :< Indexed [unListableDiff diff :: SyntaxDiff Int])) in + \ diff -> let diff' = fmap (1 <$) <$> mapAnnotations (const (0 :: Int)) (wrap (pure 0 :< Indexed [unListableDiff diff :: Diff Syntax Int])) in tableOfContentsBy (\ (n :< _) -> if n == 0 then Just n else Nothing) diff' `shouldBe` if Prologue.null diff' then [Unchanged 0] else replicate (length diff') (Changed 0) @@ -200,7 +200,7 @@ functionInfo :: Record DefaultFields functionInfo = Range 0 0 :. C.Function :. sourceSpanBetween (0,0) (0,0) :. Nil -- Filter tiers for terms that we consider "meaniningful" in TOC summaries. -isMeaningfulTerm :: ListableF SyntaxTerm a -> Bool +isMeaningfulTerm :: ListableF (Term Syntax) a -> Bool isMeaningfulTerm a = case runCofree (unListableF a) of (_ :< S.Indexed _) -> False (_ :< S.Fixed _) -> False @@ -209,7 +209,7 @@ isMeaningfulTerm a = case runCofree (unListableF a) of _ -> True -- Filter tiers for terms if the Syntax is a Method or a Function. -isMethodOrFunction :: HasField fields Category => ListableF SyntaxTerm (Record fields) -> Bool +isMethodOrFunction :: HasField fields Category => ListableF (Term Syntax) (Record fields) -> Bool isMethodOrFunction a = case runCofree (unListableF a) of (_ :< S.Method{}) -> True (_ :< S.Function{}) -> True diff --git a/test/TermSpec.hs b/test/TermSpec.hs index 14dddfa75..d06295c12 100644 --- a/test/TermSpec.hs +++ b/test/TermSpec.hs @@ -14,4 +14,4 @@ spec :: Spec spec = parallel $ do describe "Term" $ do prop "equality is reflexive" $ - \ a -> unListableF a `shouldBe` (unListableF a :: SyntaxTerm String '[Category]) + \ a -> unListableF a `shouldBe` (unListableF a :: SyntaxTerm '[Category]) From 0a089e8639500a17060c598672ada79dd1405eda Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 24 Jul 2017 11:42:32 -0400 Subject: [PATCH 19/39] Simplify the constraint for NFData on Diff. --- src/Diff.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Diff.hs b/src/Diff.hs index 3731bfb21..e29ccd941 100644 --- a/src/Diff.hs +++ b/src/Diff.hs @@ -46,7 +46,7 @@ mapAnnotations :: (Functor f, Functor g) mapAnnotations f = hoistFree (first (fmap f)) . fmap (fmap (fmap f)) -instance (NFData (f (Diff f a)), NFData (Cofree f a), NFData a, Functor f) => NFData (Diff f a) where +instance (NFData (f (Diff f a)), NFData (f (Cofree f a)), NFData a, Functor f) => NFData (Diff f a) where rnf fa = case runFree fa of Free f -> rnf f `seq` () Pure a -> rnf a `seq` () From 823a78aaf4e576793884a40dcef47bd976bed26b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 24 Jul 2017 11:44:12 -0400 Subject: [PATCH 20/39] Fix a dodgy import. --- src/SES/Myers.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SES/Myers.hs b/src/SES/Myers.hs index b8c32fd2e..ccfd5f649 100644 --- a/src/SES/Myers.hs +++ b/src/SES/Myers.hs @@ -9,7 +9,7 @@ import qualified Data.Array as Array import Data.Ix import Data.These import GHC.Show hiding (show) -import Prologue hiding (error) +import Prologue -- | An edit script, i.e. a sequence of changes/copies of elements. type EditScript a b = [These a b] From b74a9bf16a1a56579888311fc6280a7be027af99 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 24 Jul 2017 11:51:40 -0400 Subject: [PATCH 21/39] Turn on MonoLocalBinds for a few modules to silence warnings. --- src/Data/Syntax/Algebra.hs | 2 +- src/Language/Python/Syntax.hs | 2 +- src/Language/Ruby/Syntax.hs | 5 +++-- src/Renderer/TOC.hs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Data/Syntax/Algebra.hs b/src/Data/Syntax/Algebra.hs index ed15792ff..e92297c14 100644 --- a/src/Data/Syntax/Algebra.hs +++ b/src/Data/Syntax/Algebra.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, GeneralizedNewtypeDeriving, TypeOperators #-} +{-# LANGUAGE DataKinds, GeneralizedNewtypeDeriving, MonoLocalBinds, TypeOperators #-} module Data.Syntax.Algebra ( FAlgebra , RAlgebra diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 6199d9196..589b79815 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, DeriveAnyClass, RankNTypes, TypeOperators #-} +{-# LANGUAGE DataKinds, DeriveAnyClass, MonoLocalBinds, RankNTypes, TypeOperators #-} module Language.Python.Syntax ( assignment , Syntax diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index e1a5e31aa..2125b3d59 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-} +{-# LANGUAGE DataKinds, MonoLocalBinds, RankNTypes, TypeOperators #-} module Language.Ruby.Syntax ( assignment , Syntax @@ -375,7 +375,8 @@ binary = symbol Binary >>= \ loc -> children $ expression >>= \ lexpression -> g <|> mk AnonSlash Expression.DividedBy <|> mk AnonPercent Expression.Modulo <|> mk AnonStarStar Expression.Power - where mk s constr = makeTerm loc <$> (symbol s *> (constr lexpression <$> expression)) + where mk :: f :< Syntax => Grammar -> (Term -> Term -> f Term) -> Assignment + mk s constr = makeTerm loc <$> (symbol s *> (constr lexpression <$> expression)) mkNot s constr = makeTerm loc <$ symbol s <*> (Expression.Not <$> (makeTerm <$> location <*> (constr lexpression <$> expression))) conditional :: Assignment diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index fb884f98c..7e8b158ba 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveAnyClass, MultiParamTypeClasses, RankNTypes, TypeOperators #-} +{-# LANGUAGE DeriveAnyClass, MonoLocalBinds, MultiParamTypeClasses, RankNTypes, TypeOperators #-} module Renderer.TOC ( renderToCDiff , renderToCTerm From 63754588da5064111a99de59d0306b0ac4712cf4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 28 Jul 2017 10:20:13 -0400 Subject: [PATCH 22/39] Bump haskell-tree-sitter for the constraint on template-haskell. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index b7ece8ec3..2e2c8f429 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit b7ece8ec385b67856b29257a3c867759765b29b7 +Subproject commit 2e2c8f429922be6a04a3362efa710e5f113bb218 From b2456b6ee40f6672abd954579206fba72e35c6ec Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 28 Jul 2017 15:03:32 -0400 Subject: [PATCH 23/39] Bump haskell-tree-sitter. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 2e2c8f429..9c88d367b 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 2e2c8f429922be6a04a3362efa710e5f113bb218 +Subproject commit 9c88d367bbef1fafb0af99fc2aba14beb74bd2b7 From 5ff3ea09cc5ca4671c77614c343defd525e28cb3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 31 Jul 2017 09:30:06 -0400 Subject: [PATCH 24/39] =?UTF-8?q?Don=E2=80=99t=20depend=20on=20protolude.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- semantic-diff.cabal | 1 - 1 file changed, 1 deletion(-) diff --git a/semantic-diff.cabal b/semantic-diff.cabal index 08ba09ec4..6e71cbf39 100644 --- a/semantic-diff.cabal +++ b/semantic-diff.cabal @@ -171,7 +171,6 @@ test-suite test , HUnit , leancheck , mtl - , protolude , containers , recursion-schemes >= 4.1 , semantic-diff From bc27ad5250ce85f4af7d6308c4db0dd58934fe2c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 31 Jul 2017 11:00:56 -0400 Subject: [PATCH 25/39] Bump haskell-tree-sitter to fix some warnings. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 9c88d367b..b9cc863af 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 9c88d367bbef1fafb0af99fc2aba14beb74bd2b7 +Subproject commit b9cc863af16bd3e8764ce705763c3a136987d4dc From 5cdf3f8bf16173f87ce38c19b8c477ce76321c5b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 4 Aug 2017 13:01:41 -0400 Subject: [PATCH 26/39] Bump haskell-tree-sitter. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 8025cfc58..4a0573c2d 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 8025cfc584acd600f42e17ebe716b0ea27f90bb7 +Subproject commit 4a0573c2d119c4e0d50edee10a6ac3c9d571c628 From 7f1e0f084e6bde75557ceefedb0bf542ececb492 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 4 Aug 2017 13:12:51 -0400 Subject: [PATCH 27/39] Ba-bump. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 4a0573c2d..dcdc0973f 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 4a0573c2d119c4e0d50edee10a6ac3c9d571c628 +Subproject commit dcdc0973fa96fa85f2ad69d99f3b4f053264537d From ade7b82b239d7ab1916f5beaf8767a67ca46ebe6 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 4 Aug 2017 13:26:01 -0400 Subject: [PATCH 28/39] Bumpity bump. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index dcdc0973f..7b55edd8f 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit dcdc0973fa96fa85f2ad69d99f3b4f053264537d +Subproject commit 7b55edd8f0e7e0b6e10236dfec0ec2d1d4f49b10 From 6188700166ebfebc2a17316b12528d43f84b29ee Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 6 Aug 2017 17:08:25 -0400 Subject: [PATCH 29/39] :fire: Prologue (again). --- src/Prologue.hs | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 src/Prologue.hs diff --git a/src/Prologue.hs b/src/Prologue.hs deleted file mode 100644 index 1b7f71ace..000000000 --- a/src/Prologue.hs +++ /dev/null @@ -1,42 +0,0 @@ -module Prologue -( module X -, lookup -, (&&&) -, (***) -, hylo, cata, para, ana -, cofree, runCofree, free, runFree -, module Data.Hashable -) where - -import Protolude as X hiding ((<>)) -import Data.List (lookup) -import Data.Semigroup as X (Semigroup(..)) - -import Control.Comonad.Cofree as X hiding ((:<), unfold, unfoldM) -import Control.Monad.Free as X (Free()) -import Control.Monad.Free as X hiding (Free(Free, Pure), unfold, unfoldM) -import Control.Comonad.Trans.Cofree as X (CofreeF(..), headF, tailF) -import Control.Monad.Trans.Free as X (FreeF(..)) -import Control.Comonad as X -import qualified Control.Comonad.Cofree as Cofree -import qualified Control.Monad.Free as Free - -import Control.Arrow ((&&&), (***)) - -import Data.Functor.Foldable (hylo, cata, para, ana) - -import Data.Hashable - -cofree :: CofreeF f a (Cofree f a) -> Cofree f a -cofree (a :< f) = a Cofree.:< f - -runCofree :: Cofree f a -> CofreeF f a (Cofree f a) -runCofree (a Cofree.:< f) = a :< f - -free :: FreeF f a (Free f a) -> Free f a -free (Free f) = Free.Free f -free (Pure a) = Free.Pure a - -runFree :: Free f a -> FreeF f a (Free f a) -runFree (Free.Free f) = Free f -runFree (Free.Pure a) = Pure a From faf71e3980cbc07b2b417417793ca24bb084716a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Aug 2017 09:57:15 -0400 Subject: [PATCH 30/39] Ignore dist. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 551c917f9..9bee00d1f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ profiles tags cabal.project.local +dist dist-newstyle tmp/ From 1dcc5d48e4454d8fde19b291effef712a1097838 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Aug 2017 10:05:20 -0400 Subject: [PATCH 31/39] Bump haskell-tree-sitter to not treat its C sources as C11. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 7b55edd8f..db9a5728a 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 7b55edd8f0e7e0b6e10236dfec0ec2d1d4f49b10 +Subproject commit db9a5728a1b47b2ff600fe2235ff8d25a999ebeb From 2d0749f0b8a73278ad51cc6d180127539620bb13 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Aug 2017 10:29:39 -0400 Subject: [PATCH 32/39] Specify the root dirs of the various projects. --- cabal.project | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal.project b/cabal.project index 059bea068..e5d40a3de 100644 --- a/cabal.project +++ b/cabal.project @@ -1,3 +1,3 @@ -packages: semantic-diff.cabal languages/*/*.cabal -optional-packages: vendor/*/*.cabal +packages: ./ languages/*/ +optional-packages: vendor/*/ jobs: $ncpus From 887d0c0176b2a9f1a692169c6fa253975a3acae3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Aug 2017 11:35:33 -0400 Subject: [PATCH 33/39] Update the generate-example script not to use stack. --- script/generate-example | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/script/generate-example b/script/generate-example index bc9fb55ba..8607e1e4c 100755 --- a/script/generate-example +++ b/script/generate-example @@ -40,28 +40,28 @@ generate_example () { diffFileBA="${fileB%%.*}.diffB-A.txt" status $parseFileA - stack exec semantic parse -- --sexpression $fileA > $parseFileA + "$(dirname "$0")/run" semantic parse --sexpression $fileA > $parseFileA status $parseFileB - stack exec semantic parse -- --sexpression $fileB > $parseFileB + "$(dirname "$0")/run" semantic parse --sexpression $fileB > $parseFileB status $diffFileAddA - stack exec semantic diff -- --sexpression /dev/null $fileA > $diffFileAddA + "$(dirname "$0")/run" semantic diff --sexpression /dev/null $fileA > $diffFileAddA status $diffFileRemoveA - stack exec semantic diff -- --sexpression $fileA /dev/null > $diffFileRemoveA + "$(dirname "$0")/run" semantic diff --sexpression $fileA /dev/null > $diffFileRemoveA status $diffFileAddB - stack exec semantic diff -- --sexpression /dev/null $fileB > $diffFileAddB + "$(dirname "$0")/run" semantic diff --sexpression /dev/null $fileB > $diffFileAddB status $diffFileRemoveB - stack exec semantic diff -- --sexpression $fileB /dev/null > $diffFileRemoveB + "$(dirname "$0")/run" semantic diff --sexpression $fileB /dev/null > $diffFileRemoveB status $diffFileAB - stack exec semantic diff -- --sexpression $fileA $fileB > $diffFileAB + "$(dirname "$0")/run" semantic diff --sexpression $fileA $fileB > $diffFileAB status $diffFileBA - stack exec semantic diff -- --sexpression $fileB $fileA > $diffFileBA + "$(dirname "$0")/run" semantic diff --sexpression $fileB $fileA > $diffFileBA } if [[ -d $1 ]]; then From 769196ca3930f77c0b109bc97b69ec443700b20f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Aug 2017 11:40:30 -0400 Subject: [PATCH 34/39] Update the integration test fixtures. --- test/fixtures/go/call-expressions.diffA-B.txt | 8 +- test/fixtures/go/call-expressions.diffB-A.txt | 8 +- .../const-declarations-with-types.diffA-B.txt | 13 ++- .../const-declarations-with-types.diffB-A.txt | 4 +- .../go/indexing-expressions.diffB-A.txt | 9 +- .../fixtures/go/switch-statements.diffA-B.txt | 23 ++-- .../fixtures/go/switch-statements.diffB-A.txt | 34 ++++-- test/fixtures/javascript/import.diffA-B.txt | 108 +++++++----------- test/fixtures/javascript/import.diffB-A.txt | 108 +++++++----------- test/fixtures/ruby/delimiter.diffA-B.txt | 4 +- test/fixtures/ruby/delimiter.diffB-A.txt | 4 +- test/fixtures/ruby/hash.diffA-B.txt | 22 ++-- test/fixtures/ruby/hash.diffB-A.txt | 15 ++- test/fixtures/ruby/number.diffA-B.txt | 6 +- test/fixtures/ruby/number.diffB-A.txt | 10 +- .../ruby/relational-operator.diffA-B.txt | 11 +- .../ruby/relational-operator.diffB-A.txt | 7 +- test/fixtures/ruby/symbol.diffA-B.txt | 4 +- test/fixtures/typescript/class.diffB-A.txt | 20 +++- test/fixtures/typescript/import.diffA-B.txt | 108 +++++++----------- test/fixtures/typescript/import.diffB-A.txt | 108 +++++++----------- .../public-field-definition.diffA-B.txt | 45 +++----- .../public-field-definition.diffB-A.txt | 45 +++----- 23 files changed, 319 insertions(+), 405 deletions(-) diff --git a/test/fixtures/go/call-expressions.diffA-B.txt b/test/fixtures/go/call-expressions.diffA-B.txt index d5513793f..e3c439223 100644 --- a/test/fixtures/go/call-expressions.diffA-B.txt +++ b/test/fixtures/go/call-expressions.diffA-B.txt @@ -4,6 +4,10 @@ (Function (Identifier) (Args) + {+(FunctionCall + (Identifier) + (Identifier) + (Identifier))+} {+(FunctionCall (Identifier) (Identifier) @@ -13,10 +17,6 @@ ->(Identifier) } (Identifier) (Identifier)) - {+(FunctionCall - (Identifier) - (Identifier) - (Identifier))+} {-(FunctionCall (Identifier) (Identifier) diff --git a/test/fixtures/go/call-expressions.diffB-A.txt b/test/fixtures/go/call-expressions.diffB-A.txt index d5513793f..e3c439223 100644 --- a/test/fixtures/go/call-expressions.diffB-A.txt +++ b/test/fixtures/go/call-expressions.diffB-A.txt @@ -4,6 +4,10 @@ (Function (Identifier) (Args) + {+(FunctionCall + (Identifier) + (Identifier) + (Identifier))+} {+(FunctionCall (Identifier) (Identifier) @@ -13,10 +17,6 @@ ->(Identifier) } (Identifier) (Identifier)) - {+(FunctionCall - (Identifier) - (Identifier) - (Identifier))+} {-(FunctionCall (Identifier) (Identifier) diff --git a/test/fixtures/go/const-declarations-with-types.diffA-B.txt b/test/fixtures/go/const-declarations-with-types.diffA-B.txt index b40a14bda..1d18a6470 100644 --- a/test/fixtures/go/const-declarations-with-types.diffA-B.txt +++ b/test/fixtures/go/const-declarations-with-types.diffA-B.txt @@ -6,12 +6,13 @@ (Args) (Other "const_declaration" (VarAssignment - { (Identifier) - ->(Identifier) } {+(Identifier)+} { (Identifier) ->(Identifier) } - (Other "expression_list" - { (NumberLiteral) - ->(NumberLiteral) } - {+(NumberLiteral)+}))))) + { (Identifier) + ->(Identifier) } + {+(Other "expression_list" + (NumberLiteral) + (NumberLiteral))+} + {-(Other "expression_list" + (NumberLiteral))-})))) diff --git a/test/fixtures/go/const-declarations-with-types.diffB-A.txt b/test/fixtures/go/const-declarations-with-types.diffB-A.txt index 891f685fb..8eea22bdd 100644 --- a/test/fixtures/go/const-declarations-with-types.diffB-A.txt +++ b/test/fixtures/go/const-declarations-with-types.diffB-A.txt @@ -6,13 +6,13 @@ (Args) (Other "const_declaration" (VarAssignment - { (Identifier) - ->(Identifier) } + {+(Identifier)+} {+(Identifier)+} {+(Other "expression_list" (NumberLiteral))+} {-(Identifier)-} {-(Identifier)-} + {-(Identifier)-} {-(Other "expression_list" (NumberLiteral) (NumberLiteral))-})))) diff --git a/test/fixtures/go/indexing-expressions.diffB-A.txt b/test/fixtures/go/indexing-expressions.diffB-A.txt index c62c77fa7..af79f808c 100644 --- a/test/fixtures/go/indexing-expressions.diffB-A.txt +++ b/test/fixtures/go/indexing-expressions.diffB-A.txt @@ -9,12 +9,9 @@ (NumberLiteral))+} {+(Slice (Identifier))+} - {+(Slice - (Identifier) - (NumberLiteral))+} - {-(Slice - (Identifier) - (NumberLiteral))-} + (Slice + {(Identifier)->(Identifier)} + {(NumberLiteral)->(NumberLiteral)}) {-(Slice (Identifier) (NumberLiteral))-} diff --git a/test/fixtures/go/switch-statements.diffA-B.txt b/test/fixtures/go/switch-statements.diffA-B.txt index 89ac95625..030927cb0 100644 --- a/test/fixtures/go/switch-statements.diffA-B.txt +++ b/test/fixtures/go/switch-statements.diffA-B.txt @@ -15,23 +15,30 @@ ->(Identifier) }))) (FunctionCall (Identifier))) - (Case + {+(Case (Case (Other "expression_list" (RelationalOperator - { (Identifier) - ->(Identifier) } - { (Identifier) - ->(Identifier) }))) + (Identifier) + (Identifier)))) (FunctionCall - (Identifier))) + (Identifier)))+} (Case (Case (Other "expression_list" (RelationalOperator { (Identifier) ->(Identifier) } - (NumberLiteral)))) + { (Identifier) + ->(NumberLiteral) }))) (FunctionCall { (Identifier) - ->(Identifier) }))))) + ->(Identifier) })) + {-(Case + (Case + (Other "expression_list" + (RelationalOperator + (Identifier) + (NumberLiteral)))) + (FunctionCall + (Identifier)))-}))) diff --git a/test/fixtures/go/switch-statements.diffB-A.txt b/test/fixtures/go/switch-statements.diffB-A.txt index 89ac95625..b66932fcb 100644 --- a/test/fixtures/go/switch-statements.diffB-A.txt +++ b/test/fixtures/go/switch-statements.diffB-A.txt @@ -15,23 +15,35 @@ ->(Identifier) }))) (FunctionCall (Identifier))) - (Case + {+(Case (Case (Other "expression_list" (RelationalOperator - { (Identifier) - ->(Identifier) } - { (Identifier) - ->(Identifier) }))) + (Identifier) + (Identifier)))) (FunctionCall - (Identifier))) - (Case + (Identifier)))+} + {+(Case (Case (Other "expression_list" (RelationalOperator - { (Identifier) - ->(Identifier) } + (Identifier) (NumberLiteral)))) (FunctionCall - { (Identifier) - ->(Identifier) }))))) + (Identifier)))+} + {-(Case + (Case + (Other "expression_list" + (RelationalOperator + (Identifier) + (Identifier)))) + (FunctionCall + (Identifier)))-} + {-(Case + (Case + (Other "expression_list" + (RelationalOperator + (Identifier) + (NumberLiteral)))) + (FunctionCall + (Identifier)))-}))) diff --git a/test/fixtures/javascript/import.diffA-B.txt b/test/fixtures/javascript/import.diffA-B.txt index 16bdb748f..c8f733b00 100644 --- a/test/fixtures/javascript/import.diffA-B.txt +++ b/test/fixtures/javascript/import.diffA-B.txt @@ -3,83 +3,61 @@ { (StringLiteral) ->(StringLiteral) } (Identifier)) -{+(Import - (StringLiteral) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral))+} -{-(Import - (StringLiteral) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral))-}) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) })) diff --git a/test/fixtures/javascript/import.diffB-A.txt b/test/fixtures/javascript/import.diffB-A.txt index 16bdb748f..c8f733b00 100644 --- a/test/fixtures/javascript/import.diffB-A.txt +++ b/test/fixtures/javascript/import.diffB-A.txt @@ -3,83 +3,61 @@ { (StringLiteral) ->(StringLiteral) } (Identifier)) -{+(Import - (StringLiteral) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral))+} -{-(Import - (StringLiteral) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral))-}) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) })) diff --git a/test/fixtures/ruby/delimiter.diffA-B.txt b/test/fixtures/ruby/delimiter.diffA-B.txt index 9f9672576..4e0a2a1a9 100644 --- a/test/fixtures/ruby/delimiter.diffA-B.txt +++ b/test/fixtures/ruby/delimiter.diffA-B.txt @@ -1,11 +1,11 @@ (Program {+(StringLiteral)+} {+(StringLiteral)+} -{ (StringLiteral) -->(StringLiteral) } {+(StringLiteral)+} {+(StringLiteral)+} {+(StringLiteral)+} +{+(StringLiteral)+} +{-(StringLiteral)-} {-(StringLiteral)-} {-(StringLiteral)-} {-(StringLiteral)-} diff --git a/test/fixtures/ruby/delimiter.diffB-A.txt b/test/fixtures/ruby/delimiter.diffB-A.txt index d371da80f..ce4899fea 100644 --- a/test/fixtures/ruby/delimiter.diffB-A.txt +++ b/test/fixtures/ruby/delimiter.diffB-A.txt @@ -3,10 +3,10 @@ { (StringLiteral) ->(StringLiteral) } {+(StringLiteral)+} +{+(StringLiteral)+} +{+(StringLiteral)+} { (StringLiteral) ->(StringLiteral) } -{+(StringLiteral)+} -{+(StringLiteral)+} {-(StringLiteral)-} {-(StringLiteral)-} {-(StringLiteral)-} diff --git a/test/fixtures/ruby/hash.diffA-B.txt b/test/fixtures/ruby/hash.diffA-B.txt index 10e547f4f..9b25d2e89 100644 --- a/test/fixtures/ruby/hash.diffA-B.txt +++ b/test/fixtures/ruby/hash.diffA-B.txt @@ -5,18 +5,16 @@ ->(Identifier) } { (StringLiteral) ->(StringLiteral) }) - {+(Pair - (Identifier) - (IntegerLiteral))+} - {+(Pair - (Identifier) - (Boolean))+} - {-(Pair - (SymbolLiteral) - (IntegerLiteral))-} - {-(Pair - (StringLiteral) - (Boolean))-} + (Pair + { (SymbolLiteral) + ->(Identifier) } + { (IntegerLiteral) + ->(IntegerLiteral) }) + (Pair + { (StringLiteral) + ->(Identifier) } + { (Boolean) + ->(Boolean) }) {-(Pair (SymbolLiteral) (IntegerLiteral))-})) diff --git a/test/fixtures/ruby/hash.diffB-A.txt b/test/fixtures/ruby/hash.diffB-A.txt index 2946f7f43..fefff314a 100644 --- a/test/fixtures/ruby/hash.diffB-A.txt +++ b/test/fixtures/ruby/hash.diffB-A.txt @@ -5,17 +5,16 @@ ->(SymbolLiteral) } { (StringLiteral) ->(StringLiteral) }) - {+(Pair - (SymbolLiteral) - (IntegerLiteral))+} + (Pair + { (Identifier) + ->(SymbolLiteral) } + { (IntegerLiteral) + ->(IntegerLiteral) }) (Pair { (Identifier) ->(StringLiteral) } - { (IntegerLiteral) + { (Boolean) ->(Boolean) }) {+(Pair (SymbolLiteral) - (IntegerLiteral))+} - {-(Pair - (Identifier) - (Boolean))-})) + (IntegerLiteral))+})) diff --git a/test/fixtures/ruby/number.diffA-B.txt b/test/fixtures/ruby/number.diffA-B.txt index 080352a9a..a3ef0bcc3 100644 --- a/test/fixtures/ruby/number.diffA-B.txt +++ b/test/fixtures/ruby/number.diffA-B.txt @@ -1,15 +1,15 @@ (Program -{+(IntegerLiteral)+} -{+(IntegerLiteral)+} +{ (IntegerLiteral) +->(IntegerLiteral) } {+(IntegerLiteral)+} {+(IntegerLiteral)+} { (IntegerLiteral) ->(IntegerLiteral) } {+(IntegerLiteral)+} +{+(IntegerLiteral)+} {+(NumberLiteral)+} {-(IntegerLiteral)-} {-(IntegerLiteral)-} {-(IntegerLiteral)-} {-(IntegerLiteral)-} -{-(IntegerLiteral)-} {-(NumberLiteral)-}) diff --git a/test/fixtures/ruby/number.diffB-A.txt b/test/fixtures/ruby/number.diffB-A.txt index 77e0c5d0d..eea1e3e01 100644 --- a/test/fixtures/ruby/number.diffB-A.txt +++ b/test/fixtures/ruby/number.diffB-A.txt @@ -1,12 +1,12 @@ (Program -{+(IntegerLiteral)+} -{+(IntegerLiteral)+} -{+(IntegerLiteral)+} +{ (IntegerLiteral) +->(IntegerLiteral) } {+(IntegerLiteral)+} { (IntegerLiteral) ->(IntegerLiteral) } -{ (IntegerLiteral) -->(IntegerLiteral) } +{+(IntegerLiteral)+} +{+(IntegerLiteral)+} +{+(IntegerLiteral)+} {+(NumberLiteral)+} {-(IntegerLiteral)-} {-(IntegerLiteral)-} diff --git a/test/fixtures/ruby/relational-operator.diffA-B.txt b/test/fixtures/ruby/relational-operator.diffA-B.txt index d7362f650..c41adf788 100644 --- a/test/fixtures/ruby/relational-operator.diffA-B.txt +++ b/test/fixtures/ruby/relational-operator.diffA-B.txt @@ -4,19 +4,16 @@ { (Other "==") ->(Other "<=>") } (Identifier)) -{+(Binary + (Binary (Identifier) - (Other "=~") - (Identifier))+} + { (Other "!=") + ->(Other "=~") } + (Identifier)) {+(Assignment (Identifier) (Unary (Other "!") (Identifier)))+} -{-(Binary - (Identifier) - (Other "!=") - (Identifier))-} {-(Binary (Identifier) (Other "===") diff --git a/test/fixtures/ruby/relational-operator.diffB-A.txt b/test/fixtures/ruby/relational-operator.diffB-A.txt index 85e8bafa3..3faad436e 100644 --- a/test/fixtures/ruby/relational-operator.diffB-A.txt +++ b/test/fixtures/ruby/relational-operator.diffB-A.txt @@ -4,15 +4,12 @@ { (Other "<=>") ->(Other "==") } (Identifier)) -{+(Binary - (Identifier) - (Other "!=") - (Identifier))+} (Binary (Identifier) { (Other "=~") - ->(Other "===") } + ->(Other "!=") } (Identifier)) +{+(Binary(Identifier)(Other"===")(Identifier))+} {-(Assignment (Identifier) (Unary diff --git a/test/fixtures/ruby/symbol.diffA-B.txt b/test/fixtures/ruby/symbol.diffA-B.txt index 1dad1fa37..50a7ef72e 100644 --- a/test/fixtures/ruby/symbol.diffA-B.txt +++ b/test/fixtures/ruby/symbol.diffA-B.txt @@ -2,6 +2,6 @@ {+(SymbolLiteral)+} { (SymbolLiteral) ->(SymbolLiteral) } -{ (SymbolLiteral) -->(SymbolLiteral) } +{+(SymbolLiteral)+} +{-(SymbolLiteral)-} {-(SymbolLiteral)-}) diff --git a/test/fixtures/typescript/class.diffB-A.txt b/test/fixtures/typescript/class.diffB-A.txt index 387e5ccca..9e81c3e6f 100644 --- a/test/fixtures/typescript/class.diffB-A.txt +++ b/test/fixtures/typescript/class.diffB-A.txt @@ -22,19 +22,27 @@ (Identifier))) (Return (Identifier))) + {+(Method + (Identifier) + (Params + (Other "required_parameter" + (Identifier))) + (Return + (Identifier)))+} (Method { (Identifier) ->(Identifier) } (Params (Other "required_parameter" - (Identifier))) + { (Identifier) + ->(Identifier) })) (Return - (Identifier))) - (Method - { (Identifier) - ->(Identifier) } + { (Identifier) + ->(Identifier) })) + {-(Method + (Identifier) (Params (Other "required_parameter" (Identifier))) (Return - (Identifier)))))) + (Identifier)))-}))) diff --git a/test/fixtures/typescript/import.diffA-B.txt b/test/fixtures/typescript/import.diffA-B.txt index 16bdb748f..c8f733b00 100644 --- a/test/fixtures/typescript/import.diffA-B.txt +++ b/test/fixtures/typescript/import.diffA-B.txt @@ -3,83 +3,61 @@ { (StringLiteral) ->(StringLiteral) } (Identifier)) -{+(Import - (StringLiteral) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral))+} -{-(Import - (StringLiteral) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral))-}) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) })) diff --git a/test/fixtures/typescript/import.diffB-A.txt b/test/fixtures/typescript/import.diffB-A.txt index 16bdb748f..c8f733b00 100644 --- a/test/fixtures/typescript/import.diffB-A.txt +++ b/test/fixtures/typescript/import.diffB-A.txt @@ -3,83 +3,61 @@ { (StringLiteral) ->(StringLiteral) } (Identifier)) -{+(Import - (StringLiteral) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "named_imports" (Other "import_specifier" - (Identifier)) + { (Identifier) + ->(Identifier) }) (Other "import_specifier" - (Identifier) - (Identifier))))+} -{+(Import - (StringLiteral) + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) }))) + (Import + { (StringLiteral) + ->(StringLiteral) } (Identifier) (Other "namespace_import" - (Identifier)))+} -{+(Import - (StringLiteral))+} -{-(Import - (StringLiteral) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier))))-} -{-(Import - (StringLiteral) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "named_imports" - (Other "import_specifier" - (Identifier)) - (Other "import_specifier" - (Identifier) - (Identifier))))-} -{-(Import - (StringLiteral) - (Identifier) - (Other "namespace_import" - (Identifier)))-} -{-(Import - (StringLiteral))-}) + { (Identifier) + ->(Identifier) })) + (Import + { (StringLiteral) + ->(StringLiteral) })) diff --git a/test/fixtures/typescript/public-field-definition.diffA-B.txt b/test/fixtures/typescript/public-field-definition.diffA-B.txt index 1094f00d7..24b310be8 100644 --- a/test/fixtures/typescript/public-field-definition.diffA-B.txt +++ b/test/fixtures/typescript/public-field-definition.diffA-B.txt @@ -54,32 +54,25 @@ (Ty (Identifier)) (NumberLiteral)) - {+(FieldDecl - (Other "accessibility_modifier") - (Other "readonly") - (Identifier) + (FieldDecl + { (Other "readonly") + ->(Other "accessibility_modifier") } + { (Identifier) + ->(Other "readonly") } + { (Ty + (Identifier)) + ->(Identifier) } + { (NumberLiteral) + ->(Ty + (Identifier)) } + {+(StringLiteral)+}) + (FieldDecl + { (Identifier) + ->(Identifier) } (Ty (Identifier)) - (StringLiteral))+} - {+(FieldDecl + (NumberLiteral)) + (FieldDecl (Identifier) - (Ty - (Identifier)) - (NumberLiteral))+} - {+(FieldDecl - (Identifier) - (NumberLiteral))+} - {-(FieldDecl - (Other "readonly") - (Identifier) - (Ty - (Identifier)) - (NumberLiteral))-} - {-(FieldDecl - (Identifier) - (Ty - (Identifier)) - (NumberLiteral))-} - {-(FieldDecl - (Identifier) - (NumberLiteral))-}))) + { (NumberLiteral) + ->(NumberLiteral) })))) diff --git a/test/fixtures/typescript/public-field-definition.diffB-A.txt b/test/fixtures/typescript/public-field-definition.diffB-A.txt index 7e69ac6fe..efb915192 100644 --- a/test/fixtures/typescript/public-field-definition.diffB-A.txt +++ b/test/fixtures/typescript/public-field-definition.diffB-A.txt @@ -48,32 +48,25 @@ (Ty (Identifier)) (NumberLiteral)) - {+(FieldDecl - (Other "readonly") - (Identifier) + (FieldDecl + { (Other "accessibility_modifier") + ->(Other "readonly") } + { (Other "readonly") + ->(Identifier) } + { (Identifier) + ->(Ty + (Identifier)) } + { (Ty + (Identifier)) + ->(NumberLiteral) } + {-(StringLiteral)-}) + (FieldDecl + { (Identifier) + ->(Identifier) } (Ty (Identifier)) - (NumberLiteral))+} - {+(FieldDecl + (NumberLiteral)) + (FieldDecl (Identifier) - (Ty - (Identifier)) - (NumberLiteral))+} - {+(FieldDecl - (Identifier) - (NumberLiteral))+} - {-(FieldDecl - (Other "accessibility_modifier") - (Other "readonly") - (Identifier) - (Ty - (Identifier)) - (StringLiteral))-} - {-(FieldDecl - (Identifier) - (Ty - (Identifier)) - (NumberLiteral))-} - {-(FieldDecl - (Identifier) - (NumberLiteral))-}))) + { (NumberLiteral) + ->(NumberLiteral) })))) From ee65db5025e4b925e003c021615a98fe94c9bf4f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Aug 2017 11:59:23 -0400 Subject: [PATCH 35/39] Constrain cmark-gfm to correct a failing test. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cc @kivikakk — #1248 uses cabal to build instead of stack, so I added the version constraint to the cabal.project file for the time being. --- cabal.project | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cabal.project b/cabal.project index e5d40a3de..c475d39b6 100644 --- a/cabal.project +++ b/cabal.project @@ -1,3 +1,6 @@ packages: ./ languages/*/ optional-packages: vendor/*/ + jobs: $ncpus + +constraints: cmark-gfm < 0.1.2 From 09af5a7f18e036e3bc0fbcdad2d9085aac790ace Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Aug 2017 15:59:36 -0400 Subject: [PATCH 36/39] Stub in a package for listing dependencies. --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index c475d39b6..6dd21fe03 100644 --- a/cabal.project +++ b/cabal.project @@ -1,4 +1,4 @@ -packages: ./ languages/*/ +packages: ./ languages/*/ tools/*/ optional-packages: vendor/*/ jobs: $ncpus From ed94c1642278616bd6830808eeba93e9fccc513b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Aug 2017 09:14:19 -0400 Subject: [PATCH 37/39] Relax the cmark-gfm constraint. --- cabal.project | 2 -- 1 file changed, 2 deletions(-) diff --git a/cabal.project b/cabal.project index 6dd21fe03..24accf28e 100644 --- a/cabal.project +++ b/cabal.project @@ -2,5 +2,3 @@ packages: ./ languages/*/ tools/*/ optional-packages: vendor/*/ jobs: $ncpus - -constraints: cmark-gfm < 0.1.2 From 65157ac87c967cf5580c2468f44fbfc20607b144 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Aug 2017 10:40:24 -0400 Subject: [PATCH 38/39] :fire: MonoLocalBinds. --- src/Data/Syntax/Algebra.hs | 2 +- src/Language/Python/Syntax.hs | 2 +- src/Language/Ruby/Syntax.hs | 2 +- src/Renderer/TOC.hs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Data/Syntax/Algebra.hs b/src/Data/Syntax/Algebra.hs index 14305a278..1613348a5 100644 --- a/src/Data/Syntax/Algebra.hs +++ b/src/Data/Syntax/Algebra.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, GeneralizedNewtypeDeriving, MonoLocalBinds, TypeOperators #-} +{-# LANGUAGE DataKinds, GeneralizedNewtypeDeriving, TypeOperators #-} module Data.Syntax.Algebra ( FAlgebra , RAlgebra diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 0fdcd6929..dd938db26 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, DeriveAnyClass, MonoLocalBinds, RankNTypes, TypeOperators #-} +{-# LANGUAGE DataKinds, DeriveAnyClass, RankNTypes, TypeOperators #-} module Language.Python.Syntax ( assignment , Syntax diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index e05beda5b..f00a06811 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, MonoLocalBinds, RankNTypes, TypeOperators #-} +{-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-} module Language.Ruby.Syntax ( assignment , Syntax diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index 241728a1e..7feb69e38 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveAnyClass, MonoLocalBinds, MultiParamTypeClasses, RankNTypes, TypeOperators #-} +{-# LANGUAGE DeriveAnyClass, MultiParamTypeClasses, RankNTypes, TypeOperators #-} module Renderer.TOC ( renderToCDiff , renderToCTerm From 453daf7bcf3b1536666f1c7b28424e555b977d97 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Aug 2017 10:41:21 -0400 Subject: [PATCH 39/39] :fire: a type sig. --- src/Language/Ruby/Syntax.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index f00a06811..511f4f03f 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -374,8 +374,7 @@ binary = symbol Binary >>= \ loc -> children $ expression >>= \ lexpression -> g <|> mk AnonSlash Expression.DividedBy <|> mk AnonPercent Expression.Modulo <|> mk AnonStarStar Expression.Power - where mk :: f :< Syntax => Grammar -> (Term -> Term -> f Term) -> Assignment - mk s constr = makeTerm loc <$> (symbol s *> (constr lexpression <$> expression)) + where mk s constr = makeTerm loc <$> (symbol s *> (constr lexpression <$> expression)) mkNot s constr = makeTerm loc <$ symbol s <*> (Expression.Not <$> (makeTerm <$> location <*> (constr lexpression <$> expression))) conditional :: Assignment