mirror of
https://github.com/soconnor0919/tree-sitter-hack-binary.git
synced 2026-02-04 23:56:33 -05:00
Initial commit: Tree-sitter grammar for Hack Binary language
This commit is contained in:
30
grammar.js
Normal file
30
grammar.js
Normal 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
|
||||
]
|
||||
});
|
||||
Reference in New Issue
Block a user