mirror of
https://github.com/soconnor0919/nand2tetris-zed.git
synced 2025-12-15 08:34:44 -05:00
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:
6
languages/hack-assembly/brackets.scm
Normal file
6
languages/hack-assembly/brackets.scm
Normal file
@@ -0,0 +1,6 @@
|
||||
; Hack Assembly bracket matching
|
||||
|
||||
; Label declarations use parentheses
|
||||
(label_declaration
|
||||
"(" @open
|
||||
")" @close) @container
|
||||
7
languages/hack-assembly/config.toml
Normal file
7
languages/hack-assembly/config.toml
Normal 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
|
||||
103
languages/hack-assembly/highlights.scm
Normal file
103
languages/hack-assembly/highlights.scm
Normal 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
|
||||
8
languages/hack-assembly/indents.scm
Normal file
8
languages/hack-assembly/indents.scm
Normal 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
|
||||
21
languages/hack-assembly/outline.scm
Normal file
21
languages/hack-assembly/outline.scm
Normal 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")
|
||||
Reference in New Issue
Block a user