diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2023-06-12 09:54:30 -0600 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | 692b051b09935653befdb8f7ba8afdb640adf17b (patch) | |
| tree | 167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/rescript | |
| parent | feat(c-family): inherit injections (diff) | |
| download | nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2 nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip | |
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/rescript')
| -rw-r--r-- | runtime/queries/rescript/folds.scm | 12 | ||||
| -rw-r--r-- | runtime/queries/rescript/highlights.scm | 335 | ||||
| -rw-r--r-- | runtime/queries/rescript/indents.scm | 36 | ||||
| -rw-r--r-- | runtime/queries/rescript/injections.scm | 33 | ||||
| -rw-r--r-- | runtime/queries/rescript/locals.scm | 9 |
5 files changed, 425 insertions, 0 deletions
diff --git a/runtime/queries/rescript/folds.scm b/runtime/queries/rescript/folds.scm new file mode 100644 index 000000000..4e658a57c --- /dev/null +++ b/runtime/queries/rescript/folds.scm @@ -0,0 +1,12 @@ +[ + (block) + (function) + (module_declaration) + (type_declaration) + (external_declaration) + (call_expression) + (switch_expression) + (parenthesized_expression) + (record) + (include_statement)+ +] @fold diff --git a/runtime/queries/rescript/highlights.scm b/runtime/queries/rescript/highlights.scm new file mode 100644 index 000000000..e7cba9be8 --- /dev/null +++ b/runtime/queries/rescript/highlights.scm @@ -0,0 +1,335 @@ +(comment) @comment @spell + +; Identifiers +;------------ +; Escaped identifiers like \"+." +((value_identifier) @constant.macro + (#lua-match? @constant.macro "^%.*$")) + +(value_identifier) @variable + +[ + (type_identifier) + (unit_type) + (list) + (list_pattern) +] @type + +((type_identifier) @type.builtin + (#any-of? @type.builtin "int" "char" "string" "float" "bool" "unit")) + +[ + (variant_identifier) + (polyvar_identifier) +] @constructor + +(record_type_field + (property_identifier) @property) + +(record_field + (property_identifier) @property) + +(object + (field + (property_identifier) @property)) + +(object_type + (field + (property_identifier) @property)) + +(module_identifier) @module + +(member_expression + (property_identifier) @variable.member) + +(value_identifier_path + (module_identifier) + (value_identifier) @variable) + +(record_pattern + (value_identifier_path + (value_identifier) @variable.member)) + +(record_pattern + (value_identifier) @variable) + +(labeled_argument + label: (value_identifier) @variable.parameter) + +; Parameters +;---------------- +(list_pattern + (value_identifier) @variable.parameter) + +(spread_pattern + (value_identifier) @variable.parameter) + +; String literals +;---------------- +[ + (string) + (template_string) +] @string + +(character) @character + +(escape_sequence) @string.escape + +; Other literals +;--------------- +[ + (true) + (false) +] @boolean + +(number) @number + +(polyvar) @constructor + +(polyvar_string) @constructor + +; Functions +;---------- +; parameter(s) in parens +(parameter + (value_identifier) @variable.parameter) + +(labeled_parameter + (value_identifier) @variable.parameter) + +; single parameter with no parens +(function + parameter: (value_identifier) @variable.parameter) + +(parameter + (tuple_pattern + (tuple_item_pattern + (value_identifier) @variable.parameter))) + +(parameter + (array_pattern + (value_identifier) @variable.parameter)) + +(parameter + (record_pattern + (value_identifier) @variable.parameter)) + +; function identifier in let binding +(let_binding + pattern: (value_identifier) @function + body: (function)) + +; function calls +(call_expression + function: (value_identifier_path + (value_identifier) @function.method.call .)) + +(call_expression + function: (value_identifier) @function.call) + +; highlight the right-hand side of a pipe operator as a function call +(pipe_expression + (value_identifier) @function.call .) + +(pipe_expression + (value_identifier_path + (value_identifier) @function.method.call .) .) + +; Meta +;----- +(decorator_identifier) @attribute + +(extension_identifier) @keyword + +"%" @keyword + +; Misc +;----- +(polyvar_type_pattern + "#" @constructor) + +[ + "include" + "open" +] @keyword.import + +[ + "private" + "mutable" + "rec" +] @keyword.modifier + +"type" @keyword.type + +[ + "and" + "with" + "as" +] @keyword.operator + +[ + "export" + "external" + "let" + "module" + "assert" + "await" + "lazy" + "constraint" +] @keyword + +"await" @keyword.coroutine + +(function + "async" @keyword.coroutine) + +(module_unpack + "unpack" @keyword) + +[ + "if" + "else" + "switch" + "when" +] @keyword.conditional + +[ + "exception" + "try" + "catch" +] @keyword.exception + +(call_expression + function: (value_identifier) @keyword.exception + (#eq? @keyword.exception "raise")) + +[ + "for" + "in" + "to" + "downto" + "while" +] @keyword.repeat + +[ + "." + "," + "|" + ":" +] @punctuation.delimiter + +[ + "++" + "+" + "+." + "-" + "-." + "*" + "**" + "*." + "/." + "<=" + "==" + "===" + "!" + "!=" + "!==" + ">=" + "&&" + "||" + "=" + ":=" + "->" + "|>" + ":>" + "+=" + "=>" + (uncurry) +] @operator + +; Explicitly enclose these operators with binary_expression +; to avoid confusion with JSX tag delimiters +(binary_expression + [ + "<" + ">" + "/" + ] @operator) + +[ + "(" + ")" + "{" + "}" + "[" + "]" + "<" + ">" +] @punctuation.bracket + +(unit + [ + "(" + ")" + ] @constant.builtin) + +(template_substitution + "${" @punctuation.special + "}" @punctuation.special) @none + +(polyvar_type + [ + "[" + "[>" + "[<" + "]" + ] @punctuation.bracket) + +[ + "~" + "?" + ".." + "..." +] @punctuation.special + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +; JSX +;---------- +(jsx_identifier) @tag + +(jsx_element + open_tag: (jsx_opening_element + [ + "<" + ">" + ] @tag.delimiter)) + +(jsx_element + close_tag: (jsx_closing_element + [ + "<" + "/" + ">" + ] @tag.delimiter)) + +(jsx_self_closing_element + [ + "/" + ">" + "<" + ] @tag.delimiter) + +(jsx_fragment + [ + ">" + "<" + "/" + ] @tag.delimiter) + +(jsx_attribute + (property_identifier) @tag.attribute) diff --git a/runtime/queries/rescript/indents.scm b/runtime/queries/rescript/indents.scm new file mode 100644 index 000000000..0b635dd4d --- /dev/null +++ b/runtime/queries/rescript/indents.scm @@ -0,0 +1,36 @@ +[ + (block) + (record_type) + (record) + (parenthesized_expression) + (call_expression) + (function_type_parameters) + (function) + (switch_match) + (let_declaration) + (jsx_element) + (jsx_fragment) + (jsx_self_closing_element) + (object_type) +] @indent.begin + +[ + "}" + ")" + (jsx_closing_element) +] @indent.branch @indent.end + +(jsx_self_closing_element + "/" @indent.branch + ">"? @indent.end) + +; </> is captured as 3 different anonymous nodes +(jsx_fragment + "<" + "<" @indent.branch) + +(jsx_fragment + ">" + ">" @indent.end) + +(comment) @indent.auto diff --git a/runtime/queries/rescript/injections.scm b/runtime/queries/rescript/injections.scm new file mode 100644 index 000000000..434404bef --- /dev/null +++ b/runtime/queries/rescript/injections.scm @@ -0,0 +1,33 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +(extension_expression + (extension_identifier) @_name + (#eq? @_name "re") + (expression_statement + (_) @injection.content + (#set! injection.language "regex"))) + +(extension_expression + (extension_identifier) @_name + (#eq? @_name "raw") + (expression_statement + (_ + (_) @injection.content + (#set! injection.language "javascript")))) + +(extension_expression + (extension_identifier) @_name + (#eq? @_name "graphql") + (expression_statement + (_ + (_) @injection.content + (#set! injection.language "graphql")))) + +(extension_expression + (extension_identifier) @_name + (#eq? @_name "relay") + (expression_statement + (_ + (_) @injection.content + (#set! injection.language "graphql")))) diff --git a/runtime/queries/rescript/locals.scm b/runtime/queries/rescript/locals.scm new file mode 100644 index 000000000..10a663bd7 --- /dev/null +++ b/runtime/queries/rescript/locals.scm @@ -0,0 +1,9 @@ +(switch_expression) @local.scope + +; Definitions +;------------ +(type_declaration) @local.definition.type + +(let_binding) @local.definition.var + +(module_declaration) @local.definition.namespace |
