Skip to content

Commit

Permalink
Add tree-sitter-zig Go binding into our fork of go-tree-sitter
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchi committed Aug 8, 2024
1 parent 10f3438 commit 4c9876e
Show file tree
Hide file tree
Showing 5 changed files with 154,007 additions and 0 deletions.
8 changes: 8 additions & 0 deletions _automation/grammars.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,13 @@
"reference": "v0.5.0",
"revision": "6129a83eeec7d6070b1c0567ec7ce3509ead607c",
"updateBasedOn": "tag"
},
{
"language": "zig",
"url": "https://github.com/maxxnino/tree-sitter-zig/",
"files":["parser.c"],
"reference": "master",
"revision": "2bac4cc6c697d46a193905fef6d003bfa0bfabfd",
"updateBasedOn": "commit"
}
]
19 changes: 19 additions & 0 deletions zig/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package zig

// #cgo CFLAGS: -std=c11 -fPIC
// #include "parser.h"
//const TSLanguage *tree_sitter_zig();
// // NOTE: if your language has an external scanner, add it here.
import "C"

import (
"unsafe"

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

// Get the tree-sitter Language for this grammar.
func GetLanguage() *sitter.Language {
ptr := unsafe.Pointer(C.tree_sitter_zig())
return sitter.NewLanguage(ptr)
}
15 changes: 15 additions & 0 deletions zig/binding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package zig_test

import (
"testing"

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

func TestCanLoadZigGrammar(t *testing.T) {
language := tree_sitter.NewLanguage(zig.Language())
if language == nil {
t.Errorf("Error loading Zig grammar")
}
}
Loading

0 comments on commit 4c9876e

Please sign in to comment.