Fix HDL and Hack Assembly syntax highlighting and queries

- Fixed HDL highlights query syntax error with #match? predicate
- Replaced #match? with #any-of? for exact string matching
- Fixed Hack Assembly outline query invalid field name
- Improved HDL syntax highlighting with comprehensive patterns
- Added HDL bracket matching for all syntax types
- Fixed XML scope mismatch from text.xml to source.xml
- Enhanced outline queries for better code navigation
This commit is contained in:
2025-09-11 11:24:24 -04:00
commit c231dbfd27
133 changed files with 2792 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
; Compare/Output file bracket matching
; No brackets are used in compare/output file syntax
; These files contain simple tabular data with pipe separators
; No nested structures or bracket pairs to match

View File

@@ -0,0 +1,6 @@
name = "Compare Output"
grammar = "compare_output"
scope = "source.compare_output"
path_suffixes = ["cmp", "out"]
tab_size = 2
hard_tabs = false

View File

@@ -0,0 +1,40 @@
; Compare/Output file syntax highlighting queries based on actual node types
; Header row elements
(header_row) @markup.heading
; Column names in headers
(column_name) @property
; Register names in headers (RAM[0], RAM[256], etc.)
(register_name) @variable.builtin
; Pin names in headers
(pin_name) @property
; Generic names in headers
(generic_name) @property
; Data values
(binary_value) @constant.numeric
(decimal_value) @constant.numeric
(register_reference) @variable
; Table structure
"|" @punctuation.delimiter
; Separator rows
(separator_row) @comment
; Specific highlighting for common patterns
; Binary patterns (16-bit values)
(binary_value) @constant.numeric
; Decimal numbers
(decimal_value) @constant.numeric
; RAM references in headers
(register_name) @variable.builtin
; Common pin names
(pin_name) @property

View File

@@ -0,0 +1,9 @@
; Compare/Output file indentation rules
; No special indentation rules needed for compare/output files
; These files contain simple tabular data with consistent formatting
; All rows should be at the same indentation level
; Table rows should align consistently
; The pipe characters (|) provide natural alignment guides
; No nested structures require indentation changes

View File

