https://github.com/go-toolsmith/astcopy
Package astcopy implements Go AST deep copy operations.
https://github.com/go-toolsmith/astcopy
ast deep-copy go golang
Last synced: 6 months ago
JSON representation
Package astcopy implements Go AST deep copy operations.
- Host: GitHub
- URL: https://github.com/go-toolsmith/astcopy
- Owner: go-toolsmith
- License: mit
- Created: 2018-06-12T12:39:19.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-09-07T20:45:15.000Z (10 months ago)
- Last Synced: 2025-09-07T22:24:34.678Z (10 months ago)
- Topics: ast, deep-copy, go, golang
- Language: Go
- Size: 33.2 KB
- Stars: 20
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# astcopy
[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![reportcard-img]][reportcard-url]
[![version-img]][version-url]
Package `astcopy` implements Go AST reflection-free deep copy operations.
## Installation:
Go version 1.16+
```bash
go get github.com/go-toolsmith/astcopy
```
## Example
```go
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](LICENSE).
[build-img]: https://github.com/go-toolsmith/astp/workflows/build/badge.svg
[build-url]: https://github.com/go-toolsmith/astp/actions
[pkg-img]: https://pkg.go.dev/badge/go-toolsmith/astp
[pkg-url]: https://pkg.go.dev/github.com/go-toolsmith/astp
[reportcard-img]: https://goreportcard.com/badge/go-toolsmith/astp
[reportcard-url]: https://goreportcard.com/report/go-toolsmith/astp
[version-img]: https://img.shields.io/github/v/release/go-toolsmith/astp
[version-url]: https://github.com/go-toolsmith/astp/releases