Skip to content

Commit

Permalink
Support macro qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
grahambates committed Jun 26, 2024
1 parent d097b12 commit 7fe45a6
Show file tree
Hide file tree
Showing 7 changed files with 83,741 additions and 83,406 deletions.
4 changes: 2 additions & 2 deletions corpus/macro_args.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ Macro symbols in mnemonic
(source_file
(macro_call
(macro_arg)
(size)
(symbol)
(operand_list
(data_register)
(data_register)))
(macro_call
(interpolated
(macro_arg))
(size)
(symbol)
(operand_list
(data_register)
(data_register)))
Expand Down
21 changes: 21 additions & 0 deletions corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ Macro calls
============================================
MyMacro
MyMacro d0,d1
MyMacro.b d0,d1
MyMacro."1" d0,d1
MyMacro.\1 d0,d1
%getdate 3
foo: MyMacro d0,d1
bar: MyMacro
Expand All @@ -137,6 +140,24 @@ woo: MyMacro ; example
(operand_list
(data_register)
(data_register)))
(macro_call
(symbol)
(symbol)
(operand_list
(data_register)
(data_register)))
(macro_call
(symbol)
(string_literal)
(operand_list
(data_register)
(data_register)))
(macro_call
(symbol)
(macro_arg)
(operand_list
(data_register)
(data_register)))
(macro_call
(symbol)
(operand_list
Expand Down
11 changes: 9 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,8 @@ module.exports = grammar({
macro_call: ($) =>
prec.right(
seq(
$._name,
optional(seq(".", field("qualifier", $._size))),
field("name", $._identifier_nodot),
optional(seq(".", field("qualifier", $._expression))),
optional(seq($._ws, field("operands", $.operand_list))),
optional($._ws)
)
Expand Down Expand Up @@ -1400,6 +1400,9 @@ module.exports = grammar({
_identifier: ($) =>
choice($.symbol, $.interpolated, $.macro_arg, $._builtin),

_identifier_nodot: ($) =>
choice(alias($.symbol_no_dot, $.symbol), $.interpolated, $.macro_arg, $._builtin),

macro_arg: () =>
choice(
/\\[0-9]/,
Expand Down Expand Up @@ -1438,6 +1441,10 @@ module.exports = grammar({
pc: () => "*",

symbol_list: ($) => listSep($.symbol, $._sep),
symbol_no_dot: ($) =>
prec.right(
seq(optional("."), $._symbol_chars, optional("$"))
),
symbol: ($) =>
prec.right(
seq(repeat1(seq(optional("."), $._symbol_chars)), optional("$"))
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 70 additions & 3 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4120,8 +4120,12 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_name"
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_identifier_nodot"
}
},
{
"type": "CHOICE",
Expand All @@ -4138,7 +4142,7 @@
"name": "qualifier",
"content": {
"type": "SYMBOL",
"name": "_size"
"name": "_expression"
}
}
]
Expand Down Expand Up @@ -6658,6 +6662,32 @@
}
]
},
"_identifier_nodot": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "symbol_no_dot"
},
"named": true,
"value": "symbol"
},
{
"type": "SYMBOL",
"name": "interpolated"
},
{
"type": "SYMBOL",
"name": "macro_arg"
},
{
"type": "SYMBOL",
"name": "_builtin"
}
]
},
"macro_arg": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -6882,6 +6912,43 @@
}
]
},
"symbol_no_dot": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "."
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_symbol_chars"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "BLANK"
}
]
}
]
}
},
"symbol": {
"type": "PREC_RIGHT",
"value": 0,
Expand Down
54 changes: 53 additions & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1844,12 +1844,64 @@
"multiple": false,
"required": false,
"types": [
{
"type": "binary_expression",
"named": true
},
{
"type": "binary_literal",
"named": true
},
{
"type": "carg",
"named": true
},
{
"type": "decimal_literal",
"named": true
},
{
"type": "hexadecimal_literal",
"named": true
},
{
"type": "interpolated",
"named": true
},
{
"type": "macro_arg",
"named": true
},
{
"type": "size",
"type": "narg",
"named": true
},
{
"type": "octal_literal",
"named": true
},
{
"type": "parenthesized_expression",
"named": true
},
{
"type": "pc",
"named": true
},
{
"type": "reptn",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "symbol",
"named": true
},
{
"type": "unary_expression",
"named": true
}
]
Expand Down
Loading

0 comments on commit 7fe45a6

Please sign in to comment.