Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = grammar(

externals: $ => [
$.code_identifier,
$.raw_data,
$._whitespace_no_newline,
$._error_sentinel,
],
Expand All @@ -44,6 +45,7 @@ module.exports = grammar(
$.label_line,
$.memory_offset,
$.source_location,
'...',
),

header: $ => seq($.file_path, ":", "file", "format", $.identifier),
Expand Down Expand Up @@ -71,6 +73,7 @@ module.exports = grammar(
$.machine_code_bytes,
choice(
$._whitespace_no_newline,
$.raw_data,
seq(
/\s*/,
choice(
Expand All @@ -94,18 +97,28 @@ module.exports = grammar(
optional($.file_offset),
)
),
instruction: $ => /[^\n#<]+/,
bad_instruction: $ => "(bad)",
instruction: _ => /([^\n#;<]|#-?\d+)+/,
bad_instruction: _ => "(bad)",

comment: $ => seq(
"#",
choice("#", ';'),
choice(
$._comment_with_address,
$._comment_with_label,
),
),

_comment_with_label: $ => seq($.address, $.code_location, optional($.file_offset)),
_comment_with_label: $ => choice(
seq(
'(',
optional(seq(alias(/[^\d,][^,]+/, $.instruction), ',')),
$.address,
$.code_location,
optional($.file_offset),
')'
),
seq($.address, $.code_location, optional($.file_offset)),
),
_comment_with_address: $ => $.hexadecimal,

code_location: $ => seq(
Expand All @@ -117,11 +130,11 @@ module.exports = grammar(

label_line: $ => seq(alias($._label_identifier, $.label), ":"),

hexadecimal: $ => /0[xh][0-9a-fA-F]+/,
byte: $ => /[0-9a-fA-F]{2}/,
hexadecimal: _ => /0[xh][0-9a-fA-F]+/,
byte: _ => /[0-9a-fA-F]{2}|[0-9a-fA-F]{4}|[0-9a-fA-F]{8}/,
machine_code_bytes: $ => space_separated1($.byte),

address: $ => /[0-9a-fA-F]+/,
address: _ => /[0-9a-fA-F]+/,

file_offset: $ => seq("(", "File", "Offset:", $.hexadecimal, ")"),

Expand All @@ -131,15 +144,15 @@ module.exports = grammar(
":",
),

integer: $ => /\d+/,
integer: _ => /\d+/,

// TODO: Support windows paths, later. Also make sure Linux paths work
file_path: $ => /[\/\w\-\.\+]+/,
file_path: _ => /[\/\w\-\.\+]+/,

_label_identifier: $ => /[A-Za-z.@_][A-Za-z0-9.@_$-\(\)]*/, // Test this, later
identifier: $ => /[^\n]+/,
_label_identifier: _ => /[A-Za-z.@_][A-Za-z0-9.@_$-\(\)]*/, // Test this, later
identifier: _ => /[^\n]+/,

_section_name: $ => /[^:]+/,
_section_name: _ => /[^:]+/,
}
}
)
Expand Down
113 changes: 99 additions & 14 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
{
"type": "SYMBOL",
"name": "source_location"
},
{
"type": "STRING",
"value": "..."
}
]
},
Expand Down Expand Up @@ -193,6 +197,10 @@
"type": "SYMBOL",
"name": "_whitespace_no_newline"
},
{
"type": "SYMBOL",
"name": "raw_data"
},
{
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -275,7 +283,7 @@
},
"instruction": {
"type": "PATTERN",
"value": "[^\\n#<]+"
"value": "([^\\n#;<]|#-?\\d+)+"
},
"bad_instruction": {
"type": "STRING",
Expand All @@ -285,8 +293,17 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "#"
},
{
"type": "STRING",
"value": ";"
}
]
},
{
"type": "CHOICE",
Expand All @@ -304,25 +321,89 @@
]
},
"_comment_with_label": {
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "address"
},
{
"type": "SYMBOL",
"name": "code_location"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\\d,][^,]+"
},
"named": true,
"value": "instruction"
},
{
"type": "STRING",
"value": ","
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "address"
},
{
"type": "SYMBOL",
"name": "code_location"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_offset"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "file_offset"
"name": "address"
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "code_location"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_offset"
},
{
"type": "BLANK"
}
]
}
]
}
Expand Down Expand Up @@ -399,7 +480,7 @@
},
"byte": {
"type": "PATTERN",
"value": "[0-9a-fA-F]{2}"
"value": "[0-9a-fA-F]{2}|[0-9a-fA-F]{4}|[0-9a-fA-F]{8}"
},
"machine_code_bytes": {
"type": "SEQ",
Expand Down Expand Up @@ -515,6 +596,10 @@
"type": "SYMBOL",
"name": "code_identifier"
},
{
"type": "SYMBOL",
"name": "raw_data"
},
{
"type": "SYMBOL",
"name": "_whitespace_no_newline"
Expand Down
24 changes: 24 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
{
"type": "hexadecimal",
"named": true
},
{
"type": "instruction",
"named": true
}
]
}
Expand Down Expand Up @@ -209,6 +213,10 @@
{
"type": "machine_code_bytes",
"named": true
},
{
"type": "raw_data",
"named": true
}
]
}
Expand Down Expand Up @@ -291,10 +299,22 @@
"type": "+",
"named": false
},
{
"type": ",",
"named": false
},
{
"type": "...",
"named": false
},
{
"type": ":",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "<",
"named": false
Expand Down Expand Up @@ -363,6 +383,10 @@
"type": "label",
"named": true
},
{
"type": "raw_data",
"named": true
},
{
"type": "section_address",
"named": true
Expand Down
Loading