Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 2 macros #325

Merged
merged 1 commit into from
Jul 24, 2023
Merged
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
24 changes: 24 additions & 0 deletions corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
================================================================================
Expand Down
10 changes: 10 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const PREC = {

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-20.04)

ok, scala_scala/src/library/: 100.00%, expected at least 100%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-20.04)

ok, scala_scala/src/compiler/: 96.31%, expected at least 96%

Check notice on line 1 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-20.04)

ok, dotty/compiler/: 83.98%, expected at least 83%
comment: 1,
using_directive: 2,
control: 1,
Expand Down Expand Up @@ -854,7 +854,7 @@
),
),

tuple_type: $ => seq("(", trailingCommaSep1($._type), ")"),

Check notice on line 857 in grammar.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-20.04)

ok, complexity of the most complex definition tuple_type: 1269, lower than the allowed ceiling 1300

singleton_type: $ =>
prec.left(
Expand Down Expand Up @@ -1019,6 +1019,7 @@
$.while_expression,
$.do_while_expression,
$.for_expression,
$.macro_body,
$._simple_expression,
),

Expand Down Expand Up @@ -1306,6 +1307,15 @@
),
),

macro_body: $ =>
prec.left(
PREC.macro,
seq(
"macro",
choice($.infix_expression, $.prefix_expression, $._simple_expression),
)
),

/**
* PrefixExpr ::= [PrefixOperator] SimpleExpr
*/
Expand Down