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

feat: add starlark binding #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions _automation/grammars.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@
"reference": "v0.19.1",
"revision": "918f0fb948405181707a1772cab639f2d278d384"
},
{
"language": "starlark",
"url": "https://github.com/tree-sitter-grammars/tree-sitter-starlark",
"files": [
"parser.c",
"scanner.c"
],
"reference": "v1.0.0",
"revision": "b31a616aac5d05f927f3f9dd809789db7805b632"
},
{
"language": "svelte",
"url": "https://github.com/Himujjal/tree-sitter-svelte",
Expand Down
15 changes: 15 additions & 0 deletions starlark/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package starlark

//#include "parser.h"
//TSLanguage *tree_sitter_starlark();
import "C"
import (
"unsafe"

sitter "github.com/smacker/go-tree-sitter"
)

func GetLanguage() *sitter.Language {
ptr := unsafe.Pointer(C.tree_sitter_starlark())
return sitter.NewLanguage(ptr)
}
25 changes: 25 additions & 0 deletions starlark/binding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package starlark_test

import (
"context"
"testing"

sitter "github.com/smacker/go-tree-sitter"
"github.com/smacker/go-tree-sitter/starlark"
"github.com/stretchr/testify/assert"
)

func TestGrammar(t *testing.T) {
assert := assert.New(t)

code := `def myfunc(a):
pass
`

n, err := sitter.ParseCtx(context.Background(), []byte(code), starlark.GetLanguage())
assert.NoError(err)
assert.Equal(
"(module (function_definition name: (identifier) parameters: (parameters (identifier)) body: (block (pass_statement))))",
n.String(),
)
}
Loading