mirror of
https://github.com/soconnor0919/tree-sitter-hack-binary.git
synced 2026-02-04 23:56:33 -05:00
31 lines
510 B
JavaScript
31 lines
510 B
JavaScript
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
|
|
]
|
|
});
|