From 7afd0598439fc198afba5a4dda60768d75084825 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 23 Jul 2023 14:13:02 -0400 Subject: [PATCH] Scala 2 macros Problem ------- Scala 2 macro definition is not supported. Solution -------- This adds macro_body as an expression. --- corpus/expressions.txt | 24 ++++++++++++++++++++++++ grammar.js | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/corpus/expressions.txt b/corpus/expressions.txt index b98c8e9..4a8dce4 100644 --- a/corpus/expressions.txt +++ b/corpus/expressions.txt @@ -1522,6 +1522,30 @@ def main() { (identifier) (identifier))))) +================================================================================ +Macros (Scala 2 syntax) +================================================================================ + +class Foo { + def a: A = + macro B.b +} + +-------------------------------------------------------------------------------- + +(compilation_unit + (class_definition + (identifier) + (template_body + (function_definition + (identifier) + (type_identifier) + (indented_block + (macro_body + (field_expression + (identifier) + (identifier)))))))) + ================================================================================ Macros (Scala 3 syntax) ================================================================================ diff --git a/grammar.js b/grammar.js index f55bff3..a624f63 100644 --- a/grammar.js +++ b/grammar.js @@ -1019,6 +1019,7 @@ module.exports = grammar({ $.while_expression, $.do_while_expression, $.for_expression, + $.macro_body, $._simple_expression, ), @@ -1306,6 +1307,15 @@ module.exports = grammar({ ), ), + macro_body: $ => + prec.left( + PREC.macro, + seq( + "macro", + choice($.infix_expression, $.prefix_expression, $._simple_expression), + ) + ), + /** * PrefixExpr ::= [PrefixOperator] SimpleExpr */