From 22b1d7526a72a0d72db2396d6c6719bee13bae0b Mon Sep 17 00:00:00 2001 From: Kalman Szenes Date: Wed, 13 Aug 2025 09:40:07 +0200 Subject: [PATCH] feat(orca): add support for ORCA input files --- SUPPORTED_LANGUAGES.md | 1 + lua/nvim-treesitter/parsers.lua | 8 + plugin/filetypes.lua | 1 + runtime/queries/orca/folds.scm | 9 + runtime/queries/orca/highlights.scm | 252 ++++++++++++++++++++++++++++ runtime/queries/orca/indents.scm | 21 +++ 6 files changed, 292 insertions(+) create mode 100644 runtime/queries/orca/folds.scm create mode 100644 runtime/queries/orca/highlights.scm create mode 100644 runtime/queries/orca/indents.scm diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index ceb928e72..d31e148b0 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -200,6 +200,7 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | | @steelsojka [ocaml_interface](https://github.com/tree-sitter/tree-sitter-ocaml) | unstable | `HFIJL` | | @undu [ocamllex](https://github.com/atom-ocaml/tree-sitter-ocamllex) | unstable | `H  J ` | | @undu [odin](https://github.com/tree-sitter-grammars/tree-sitter-odin) | unstable | `HFIJL` | | @amaanq +[orca](https://github.com/kszenes/tree-sitter-orca) | unstable | `HFI  ` | | @kszenes [pascal](https://github.com/Isopod/tree-sitter-pascal) | unstable | `HFIJL` | | @Isopod [passwd](https://github.com/ath3/tree-sitter-passwd) | unstable | `H    ` | | @amaanq [pem](https://github.com/tree-sitter-grammars/tree-sitter-pem) | unstable | `HF J ` | | @ObserverOfTime diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 5802d3c4d..6d981dedd 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1538,6 +1538,14 @@ return { maintainers = { '@amaanq' }, tier = 2, }, + orca = { + install_info = { + revision = '6b74f981bcb62edd78c2a04f43e3975f9e1d546b', + url = "https://github.com/kszenes/tree-sitter-orca", + }, + maintainers = { '@kszenes' }, + tier = 2, + }, pascal = { install_info = { revision = '5054931bcd022860dd5936864f981e359fb63aef', diff --git a/plugin/filetypes.lua b/plugin/filetypes.lua index a7bb3bcc0..53e27efa1 100644 --- a/plugin/filetypes.lua +++ b/plugin/filetypes.lua @@ -32,6 +32,7 @@ local filetypes = { markdown = { 'pandoc' }, muttrc = { 'neomuttrc' }, ocaml_interface = { 'ocamlinterface' }, + orca = { 'inp' }, perl = { 'pl' }, poe_filter = { 'poefilter' }, powershell = { 'ps1' }, diff --git a/runtime/queries/orca/folds.scm b/runtime/queries/orca/folds.scm new file mode 100644 index 000000000..6dd5f10a4 --- /dev/null +++ b/runtime/queries/orca/folds.scm @@ -0,0 +1,9 @@ +[ + (input_block) + (geom_block) + (subblock) + (compound_script) + (compound_step_block) + (compound_for_loop) + (compound_if_block) +] @fold diff --git a/runtime/queries/orca/highlights.scm b/runtime/queries/orca/highlights.scm new file mode 100644 index 000000000..b694b6042 --- /dev/null +++ b/runtime/queries/orca/highlights.scm @@ -0,0 +1,252 @@ +(comment) @comment + +(integer) @number + +(float) @number.float + +(element) @string + +(simple_line) @variable.parameter + +(input_title) @keyword + +(input_key) @property + +(quoted_string) @string + +(geom_line_types) @type + +[ + (geom_line_types) + "xyz" + "int" + "gzmt" +] @type + +"*" @keyword + +(string) @number + +; Variables (FIRST - higher priority than general rules) - using @function for prominence +(variable_ref + (variable_name) @operator) ; {r} in geometry blocks + +(variable_ref + "{" @punctuation.bracket) + +(variable_ref + "}" @punctuation.bracket) + +(variable_def + (variable_name) @operator) ; r in variable definitions + +(variable_range + (float) @number.float) + +(variable_array + (float) @number.float) + +; Variable definitions in %paras blocks (when parsed as regular kv_pair) +(input_block + (input_title + (word) @_paras) + (input_body + (kv_pair + (input_key + (word) @operator))) + (#eq? @_paras "paras")) + +; Variable definitions in pardef subblocks +(subblock + (word) @_pardef + (input_body + (kv_pair + (input_key + (word) @operator))) + (#eq? @_pardef "pardef")) + +";" @punctuation.delimiter + +; Brace blocks +(brace_block + "{" @property) + +(brace_block + "}" @property) + +(brace_value + (float) @number.float) + +(brace_value + (integer) @number) + +(constraint_content) @string + +"," @punctuation.delimiter + +; General word values (LAST - lower priority) +(value_atom + (word) @number) ; Words used as values get same color as other values + +; Internal coordinate highlighting +(int_line + connect1: (integer) @operator) + +(int_line + connect2: (integer) @operator) + +(int_line + connect3: (integer) @operator) + +(int_line + (coord_value + (float) @number.float)) + +(int_line + (coord_value + (variable_ref) @operator)) + +; Zmatrix coordinate highlighting - alternating pattern like internal coords +(zmat_line2 + zmat_atom1: (integer) @operator) + +(zmat_line2 + (coord_value + (float) @number.float)) + +(zmat_line2 + (coord_value + (variable_ref) @operator)) + +(zmat_line3 + zmat_atom1: (integer) @operator) + +(zmat_line3 + zmat_atom2: (integer) @operator) + +(zmat_line3 + (coord_value + (float) @number.float)) + +(zmat_line3 + (coord_value + (variable_ref) @operator)) + +(zmat_line4 + zmat_atom1: (integer) @operator) + +(zmat_line4 + zmat_atom2: (integer) @operator) + +(zmat_line4 + zmat_atom3: (integer) @operator) + +(zmat_line4 + (coord_value + (float) @number.float)) + +(zmat_line4 + (coord_value + (variable_ref) @operator)) + +; Subblocks +(subblock + name: (word) @character) + +(subblock + "end" @character) + +; Compound script highlighting - use node types instead of regexes +(compound_script) @keyword + +(compound_variable_declaration) @keyword + +(compound_step_block) @keyword + +(compound_end) @keyword + +(compound_variable_declaration + (variable_name) @function) + +(compound_variable_reference + (variable_name) @function) + +(compound_variable_reference + "&{" @punctuation.bracket) + +(compound_variable_reference + "}" @punctuation.bracket) + +(compound_boolean) @boolean + +(compound_assignment + (variable_name) @function) + +(coord_value + (compound_variable_reference) @function) + +; Control flow structures +(compound_for_loop) @keyword + +(compound_if_block) @keyword + +; For loop keywords and components +(compound_for_loop + (variable_name) @function) + +; If/else condition components +(compound_condition) @keyword.conditional + +(compound_comparison) @operator + +; Array access +(compound_array_access + (variable_name) @function) + +(compound_array_access + "[" @punctuation.bracket) + +(compound_array_access + "]" @punctuation.bracket) + +; Function calls +(compound_function_call + (variable_name) @function.call) + +(compound_function_call + "(" @punctuation.bracket) + +(compound_function_call + ")" @punctuation.bracket) + +; Array assignments +(compound_array_assignment + (compound_array_access + (variable_name) @function)) + +; Variables in expressions - general pattern to catch all variable usage +(compound_primary_expr + (variable_name) @function) + +[ + "*" + "/" + "+" + "-" + "=" +] @operator + +; Parentheses in expressions and conditions +(compound_primary_expr + "(" @punctuation.bracket) + +(compound_primary_expr + ")" @punctuation.bracket) + +(compound_if_block + "(" @punctuation.bracket) + +(compound_if_block + ")" @punctuation.bracket) + +";" @punctuation.delimiter diff --git a/runtime/queries/orca/indents.scm b/runtime/queries/orca/indents.scm new file mode 100644 index 000000000..a686600a6 --- /dev/null +++ b/runtime/queries/orca/indents.scm @@ -0,0 +1,21 @@ +[ + (input_block) + (subblock) + (geom_block) + (compound_script) + (compound_step_block) + (compound_for_loop) + (compound_if_block) +] @indent.begin + +[ + (input_block) + (subblock) + (geom_block) + (compound_script) + (compound_step_block) + (compound_for_loop) + (compound_if_block) +] @indent.end + +"*" @indent.end