Categorygithub.com/smacker/gum
repositorypackage
0.0.0-20191210202023-2be77f0b3794
Repository: https://github.com/smacker/gum.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Gum

Gum is a library to compute differences between ASTs using gum-tree-diff algorithm.

Usage

API: https://godoc.org/github.com/smacker/gum

import "github.com/smacker/gum"

// list of matched nodes in both trees
mapping := gum.Match(srcTree, dstTree)
// list of actions to transform srcTree to dstTree
actions := gum.Patch(srcTree, dstTree, mapping)

Parsers

Bblfsh

The library provides basic integration with bblfsh.

Golang

The library contains incomplete integration with native Go parser.

Custom

Any other parser can be used but would require transformation into gum.Tree:

t := &gum.Tree{
    Type:     "string", // type of a node
    Value:    "string", // value/token/label of a node
    Children: []*gum.Tree{}, // list of children
    Meta:     n, // optional pointer to the original node
}

t.Refresh() // update internal state of the tree

Cli

To explore how library works use built-in command line interface.

Nodes matching:

gum match srcFile dstFile

Patch generation:

gum diff srcFile dstFile

Highlighted diff:

gum webdiff srcFile dstFile

webdiff

Developement

Testing

(Optional) Get and prepare samples to compare results with reference implementation:

git submodule update
JAVA_GUM_BIN=/path/to/gumtree-2.1.2/bin ./testdata/process_samples.sh

Run the tests:

go test -v ./...

Credits