blob: 4dae5c41b21d8f68a35e3513284e704d568650d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
[](https://goreportcard.com/report/github.com/go-toolsmith/astcopy)
[](https://godoc.org/github.com/go-toolsmith/astcopy)
[](https://travis-ci.org/go-toolsmith/astcopy)
# astcopy
Package astcopy implements Go AST reflection-free deep copy operations.
## Installation:
```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
}
```
|