-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Matching tt
is almost useless
#9364
Comments
This came up as I was trying to parse Rust syntax using macros:
|
I suppose the other way to fix this would be to allow passing interpolated stms as macro parameters. I could then write my statement sequence pattern as |
@vadimcn Passing interpolated statements is allowed; the problem is that they cannot be broken apart and re-parsed after they have been parsed once. |
…g options..." error in macros, which often occurs when trying to match parts of Rust syntax. For example, this matcher: `fn $name:ident( $($param:ident : $pty:ty),* )` would fail when parsing `fn foo()`, because macro parser wouldn't realize that an ident cannot start with `)`. This resolves rust-lang#5902, and at least partially mitigates rust-lang#9364 and rust-lang#3232.
Triage: updated code:
updated error and output:
|
/cc @kmcallister |
macro_rules! foo {
($($x:tt)*) => (println!($($x)*));
}
fn main() {
foo!("Hello, {}!", "world");
} The example originally given by @vadimcn should not have It seems like the issue @paulstansifer originally raised here was fixed at some point, although I'm not sure. |
Yeah, currently, interpolated tokens on the RHS can only be used as input to other macros. The parsing problem on the LHS (which is what this issue is about) had been mitigated, - now it is at least possible to match |
Okay, cool. In that case I'm closing this as a dupe of #3232. |
Because of #3232, the macro parser can't match syntax of the form
$($x:some_nt)*
under any circumstances. However, this is the natural way to deal with token trees, and adding a delimiter of some kind is prohibitively unergonomic.As a short-term fix, we could special-case
tt
so that the macro parser doesn't farm it out to the main Rust parser. We could also introduce attseq
or something to mean "zero or morett
s". It's conceivable that we could also try being smarter with lookahead, but I don't think that's going to be fruitful.The text was updated successfully, but these errors were encountered: