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,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