Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upmacros should be parsed more lazily #6994
Comments
This comment has been minimized.
This comment has been minimized.
|
Nominating for well-defined. |
This comment has been minimized.
This comment has been minimized.
|
double triage before triage meeting. i think this could maybe be well-covered; we understand how it should work, and it's not a backwards-compat hazard. |
This comment has been minimized.
This comment has been minimized.
kud1ing
commented
Aug 9, 2013
|
I think the tag "A-macos" is unfortunate, since this is not Mac OS specific. Or is it? |
This comment has been minimized.
This comment has been minimized.
|
I imagine it's just a typo because |
This comment has been minimized.
This comment has been minimized.
kud1ing
commented
Aug 9, 2013
|
I guess so. Maybe rename "A-macos" to "A-mac_os" or "A-mac"? |
This comment has been minimized.
This comment has been minimized.
|
Accepted for milestone 3, feature-complete |
This comment has been minimized.
This comment has been minimized.
|
Wow! glad to see this wind up on a milestone... |
This comment has been minimized.
This comment has been minimized.
|
P-low, not 1.0. |
pnkfelix
added
P-low
and removed
P-high-untriaged
labels
Mar 20, 2014
huonw
referenced this issue
Jul 13, 2014
Closed
error w/ macros that expand into macro definitions #6795
This comment has been minimized.
This comment has been minimized.
|
Would this be fixable by allowing // the z flows into and out of two macros (g & f) along one path, and one (just g) along the
// other, so the result of the whole thing should be "let z_123 = 3; z_123
macro_rules! g (
($x:ident) =>
(
{macro_rules! f(
($$y:ident)=>({let $$y=3;$x})
);
f!($x)})
)
fn a(){g!(z)}The |
This comment has been minimized.
This comment has been minimized.
|
No, don't go down that road; I don't believe that will lead to a nice solution. |
This comment has been minimized.
This comment has been minimized.
|
OK. It would be nice if the eventual solution was not specific to nested (I could easily imagine other more common procedural macros that may wish to "overload" the |
This comment has been minimized.
This comment has been minimized.
|
Hang on... where is the $a bound, in your example? |
This comment has been minimized.
This comment has been minimized.
|
Sorry, was on my phone making it difficult to explain fully. I meant something like let a: i32 = ...;
macro_rules! foo {
($e: expr) => { quote_expr!(cx, $$a + $e) }
}
foo!(1);
foo!(2);The above is theoretically equivalent to the following, which is unquoting/splicing
(The |
This comment has been minimized.
This comment has been minimized.
|
in this case, you shouldn't need |
This comment has been minimized.
This comment has been minimized.
|
I'm thinking more about this issue, and I think it's misnamed. The fundamental issue here is how the transcription engine matches up bindings of macro variables with uses of those variables. The solution, I think, is pretty straightforward: the transcription engine should just ignore transcription Also, hygiene should stick its nose in, here. There should be a renaming of all pattern identifiers. I think the sneaky side-effect of this will be to make the $'s in the right-hand sides redundant. |
This comment has been minimized.
This comment has been minimized.
No, The ones with |
This comment has been minimized.
This comment has been minimized.
|
Hey! Let's argue! :) I understand now better what you're looking for. Specifically, you want to use $ as an unquote mechanism in procedural macros, in order to splice in other syntactic terms and values from the context of the macro definition (specifically, I missed the fact that you were using quote_expr! before, sorry). This is plausible, but I'd like to point out that it's not the same as what $a does currently—it's not an unquoting mechanism. This is perhaps most clear when the identifier 'a' is bound to a sequence rather than a single syntactic term, but even in the single-match case, the RHS use of $a is not actually inserting the value of an 'a' variable defined in a surrounding context. I think that something like this is possible, but I don't think that re-using $ is the right way to go. Lemme fix this, and then we'll see where we are. |
This comment has been minimized.
This comment has been minimized.
|
Oh dear Lord... I may have spoken too quickly. Or perhaps I meant to say, I may have spoken way too late. I see that the source is already peppered with uses of $ that may in fact be unquotes. Reading more... |
This comment has been minimized.
This comment has been minimized.
|
Yes, I see that it absolutely is used that way. That's a bad pun, and I think it might be painful.... |
This comment has been minimized.
This comment has been minimized.
|
The problem would be resolved IMO if we have some technique that works for those cases that's not |
pczarn
referenced this issue
Oct 6, 2014
Merged
Improve interpolation of macro lhs and doc comments. Remove `Matcher`s #17830
paulstansifer
referenced this issue
Nov 5, 2014
Closed
Decide on our long term/ideal goals for macros #440
This comment has been minimized.
This comment has been minimized.
|
Triage: OP's code, with a semicolon, still generates the same error. |
mitsuhiko
referenced this issue
Aug 2, 2015
Closed
Nested macros can't define any new variables #26329
This comment has been minimized.
This comment has been minimized.
|
Triage: There is still the same error happening on // the z flows into and out of two macros (g & f) along one path, and one (just g) along the
// other, so the result of the whole thing should be "let z_123 = 3; z_123
macro_rules! g (
($x:ident) =>
(
{macro_rules! f(
($y:ident)=>({let $y=3;$x})
);
f!($x)})
);
fn a(){g!(z)}Error:
|
jbclements commentedJun 7, 2013
This is a FIXME issue; currently, macro invocations are parsed too eagerly. In particular, the current system decides before expansion time whether a rhs pattern-use (e.g. $y) is bound or unbound. This is incompatible with macro-producing macros that use a given identifier in a pattern position. It's also incompatible with macros inside macros, where inner binding patterns are believed to be pattern uses. The solution is to delay this decision until the macro is encountered at expansion-time, by which time all outer macros have been expanded.
Here's an example of a macro that doesn't work in the current system:
Trying to expand this yields this error:
... indicating that the $y is believed to be a use, rather than a binder.