Skip to content

Commit

Permalink
comments only
Browse files Browse the repository at this point in the history
  • Loading branch information
jbclements committed Jul 28, 2013
1 parent 5c95645 commit 03be3c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ pub enum matcher_ {
// lo, hi position-in-match-array used:
match_seq(~[matcher], Option<::parse::token::Token>, bool, uint, uint),
// parse a Rust NT: name to bind, name of NT, position in match array:
// NOTE: 'name of NT' shouldnt really be represented as an ident, should it?
match_nonterminal(ident, ident, uint)
}

Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub fn path_name_i(idents: &[ident]) -> ~str {
idents.map(|i| token::interner_get(i.name)).connect("::")
}

// totally scary function: ignores all but the last element, should have
// a different name
pub fn path_to_ident(p: &Path) -> ident {
*p.idents.last()
}
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,8 @@ mod test {
// 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)}"
// create a really evil test case where a $x appears inside a binding of $x but *shouldnt*
// bind because it was inserted by a different macro....
];
for teststrs.iter().advance |s| {
// we need regexps to test these!
Expand Down
6 changes: 6 additions & 0 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ use parse::token::{get_ident_interner, special_idents, gensym_ident, ident_to_st
use parse::token::{FAT_ARROW, SEMI, nt_matchers, nt_tt};
use print;

// this procedure performs the expansion of the
// macro_rules! macro. It parses the RHS and adds
// an extension to the current context.
pub fn add_new_extension(cx: @ExtCtxt,
sp: span,
name: ident,
arg: ~[ast::token_tree])
-> base::MacResult {
// Wrap a matcher_ in a spanned to produce a matcher.
// these spans won't matter, anyways
fn ms(m: matcher_) -> matcher {
spanned {
Expand All @@ -39,11 +43,13 @@ pub fn add_new_extension(cx: @ExtCtxt,
let lhs_nm = gensym_ident("lhs");
let rhs_nm = gensym_ident("rhs");

// The pattern that macro_rules matches.
// The grammar for macro_rules! is:
// $( $lhs:mtcs => $rhs:tt );+
// ...quasiquoting this would be nice.
let argument_gram = ~[
ms(match_seq(~[
// NOTE : probably just use an enum for the NT_name ?
ms(match_nonterminal(lhs_nm, special_idents::matchers, 0u)),
ms(match_tok(FAT_ARROW)),
ms(match_nonterminal(rhs_nm, special_idents::tt, 1u)),
Expand Down

0 comments on commit 03be3c8

Please sign in to comment.