Skip to content

Commit 731d6fa

Browse files
committed
matlab go binding
1 parent fb1f1c2 commit 731d6fa

File tree

8 files changed

+74856
-0
lines changed

8 files changed

+74856
-0
lines changed

_automation/grammars.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,17 @@
347347
"reference": "gh-pages",
348348
"revision": "c67ecbd37d8d12f22e4cc7138afd14bc20253e10",
349349
"updateBasedOn": "commit"
350+
},
351+
{
352+
"language": "matlab",
353+
"url": "https://github.com/acristoffers/tree-sitter-matlab",
354+
"files": [
355+
"parser.c",
356+
"parser.h",
357+
"scanner.c"
358+
],
359+
"reference": "v1.2.0",
360+
"revision": "96a3e8fb0a4ebd0db64db6b52043483937e9ca3a",
361+
"updateBasedOn": "tag"
350362
}
351363
]

matlab/binding.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package matlab
2+
3+
//#include "parser.h"
4+
//TSLanguage *tree_sitter_matlab();
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_matlab())
14+
return sitter.NewLanguage(ptr)
15+
}

matlab/binding_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package matlab_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
sitter "github.com/smacker/go-tree-sitter"
8+
"github.com/smacker/go-tree-sitter/matlab"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestGrammar(t *testing.T) {
13+
assert := assert.New(t)
14+
15+
n, err := sitter.ParseCtx(context.Background(), []byte("function result = myFunction(x)\n result = x * 2;\nend"), matlab.GetLanguage())
16+
assert.NoError(err)
17+
assert.NotNil(n)
18+
assert.Contains(n.String(), "function")
19+
}

matlab/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/smacker/go-tree-sitter/matlab
2+
3+
go 1.23.3
4+
5+
require github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82

matlab/go.sum

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6+
github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 h1:DxgjlvWYsb80WEN2Zv3WqJFAg2DKjUQJO6URGdf1x6Y=
7+
github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8/go.mod h1:q99oHDsbP0xRwmn7Vmob8gbSMNyvJ83OauXPSuHQuKE=
8+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
10+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
11+
github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM=
12+
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
14+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
15+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
16+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
17+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)