Initial commit: Tree-sitter grammar for Hack Binary language

This commit is contained in:
2025-09-10 23:50:42 -04:00
commit d408c50827
9 changed files with 1153 additions and 0 deletions

30
grammar.js Normal file
View File

@@ -0,0 +1,30 @@
module.exports = grammar({
name: 'hack_binary',
rules: {
source_file: $ => repeat($._item),
_item: $ => choice(
$.binary_instruction,
$.comment,
$._whitespace
),
// 16-bit binary instruction
binary_instruction: $ => $.bit_sequence,
// 16-bit sequence of 0s and 1s
bit_sequence: $ => /[01]{16}/,
// Comments
comment: $ => token(seq('//', /.*/)),
// Whitespace
_whitespace: $ => /\s+/
},
extras: $ => [
/\s/,
$.comment
]
});