Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
184 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Generate GDiff GADTs and Associated Instances | ||
============= | ||
gdiff-th is a library for generating the necessary apparatus for preforming type safe diffs and patches with the gdiff library. | ||
|
||
If you are unfamiliar with the gdiff library it can be found here http://hackage.haskell.org/package/gdiff | ||
|
||
###Usage | ||
|
||
First install the library from here or from cabal. | ||
#####With git | ||
git clone https://github.com/jfischoff/gdiff-th | ||
cd gdiff-th | ||
cabal install | ||
|
||
#####With cabal | ||
cabal update | ||
cabal install gdiff-th | ||
|
||
Below is a simple example of how to use the library to view a colored diff. | ||
|
||
module Example where | ||
import Data.Generic.Diff | ||
import Data.Generic.Diff.TH | ||
import System.Console.Terminfo.Color | ||
import Text.PrettyPrint.Free hiding (parens) | ||
import System.Console.Terminfo.PrettyPrint | ||
|
||
data Exp = Exp :+: Exp | ||
| Exp :*: Exp | ||
| B Integer | ||
deriving(Show, Eq, Typeable) | ||
|
||
-- Make the GDiff apparatus | ||
makeGDiff ''Exp | ||
|
||
testA :: Exp | ||
testA = foldl1 (:+:) . map B $ [0..20] | ||
|
||
testB :: Exp | ||
testB = foldl1 (:+:) . map B $ [0..8] ++ [42] ++ [10..20] | ||
|
||
-- Make a type signature to help inference | ||
diffExp :: Type ExpFamily Exp => Exp -> Exp -> EditScript ExpFamily Exp Exp | ||
diffExp = diff | ||
|
||
diffAandB = showCompressed $ diffExp testA testB | ||
|
||
main = diffAandB | ||
|
||
-- Utility functions to show colored diffs | ||
showEdits :: forall (f :: * -> * -> *) txs tys. | ||
EditScriptL f txs tys -> IO () | ||
showEdits = display . pprEdits | ||
|
||
showCompressed :: Family f => EditScriptL f txs tys -> IO () | ||
showCompressed = display . pprEdits . compress | ||
|
||
pprEdits :: EditScriptL f txs tys -> TermDoc | ||
pprEdits x = case x of | ||
Cpy c d -> (text $ string c) + pprEdits d | ||
CpyTree d -> text " ... " + pprEdits d | ||
Del c d -> (with (Foreground Red) . text $ "- " ++ string c) + pprEdits d | ||
Ins c d -> (with (Foreground Green) . text $ "+ " ++ string c) + pprEdits d | ||
End -> line | ||
Running the main function above would result in the following output | ||
|
||
:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: ... B + 42 - 9 ... ... ... ... ... ... ... ... ... ... ... | ||
|
||
Except with pretty colors :). | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
[InstalledPackageInfo {installedPackageId = InstalledPackageId "gdiff-th-0.0.0.1-inplace", sourcePackageId = PackageIdentifier {pkgName = PackageName "gdiff-th", pkgVersion = Version {versionBranch = [0,0,0,1], versionTags = []}}, license = BSD3, copyright = "", maintainer = "jonathangfischoff@gmail.com", author = "", stability = "", homepage = "", pkgUrl = "", synopsis = "Generate gdiff GADTs and Instances.", description = "Generate gdiff GADTs and Instances. Very Alpha. Does not yet support GADTs among other this I'm sure.", category = "Generics", exposed = True, exposedModules = ["Data.Generic.Diff.TH"], hiddenModules = ["Data.Generic.Diff.TH.Conversion","Data.Generic.Diff.TH.Internal","Data.Generic.Diff.TH.Types","Data.Generic.Diff.TH.Specialize"], trusted = False, importDirs = ["/Users/jfischoff/tools/gdiff-th/dist/build"], libraryDirs = ["/Users/jfischoff/tools/gdiff-th/dist/build"], hsLibraries = ["HSgdiff-th-0.0.0.1"], extraLibraries = [], extraGHCiLibraries = [], includeDirs = [], includes = [], depends = [InstalledPackageId "base-4.6.0.0-6898b0af758ec9881050c7cd4b3d7df3",InstalledPackageId "containers-0.5.0.0-e49be7a240765a4edc5c09f677ec6a81",InstalledPackageId "gdiff-1.0-97a814a189b2afdf44517ae95ca5607f",InstalledPackageId "lens-3.0.2-965fb54790e6f0a032eff3b538a5bcd4",InstalledPackageId "mtl-2.1.2-25dca0019d088a7438da0485cd8b4e7a",InstalledPackageId "pointless-haskell-0.0.8-e4082776f5b4b881920ce54cdacca648",InstalledPackageId "template-haskell-2.8.0.0-9d6abcdc55a03c75b4d8fd14551e6c73",InstalledPackageId "th-expand-syns-0.3.0.3-70d3561e986a14a4bf268611d7a3142d",InstalledPackageId "uniplate-1.6.7-357efbd3ab6434f54ee5fd93aa3353c8"], hugsOptions = [], ccOptions = [], ldOptions = [], frameworkDirs = [], frameworks = [], haddockInterfaces = ["/Users/jfischoff/tools/gdiff-th/dist/doc/html/gdiff-th/gdiff-th.haddock"], haddockHTMLs = ["/Users/jfischoff/tools/gdiff-th/dist/doc/html/gdiff-th"]} | ||
] | ||
[] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,66 @@ | ||
module Data.Generic.Diff.TH (makeGDiff, makeGDiffWith, defaultFamSuffix, | ||
defaultConstructorRenamer, defaultPrimitives) where | ||
-- | This module exports the Template Haskell functions necessary | ||
-- deriving gdiff GADTs and associated instances. Usage is pretty | ||
-- straightforward. | ||
-- | ||
-- @ | ||
--module Example where | ||
--import "Data.Generic.Diff" | ||
--import "Data.Generic.Diff.TH" | ||
--import "System.Console.Terminfo.Color" | ||
--import "Text.PrettyPrint.Free hiding (parens)" | ||
--import "System.Console.Terminfo.PrettyPrint" | ||
-- | ||
--data Exp = Exp :+: Exp | ||
-- | Exp :*: Exp | ||
-- | B Integer | ||
-- deriving(Show, Eq, Typeable) | ||
-- | ||
--{- Make the GDiff apparatus -} | ||
--makeGDiff ''Exp | ||
-- | ||
--testA :: Exp | ||
--testA = foldl1 (:+:) . map B $ [0..20] | ||
-- | ||
--testB :: Exp | ||
--testB = foldl1 (:+:) . map B $ [0..8] ++ [42] ++ [10..20] | ||
-- | ||
--{- Make a type signature to help inference -} | ||
--diffExp :: Type ExpFamily Exp => Exp -> Exp -> EditScript ExpFamily Exp Exp | ||
--diffExp = diff | ||
-- | ||
--diffAandB = showCompressed $ diffExp testA testB | ||
-- | ||
--main = diffAandB | ||
-- | ||
--{- Utility functions to show colored diffs -} | ||
--showEdits :: forall (f :: * -> * -> *) txs tys. | ||
-- EditScriptL f txs tys -> IO () | ||
--showEdits = display . pprEdits | ||
-- | ||
--showCompressed :: Family f => EditScriptL f txs tys -> IO () | ||
--showCompressed = display . pprEdits . compress | ||
-- | ||
--pprEdits :: EditScriptL f txs tys -> TermDoc | ||
--pprEdits x = case x of | ||
-- Cpy c d -> (text $ string c) <+> pprEdits d | ||
-- CpyTree d -> text \" ... \" <+> pprEdits d | ||
-- Del c d -> (with (Foreground Red) . text $ \"- \" ++ string c) <+> pprEdits d | ||
-- Ins c d -> (with (Foreground Green) . text $ \"+ \" ++ string c) <+> pprEdits d | ||
-- End -> line | ||
-- @ | ||
-- | ||
-- Running the main function above would result in the following output | ||
-- @ | ||
--:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: ... B + 42 - 9 ... ... ... ... ... ... ... ... ... ... ... | ||
-- @ | ||
-- Except with pretty colors | ||
module Data.Generic.Diff.TH ( | ||
-- * Main Creation Function | ||
makeGDiff, | ||
-- * Customizable Creation | ||
makeGDiffWith, | ||
defaultFamSuffix, | ||
defaultConstructorRenamer, | ||
defaultPrimitives, | ||
ConstructorRenamer) where | ||
import Data.Generic.Diff.TH.Internal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters