-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from jochil/groovy-support
feat: add Groovy support
- Loading branch information
Showing
6 changed files
with
183,344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package groovy | ||
|
||
//#include "parser.h" | ||
//TSLanguage *tree_sitter_groovy(); | ||
import "C" | ||
import ( | ||
"unsafe" | ||
|
||
sitter "github.com/smacker/go-tree-sitter" | ||
) | ||
|
||
func GetLanguage() *sitter.Language { | ||
ptr := unsafe.Pointer(C.tree_sitter_groovy()) | ||
return sitter.NewLanguage(ptr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package groovy_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
sitter "github.com/smacker/go-tree-sitter" | ||
"github.com/smacker/go-tree-sitter/groovy" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var gradleGroovyCode = ` | ||
plugins { | ||
id 'application' | ||
id 'foo' | ||
} | ||
` | ||
|
||
var testCases = []struct { | ||
name string | ||
input string | ||
expected string | ||
}{ | ||
{ | ||
name: "hello-world", | ||
input: ` | ||
class Example { | ||
static void main(String[] args) { | ||
println('Hello World'); | ||
} | ||
}`, | ||
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)))))))))", | ||
}, | ||
{ | ||
name: "gradle", | ||
input: ` | ||
plugins { | ||
id 'application' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
application { | ||
mainClass = 'example.App' | ||
} | ||
`, | ||
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)))))))", | ||
}, | ||
} | ||
|
||
func TestGrammar(t *testing.T) { | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
n, err := sitter.ParseCtx(context.Background(), []byte(tc.input), groovy.GetLanguage()) | ||
assert.Nil(t, err) | ||
assert.Equal(t, tc.expected, n.String()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.