format: parsers.lua file and ORCA queries

This commit is contained in:
Kalman Szenes 2025-08-10 11:45:27 +02:00
parent f0f65a07d5
commit 661ba3fec8
4 changed files with 244 additions and 99 deletions

View file

@ -1622,19 +1622,19 @@ list.odin = {
} }
-- Define filetype for ORCA input files -- Define filetype for ORCA input files
vim.filetype.add({ vim.filetype.add {
extension = { extension = {
inp = "inp", inp = "inp",
}, },
}) }
list.orca = { list.orca = {
install_info = { install_info = {
url = "https://github.com/kszenes/tree-sitter-orca.git", url = "https://github.com/kszenes/tree-sitter-orca.git",
files = { "src/parser.c" } files = { "src/parser.c" },
}, },
filetype = "inp", filetype = "inp",
maintainers = { "@kszenes" } maintainers = { "@kszenes" },
} }
list.pascal = { list.pascal = {

View file

@ -1,6 +1,6 @@
[ [
(input_block) (input_block)
(geom_block) (geom_block)
(subblock) (subblock)
(compound_script) (compound_script)
(compound_step_block) (compound_step_block)

View file

@ -1,131 +1,276 @@
(comment) @comment (comment) @comment
(integer) @number (integer) @number
(float) @float (float) @float
(element) @string (element) @string
(simple_line) @variable.parameter @markup.strong (simple_line) @variable.parameter @markup.strong
(input_title) @keyword (input_title) @keyword
(input_key) @property
(quoted_string) @string (input_key) @property
(quoted_string) @string
(geom_line_types) @type (geom_line_types) @type
"xyz" @type "xyz" @type
"int" @type "int" @type
"gzmt" @type "gzmt" @type
"end" @keyword "end" @keyword
"*" @keyword "*" @keyword
(string) @number
;; Variables (FIRST - higher priority than general rules) - using @function for prominence (string) @number
(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) @float)
(variable_array (float) @float)
;; Variable definitions in %paras blocks (when parsed as regular kv_pair) ; Variables (FIRST - higher priority than general rules) - using @function for prominence
(input_block (input_title (word) @_paras) (input_body (kv_pair (input_key (word) @operator))) (#eq? @_paras "paras")) (variable_ref
;; Variable definitions in pardef subblocks (variable_name) @operator) ; {r} in geometry blocks
(subblock (word) @_pardef (input_body (kv_pair (input_key (word) @operator))) (#eq? @_pardef "pardef"))
(variable_ref
"{" @punctuation.bracket)
(variable_ref
"}" @punctuation.bracket)
(variable_def
(variable_name) @operator) ; r in variable definitions
(variable_range
(float) @float)
(variable_array
(float) @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 ";" @punctuation.delimiter
;; Brace blocks ; Brace blocks
(brace_block "{" @property) (brace_block
(brace_block "}" @property) "{" @property)
(brace_value (float) @float)
(brace_value (integer) @number) (brace_block
"}" @property)
(brace_value
(float) @float)
(brace_value
(integer) @number)
(constraint_content) @string (constraint_content) @string
"," @punctuation.delimiter "," @punctuation.delimiter
;; General word values (LAST - lower priority) ; General word values (LAST - lower priority)
(value_atom (word) @number) ; Words used as values get same color as other values (value_atom
(word) @number) ; Words used as values get same color as other values
;; Internal coordinate highlighting ; Internal coordinate highlighting
(int_line connect1: (integer) @operator) (int_line
(int_line connect2: (integer) @operator) connect1: (integer) @operator)
(int_line connect3: (integer) @operator)
(int_line (coord_value (float) @float))
(int_line (coord_value (variable_ref) @operator))
;; Zmatrix coordinate highlighting - alternating pattern like internal coords (int_line
(zmat_line2 zmat_atom1: (integer) @operator) connect2: (integer) @operator)
(zmat_line2 (coord_value (float) @float))
(zmat_line2 (coord_value (variable_ref) @operator))
(zmat_line3 zmat_atom1: (integer) @operator) (int_line
(zmat_line3 zmat_atom2: (integer) @operator) connect3: (integer) @operator)
(zmat_line3 (coord_value (float) @float))
(zmat_line3 (coord_value (variable_ref) @operator))
(zmat_line4 zmat_atom1: (integer) @operator) (int_line
(zmat_line4 zmat_atom2: (integer) @operator) (coord_value
(zmat_line4 zmat_atom3: (integer) @operator) (float) @float))
(zmat_line4 (coord_value (float) @float))
(zmat_line4 (coord_value (variable_ref) @operator))
;; Subblocks (int_line
(subblock name: (word) @character) (coord_value
(subblock "end" @character) (variable_ref) @operator))
; Zmatrix coordinate highlighting - alternating pattern like internal coords
(zmat_line2
zmat_atom1: (integer) @operator)
(zmat_line2
(coord_value
(float) @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) @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) @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 script highlighting - use node types instead of regexes
(compound_script) @keyword
(compound_variable_declaration) @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_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_for_loop) @keyword
(compound_if_block) @keyword (compound_if_block) @keyword
;; For loop keywords and components ; For loop keywords and components
(compound_for_loop (variable_name) @function) (compound_for_loop
(variable_name) @function)
;; If/else condition components ; If/else condition components
(compound_condition) @conditional (compound_condition) @conditional
(compound_comparison) @operator (compound_comparison) @operator
;; Array access ; Array access
(compound_array_access (variable_name) @function) (compound_array_access
(compound_array_access "[" @punctuation.bracket) (variable_name) @function)
(compound_array_access "]" @punctuation.bracket)
;; Function calls (compound_array_access
(compound_function_call (variable_name) @function.call) "[" @punctuation.bracket)
(compound_function_call "(" @punctuation.bracket)
(compound_function_call ")" @punctuation.bracket)
;; Array assignments (compound_array_access
(compound_array_assignment (compound_array_access (variable_name) @function)) "]" @punctuation.bracket)
;; Variables in expressions - general pattern to catch all variable usage ; Function calls
(compound_primary_expr (variable_name) @function) (compound_function_call
(variable_name) @function.call)
;; Operators in expressions (compound_function_call
(compound_multiplicative_expr "*" @operator) "(" @punctuation.bracket)
(compound_multiplicative_expr "/" @operator)
(compound_additive_expr "+" @operator)
(compound_additive_expr "-" @operator)
;; Assignment operators (compound_function_call
(compound_assignment "=" @operator) ")" @punctuation.bracket)
(compound_array_assignment "=" @operator)
;; Parentheses in expressions and conditions ; Array assignments
(compound_primary_expr "(" @punctuation.bracket) (compound_array_assignment
(compound_primary_expr ")" @punctuation.bracket) (compound_array_access
(compound_if_block "(" @punctuation.bracket) (variable_name) @function))
(compound_if_block ")" @punctuation.bracket)
;; Semicolons ; Variables in expressions - general pattern to catch all variable usage
(compound_assignment ";" @punctuation.delimiter) (compound_primary_expr
(compound_array_assignment ";" @punctuation.delimiter) (variable_name) @function)
(compound_variable_declaration ";" @punctuation.delimiter)
(compound_function_call ";" @punctuation.delimiter)
; Operators in expressions
(compound_multiplicative_expr
"*" @operator)
(compound_multiplicative_expr
"/" @operator)
(compound_additive_expr
"+" @operator)
(compound_additive_expr
"-" @operator)
; Assignment operators
(compound_assignment
"=" @operator)
(compound_array_assignment
"=" @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)
; Semicolons
(compound_assignment
";" @punctuation.delimiter)
(compound_array_assignment
";" @punctuation.delimiter)
(compound_variable_declaration
";" @punctuation.delimiter)
(compound_function_call
";" @punctuation.delimiter)

View file

@ -1,6 +1,6 @@
[ [
(input_block) (input_block)
(subblock) (subblock)
(geom_block) (geom_block)
(compound_script) (compound_script)
(compound_step_block) (compound_step_block)
@ -10,7 +10,7 @@
[ [
(input_block) (input_block)
(subblock) (subblock)
(geom_block) (geom_block)
(compound_script) (compound_script)
(compound_step_block) (compound_step_block)
@ -18,4 +18,4 @@
(compound_if_block) (compound_if_block)
] @indent.end ] @indent.end
"*" @indent.end "*" @indent.end