Skip to content

Commit c051218

Browse files
committed
---
yaml --- r: 79503 b: refs/heads/snap-stage3 c: fddc815 h: refs/heads/master i: 79501: 3a759a2 79499: 42d762c 79495: 70e5de5 79487: 98ad019 v: v3
1 parent ded61a1 commit c051218

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 124eb2119c78651cfaaa7a046a101fa2e20f83ca
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: e681e7843e6da4348648dcbdf11a633828c1b1a9
4+
refs/heads/snap-stage3: fddc815adaabb87c23e74c2bce41cddb5d433326
55
refs/heads/try: ac820906c0e53eab79a98ee64f7231f57c3887b4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libsyntax/ast_util.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,16 @@ pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> ~[Mrk] {
10101010
}
10111011
}
10121012
1013+
/// Return the outer mark for a context with a mark at the outside.
1014+
/// FAILS when outside is not a mark.
1015+
pub fn mtwt_outer_mark(ctxt: SyntaxContext) -> Mrk {
1016+
let sctable = get_sctable();
1017+
match sctable.table[ctxt] {
1018+
ast::Mark(mrk,_) => mrk,
1019+
_ => fail!("can't retrieve outer mark when outside is not a mark")
1020+
}
1021+
}
1022+
10131023
/// Push a name... unless it matches the one on top, in which
10141024
/// case pop and discard (so two of the same marks cancel)
10151025
pub fn xorPush(marks: &mut ~[uint], mark: uint) {

branches/snap-stage3/src/libsyntax/ext/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ pub fn syntax_expander_table() -> SyntaxEnv {
152152
pending_renames : @mut ~[]
153153
}));
154154
syntax_expanders.insert(intern(&"macro_rules"),
155-
builtin_item_tt_no_ctxt(
156-
ext::tt::macro_rules::add_new_extension));
155+
@SE(IdentTT(ext::tt::macro_rules::add_new_extension, None)));
157156
syntax_expanders.insert(intern(&"fmt"),
158157
builtin_normal_tt_no_ctxt(ext::fmt::expand_syntax_ext));
159158
syntax_expanders.insert(intern(&"format"),

branches/snap-stage3/src/libsyntax/ext/expand.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use ast::{Local, Ident, mac_invoc_tt};
1313
use ast::{item_mac, Mrk, Stmt_, StmtDecl, StmtMac, StmtExpr, StmtSemi};
1414
use ast::{token_tree};
1515
use ast;
16-
use ast_util::{new_rename, new_mark};
16+
use ast_util::{mtwt_outer_mark, new_rename, new_mark};
17+
use ast_util;
1718
use attr;
1819
use attr::AttrMetaMethods;
1920
use codemap;
@@ -1507,7 +1508,10 @@ pub fn renames_to_fold(renames : @mut ~[(ast::Ident,ast::Name)]) -> @AstFoldFns
15071508
}
15081509

15091510
// just a convenience:
1510-
pub fn new_mark_folder(m : Mrk) -> @AstFoldFns { fun_to_ctxt_folder(@Marker{mark:m}) }
1511+
pub fn new_mark_folder(m : Mrk) -> @AstFoldFns {
1512+
fun_to_ctxt_folder(@Marker{mark:m})
1513+
}
1514+
15111515
pub fn new_rename_folder(from : ast::Ident, to : ast::Name) -> @AstFoldFns {
15121516
fun_to_ctxt_folder(@Renamer{from:from,to:to})
15131517
}
@@ -1538,6 +1542,16 @@ pub fn replace_ctxts(expr : @ast::Expr, ctxt : SyntaxContext) -> @ast::Expr {
15381542
fun_to_ctxt_folder(@Repainter{ctxt:ctxt}).fold_expr(expr)
15391543
}
15401544

