Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Groovy programming language #1543

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@
[submodule "parsers/scala"]
path = parsers/scala
url = https://github.com/tree-sitter/tree-sitter-scala.git
[submodule "parsers/groovy"]
path = parsers/groovy
url = https://github.com/murtaza64/tree-sitter-groovy.git
1 change: 1 addition & 0 deletions lib/src/lib/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class LanguagePicker {
new ProgrammingLanguage("java", [".java"]),
new ProgrammingLanguage("javascript", [".js"]),
new ProgrammingLanguage("elm", [".elm"]),
new ProgrammingLanguage("groovy", [".groovy", ".gvy", ".gy", ".gsh"]),
new ProgrammingLanguage("r", [".r", ".rdata", ".rds", ".rda"]),
new ProgrammingLanguage("scala", [".scala", ".sc"]),
new ProgrammingLanguage("sql", [".sql"]),
Expand Down
289 changes: 289 additions & 0 deletions lib/src/test/snapshots/tokenizer.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -7673,6 +7673,295 @@ Generated by [AVA](https://avajs.dev).
')',
]

## tokenizer works for groovy

> stable tokenization

[
'(',
'source_file',
'(',
'function_definition',
'(',
'identifier',
')',
'(',
'parameter_list',
'(',
'parameter',
'(',
'identifier',
')',
')',
'(',
'parameter',
'(',
'identifier',
')',
')',
')',
'(',
'closure',
'(',
'declaration',
'(',
'identifier',
')',
'(',
'unary_op',
'(',
'function_call',
'(',
'identifier',
')',
'(',
'argument_list',
')',
')',
')',
')',
'(',
'juxt_function_call',
'(',
'dotted_identifier',
'(',
'identifier',
')',
'(',
'identifier',
')',
')',
'(',
'argument_list',
'(',
'closure',
'(',
'parameter_list',
'(',
'parameter',
'(',
'identifier',
')',
')',
')',
'(',
'declaration',
'(',
'builtintype',
')',
'(',
'identifier',
')',
'(',
'binary_op',
'(',
'index',
'(',
'identifier',
')',
'(',
'number_literal',
')',
')',
'(',
'identifier',
')',
')',
')',
'(',
'switch_statement',
'(',
'identifier',
')',
'(',
'switch_block',
'(',
'case',
'(',
'binary_op',
'(',
'string',
'(',
'string_content',
')',
')',
'(',
'string',
'(',
'string_content',
')',
')',
')',
'(',
'assignment',
'(',
'identifier',
')',
'(',
'binary_op',
'(',
'binary_op',
'(',
'binary_op',
'(',
'binary_op',
'(',
'identifier',
')',
'(',
'number_literal',
')',
')',
'(',
'identifier',
')',
')',
'(',
'number_literal',
')',
')',
'(',
'number_literal',
')',
')',
')',
'(',
'break',
')',
')',
'(',
'case',
'(',
'binary_op',
'(',
'string',
'(',
'string_content',
')',
')',
'(',
'string',
'(',
'string_content',
')',
')',
')',
'(',
'assignment',
'(',
'identifier',
')',
'(',
'binary_op',
'(',
'binary_op',
'(',
'binary_op',
'(',
'binary_op',
'(',
'identifier',
')',
'(',
'number_literal',
')',
')',
'(',
'identifier',
')',
')',
'(',
'number_literal',
')',
')',
'(',
'number_literal',
')',
')',
')',
'(',
'break',
')',
')',
')',
')',
'(',
'binary_op',
'(',
'identifier',
')',
'(',
'binary_op',
'(',
'identifier',
')',
'(',
'identifier',
')',
')',
')',
')',
')',
')',
'(',
'binary_op',
'(',
'identifier',
')',
'(',
'identifier',
')',
')',
')',
')',
'(',
'function_definition',
'(',
'identifier',
')',
'(',
'parameter_list',
'(',
'parameter',
'(',
'identifier',
')',
')',
'(',
'parameter',
'(',
'identifier',
')',
')',
')',
'(',
'closure',
'(',
'function_call',
'(',
'identifier',
')',
'(',
'argument_list',
'(',
'binary_op',
'(',
'number_literal',
')',
'(',
'identifier',
')',
')',
'(',
'identifier',
')',
')',
')',
')',
')',
')',
]

## tokenizer works for java

> stable tokenization
Expand Down
Binary file modified lib/src/test/snapshots/tokenizer.test.ts.snap
Binary file not shown.
1 change: 1 addition & 0 deletions lib/src/test/tokenizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const languageFiles = {
"char": "../samples/char/caesar.txt",
"cpp": "../samples/cpp/caesar.cpp",
"elm": "../samples/elm/Caesar.elm",
"groovy": "../samples/groovy/caesar.groovy",
"java": "../samples/java/Caesar.java",
"javascript": "../samples/javascript/sample.js",
"python": "../samples/python/caesar.py",
Expand Down
1 change: 1 addition & 0 deletions parsers/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"cpp/binding.gyp",
"c_sharp/binding.gyp",
"elm/binding.gyp",
"groovy/binding.gyp",
"java/binding.gyp",
"javascript/binding.gyp",
"modelica/binding.gyp",
Expand Down
1 change: 1 addition & 0 deletions parsers/groovy
Submodule groovy added at 6c5c88
3 changes: 3 additions & 0 deletions parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ parsers.elm.nodeTypeInfo = require("./elm/src/node-types.json");
parsers.java = require("./build/Release/tree_sitter_java_binding");
parsers.java.nodeTypeInfo = require("./java/src/node-types.json");

parsers.groovy = require("./build/Release/tree_sitter_groovy_binding");
parsers.groovy.nodeTypeInfo = require("./groovy/src/node-types.json");

parsers.javascript = require("./build/Release/tree_sitter_javascript_binding");
parsers.javascript.nodeTypeInfo = require("./javascript/src/node-types.json");

Expand Down
13 changes: 13 additions & 0 deletions samples/groovy/caesar.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
builder << (ch as char)
}
builder as String
}
def caesarDecode(cipherKey, text) { caesarEncode(26 - cipherKey, text) }
4 changes: 4 additions & 0 deletions web/src/components/upload/UploadFormCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ const languages = [
name: "Elm",
value: "elm",
},
{
name: "Groovy",
value: "groovy",
},
{
name: "Java",
value: "java",
Expand Down