Skip to content

Commit

Permalink
feat: add macro call support (#52)
Browse files Browse the repository at this point in the history
Part of #29.

---------

Signed-off-by: Sasha Pourcelot <[email protected]>
  • Loading branch information
scrabsha authored Jun 24, 2024
1 parent b67f28a commit 98d11db
Show file tree
Hide file tree
Showing 10 changed files with 1,381 additions and 765 deletions.
317 changes: 228 additions & 89 deletions rust-grammar-dpdfa/grammar.rs

Large diffs are not rendered by default.

1,750 changes: 1,081 additions & 669 deletions rust-grammar-dpdfa/src/generated.rs

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions rust-grammar-dpdfa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,15 @@ check_parse! {
}
}
}

check_parse! {
fn braced_macro_nosemi() {
expr,
{
{
macro_call! {}
42
}
}
}
}
2 changes: 1 addition & 1 deletion tests/ui/fail/bad_range_pattern.stderr_nightly
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Potentially invalid expansion. Expected `=`, `|`.
error: Potentially invalid expansion. Expected `:`, `=`, `|`.
--> tests/ui/fail/bad_range_pattern.rs:6:15
|
6 | let $p..=0 = ();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fail/bad_range_pattern.stderr_stable
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Potentially invalid expansion. Expected `=`, `|`.
error: Potentially invalid expansion. Expected `:`, `=`, `|`.
--> tests/ui/fail/bad_range_pattern.rs:6:15
|
6 | let $p..=0 = ();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fail/expr-tuple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error: Potentially invalid expansion. Expected an expression, an identifier, `::
13 | (42,, 42)
| ^

error: Potentially invalid expansion. Expected `!=`, `%`, `&&`, `&`, `*`, `+` or 20 others.
error: Potentially invalid expansion. Expected `!=`, `!`, `%`, `&&`, `&`, `*` or 21 others.
--> tests/ui/fail/expr-tuple.rs:20:12
|
20 | (a b)
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/fail/fn_args.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error: Potentially invalid expansion. Expected a pattern, an identifier, `&`, `-`, `..=`, `..` or 10 others.
error: Potentially invalid expansion. Expected a pattern, an identifier, `&`, `-`, `..=`, `..` or 11 others.
--> tests/ui/fail/fn_args.rs:5:17
|
5 | fn test(,) -> u8 {
| ^

error: Potentially invalid expansion. Expected a pattern, an identifier, `&`, `-`, `..=`, `..` or 10 others.
error: Potentially invalid expansion. Expected a pattern, an identifier, `&`, `-`, `..=`, `..` or 11 others.
--> tests/ui/fail/fn_args.rs:15:23
|
15 | fn test(a: u8,,) -> u8 {
| ^

error: Potentially invalid expansion. Expected `..=`, `..`, `:`, `@`, `|`, a `(` or 1 others.
error: Potentially invalid expansion. Expected `!`, `..=`, `..`, `::`, `:`, `|` or 2 others.
--> tests/ui/fail/fn_args.rs:25:16
|
25 | fn test(a) -> u8 {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fail/loops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error: Potentially invalid expansion. Expected an identifier, `Self`, `_`, `self
13 | while < 42 {}
| ^^

error: Potentially invalid expansion. Expected a pattern, an identifier, `&`, `-`, `..=`, `..` or 9 others.
error: Potentially invalid expansion. Expected a pattern, an identifier, `&`, `-`, `..=`, `..` or 10 others.
--> tests/ui/fail/loops.rs:20:13
|
20 | for ! in in {}
Expand Down
25 changes: 25 additions & 0 deletions tests/ui/pass/blocks-are-insanely-complex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[allow(unused)]
#[expandable::expr]
macro_rules! test {
($e:expr, $i:ident) => {{
let a = 42;
let $i = 42;
let a: path::to::somewhere = ();
let a: macro::call!() = ();
let a = macro_call!();
let a = macro_call!() + macro_call!();
let a = macro_call!() + (anything, actually);
just.an.expression;
macro_call!();
macro_call! {}
macro_call!() + 42;
macro_call! {} + 42;
;
;
;
;
foo + bar
}};
}

fn main() {}
28 changes: 28 additions & 0 deletions tests/ui/pass/macro-calls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![allow(unused)]

#[expandable::expr]
macro_rules! a {
() => {{
foo!();
foo::bar::baz!();
foo!([], {}{});
}};
}

#[expandable::expr]
macro_rules! b {
() => {{
let _: foo!() = ();
let _: bar![] = ();
}};
}

#[expandable::expr]
macro_rules! c {
() => {{
let foo!() = ();
let ::foo::bar::baz![{}] = ();
}};
}

fn main() {}

0 comments on commit 98d11db

Please sign in to comment.