@@ -0,0 +1,13 @@
; Compare/Output file outline queries
; Show header rows in the outline for navigation
(header_row
(header_cell (column_name) @name)) @item
(#set! item.kind "table")
; Show table structure - group data rows by sections
(table_row) @item
(#set! item.kind "row")
; No other special outline patterns needed for simple tabular data
; The header row provides the main navigation structure

View File

@@ -0,0 +1,6 @@
; Hack Assembly bracket matching
; Label declarations use parentheses
(label_declaration
"(" @open
")" @close) @container

View File

@@ -0,0 +1,7 @@
name = "Hack Assembly"
grammar = "hack_assembly"
scope = "source.hack_assembly"
path_suffixes = ["asm"]
line_comments = ["// "]
tab_size = 4
hard_tabs = false

View File

@@ -0,0 +1,103 @@
; Hack Assembly syntax highlighting queries based on actual node types
; A-instruction marker
"@" @punctuation.special
; A-instruction components
(a_instruction
(constant) @constant.numeric)
(a_instruction
(symbol
(predefined_symbol) @constant.builtin))
(a_instruction
(symbol
(user_symbol) @variable))
; C-instruction components
(dest) @type
(comp) @operator
(jump) @keyword.control
; Assignment and jump operators
"=" @operator
";" @punctuation.delimiter
; Label declarations
(label_declaration
"(" @punctuation.bracket
(symbol) @label
")" @punctuation.bracket)
; Comments
(comment) @comment
; Predefined symbols
"SP" @constant.builtin
"LCL" @constant.builtin
"ARG" @constant.builtin
"THIS" @constant.builtin
"THAT" @constant.builtin
"SCREEN" @constant.builtin
"KBD" @constant.builtin
; Virtual registers R0-R15 (handled by predefined_symbol pattern)
(predefined_symbol) @constant.builtin
; User-defined symbols
(user_symbol) @variable
; Constants
(constant) @constant.numeric
; Computation operations
"0" @constant.numeric
"1" @constant.numeric
"-1" @constant.numeric
; Register references
"D" @variable.builtin
"A" @variable.builtin
"M" @variable.builtin
; Arithmetic operations
"D+1" @operator
"A+1" @operator
"M+1" @operator
"D-1" @operator
"A-1" @operator
"M-1" @operator
"D+A" @operator
"D-A" @operator
"A-D" @operator
"D+M" @operator
"D-M" @operator
"M-D" @operator
; Logical operations
"!D" @operator
"!A" @operator
"!M" @operator
"-D" @operator
"-A" @operator
"-M" @operator
"D&A" @operator
"D|A" @operator
"D&M" @operator
"D|M" @operator
; Destination combinations
"MD" @type
"AM" @type
"AD" @type
"AMD" @type
; Jump conditions
"JGT" @keyword.control
"JEQ" @keyword.control
"JGE" @keyword.control
"JLT" @keyword.control
"JNE" @keyword.control
"JLE" @keyword.control
"JMP" @keyword.control

View File

@@ -0,0 +1,8 @@
; Hack Assembly indentation rules
; No special indentation rules needed for Hack Assembly
; since it's a flat assembly language with no nested structures
; All instructions should be at the same indentation level
; Labels can optionally be outdented or at the same level
; but we'll keep them at the same level for simplicity

View File

@@ -0,0 +1,21 @@
; Hack Assembly outline queries
; Show label declarations in the outline
(label_declaration
(symbol) @name) @item
; Show A-instructions with symbols as outline items
(a_instruction
(symbol) @name) @item
; Show A-instructions with constants as outline items
(a_instruction
(constant) @name) @item
; Show C-instructions with jumps as outline items (control flow)
(c_instruction
(jump) @name) @item
; Show comments that look like section headers
(comment) @item
(#match? @item "^//\\s*[A-Z].*|^//.*[Ss]ection|^//.*[Pp]art|^//.*[Ff]unction|^//.*[Ll]oop|^//.*[Ee]nd")

View File

@@ -0,0 +1,6 @@
; Bracket matching for Hack Binary
; No special brackets needed for binary files

View File

@@ -0,0 +1,11 @@
name = "Hack Binary"
grammar = "hack_binary"
scope = "source.hack_binary"
path_suffixes = ["hackbin"]
line_comments = ["// "]
tab_size = 4
hard_tabs = false

View File

@@ -0,0 +1,14 @@
; Hack Binary syntax highlighting queries
; 16-bit binary instructions
(bit_sequence) @constant.numeric
; Comments
(comment) @comment
; Binary digits highlighting
(bit_sequence) @constant.numeric

View File

@@ -0,0 +1,4 @@
; Hack Binary indentation rules
; Binary files typically don't need special indentation

View File

@@ -0,0 +1,4 @@
; Hack Binary outline rules
; Binary instructions don't have hierarchical structure

View File

@@ -0,0 +1,28 @@
; HDL bracket matching
; Parentheses for part instantiations and connections
"(" @open
")" @close
; Square brackets for bus identifiers
"[" @open
"]" @close
; Curly braces for chip definitions
"{" @open
"}" @close
; Part instantiation containers
(part
"(" @open
")" @close) @container
; Bus identifier containers
(bus_identifier
"[" @open
"]" @close) @container
; Chip definition container
(chip_definition
"{" @open
"}" @close) @container

View File

@@ -0,0 +1,7 @@
name = "HDL"
grammar = "hdl"
scope = "source.hdl"
path_suffixes = ["hdl"]
line_comments = ["// "]
tab_size = 4
hard_tabs = false

View File

@@ -0,0 +1,88 @@
; Enhanced HDL syntax highlighting based on actual usage patterns
; Main keywords
"CHIP" @keyword
"IN" @keyword
"OUT" @keyword
"PARTS" @keyword
"BUILTIN" @keyword
"CLOCKED" @keyword
; Section headers
(in_section) @keyword
(out_section) @keyword
(parts_body) @keyword
; Chip definition
(chip_definition
name: (identifier) @type) @type
; Pin definitions with proper field highlighting
(in_section
input_pin_name: (identifier) @variable.parameter) @variable.parameter
(out_section
output_pin_name: (identifier) @variable.parameter) @variable.parameter
; Bus identifiers (arrays)
(bus_identifier
(identifier) @variable
"[" @punctuation.bracket
(number) @constant.numeric
"]" @punctuation.bracket) @variable
; Part instantiations
(part
chip_name: (identifier) @function) @function
; Connections
(connection
part_pin: (identifier) @variable.parameter
"=" @operator
chip_pin: (identifier) @variable) @variable
; Built-in chip references
(builtin_body
chip_name: (identifier) @function.builtin) @function.builtin
; Clocked body
(clocked_body
(identifier) @variable) @variable
; Comments (both single-line and multi-line)
(comment) @comment
; Numbers
(number) @constant.numeric
; Identifiers (general)
(identifier) @variable
; Punctuation
"," @punctuation.delimiter
";" @punctuation.delimiter
":" @punctuation.delimiter
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
"=" @operator
; Special highlighting for common HDL patterns
; Bit width specifications (simplified - no regex matching)
(bus_identifier
(identifier) @type)
; Common built-in chips (simplified - no regex matching)
(identifier) @function.builtin
(#any-of? @function.builtin "Nand" "Not" "And" "Or" "Xor" "Mux" "DMux" "Not16" "And16" "Or16" "Xor16" "Mux16" "DMux16" "Mux4Way16" "Mux8Way16" "DMux4Way" "DMux8Way" "Or8Way" "HalfAdder" "FullAdder" "Add16" "Inc16" "ALU" "Bit" "Register" "PC" "RAM8" "RAM64" "RAM512" "RAM4K" "RAM16K" "ROM32K" "Screen" "Keyboard" "DFF" "ARegister" "DRegister")
; Common control signals (simplified - no regex matching)
(identifier) @variable.builtin
(#any-of? @variable.builtin "load" "sel" "in" "out" "reset" "inc" "true" "false" "a" "b" "c" "d" "e" "f" "g" "h" "x" "y" "zx" "nx" "zy" "ny" "f" "no" "zr" "ng" "pos" "neg" "zero" "one" "minus_one")
; Memory address patterns (simplified - no regex matching)
(identifier) @variable.parameter
(#any-of? @variable.parameter "address" "load" "write" "read" "data" "value" "input" "output" "control" "enable" "disable" "clock" "reset" "clear" "set" "toggle")

10
languages/hdl/indents.scm Normal file
View File

@@ -0,0 +1,10 @@
; HDL indentation rules
; Indent inside chip definition body
(chip_body) @indent
; Indent inside chip definition
(chip_definition) @indent
; Indent inside part connections
(part) @indent

29
languages/hdl/outline.scm Normal file
View File

@@ -0,0 +1,29 @@
; HDL outline queries for code structure
; Chip declarations as main outline items
(chip_definition
name: (identifier) @name) @item
; Input pins in IN section (grouped under chip)
(in_section
input_pin_name: (identifier) @name) @item
; Output pins in OUT section (grouped under chip)
(out_section
output_pin_name: (identifier) @name) @item
; Built-in chip references
(builtin_body
chip_name: (identifier) @name) @item
; Clocked body references
(clocked_body
(identifier) @name) @item
; Part instantiations within PARTS section
(part
chip_name: (identifier) @name) @item
; Connections within parts (for detailed view)
(connection
part_pin: (identifier) @name) @item

View File

@@ -0,0 +1,3 @@
; Bracket matching for Jack
("{" @open "}" @close)
("(" @open ")" @close)

View File

@@ -0,0 +1,8 @@
name = "Jack"
grammar = "jack"
scope = "source.jack"
path_suffixes = ["jack"]
line_comments = ["// "]
block_comments = [["/*", "*/"]]
tab_size = 4
hard_tabs = false

View File

@@ -0,0 +1,101 @@
; Jack syntax highlighting queries for tree-sitter
; Keywords as string terminals
"class" @keyword
"static" @keyword
"function" @keyword
"constructor" @keyword
"method" @keyword
"field" @keyword
"var" @keyword
"let" @keyword
"do" @keyword
"if" @keyword
"else" @keyword
"while" @keyword
"return" @keyword
; Operators and punctuation
"=" @operator
"+" @operator
"-" @operator
"*" @operator
"/" @operator
"&" @operator
"|" @operator
"<" @operator
">" @operator
"~" @operator
";" @punctuation.delimiter
"," @punctuation.delimiter
"." @punctuation.delimiter
"{" @punctuation.bracket
"}" @punctuation.bracket
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
; Special alias nodes (these are created by the grammar)
(this) @variable.builtin
(true) @boolean
(false) @boolean
(null) @constant.builtin
; Class declarations
(class_declaration
name: (identifier) @type)
; Class name references
(class_name) @type
; Subroutine declarations
(subroutine_declaration
name: (identifier) @function)
; Parameters
(parameter
(identifier) @variable.parameter)
; Variable declarations
(class_variable_declaration
(identifier) @property)
(local_variable_declaration
(identifier) @variable)
; Function calls
(call_expression
function: (identifier) @function)
(call_expression
function: (member_expression
property: (identifier) @function))
; Member access
(member_expression
object: (identifier) @variable
property: (identifier) @property)
; Subscript access
(subscript_expression
object: (identifier) @variable)
; Let statement variable
(let_statement
(identifier) @variable)
(let_statement
(subscript_expression
object: (identifier) @variable))
; General identifiers
(identifier) @variable
; Literals
(integer) @number
(string) @string
; Comments
(comment) @comment
(doc_comment) @comment.doc

View File

@@ -0,0 +1,16 @@
; Jack indentation rules
; Indent inside class body
(class_body) @indent
; Indent inside subroutine body
(subroutine_body) @indent
; Indent inside statement blocks
(statement_block) @indent
; Indent inside formal parameters
(formal_parameters) @indent
; Indent inside arguments
(arguments) @indent

View File

@@ -0,0 +1,26 @@
; Jack outline queries for code structure
; Class declarations as main outline items
(class_declaration
name: (identifier) @name) @item
; Subroutine declarations
(subroutine_declaration
kind: "constructor"
name: (identifier) @name) @item
(subroutine_declaration
kind: "function"
name: (identifier) @name) @item
(subroutine_declaration
kind: "method"
name: (identifier) @name) @item
; Class variable declarations (field and static)
(class_variable_declaration
(identifier) @name) @item
; Local variable declarations
(local_variable_declaration
(identifier) @name) @item

View File

@@ -0,0 +1,15 @@
; Test script bracket matching
; Repeat blocks use curly braces
(repeat_command
"{" @open
"}" @close) @container
; While blocks use curly braces
(while_command
"{" @open
"}" @close) @container
; Square brackets for array references
"[" @open
"]" @close

View File

@@ -0,0 +1,7 @@
name = "Test Script"
grammar = "test_script"
scope = "source.test_script"
path_suffixes = ["tst"]
line_comments = ["// "]
tab_size = 2
hard_tabs = false

View File

@@ -0,0 +1,66 @@
; Test script syntax highlighting queries based on actual node types
; Commands
"load" @keyword
"output-file" @keyword
"compare-to" @keyword
"output-list" @keyword
"set" @keyword
"eval" @keyword
"output" @keyword
"tick" @keyword
"tock" @keyword
"ticktock" @keyword
"repeat" @keyword
"while" @keyword
"echo" @keyword
; Control flow keywords
"repeat" @keyword.control
"while" @keyword.control
; File operations
(load_command "load" @keyword)
(output_file_command "output-file" @keyword)
(compare_to_command "compare-to" @keyword)
; Variable references
(memory_reference "RAM" @type.builtin)
(register_reference) @variable.builtin
; Pin references
(pin_reference) @property
; Numbers and indices
(number) @constant.numeric
; Binary values
(binary_value) @constant.numeric
; Format specifications
(format_spec) @string.special
; Filenames
(filename) @string
; Strings
(string) @string
; Comments
(comment) @comment
; Punctuation
"," @punctuation.delimiter
";" @punctuation.delimiter
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
; Special memory references
"DRegister[]" @variable.builtin
"ARegister[]" @variable.builtin
"PC[]" @variable.builtin
; Conditions in while loops
(condition) @string.special

View File

@@ -0,0 +1,15 @@
; Test script indentation rules
; Indent content inside repeat blocks
(repeat_command
"{" @indent) @container
; Indent content inside while blocks
(while_command
"{" @indent) @container
; Dedent closing braces
"}" @dedent
; No other special indentation rules needed
; Most test script commands are at the same level

View File

@@ -0,0 +1,26 @@
; Test script outline queries
; Show repeat blocks in the outline
(repeat_command
(number) @name) @item
(#set! item.kind "loop")
; Show while blocks in the outline
(while_command
(condition) @name) @item
(#set! item.kind "loop")
; Show load commands for file references
(load_command
(filename) @name) @item
(#set! item.kind "file")
; Show set commands with variable assignments
(set_command
(variable_reference) @name) @item
(#set! item.kind "variable")
; Show comments that look like section headers
(comment) @item
(#match? @item "^//\\s*[A-Z].*|^//.*[Ss]ection|^//.*[Tt]est|^//.*[Pp]hase")
(#set! item.kind "comment")

View File

@@ -0,0 +1,5 @@
; VM language bracket matching
; No brackets are used in VM language syntax
; VM language is line-based with simple command structure
; No nested structures or bracket pairs to match

7
languages/vm/config.toml Normal file
View File

@@ -0,0 +1,7 @@
name = "VM"
grammar = "vm"
scope = "source.vm"
path_suffixes = ["vm"]
line_comments = ["// "]
tab_size = 4
hard_tabs = false

View File

@@ -0,0 +1,54 @@
; VM language syntax highlighting queries based on actual node types
; Arithmetic and logical commands
(arithmetic_command) @keyword
; Memory access commands
"push" @keyword
"pop" @keyword
; Memory segments
(memory_segment) @type
; Program flow commands
"label" @keyword.control
"goto" @keyword.control
"if-goto" @keyword.control
; Function commands
"function" @keyword.function
"call" @keyword.function
(return_command) @keyword.function
; Numbers (indices, counts)
(index) @constant.numeric
(local_vars_count) @constant.numeric
(args_count) @constant.numeric
; Identifiers
(label_name) @label
(function_name) @function
; Comments
(comment) @comment
; Specific memory segments highlighting
"argument" @type.builtin
"local" @type.builtin
"static" @type.builtin
"constant" @type.builtin
"this" @type.builtin
"that" @type.builtin
"pointer" @type.builtin
"temp" @type.builtin
; Arithmetic operations
"add" @operator
"sub" @operator
"neg" @operator
"eq" @operator
"gt" @operator
"lt" @operator
"and" @operator
"or" @operator
"not" @operator

14
languages/vm/indents.scm Normal file
View File

@@ -0,0 +1,14 @@
; VM language indentation rules
; No special indentation rules needed for VM language
; since it's a flat, line-based language with simple command structure
; All commands should be at the same indentation level
; Optional: indent commands inside function bodies for readability
; but this is not required by the VM specification
; Function declarations can be at base level
; with their contents optionally indented
(function_declaration) @indent
; No other special indentation patterns needed

17
languages/vm/outline.scm Normal file
View File

@@ -0,0 +1,17 @@
; VM language outline queries
; Show function declarations in the outline
(function_declaration
(function_name) @name) @item
; Show label declarations for program flow
(label_command
(label_name) @name) @item
; Show function calls as outline items for navigation
(call_command
(function_name) @name) @item
; Show comments that look like section headers
(comment) @item
(#match? @item "^//\\s*[A-Z].*|^//.*[Ss]ection|^//.*[Pp]art|^//.*[Ff]unction|^//.*[Cc]lass")

View File

@@ -0,0 +1,9 @@
; Bracket matching for XML
("<" @open ">" @close)
("</" @open ">" @close)

View File

@@ -0,0 +1,8 @@
name = "XML"
grammar = "xml"
scope = "source.xml"
path_suffixes = ["xml"]
tab_size = 2
hard_tabs = false

View File

@@ -0,0 +1,14 @@
; XML syntax highlighting queries
; Tags
(tag_name) @tag
(attribute_name) @property
(attribute_value) @string
; Text content
(text) @text
; Comments
(comment) @comment

View File

@@ -0,0 +1,8 @@
; XML indentation rules
(element) @indent

View File

@@ -0,0 +1,9 @@
; XML outline queries
(element
(tag_name) @name) @item