feat: improve tree-sitter syntax highlighting with named nodes

- Add aliases for keywords (VAR_INPUT, BEGIN, IF, etc.) as named nodes
- Add aliases for built-in types (INT, BOOL, STRING, etc.) as type_builtin
- Add aliases for constants (TRUE, FALSE)
- Add aliases for operators (AND, OR, NOT, MOD)
- Add prefix node for # variable prefix highlighting
- Highlight FB instance names in calls
- Highlight FB parameter names as properties
- Update README with detailed syntax highlighting features
- Update .gitignore for *.wasm files
This commit is contained in:
2026-02-20 23:29:26 +01:00
parent 2cd59f572f
commit 69f5c7b215
6 changed files with 294 additions and 232 deletions
+56 -191
View File
@@ -1,211 +1,76 @@
; Comprehensive SCL highlight queries for Neovim
; SCL highlights
; ============================================
; Comments
; ============================================
(line_comment) @comment
(block_comment) @comment
(c_style_comment) @comment
; ============================================
; Literals
; ============================================
(number) @number
(hex_number) @number
(string) @string
(time_value) @number
; ============================================
; Constants
; ============================================
(
(identifier) @constant.builtin
(#match? @constant.builtin "^(TRUE|FALSE|TRUE#|FALSE#)$")
)
(
(type) @type.builtin
(#match? @type.builtin "^(TRUE|FALSE)$")
)
(prefix) @punctuation.special
; ============================================
; Identifiers
; ============================================
(identifier) @variable
(prefixed_identifier) @variable
; ============================================
; Types - Basic
; ============================================
(
(type) @type.builtin
(#match? @type.builtin "^(BOOL|Bool|INT|Int|DINT|DInt|SINT|SInt|USINT|USInt|UINT|UInt|WORD|Word|DWORD|DWord|BYTE|Byte|REAL|Real|LREAL|LReal|TIME|Time|TOD|Tod|DT|Dt|String|STRING|CHAR|Char|WSTRING|WString)$")
)
; FB instance calls - highlight instance name as type
(fb_call
instance: (prefixed_identifier
(identifier) @type))
(fb_call
instance: (identifier) @type)
; Types - User defined (quoted strings like "UDT_Type")
(type
(string) @type
)
; ============================================
; Keywords - Block definitions
; ============================================
"ORGANIZATION_BLOCK" @keyword
"FUNCTION_BLOCK" @keyword
"FUNCTION" @keyword
"END_ORGANIZATION_BLOCK" @keyword
"END_FUNCTION_BLOCK" @keyword
"END_FUNCTION" @keyword
"BEGIN" @keyword
; ============================================
; Keywords - Variable sections
; ============================================
"VAR_INPUT" @keyword
"VAR_OUTPUT" @keyword
"VAR_IN_OUT" @keyword
"VAR" @keyword
"VAR_TEMP" @keyword
"VAR_CONSTANT" @keyword
"END_VAR" @keyword
"CONSTANT" @keyword
"RETAIN" @keyword
"NON_RETAIN" @keyword
; ============================================
; Keywords - Control flow
; ============================================
"IF" @conditional
"THEN" @conditional
"ELSIF" @conditional
"ELSE" @conditional
"END_IF" @conditional
"CASE" @conditional
"OF" @conditional
"END_CASE" @conditional
; ============================================
; Keywords - Loops
; ============================================
"FOR" @repeat
"TO" @repeat
"BY" @repeat
"DO" @repeat
"END_FOR" @repeat
"WHILE" @repeat
"END_WHILE" @repeat
"REPEAT" @repeat
"UNTIL" @repeat
"END_REPEAT" @repeat
"EXIT" @keyword
"CONTINUE" @keyword
; ============================================
; Keywords - Regions
; ============================================
"REGION" @namespace
"END_REGION" @namespace
; ============================================
; Keywords - Other
; ============================================
"TITLE" @keyword
"VERSION" @keyword
"ARRAY" @keyword
"OF" @keyword
; ============================================
; Fields
; ============================================
(block
name: (string) @namespace)
(block
name: (identifier) @namespace)
(var_item
; FB parameter names (IN :=, PT :=, etc.)
(fb_parameter
name: (identifier) @property)
; Function call names
(function_call
(identifier) @function)
; Variable declarations
(var_item
type: (type) @type)
name: (identifier) @variable)
; ============================================
; Functions and function calls
; ============================================
(function_call
(identifier) @function.call)
; Type references in declarations
(type
(identifier) @type)
(function_call
(string) @function.call)
(type_builtin) @type.builtin
(parameter
(identifier) @parameter)
(keyword) @keyword
(constant) @constant.builtin
(operator) @operator
; ============================================
; Array access
; ============================================
(array_access
"[" @punctuation.bracket
"]" @punctuation.bracket)
(assignment) @operator
(binary_expression) @operator
(unary_expression) @operator
; ============================================
; Field access
; ============================================
(field_access
"." @punctuation.delimiter)
; ============================================
; Attribute lists
; ============================================
(attribute_list
"{" @punctuation.bracket
"}" @punctuation.bracket)
(attribute_list
"," @punctuation.delimiter)
(attribute_list
";" @punctuation.delimiter)
(attribute
"."
(identifier) @property)
; ============================================
; Operators - Logical
; ============================================
"AND" @operator
"OR" @operator
"XOR" @operator
"NOT" @operator
(array_access) @property
; ============================================
; Operators - Comparison
; ============================================
"=" @operator
"<>" @operator
"<" @operator
">" @operator
"<=" @operator
">=" @operator
(attribute_list) @attribute
(attribute) @attribute
(attribute_value) @string
; ============================================
; Operators - Arithmetic
; ============================================
"+" @operator
"-" @operator
"*" @operator
"/" @operator
"MOD" @operator
"**" @operator
(var_item) @property
; ============================================
; Operators - Assignment
; ============================================
":=" @operator
"=>" @operator
(function_call) @function.call
(fb_call) @function.call
(if_statement) @conditional
(elsif_clause) @conditional
(else_clause) @conditional
(case_statement) @conditional
(case_item) @conditional
(for_statement) @repeat
(while_statement) @repeat
(repeat_statement) @repeat
; ============================================
; Punctuation
; ============================================
";" @punctuation.delimiter
":" @punctuation.delimiter
"," @punctuation.delimiter
@@ -214,17 +79,17 @@
"[" @punctuation.bracket
"]" @punctuation.bracket
"." @punctuation.delimiter
".." @punctuation.delimiter
"#" @punctuation.special
; ============================================
; Binary and unary expressions
; ============================================
(binary_expression) @operator
(unary_expression) @operator
":=" @operator
"=>" @operator
"=" @operator
"<>" @operator
"<" @operator
">" @operator
"<=" @operator
">=" @operator
; ============================================
; Range expressions
; ============================================
(range
".." @punctuation.delimiter)
"+" @operator
"-" @operator
"*" @operator
"/" @operator