-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitter.go
42 lines (33 loc) · 1.12 KB
/
sitter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//go:generate stringer -type=SymbolType -trimprefix=SymbolType -output=stringer1.go .
//go:generate stringer -type=IterMode -output=stringer2.go .
//go:generate stringer -type=QueryError -trimprefix=QueryError -output=stringer3.go .
//go:generate stringer -type=QueryPredicateStepType -trimprefix=QueryPredicateStepType -output=stringer4.go .
package sitter
// #include "sitter.h"
import "C"
import (
"context"
"unsafe"
)
//nolint:revive,stylecheck // ok
const (
TREE_SITTER_LANGUAGE_VERSION = int(C.TREE_SITTER_LANGUAGE_VERSION)
TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION = int(C.TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION)
)
// Parse is a shortcut for parsing bytes of source code, returns root node.
func Parse(ctx context.Context, content []byte, lang *Language) (n *Node, err error) {
p := NewParser()
p.SetLanguage(lang)
tree, err := p.ParseString(ctx, nil, content)
if err != nil {
return
}
return tree.RootNode(), nil
}
// NewLanguage initializes a new language from the provided pointer.
func NewLanguage(ptr unsafe.Pointer) (l *Language) {
if ptr == nil {
return
}
return &Language{ptr: ptr}
}