Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fddc815a
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fddc815a
编写于
7月 14, 2013
作者:
J
John Clements
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP: adding mark-cancelling for macro_rules
上级
e681e784
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
7 deletion
+57
-7
src/libsyntax/ast_util.rs
src/libsyntax/ast_util.rs
+10
-0
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+1
-2
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+42
-4
src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/ext/tt/macro_rules.rs
+4
-1
未找到文件。
src/libsyntax/ast_util.rs
浏览文件 @
fddc815a
...
...
@@ -1010,6 +1010,16 @@ pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> ~[Mrk] {
}
}
/// Return the outer mark for a context with a mark at the outside.
/// FAILS when outside is not a mark.
pub
fn
mtwt_outer_mark
(
ctxt
:
SyntaxContext
)
->
Mrk
{
let
sctable
=
get_sctable
();
match
sctable
.table
[
ctxt
]
{
ast
::
Mark
(
mrk
,
_
)
=>
mrk
,
_
=>
fail
!
(
"can't retrieve outer mark when outside is not a mark"
)
}
}
/// Push a name... unless it matches the one on top, in which
/// case pop and discard (so two of the same marks cancel)
pub
fn
xorPush
(
marks
:
&
mut
~
[
uint
],
mark
:
uint
)
{
...
...
src/libsyntax/ext/base.rs
浏览文件 @
fddc815a
...
...
@@ -152,8 +152,7 @@ fn builtin_item_tt_no_ctxt(f: SyntaxExpanderTTItemFunNoCtxt) -> @Transformer {
pending_renames
:
@
mut
~
[]
}));
syntax_expanders
.insert
(
intern
(
&
"macro_rules"
),
builtin_item_tt_no_ctxt
(
ext
::
tt
::
macro_rules
::
add_new_extension
));
@
SE
(
IdentTT
(
ext
::
tt
::
macro_rules
::
add_new_extension
,
None
)));
syntax_expanders
.insert
(
intern
(
&
"fmt"
),
builtin_normal_tt_no_ctxt
(
ext
::
fmt
::
expand_syntax_ext
));
syntax_expanders
.insert
(
intern
(
&
"format"
),
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
fddc815a
...
...
@@ -13,7 +13,8 @@
use
ast
::{
item_mac
,
Mrk
,
Stmt_
,
StmtDecl
,
StmtMac
,
StmtExpr
,
StmtSemi
};
use
ast
::{
token_tree
};
use
ast
;
use
ast_util
::{
new_rename
,
new_mark
};
use
ast_util
::{
mtwt_outer_mark
,
new_rename
,
new_mark
};
use
ast_util
;
use
attr
;
use
attr
::
AttrMetaMethods
;
use
codemap
;
...
...
@@ -1507,7 +1508,10 @@ pub fn renames_to_fold(renames : @mut ~[(ast::Ident,ast::Name)]) -> @AstFoldFns
}
// just a convenience:
pub
fn
new_mark_folder
(
m
:
Mrk
)
->
@
AstFoldFns
{
fun_to_ctxt_folder
(
@
Marker
{
mark
:
m
})
}
pub
fn
new_mark_folder
(
m
:
Mrk
)
->
@
AstFoldFns
{
fun_to_ctxt_folder
(
@
Marker
{
mark
:
m
})
}
pub
fn
new_rename_folder
(
from
:
ast
::
Ident
,
to
:
ast
::
Name
)
->
@
AstFoldFns
{
fun_to_ctxt_folder
(
@
Renamer
{
from
:
from
,
to
:
to
})
}
...
...
@@ -1538,6 +1542,16 @@ pub fn replace_ctxts(expr : @ast::Expr, ctxt : SyntaxContext) -> @ast::Expr {
fun_to_ctxt_folder
(
@
Repainter
{
ctxt
:
ctxt
})
.fold_expr
(
expr
)
}
// take the mark from the given ctxt (that has a mark at the outside),
// and apply it to everything in the token trees, thereby cancelling
// that mark.
pub
fn
mtwt_cancel_outer_mark
(
tts
:
&
[
ast
::
token_tree
],
ctxt
:
ast
::
SyntaxContext
)
->
~
[
ast
::
token_tree
]
{
let
outer_mark
=
mtwt_outer_mark
(
ctxt
);
mark_tts
(
tts
,
outer_mark
)
}
#[cfg(test)]
mod
test
{
use
super
::
*
;
...
...
@@ -1546,13 +1560,15 @@ mod test {
use
ast_util
::{
get_sctable
,
mtwt_marksof
,
mtwt_resolve
,
new_rename
};
use
codemap
;
use
codemap
::
Spanned
;
use
fold
;
use
parse
;
use
parse
::
token
::{
gensym
,
intern
,
get_ident_interner
,
ident_to_str
};
use
parse
::
token
::{
fresh_mark
,
gensym
,
intern
,
get_ident_interner
,
ident_to_str
};
use
parse
::
token
;
use
print
::
pprust
;
use
std
;
use
std
::
vec
;
use
util
::
parser_testing
::{
string_to_crate
,
string_to_crate_and_sess
,
string_to_item
};
use
util
::
parser_testing
::{
string_to_pat
,
strs_to_idents
};
use
util
::
parser_testing
::{
string_to_pat
,
str
ing_to_tts
,
str
s_to_idents
};
use
visit
;
// make sure that fail! is present
...
...
@@ -1651,6 +1667,28 @@ fn make_dummy_attr(s: @str) -> ast::Attribute {
}
}
#[test]
fn
cancel_outer_mark_test
(){
let
invalid_name
=
token
::
special_idents
::
invalid
.name
;
let
ident_str
=
@
"x"
;
let
tts
=
string_to_tts
(
ident_str
);
let
fm
=
fresh_mark
();
let
marked_once
=
fold
::
fold_tts
(
tts
,
new_mark_folder
(
fm
)
as
@
fold
::
ast_fold
);
assert_eq!
(
marked_once
.len
(),
1
);
let
marked_once_ctxt
=
match
marked_once
[
0
]
{
ast
::
tt_tok
(
_
,
token
::
IDENT
(
id
,
_
))
=>
id
.ctxt
,
_
=>
fail
!
(
fmt!
(
"unexpected shape for marked tts: %?"
,
marked_once
[
0
]))
};
assert_eq!
(
mtwt_marksof
(
marked_once_ctxt
,
invalid_name
),
~
[
fm
]);
let
remarked
=
mtwt_cancel_outer_mark
(
marked_once
,
marked_once_ctxt
);
assert_eq!
(
remarked
.len
(),
1
);
match
remarked
[
0
]
{
ast
::
tt_tok
(
_
,
token
::
IDENT
(
id
,
_
))
=>
assert_eq!
(
mtwt_marksof
(
id
.ctxt
,
invalid_name
),
~
[]),
_
=>
fail
!
(
fmt!
(
"unexpected shape for marked tts: %?"
,
remarked
[
0
]))
}
}
#[test]
fn
renaming
()
{
let
item_ast
=
string_to_crate
(
@
"fn f() -> int { a }"
);
...
...
src/libsyntax/ext/tt/macro_rules.rs
浏览文件 @
fddc815a
...
...
@@ -14,6 +14,7 @@
use
codemap
::{
Span
,
Spanned
,
dummy_sp
};
use
ext
::
base
::{
ExtCtxt
,
MacResult
,
MRAny
,
MRDef
,
MacroDef
,
NormalTT
};
use
ext
::
base
;
use
ext
::
expand
;
use
ext
::
tt
::
macro_parser
::{
error
};
use
ext
::
tt
::
macro_parser
::{
named_match
,
matched_seq
,
matched_nonterminal
};
use
ext
::
tt
::
macro_parser
::{
parse
,
parse_or_else
,
success
,
failure
};
...
...
@@ -29,8 +30,10 @@
pub
fn
add_new_extension
(
cx
:
@
ExtCtxt
,
sp
:
Span
,
name
:
Ident
,
arg
:
~
[
ast
::
token_tree
])
arg
:
~
[
ast
::
token_tree
],
stx_ctxt
:
ast
::
SyntaxContext
)
->
base
::
MacResult
{
let
arg
=
expand
::
mtwt_cancel_outer_mark
(
arg
,
stx_ctxt
);
// Wrap a matcher_ in a spanned to produce a matcher.
// these spans won't matter, anyways
fn
ms
(
m
:
matcher_
)
->
matcher
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录