1545+
// take the mark from the given ctxt (that has a mark at the outside),
1546+
// and apply it to everything in the token trees, thereby cancelling
1547+
// that mark.
1548+
pub fn mtwt_cancel_outer_mark(tts: &[ast::token_tree], ctxt: ast::SyntaxContext)
1549+
-> ~[ast::token_tree] {
1550+
let outer_mark = mtwt_outer_mark(ctxt);
1551+
mark_tts(tts,outer_mark)
1552+
}
1553+
1554+
15411555
#[cfg(test)]
15421556
mod test {
15431557
use super::*;
@@ -1546,13 +1560,15 @@ mod test {
15461560
use ast_util::{get_sctable, mtwt_marksof, mtwt_resolve, new_rename};
15471561
use codemap;
15481562
use codemap::Spanned;
1563+
use fold;
15491564
use parse;
1550-
use parse::token::{gensym, intern, get_ident_interner, ident_to_str};
1565+
use parse::token::{fresh_mark, gensym, intern, get_ident_interner, ident_to_str};
1566+
use parse::token;
15511567
use print::pprust;
15521568
use std;
15531569
use std::vec;
15541570
use util::parser_testing::{string_to_crate, string_to_crate_and_sess, string_to_item};
1555-
use util::parser_testing::{string_to_pat, strs_to_idents};
1571+
use util::parser_testing::{string_to_pat, string_to_tts, strs_to_idents};
15561572
use visit;
15571573

15581574
// make sure that fail! is present
@@ -1651,6 +1667,28 @@ mod test {
16511667
}
16521668
}
16531669

1670+
#[test] fn cancel_outer_mark_test(){
1671+
let invalid_name = token::special_idents::invalid.name;
1672+
let ident_str = @"x";
1673+
let tts = string_to_tts(ident_str);
1674+
let fm = fresh_mark();
1675+
let marked_once = fold::fold_tts(tts,new_mark_folder(fm) as @fold::ast_fold);
1676+
assert_eq!(marked_once.len(),1);
1677+
let marked_once_ctxt =
1678+
match marked_once[0] {
1679+
ast::tt_tok(_,token::IDENT(id,_)) => id.ctxt,
1680+
_ => fail!(fmt!("unexpected shape for marked tts: %?",marked_once[0]))
1681+
};
1682+
assert_eq!(mtwt_marksof(marked_once_ctxt,invalid_name),~[fm]);
1683+
let remarked = mtwt_cancel_outer_mark(marked_once,marked_once_ctxt);
1684+
assert_eq!(remarked.len(),1);
1685+
match remarked[0] {
1686+
ast::tt_tok(_,token::IDENT(id,_)) =>
1687+
assert_eq!(mtwt_marksof(id.ctxt,invalid_name),~[]),
1688+
_ => fail!(fmt!("unexpected shape for marked tts: %?",remarked[0]))
1689+
}
1690+
}
1691+
16541692
#[test]
16551693
fn renaming () {
16561694
let item_ast = string_to_crate(@"fn f() -> int { a }");

branches/snap-stage3/src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use ast;
1414
use codemap::{Span, Spanned, dummy_sp};
1515
use ext::base::{ExtCtxt, MacResult, MRAny, MRDef, MacroDef, NormalTT};
1616
use ext::base;
17+
use ext::expand;
1718
use ext::tt::macro_parser::{error};
1819
use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal};
1920
use ext::tt::macro_parser::{parse, parse_or_else, success, failure};
@@ -29,8 +30,10 @@ use print;
2930
pub fn add_new_extension(cx: @ExtCtxt,
3031
sp: Span,
3132
name: Ident,
32-
arg: ~[ast::token_tree])
33+
arg: ~[ast::token_tree],
34+
stx_ctxt: ast::SyntaxContext)
3335
-> base::MacResult {
36+
let arg = expand::mtwt_cancel_outer_mark(arg,stx_ctxt);
3437
// Wrap a matcher_ in a spanned to produce a matcher.
3538
// these spans won't matter, anyways
3639
fn ms(m: matcher_) -> matcher {

0 commit comments

Comments
 (0)