Skip to content

Commit

Permalink
Support multiple interpolated macro args
Browse files Browse the repository at this point in the history
  • Loading branch information
grahambates committed Jun 27, 2024
1 parent fe7cde6 commit 5840c68
Show file tree
Hide file tree
Showing 6 changed files with 47,260 additions and 92,688 deletions.
15 changes: 14 additions & 1 deletion corpus/macro_args.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Macro symbols in labels
l\@:
CFX_\1FILL:
Color\<REPTN>:
\1foo:
foo\1:
foo\1bar:
foo\1bar\2:
---
(source_file
(label (macro_arg))
Expand All @@ -116,7 +120,16 @@ Color\<REPTN>:
(label
(interpolated (macro_arg)))
(label
(interpolated (macro_arg))))
(interpolated (macro_arg)))
(label
(interpolated (macro_arg)))
(label
(interpolated (macro_arg)))
(label
(interpolated (macro_arg)))
(label
(interpolated (macro_arg) (macro_arg)))
)

============================================
Macro symbols in mnemonic
Expand Down
23 changes: 15 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ module.exports = grammar({
$._block
),

_standalone_label: ($) => seq($._label, optional($.comment)),
_standalone_label: ($) => seq(
choice($._label, alias($._name, $.label)), optional($.comment)),

_standalone_comment: ($) => prec(-1, seq(optional($._ws), $.comment)),

Expand Down Expand Up @@ -685,7 +686,10 @@ module.exports = grammar({
_name: ($) => field("name", $._identifier),

_label_definition: ($) =>
seq(choice($._label_colon, $._name), optional($._ws)),
choice(
seq($._label_colon, optional($._ws)),
seq($._name, $._ws),
),

// colon required with leading whitespace
_label_colon: ($) => seq(optional($._ws), $._name, ":"),
Expand Down Expand Up @@ -1120,7 +1124,7 @@ module.exports = grammar({
prec(
PREC.definition,
seq(
$._label_definition,
choice($._label_definition, $._name),
choice(
seq(
"=",
Expand Down Expand Up @@ -1437,16 +1441,19 @@ module.exports = grammar({
/\\<[^>]+>/
),

// Symbol containing one or more macro args
// e.g. foo\1bar
interpolated: ($) =>
prec.right(
1,
seq(
choice(
seq($.macro_arg, $._symbol_chars),
seq(optional("."), $._symbol_chars, $.macro_arg),
seq(".", $.macro_arg)
optional("."),
optional($._symbol_chars),
repeat1(
prec.right(-1,
seq($.macro_arg, optional($._symbol_chars))
),
),
repeat(choice($.macro_arg, $._symbol_chars)),
optional("$")
)
),
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"nan": "^2.15.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.6"
"tree-sitter-cli": "^0.20.8"
},
"repository": "https://github.com/grahambates/tree-sitter-m68k",
"tree-sitter": [
Expand Down
130 changes: 71 additions & 59 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,22 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_label"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_label"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_name"
},
"named": true,
"value": "label"
}
]
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -332,30 +346,39 @@
}
},
"_label_definition": {
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_label_colon"
},
{
"type": "SYMBOL",
"name": "_name"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
"name": "_name"
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "_ws"
}
]
}
Expand Down Expand Up @@ -4988,8 +5011,17 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_label_definition"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_label_definition"
},
{
"type": "SYMBOL",
"name": "_name"
}
]
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -6901,72 +6933,52 @@
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "."
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_symbol_chars"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "PREC_RIGHT",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "macro_arg"
},
{
"type": "SYMBOL",
"name": "_symbol_chars"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "."
"type": "SYMBOL",
"name": "_symbol_chars"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_symbol_chars"
},
{
"type": "SYMBOL",
"name": "macro_arg"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "."
},
{
"type": "SYMBOL",
"name": "macro_arg"
}
]
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "macro_arg"
},
{
"type": "SYMBOL",
"name": "_symbol_chars"
}
]
}
},
{
Expand Down
Loading

0 comments on commit 5840c68

Please sign in to comment.