Skip to content

Commit

Permalink
improve path handling while walking the AST
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Feb 10, 2025
1 parent a05aca1 commit 673262e
Show file tree
Hide file tree
Showing 10 changed files with 1,516 additions and 1,412 deletions.
21 changes: 2 additions & 19 deletions go/tools/asthelpergen/integration/ast_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"fmt"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestWalkAllPartsOfAST(t *testing.T) {
Expand All @@ -32,7 +30,7 @@ func TestWalkAllPartsOfAST(t *testing.T) {
ASTImplementationElements: []*Leaf{{v: 1}, {v: 2}},
}

for i := range 300 {
for i := range 20 {
sliceContainer.ASTImplementationElements = append(sliceContainer.ASTImplementationElements, &Leaf{v: i})
}

Expand All @@ -42,27 +40,12 @@ func TestWalkAllPartsOfAST(t *testing.T) {
ASTImplementationType: &Leaf{v: 3},
}

v := make(map[ASTPath]AST)

RewriteWithPaths(ast, func(c *Cursor) bool {
node := c.Node()
if !reflect.TypeOf(node).Comparable() {
return true
}
current := c.current
v[current] = node
fmt.Println(ASTPath(c.current.ToPath()).DebugString())
return true
}, nil)

fmt.Println("walked all parts of AST")

assert.NotEmpty(t, v)

for path, n1 := range v {
s := path.DebugString()
fmt.Println(s)
_ = n1
//n2 := WalkASTPath(ast, path)
//assert.Equal(t, n1, n2)
}
}
109 changes: 61 additions & 48 deletions go/tools/asthelpergen/integration/ast_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 673262e

Please sign in to comment.