Skip to content

Commit 1f283e2

Browse files
authored
Merge pull request #146 from jochil/groovy-support
feat: add Groovy support
2 parents 746cc92 + 2315621 commit 1f283e2

File tree

6 files changed

+183344
-0
lines changed

6 files changed

+183344
-0
lines changed

_automation/grammars.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@
9696
"reference": "master",
9797
"revision": "64457ea6b73ef5422ed1687178d4545c3e91334a"
9898
},
99+
{
100+
"language": "groovy",
101+
"url": "https://github.com/murtaza64/tree-sitter-groovy",
102+
"files": [
103+
"parser.c",
104+
"scanner.c"
105+
],
106+
"reference": "main",
107+
"revision": "235009aad0f580211fc12014bb0846c3910130c1"
108+
},
99109
{
100110
"language": "hcl",
101111
"url": "https://github.com/MichaHoffmann/tree-sitter-hcl",

groovy/binding.go

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

groovy/binding_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package groovy_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
sitter "github.com/smacker/go-tree-sitter"
8+
"github.com/smacker/go-tree-sitter/groovy"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
var gradleGroovyCode = `
13+
plugins {
14+
id 'application'
15+
id 'foo'
16+
}
17+
`
18+
19+
var testCases = []struct {
20+
name string
21+
input string
22+
expected string
23+
}{
24+
{
25+
name: "hello-world",
26+
input: `
27+
class Example {
28+
static void main(String[] args) {
29+
println('Hello World');
30+
}
31+
}`,
32+
expected: "(source_file (class_definition name: (identifier) body: (closure (function_definition (modifier) type: (builtintype) function: (identifier) parameters: (parameter_list (parameter type: (array_type (identifier)) name: (identifier))) body: (closure (function_call function: (identifier) args: (argument_list (string (string_content)))))))))",
33+
},
34+
{
35+
name: "gradle",
36+
input: `
37+
plugins {
38+
id 'application'
39+
}
40+
41+
repositories {
42+
mavenCentral()
43+
}
44+
45+
application {
46+
mainClass = 'example.App'
47+
}
48+
`,
49+
expected: "(source_file (juxt_function_call function: (identifier) args: (argument_list (closure (juxt_function_call function: (identifier) args: (argument_list (string (string_content))))))) (juxt_function_call function: (identifier) args: (argument_list (closure (function_call function: (identifier) args: (argument_list))))) (juxt_function_call function: (identifier) args: (argument_list (closure (assignment (identifier) (string (string_content)))))))",
50+
},
51+
}
52+
53+
func TestGrammar(t *testing.T) {
54+
for _, tc := range testCases {
55+
t.Run(tc.name, func(t *testing.T) {
56+
n, err := sitter.ParseCtx(context.Background(), []byte(tc.input), groovy.GetLanguage())
57+
assert.Nil(t, err)
58+
assert.Equal(t, tc.expected, n.String())
59+
})
60+
}
61+
}

0 commit comments

Comments
 (0)