Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

go-toolsmith/astcopy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

26 Commits

Repository files navigation

astcopy

build-img pkg-img reportcard-img version-img

Package astcopy implements Go AST reflection-free deep copy operations.

Installation:

Go version 1.16+

go get github.com/go-toolsmith/astcopy

Example

package main
import (
	"fmt"
	"go/ast"
	"go/token"
	"github.com/go-toolsmith/astcopy"
	"github.com/go-toolsmith/astequal"
	"github.com/go-toolsmith/strparse"
)
func main() {
	x := strparse.Expr(`1 + 2`).(*ast.BinaryExpr)
	y := astcopy.BinaryExpr(x)
	fmt.Println(astequal.Expr(x, y)) // => true
	// Now modify x and make sure y is not modified.
	z := astcopy.BinaryExpr(y)
	x.Op = token.SUB
	fmt.Println(astequal.Expr(y, z)) // => true
	fmt.Println(astequal.Expr(x, y)) // => false
}

License

MIT License.

About

Package astcopy implements Go AST deep copy operations.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

Languages

AltStyle によって変換されたページ (->オリジナル) /