I encountered a very strange problem while using it.
I have no problem using javasript
packages and can parse them normally. However, when using cpp
or c
, errors will be reported.
He seems to be a problem with cgo, but JavaScript packages are also used. Why can cgo succeed.
!!!!!!!
this is my code:
package main
import (
"context"
"fmt"
sitter "github.com/smacker/go-tree-sitter"
cpp "github.com/smacker/go-tree-sitter/javascript"
// cpp "github.com/smacker/go-tree-sitter/cpp"
)
func main() {
parser := sitter.NewParser()
parser.SetLanguage(cpp.GetLanguage())
// sourceCode := `
// int main(int argc, char *argv[])
// {
// msfn();
// for (int i = 0; i < argc; i++)
// {
// std::cout << " ====" << argv[i] << std::endl;
// }
// CustomNameSpace::fn1(1);
// return 0;
// }
// `
sourceCode := `function fn1(){ console.log("hello, world") }`
tree, _ := parser.ParseCtx(context.Background(), nil, []byte(sourceCode))
n := tree.RootNode()
fmt.Println(n)
child := n.NamedChild(0)
fmt.Println(child.Type())
fmt.Println(child.StartByte())
fmt.Println(child.EndByte())
}