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

Split current "macro_rules" chapter ", cover more topics #110

Closed
7 tasks
japaric opened this issue Jun 17, 2014 · 2 comments
Closed
7 tasks

Split current "macro_rules" chapter ", cover more topics #110

japaric opened this issue Jun 17, 2014 · 2 comments

Comments

@japaric
Copy link
Member

japaric commented Jun 17, 2014

This chapter needs splitting:

  • intro: macro_rules is behind a feature gate + simple example (no arguments)
  • arguments and designators: $foo:expr
  • variable number of arguments: I would like to use @vks range! example here
  • commas are not needed to separate the arguments: do!($this and $that)
  • + and * expansion
  • stay DRY: generating test suite / trait implementations using macros

We also want to cover:

  • How to link "macro" crates #[phase(plugin)]
@japaric japaric mentioned this issue Jun 17, 2014
52 tasks
@japaric japaric changed the title Topics for the "macro_rules" chapter Split current "macro_rules" chapter " Jun 17, 2014
@japaric japaric changed the title Split current "macro_rules" chapter " Split current "macro_rules" chapter ", cover more topics Jun 17, 2014
@mdinger
Copy link
Contributor

mdinger commented Jul 6, 2014

This is applicable here for when you expand on macros.

In macros example repeat.rs I find the $($y:expr),+ part slightly unclear.

($x:expr, $($y:expr),+) => {std::cmp::min($x, min!($($y),+)) }

It's unclear what $(...) is supposed to signify or how the + operator is applied. Here are some options I thought might match $(...),+ (the rules are unclear so I'm not sure what rules to apply):

// Assume `+` applies to previous character only
$(...), $(...),,,,,,,,, // Could match

// Using [x,y) range notation on the next line:
// Assume `+` applies to range [$(...),+)
$(...), $(...), $(...), // Could match (note the last comma)

// `+` always duplicates everything so there should be a final `,`
$(...), $(...), $(...) // Don't expect to match (note the last comma is missing)

If $(...) is a grouping operator, then I would expect the example to be written this way:

$($x:expr, )+$y:expr // Possible way to write it
$x:expr $($y:expr),+ $($z:expr) // Z needed to handle missing comma

Calls fail similarly:

min!(1u, 2u, ); // Surprisingly fails
min!(1u, 2u);  // Succeeds though!?!

@steveklabnik
Copy link
Member

I'm going to close this issue as stale; there are improvements to be made here, but most of this ticket isn't relevant in today's Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants