Files
tree-sitter-hack-binary/grammar.js

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
]
});