Skip to content

Commit

Permalink
Add macroexp syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
euclidianAce committed Oct 11, 2024
1 parent fa21917 commit 485fbdc
Show file tree
Hide file tree
Showing 6 changed files with 10,875 additions and 9,540 deletions.
19 changes: 19 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = grammar({
$.repeat_statement,
$.function_call,
$.function_statement,
$.macroexp_statement,
$.if_statement,
seq("::", alias($.identifier, $.label), "::"),
$.goto
Expand Down Expand Up @@ -321,6 +322,23 @@ module.exports = grammar({
)
),

macroexp_statement: $ => seq(
"local",
$._macroexp_def
),

_macroexp_def: $ => seq(
"macroexp",
field("name", $.identifier),
field("signature", alias($.function_signature, $.macroexp_signature)),
field("body", $.macroexp_body)
),

macroexp_body: $ => seq(
$.return_statement,
"end"
),

variadic_type: $ => prec(prec_type_op.index - 1, seq($._type, "...")),
_type_list_maybe_vararg: $ => seq(list($._type), optional(seq(",", $.variadic_type))),
return_type: $ => choice(
Expand Down Expand Up @@ -395,6 +413,7 @@ module.exports = grammar({
alias($._record_def, $.record_declaration),
alias($._enum_def, $.enum_declaration),
alias($._interface_def, $.interface_declaration),
alias($._macroexp_def, $.macroexp_declaration),
),

metamethod_annotation: $ => seq(
Expand Down
8 changes: 8 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
(interface_declaration "global" @keyword)
(enum_declaration "global" @keyword)

(macroexp_statement "macroexp" @keyword)

;; Ops
(bin_op (op) @operator)
(unary_op (op) @operator)
Expand Down Expand Up @@ -86,6 +88,9 @@
(typedef
. "type" @keyword
. name: (identifier) @type . "="))
(record_body
(macroexp_declaration
. [ "macroexp" ] @keyword))
(record_body (metamethod "metamethod" @keyword))
(record_body (userdata) @keyword)

Expand All @@ -110,6 +115,9 @@
(typedef
. "type" @keyword
. name: (identifier) @type . "="))
(interface_body
(macroexp_declaration
. [ "macroexp" ] @keyword))
(interface_body (metamethod "metamethod" @keyword))
(interface_body (userdata) @keyword)

Expand Down
77 changes: 77 additions & 0 deletions src/grammar.json

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

Loading

0 comments on commit 485fbdc

Please sign in to comment.