Skip to content

Commit c3cd476

Browse files
committed
feat: add starlark binding
1 parent 1f283e2 commit c3cd476

File tree

6 files changed

+92951
-0
lines changed

6 files changed

+92951
-0
lines changed

_automation/grammars.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@
237237
"reference": "v0.19.1",
238238
"revision": "918f0fb948405181707a1772cab639f2d278d384"
239239
},
240+
{
241+
"language": "starlark",
242+
"url": "https://github.com/tree-sitter-grammars/tree-sitter-starlark",
243+
"files": [
244+
"parser.c",
245+
"scanner.c"
246+
],
247+
"reference": "v1.0.0",
248+
"revision": "b31a616aac5d05f927f3f9dd809789db7805b632"
249+
},
240250
{
241251
"language": "svelte",
242252
"url": "https://github.com/Himujjal/tree-sitter-svelte",

starlark/binding.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package starlark
2+
3+
//#include "parser.h"
4+
//TSLanguage *tree_sitter_starlark();
5+
import "C"
6+
import (
7+
"unsafe"
8+
9+
sitter "github.com/smacker/go-tree-sitter"
10+
)
11+
12+
func GetLanguage() *sitter.Language {
13+
ptr := unsafe.Pointer(C.tree_sitter_starlark())
14+
return sitter.NewLanguage(ptr)
15+
}

starlark/binding_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package starlark_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
sitter "github.com/smacker/go-tree-sitter"
8+
"github.com/smacker/go-tree-sitter/starlark"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestGrammar(t *testing.T) {
13+
assert := assert.New(t)
14+
15+
code := `def myfunc(a):
16+
pass
17+
`
18+
19+
n, err := sitter.ParseCtx(context.Background(), []byte(code), cue.GetLanguage())
20+
assert.NoError(err)
21+
assert.Equal(
22+
"(source_file (field (label (identifier)) (value (struct_lit (field (label alias: (identifier) (identifier)) (value (string_type))) (field (label alias: (identifier) (simple_string_lit)) (value (bool_type)))))))",
23+
n.String(),
24+
)
25+
}

0 commit comments

Comments
 (0)