Comments (1)
func TestChildTraversal(t *testing.T) {
b, _ := os.ReadFile("normalization_data.c")
root := mustParseGo(string(b))
var visit func(n *sitter.Node, name string, depth int)
visit = func(n *sitter.Node, name string, depth int) {
fmt.Println("depth:", depth)
printNode(n, depth, name)
for i := 0; i < int(n.ChildCount()); i++ {
visit(n.Child(i), n.FieldNameForChild(i), depth+1)
}
}
visit(root, "root", 0)
}
func mustParseC(src string) *sitter.Node {
root, err := sitter.ParseCtx(context.Background(), []byte(src), c.GetLanguage())
if err != nil {
log.Fatal(err)
}
return root
}
func printNode(n *sitter.Node, depth int, name string) {
prefix := ""
if name != "" {
prefix = name + ": "
}
fmt.Printf("%s%s%s [%d-%d]\n", strings.Repeat(" ", depth), prefix, n.Type(), n.StartByte(), n.EndByte())
}
from go-tree-sitter.
Related Issues (20)
- query result inconsistency between cli and lib HOT 1
- This needs a proper reference to where I got most of the code. Sorry, I thought I had done proper attribution!
- Lua parser does not compile on current master HOT 1
- go mod error HOT 2
- Upstreaming generation of bindings HOT 6
- Update javascript grammer
- Unable to build for windows HOT 6
- How can I support Objective-C and Swift? HOT 1
- صباح HOT 1
- add vue
- ld: library not found for -lcrt0.o for python
- Cannot build library with MacOS HOT 1
- Grammar update script not working HOT 1
- Panic when parsing C++ code in tree-sitter > 0.20.0 HOT 3
- Why do I need to call FilterPredicates to apply the predicates?
- An error occurred when parsing the JS file
- Tags support? HOT 1
- Querying does not always work as it should HOT 1
- Missing typescript module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-tree-sitter.