diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 59be83a32..de2f678cf 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -249,6 +249,7 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | @steelsojka [robots_txt](https://github.com/opa-oz/tree-sitter-robots-txt) | unstable | `H  J ` | @opa-oz [roc](https://github.com/faldor20/tree-sitter-roc) | unstable | `H IJL` | @nat-418 [ron](https://github.com/tree-sitter-grammars/tree-sitter-ron) | unstable | `HFIJL` | @amaanq +[roto](https://github.com/NLnetLabs/tree-sitter-roto) | unstable | `H   L` | @bsamseth [rst](https://github.com/stsewd/tree-sitter-rst) | unstable | `H  JL` | @stsewd [ruby](https://github.com/tree-sitter/tree-sitter-ruby) | unstable | `HFIJL` | @TravonteD [runescript](https://github.com/2004Scape/tree-sitter-runescript) | unstable | `H  J ` | @2004Scape diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 1bee7e59b..cb67ef9dc 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1954,6 +1954,15 @@ return { maintainers = { '@amaanq' }, tier = 2, }, + roto = { + install_info = { + branch = 'main', + revision = '9ac03409ddee6ab8f3b74746756f12fc6adec740', + url = 'https://github.com/NLnetLabs/tree-sitter-roto', + }, + maintainers = { '@bsamseth' }, + tier = 2, + }, rst = { install_info = { revision = '4e562e1598b95b93db4f3f64fe40ddefbc677a15', diff --git a/runtime/queries/roto/highlights.scm b/runtime/queries/roto/highlights.scm new file mode 100644 index 000000000..2b6a4f58e --- /dev/null +++ b/runtime/queries/roto/highlights.scm @@ -0,0 +1,111 @@ +; Identifiers +(identifier) @variable + +; Assume that uppercase names in paths are types +((identifier) @type + (#match? @type "^[A-Z]")) + +(optional_type) @type + +(type_name) @type + +(unit) @type.builtin + +(never) @type.builtin + +(record_type) @type + +(type_name + (path + (identifier) @type.builtin) + (#match? @type.builtin "^(u8|u16|u32|u64|i8|i16|i32|i64|f32|f64|String|bool|Asn|IpAddr|Prefix)$")) + +; Assume all-caps names are constants +((identifier) @constant + (#match? @constant "^[A-Z][A-Z\\d_]+$'")) + +; Function calls +; Unfortunately, we can't really distinguish them from methods if it's called +; on a path +(call_expression + function: (path + (identifier) @function .)) + +(call_expression + function: (access_expression + (identifier) @function.method .)) + +; Calling a function with an uppercase letter: it's an enum constructor +(call_expression + function: (path + (identifier) @constructor .) + (#match? @constructor "^[A-Z]")) + +; Function definitions +(function_item + (identifier) @function) + +(filtermap_item + (identifier) @function) + +(test_item + (identifier) @function) + +(line_comment) @comment + +(parameter + (identifier) @variable.parameter) + +[ + "*" + "=" + "==" + "!=" + "&&" + "|" + "||" + "-" + "+" + "/" + ">" + "<" + ">=" + "<=" + "?" +] @operator + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + ":" + "." + "," + ";" + "->" +] @punctuation.delimiter + +[ + "filter" + "filtermap" + "fn" + "test" +] @keyword.function + +"in" @keyword + +; "dep" @keyword +; "std" @keyword +; "super" @keyword +; "pkg" @keyword +"not" @keyword.operator + +(string_literal) @string + +(unit_literal) @constant.builtin diff --git a/runtime/queries/roto/locals.scm b/runtime/queries/roto/locals.scm new file mode 100644 index 000000000..dabfd6d54 --- /dev/null +++ b/runtime/queries/roto/locals.scm @@ -0,0 +1,17 @@ +[ + (function_item) + (filtermap_item) + (test_item) + (block) +] @local.scope + +(let_statement + (identifier) @local.definition) + +(parameter + (identifier) @local.definition) + +(for_expression + (identifier) @local.definition) + +(identifier) @local.reference diff --git a/runtime/queries/roto/outline.scm b/runtime/queries/roto/outline.scm new file mode 100644 index 000000000..e5d28de82 --- /dev/null +++ b/runtime/queries/roto/outline.scm @@ -0,0 +1,23 @@ +(function_item + "fn" @context + name: (_) @name) @item + +(filtermap_item + "filtermap" @context + name: (_) @name) @item + +(filtermap_item + "filter" @context + name: (_) @name) @item + +(record_item + "record" @context + name: (_) @name) @item + +(variant_item + "variant" @context + name: (_) @name) @item + +(test_item + "test" @context + name: (_) @name) @item diff --git a/runtime/queries/roto/tags.scm b/runtime/queries/roto/tags.scm new file mode 100644 index 000000000..43829e870 --- /dev/null +++ b/runtime/queries/roto/tags.scm @@ -0,0 +1,14 @@ +(function_item + name: (identifier) @definition.function) + +(filtermap_item + name: (identifier) @definition.function) + +(test_item + name: (identifier) @definition.function) + +(record_item + name: (identifier) @definition.type) + +(variant_item + name: (identifier) @definition.type) diff --git a/runtime/queries/roto/textobjects.scm b/runtime/queries/roto/textobjects.scm new file mode 100644 index 000000000..2e4f17121 --- /dev/null +++ b/runtime/queries/roto/textobjects.scm @@ -0,0 +1,18 @@ +(function_item + body: (block) @function.inside) @function.around + +(filtermap_item + body: (block) @function.inside) @function.around + +(test_item + body: (block) @test.inside) @test.around + +(record_item + fields: (record_type) @class.inside) @class.around + +(variant_item + constructors: (variant_constructors) @class.inside) @class.around + +(line_comment) @comment.inside + +(line_comment)+ @comment.around