Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse c is oom, please take a look. #152

Open
xuesongtao opened this issue Mar 21, 2024 · 2 comments
Open

parse c is oom, please take a look. #152

xuesongtao opened this issue Mar 21, 2024 · 2 comments

Comments

@xuesongtao
Copy link

normalization_data.c.txt

@xuesongtao
Copy link
Author

xuesongtao commented Mar 21, 2024

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())
}

@xuesongtao xuesongtao reopened this Mar 21, 2024
@adam-eda
Copy link

is this issue resolved?I also meet this question when parse a large c source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants