Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9a4c6698
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,发现更多精彩内容 >>
提交
9a4c6698
编写于
12月 12, 2012
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
syntax: remove remaining #syntaxext machinery. Close #3516.
上级
e24ae850
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
150 addition
and
272 deletion
+150
-272
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+0
-8
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+49
-102
src/libsyntax/ext/concat_idents.rs
src/libsyntax/ext/concat_idents.rs
+24
-11
src/libsyntax/ext/env.rs
src/libsyntax/ext/env.rs
+9
-8
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+1
-34
src/libsyntax/ext/fmt.rs
src/libsyntax/ext/fmt.rs
+7
-4
src/libsyntax/ext/ident_to_str.rs
src/libsyntax/ext/ident_to_str.rs
+0
-20
src/libsyntax/ext/source_util.rs
src/libsyntax/ext/source_util.rs
+34
-42
src/libsyntax/print/pp.rs
src/libsyntax/print/pp.rs
+1
-3
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+19
-16
src/libsyntax/syntax.rc
src/libsyntax/syntax.rc
+0
-3
src/test/compile-fail/ext-noname.rs
src/test/compile-fail/ext-noname.rs
+0
-15
src/test/compile-fail/extenv-no-args.rs
src/test/compile-fail/extenv-no-args.rs
+1
-1
src/test/compile-fail/extenv-too-many-args.rs
src/test/compile-fail/extenv-too-many-args.rs
+1
-1
src/test/compile-fail/extfmt-no-args.rs
src/test/compile-fail/extfmt-no-args.rs
+1
-1
src/test/run-pass/class-attributes-1.rs
src/test/run-pass/class-attributes-1.rs
+1
-1
src/test/run-pass/syntax-extension-minor.rs
src/test/run-pass/syntax-extension-minor.rs
+1
-1
src/test/run-pass/syntax-extension-source-utils.rs
src/test/run-pass/syntax-extension-source-utils.rs
+1
-1
未找到文件。
src/libsyntax/ast.rs
浏览文件 @
9a4c6698
...
...
@@ -831,14 +831,6 @@ enum matcher_ {
type
mac
=
spanned
<
mac_
>
;
type
mac_arg
=
Option
<@
expr
>
;
#[auto_serialize]
#[auto_deserialize]
type
mac_body_
=
{
span
:
span
};
type
mac_body
=
Option
<
mac_body_
>
;
#[auto_serialize]
#[auto_deserialize]
enum
mac_
{
...
...
src/libsyntax/ext/base.rs
浏览文件 @
9a4c6698
...
...
@@ -13,11 +13,8 @@
use
diagnostic
::
span_handler
;
use
codemap
::{
CodeMap
,
span
,
ExpnInfo
,
ExpandedFrom
};
use
ast_util
::
dummy_sp
;
use
parse
::
token
;
// obsolete old-style #macro code:
//
// syntax_expander, normal, builtin
//
// new-style macro! tt code:
//
// syntax_expander_tt, syntax_expander_tt_item, mac_result,
...
...
@@ -27,12 +24,6 @@
// is now probably a redundant AST node, can be merged with
// ast::mac_invoc_tt.
// second argument is the span to blame for general argument problems
type
syntax_expander_
=
fn
@
(
ext_ctxt
,
span
,
ast
::
mac_arg
,
ast
::
mac_body
)
->
@
ast
::
expr
;
// second argument is the origin of the macro, if user-defined
type
syntax_expander
=
{
expander
:
syntax_expander_
,
span
:
Option
<
span
>
};
type
macro_def
=
{
name
:
~
str
,
ext
:
syntax_extension
};
type
item_decorator
=
...
...
@@ -56,10 +47,7 @@ enum mac_result {
enum
syntax_extension
{
// normal() is obsolete, remove when #old_macros go away.
normal
(
syntax_expander
),
// #[auto_serialize] and such. will probably survive death of #old_macros
// #[auto_serialize] and such
item_decorator
(
item_decorator
),
// Token-tree expanders
...
...
@@ -73,8 +61,6 @@ enum syntax_extension {
// A temporary hard-coded map of methods for expanding syntax extension
// AST nodes into full ASTs
fn
syntax_expander_table
()
->
HashMap
<~
str
,
syntax_extension
>
{
fn
builtin
(
f
:
syntax_expander_
)
->
syntax_extension
{
normal
({
expander
:
f
,
span
:
None
})}
fn
builtin_normal_tt
(
f
:
syntax_expander_tt_
)
->
syntax_extension
{
normal_tt
({
expander
:
f
,
span
:
None
})
}
...
...
@@ -85,18 +71,19 @@ fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
syntax_expanders
.insert
(
~
"macro_rules"
,
builtin_item_tt
(
ext
::
tt
::
macro_rules
::
add_new_extension
));
syntax_expanders
.insert
(
~
"fmt"
,
builtin
(
ext
::
fmt
::
expand_syntax_ext
));
syntax_expanders
.insert
(
~
"fmt"
,
builtin_normal_tt
(
ext
::
fmt
::
expand_syntax_ext
));
syntax_expanders
.insert
(
~
"auto_serialize"
,
item_decorator
(
ext
::
auto_serialize
::
expand_auto_serialize
));
syntax_expanders
.insert
(
~
"auto_deserialize"
,
item_decorator
(
ext
::
auto_serialize
::
expand_auto_deserialize
));
syntax_expanders
.insert
(
~
"env"
,
builtin
(
ext
::
env
::
expand_syntax_ext
));
syntax_expanders
.insert
(
~
"env"
,
builtin_normal_tt
(
ext
::
env
::
expand_syntax_ext
));
syntax_expanders
.insert
(
~
"concat_idents"
,
builtin
(
ext
::
concat_idents
::
expand_syntax_ext
));
syntax_expanders
.insert
(
~
"ident_to_str"
,
builtin
(
ext
::
ident_to_str
::
expand_syntax_ext
));
builtin_normal_tt
(
ext
::
concat_idents
::
expand_syntax_ext
));
syntax_expanders
.insert
(
~
"log_syntax"
,
builtin_normal_tt
(
ext
::
log_syntax
::
expand_syntax_ext
));
...
...
@@ -122,21 +109,29 @@ fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
builtin_normal_tt
(
ext
::
quote
::
expand_quote_stmt
));
syntax_expanders
.insert
(
~
"line"
,
builtin
(
ext
::
source_util
::
expand_line
));
builtin_normal_tt
(
ext
::
source_util
::
expand_line
));
syntax_expanders
.insert
(
~
"col"
,
builtin
(
ext
::
source_util
::
expand_col
));
builtin_normal_tt
(
ext
::
source_util
::
expand_col
));
syntax_expanders
.insert
(
~
"file"
,
builtin
(
ext
::
source_util
::
expand_file
));
builtin_normal_tt
(
ext
::
source_util
::
expand_file
));
syntax_expanders
.insert
(
~
"stringify"
,
builtin
(
ext
::
source_util
::
expand_stringify
));
builtin_normal_tt
(
ext
::
source_util
::
expand_stringify
));
syntax_expanders
.insert
(
~
"include"
,
builtin
(
ext
::
source_util
::
expand_include
));
builtin_normal_tt
(
ext
::
source_util
::
expand_include
));
syntax_expanders
.insert
(
~
"include_str"
,
builtin
(
ext
::
source_util
::
expand_include_str
));
builtin_normal_tt
(
ext
::
source_util
::
expand_include_str
));
syntax_expanders
.insert
(
~
"include_bin"
,
builtin
(
ext
::
source_util
::
expand_include_bin
));
builtin_normal_tt
(
ext
::
source_util
::
expand_include_bin
));
syntax_expanders
.insert
(
~
"module_path"
,
builtin
(
ext
::
source_util
::
expand_mod
));
builtin_normal_tt
(
ext
::
source_util
::
expand_mod
));
syntax_expanders
.insert
(
~
"proto"
,
builtin_item_tt
(
ext
::
pipes
::
expand_proto
));
syntax_expanders
.insert
(
...
...
@@ -292,87 +287,39 @@ fn expr_to_ident(cx: ext_ctxt,
}
}
fn
get_mac_args_no_max
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
min
:
uint
,
name
:
~
str
)
->
~
[
@
ast
::
expr
]
{
return
get_mac_args
(
cx
,
sp
,
arg
,
min
,
None
,
name
);
fn
check_zero_tts
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
&
[
ast
::
token_tree
],
name
:
&
str
)
{
if
tts
.len
()
!=
0
{
cx
.span_fatal
(
sp
,
fmt!
(
"%s takes no arguments"
,
name
));
}
}
fn
get_mac_args
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
min
:
uint
,
max
:
Option
<
uint
>
,
name
:
~
str
)
->
~
[
@
ast
::
expr
]
{
match
arg
{
Some
(
expr
)
=>
match
expr
.node
{
ast
::
expr_vec
(
elts
,
_
)
=>
{
let
elts_len
=
vec
::
len
(
elts
);
match
max
{
Some
(
max
)
if
!
(
min
<=
elts_len
&&
elts_len
<=
max
)
=>
{
cx
.span_fatal
(
sp
,
fmt!
(
"%s! takes between %u and %u arguments."
,
name
,
min
,
max
));
}
None
if
!
(
min
<=
elts_len
)
=>
{
cx
.span_fatal
(
sp
,
fmt!
(
"%s! needs at least %u arguments."
,
name
,
min
));
}
_
=>
return
elts
/* we are good */
}
}
_
=>
{
cx
.span_fatal
(
sp
,
fmt!
(
"%s!: malformed invocation"
,
name
))
}
},
None
=>
cx
.span_fatal
(
sp
,
fmt!
(
"%s!: missing arguments"
,
name
))
fn
get_single_str_from_tts
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
&
[
ast
::
token_tree
],
name
:
&
str
)
->
~
str
{
if
tts
.len
()
!=
1
{
cx
.span_fatal
(
sp
,
fmt!
(
"%s takes 1 argument."
,
name
));
}
}
fn
get_mac_body
(
cx
:
ext_ctxt
,
sp
:
span
,
args
:
ast
::
mac_body
)
->
ast
::
mac_body_
{
match
(
args
)
{
Some
(
body
)
=>
body
,
None
=>
cx
.span_fatal
(
sp
,
~
"missing macro body"
)
match
tts
[
0
]
{
ast
::
tt_tok
(
_
,
token
::
LIT_STR
(
ident
))
=>
cx
.str_of
(
ident
),
_
=>
cx
.span_fatal
(
sp
,
fmt!
(
"%s requires a string."
,
name
))
}
}
// Massage syntactic form of new-style arguments to internal representation
// of old-style macro args, such that old-style macro can be run and invoked
// using new syntax. This will be obsolete when #old_macros go away.
fn
tt_args_to_original_flavor
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
~
[
ast
::
token_tree
])
->
ast
::
mac_arg
{
use
ast
::{
matcher
,
matcher_
,
match_tok
,
match_seq
,
match_nonterminal
};
use
parse
::
lexer
::{
new_tt_reader
,
reader
};
use
tt
::
macro_parser
::{
parse_or_else
,
matched_seq
,
matched_nonterminal
};
// these spans won't matter, anyways
fn
ms
(
m
:
matcher_
)
->
matcher
{
{
node
:
m
,
span
:
dummy_sp
()}
fn
get_exprs_from_tts
(
cx
:
ext_ctxt
,
tts
:
~
[
ast
::
token_tree
])
->
~
[
@
ast
::
expr
]
{
let
p
=
parse
::
new_parser_from_tts
(
cx
.parse_sess
(),
cx
.cfg
(),
tts
);
let
mut
es
=
~
[];
while
p
.token
!=
token
::
EOF
{
if
es
.len
()
!=
0
{
p
.eat
(
token
::
COMMA
);
}
es
.push
(
p
.parse_expr
());
}
let
arg_nm
=
cx
.parse_sess
()
.interner
.gensym
(
@~
"arg"
);
let
argument_gram
=
~
[
ms
(
match_seq
(
~
[
ms
(
match_nonterminal
(
arg_nm
,
parse
::
token
::
special_idents
::
expr
,
0u
))
],
Some
(
parse
::
token
::
COMMA
),
true
,
0u
,
1u
))];
let
arg_reader
=
new_tt_reader
(
cx
.parse_sess
()
.span_diagnostic
,
cx
.parse_sess
()
.interner
,
None
,
arg
);
let
args
=
match
parse_or_else
(
cx
.parse_sess
(),
cx
.cfg
(),
arg_reader
as
reader
,
argument_gram
)
.get
(
arg_nm
)
{
@
matched_seq
(
s
,
_
)
=>
{
do
s
.map
()
|
lf
|
{
match
*
lf
{
@
matched_nonterminal
(
parse
::
token
::
nt_expr
(
arg
))
=>
arg
,
/* whew! list of exprs, here we come! */
_
=>
fail
~
"badly-structured parse result"
}
}
},
_
=>
fail
~
"badly-structured parse result"
};
return
Some
(
@
{
id
:
parse
::
next_node_id
(
cx
.parse_sess
()),
callee_id
:
parse
::
next_node_id
(
cx
.parse_sess
()),
node
:
ast
::
expr_vec
(
args
,
ast
::
m_imm
),
span
:
sp
});
es
}
//
...
...
src/libsyntax/ext/concat_idents.rs
浏览文件 @
9a4c6698
...
...
@@ -10,19 +10,32 @@
use
base
::
*
;
fn
expand_syntax_ext
(
cx
:
ext_ctxt
,
sp
:
codemap
::
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args_no_max
(
cx
,
sp
,
arg
,
1u
,
~
"concat_idents"
);
fn
expand_syntax_ext
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
let
mut
res_str
=
~
""
;
for
args
.each
|
e
|
{
res_str
+=
*
cx
.parse_sess
()
.interner
.get
(
expr_to_ident
(
cx
,
*
e
,
~
"expected an ident"
));
for
tts
.eachi
|
i
,
e
|
{
if
i
&
1
==
1
{
match
*
e
{
ast
::
tt_tok
(
_
,
token
::
COMMA
)
=>
(),
_
=>
cx
.span_fatal
(
sp
,
~
"concat_idents!
\
expecting comma."
)
}
}
else
{
match
*
e
{
ast
::
tt_tok
(
_
,
token
::
IDENT
(
ident
,
_
))
=>
res_str
+=
cx
.str_of
(
ident
),
_
=>
cx
.span_fatal
(
sp
,
~
"concat_idents!
\
requires ident args."
)
}
}
}
let
res
=
cx
.parse_sess
()
.interner
.intern
(
@
res_str
);
return
@
{
id
:
cx
.next_id
(),
callee_id
:
cx
.next_id
(),
node
:
ast
::
expr_path
(
@
{
span
:
sp
,
global
:
false
,
idents
:
~
[
res
],
rp
:
None
,
types
:
~
[]}),
span
:
sp
};
let
e
=
@
{
id
:
cx
.next_id
(),
callee_id
:
cx
.next_id
(),
node
:
ast
::
expr_path
(
@
{
span
:
sp
,
global
:
false
,
idents
:
~
[
res
],
rp
:
None
,
types
:
~
[]}),
span
:
sp
};
mr_expr
(
e
)
}
src/libsyntax/ext/env.rs
浏览文件 @
9a4c6698
...
...
@@ -18,18 +18,19 @@
use
build
::
mk_uniq_str
;
export
expand_syntax_ext
;
fn
expand_syntax_ext
(
cx
:
ext_ctxt
,
sp
:
codemap
::
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args
(
cx
,
sp
,
arg
,
1u
,
option
::
Some
(
1u
),
~
"env"
);
fn
expand_syntax_ext
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
let
var
=
get_single_str_from_tts
(
cx
,
sp
,
tts
,
"env!"
);
// FIXME (#2248): if this was more thorough it would manufacture an
// Option<str> rather than just an maybe-empty string.
let
var
=
expr_to_str
(
cx
,
args
[
0
],
~
"env! requires a string"
);
match
os
::
getenv
(
var
)
{
option
::
None
=>
return
mk_uniq_str
(
cx
,
sp
,
~
""
),
option
::
Some
(
ref
s
)
=>
return
mk_uniq_str
(
cx
,
sp
,
(
*
s
))
}
let
e
=
match
os
::
getenv
(
var
)
{
option
::
None
=>
mk_uniq_str
(
cx
,
sp
,
~
""
),
option
::
Some
(
ref
s
)
=>
mk_uniq_str
(
cx
,
sp
,
(
*
s
))
};
mr_expr
(
e
)
}
//
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
9a4c6698
...
...
@@ -62,21 +62,6 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
(
fully_expanded
,
s
)
}
Some
(
normal
({
expander
:
exp
,
span
:
exp_sp
}))
=>
{
cx
.bt_push
(
ExpandedFrom
({
call_site
:
s
,
callie
:
{
name
:
*
extname
,
span
:
exp_sp
}}));
//convert the new-style invoc for the old-style macro
let
arg
=
base
::
tt_args_to_original_flavor
(
cx
,
pth
.span
,
(
*
tts
));
let
expanded
=
exp
(
cx
,
(
*
mac
)
.span
,
arg
,
None
);
//keep going, outside-in
let
fully_expanded
=
fld
.fold_expr
(
expanded
)
.node
;
cx
.bt_pop
();
(
fully_expanded
,
s
)
}
_
=>
{
cx
.span_fatal
(
pth
.span
,
fmt!
(
"'%s' is not a tt-style macro"
,
...
...
@@ -119,8 +104,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
ast
::
meta_list
(
ref
n
,
_
)
=>
(
*
n
)
};
match
exts
.find
(
mname
)
{
None
|
Some
(
normal
(
_
))
|
Some
(
normal_tt
(
_
))
|
Some
(
item_tt
(
*
))
=>
items
,
None
|
Some
(
normal_tt
(
_
))
|
Some
(
item_tt
(
*
))
=>
items
,
Some
(
item_decorator
(
dec_fn
))
=>
{
cx
.bt_push
(
ExpandedFrom
({
call_site
:
attr
.span
,
callie
:
{
name
:
copy
mname
,
...
...
@@ -262,23 +246,6 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
(
fully_expanded
,
sp
)
}
Some
(
normal
({
expander
:
exp
,
span
:
exp_sp
}))
=>
{
cx
.bt_push
(
ExpandedFrom
({
call_site
:
sp
,
callie
:
{
name
:
*
extname
,
span
:
exp_sp
}}));
//convert the new-style invoc for the old-style macro
let
arg
=
base
::
tt_args_to_original_flavor
(
cx
,
pth
.span
,
tts
);
let
exp_expr
=
exp
(
cx
,
mac
.span
,
arg
,
None
);
let
expanded
=
@
{
node
:
stmt_expr
(
exp_expr
,
cx
.next_id
()),
span
:
exp_expr
.span
};
//keep going, outside-in
let
fully_expanded
=
fld
.fold_stmt
(
expanded
)
.node
;
cx
.bt_pop
();
(
fully_expanded
,
sp
)
}
_
=>
{
cx
.span_fatal
(
pth
.span
,
fmt!
(
"'%s' is not a tt-style macro"
,
*
extname
))
...
...
src/libsyntax/ext/fmt.rs
浏览文件 @
9a4c6698
...
...
@@ -21,9 +21,12 @@
use
ext
::
build
::
*
;
export
expand_syntax_ext
;
fn
expand_syntax_ext
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args_no_max
(
cx
,
sp
,
arg
,
1u
,
~
"fmt"
);
fn
expand_syntax_ext
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
let
args
=
get_exprs_from_tts
(
cx
,
copy
tts
);
if
args
.len
()
==
0
{
cx
.span_fatal
(
sp
,
"fmt! takes at least 1 argument."
);
}
let
fmt
=
expr_to_str
(
cx
,
args
[
0
],
~
"first argument to fmt! must be a string literal."
);
...
...
@@ -37,7 +40,7 @@ fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: &str) -> ! {
parse_fmt_err_
(
cx
,
fmtspan
,
s
)
};
let
pieces
=
parse_fmt_string
(
fmt
,
parse_fmt_err
);
return
pieces_to_expr
(
cx
,
sp
,
pieces
,
args
);
mr_expr
(
pieces_to_expr
(
cx
,
sp
,
pieces
,
args
))
}
// FIXME (#2249): A lot of these functions for producing expressions can
...
...
src/libsyntax/ext/ident_to_str.rs
已删除
100644 → 0
浏览文件 @
e24ae850
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
base
::
*
;
use
build
::
mk_uniq_str
;
fn
expand_syntax_ext
(
cx
:
ext_ctxt
,
sp
:
codemap
::
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args
(
cx
,
sp
,
arg
,
1u
,
option
::
Some
(
1u
),
~
"ident_to_str"
);
return
mk_uniq_str
(
cx
,
sp
,
*
cx
.parse_sess
()
.interner
.get
(
expr_to_ident
(
cx
,
args
[
0u
],
~
"expected an ident"
)));
}
src/libsyntax/ext/source_util.rs
浏览文件 @
9a4c6698
...
...
@@ -23,63 +23,58 @@
export
expand_include_bin
;
/* line!(): expands to the current line number */
fn
expand_line
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
get_mac_args
(
cx
,
sp
,
arg
,
0u
,
option
::
Some
(
0u
),
~
"line
"
);
fn
expand_line
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
base
::
check_zero_tts
(
cx
,
sp
,
tts
,
"line!
"
);
let
loc
=
cx
.codemap
()
.lookup_char_pos
(
sp
.lo
);
return
mk_uint
(
cx
,
sp
,
loc
.line
);
base
::
mr_expr
(
mk_uint
(
cx
,
sp
,
loc
.line
))
}
/* col!(): expands to the current column number */
fn
expand_col
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
get_mac_args
(
cx
,
sp
,
arg
,
0u
,
option
::
Some
(
0u
),
~
"col
"
);
fn
expand_col
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
base
::
check_zero_tts
(
cx
,
sp
,
tts
,
"col!
"
);
let
loc
=
cx
.codemap
()
.lookup_char_pos
(
sp
.lo
);
return
mk_uint
(
cx
,
sp
,
loc
.col
.to_uint
());
base
::
mr_expr
(
mk_uint
(
cx
,
sp
,
loc
.col
.to_uint
()))
}
/* file!(): expands to the current filename */
/* The filemap (`loc.file`) contains a bunch more information we could spit
* out if we wanted. */
fn
expand_file
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
get_mac_args
(
cx
,
sp
,
arg
,
0u
,
option
::
Some
(
0u
),
~
"file
"
);
fn
expand_file
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
base
::
check_zero_tts
(
cx
,
sp
,
tts
,
"file!
"
);
let
Loc
{
file
:
@
FileMap
{
name
:
filename
,
_
},
_
}
=
cx
.codemap
()
.lookup_char_pos
(
sp
.lo
);
return
mk_uniq_str
(
cx
,
sp
,
filename
);
base
::
mr_expr
(
mk_uniq_str
(
cx
,
sp
,
filename
))
}
fn
expand_stringify
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args
(
cx
,
sp
,
arg
,
1u
,
option
::
Some
(
1u
),
~
"stringify"
);
let
s
=
pprust
::
expr_to_str
(
args
[
0
],
cx
.parse_sess
()
.interner
);
return
mk_uniq_str
(
cx
,
sp
,
s
);
fn
expand_stringify
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
let
s
=
pprust
::
tts_to_str
(
tts
,
cx
.parse_sess
()
.interner
);
base
::
mr_expr
(
mk_uniq_str
(
cx
,
sp
,
s
))
}
fn
expand_mod
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
get_mac_args
(
cx
,
sp
,
arg
,
0u
,
option
::
Some
(
0u
),
~
"file
"
);
return
mk_uniq_str
(
cx
,
sp
,
str
::
connect
(
cx
.mod_path
()
.map
(
|
x
|
cx
.str_of
(
*
x
)),
~
"::"
));
fn
expand_mod
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
]
)
->
base
::
mac_result
{
base
::
check_zero_tts
(
cx
,
sp
,
tts
,
"module_path!
"
);
base
::
mr_expr
(
mk_uniq_str
(
cx
,
sp
,
str
::
connect
(
cx
.mod_path
()
.map
(
|
x
|
cx
.str_of
(
*
x
)),
~
"::"
)))
}
fn
expand_include
(
cx
:
ext_ctxt
,
sp
:
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args
(
cx
,
sp
,
arg
,
1u
,
option
::
Some
(
1u
),
~
"include"
);
let
file
=
expr_to_str
(
cx
,
args
[
0
],
~
"include_str! requires a string"
);
fn
expand_include
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
let
file
=
get_single_str_from_tts
(
cx
,
sp
,
tts
,
"include!"
);
let
p
=
parse
::
new_sub_parser_from_file
(
cx
.parse_sess
(),
cx
.cfg
(),
&
res_rel_file
(
cx
,
sp
,
&
Path
(
file
)),
sp
);
return
p
.parse_expr
();
base
::
mr_expr
(
p
.parse_expr
())
}
fn
expand_include_str
(
cx
:
ext_ctxt
,
sp
:
codemap
::
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args
(
cx
,
sp
,
arg
,
1u
,
option
::
Some
(
1u
),
~
"include_str"
);
let
file
=
expr_to_str
(
cx
,
args
[
0
],
~
"include_str! requires a string"
);
fn
expand_include_str
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
let
file
=
get_single_str_from_tts
(
cx
,
sp
,
tts
,
"include_str!"
);
let
res
=
io
::
read_whole_file_str
(
&
res_rel_file
(
cx
,
sp
,
&
Path
(
file
)));
match
res
{
result
::
Ok
(
_
)
=>
{
/* Continue. */
}
...
...
@@ -88,21 +83,18 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
}
}
return
mk_uniq_str
(
cx
,
sp
,
result
::
unwrap
(
res
));
base
::
mr_expr
(
mk_uniq_str
(
cx
,
sp
,
result
::
unwrap
(
res
)))
}
fn
expand_include_bin
(
cx
:
ext_ctxt
,
sp
:
codemap
::
span
,
arg
:
ast
::
mac_arg
,
_
body
:
ast
::
mac_body
)
->
@
ast
::
expr
{
let
args
=
get_mac_args
(
cx
,
sp
,
arg
,
1u
,
option
::
Some
(
1u
),
~
"include_bin"
);
let
file
=
expr_to_str
(
cx
,
args
[
0
],
~
"include_bin! requires a string"
);
fn
expand_include_bin
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
~
[
ast
::
token_tree
])
->
base
::
mac_result
{
let
file
=
get_single_str_from_tts
(
cx
,
sp
,
tts
,
"include_bin!"
);
match
io
::
read_whole_file
(
&
res_rel_file
(
cx
,
sp
,
&
Path
(
file
)))
{
result
::
Ok
(
src
)
=>
{
let
u8_exprs
=
vec
::
map
(
src
,
|
char
|
{
mk_u8
(
cx
,
sp
,
*
char
)
});
return
mk_base_vec_e
(
cx
,
sp
,
u8_exprs
);
base
::
mr_expr
(
mk_base_vec_e
(
cx
,
sp
,
u8_exprs
))
}
result
::
Err
(
ref
e
)
=>
{
cx
.parse_sess
()
.span_diagnostic
.handler
()
.fatal
((
*
e
))
...
...
src/libsyntax/print/pp.rs
浏览文件 @
9a4c6698
...
...
@@ -154,8 +154,7 @@ fn mk_printer(out: io::Writer, linewidth: uint) -> printer {
mut
top
:
0
,
mut
bottom
:
0
,
print_stack
:
DVec
(),
mut
pending_indentation
:
0
,
mut
token_tree_last_was_ident
:
false
})
mut
pending_indentation
:
0
})
}
...
...
@@ -261,7 +260,6 @@ fn mk_printer(out: io::Writer, linewidth: uint) -> printer {
print_stack
:
DVec
<
print_stack_elt
>
,
// buffered indentation to avoid writing trailing whitespace
mut
pending_indentation
:
int
,
mut
token_tree_last_was_ident
:
bool
};
enum
printer
{
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
9a4c6698
...
...
@@ -118,6 +118,10 @@ fn tt_to_str(tt: ast::token_tree, intr: @ident_interner) -> ~str {
to_str
(
tt
,
print_tt
,
intr
)
}
fn
tts_to_str
(
tts
:
&
[
ast
::
token_tree
],
intr
:
@
ident_interner
)
->
~
str
{
to_str
(
tts
,
print_tts
,
intr
)
}
fn
stmt_to_str
(
s
:
ast
::
stmt
,
intr
:
@
ident_interner
)
->
~
str
{
to_str
(
s
,
print_stmt
,
intr
)
}
...
...
@@ -584,9 +588,7 @@ fn print_item(s: ps, &&item: @ast::item) {
print_ident
(
s
,
item
.ident
);
cbox
(
s
,
indent_unit
);
popen
(
s
);
for
(
*
tts
)
.each
|
tt
|
{
print_tt
(
s
,
*
tt
);
}
print_tts
(
s
,
*
tts
);
pclose
(
s
);
end
(
s
);
}
...
...
@@ -736,17 +738,9 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
/// expression arguments as expressions). It can be done! I think.
fn
print_tt
(
s
:
ps
,
tt
:
ast
::
token_tree
)
{
match
tt
{
ast
::
tt_delim
(
ref
tts
)
=>
for
(
*
tts
)
.each
()
|
tt_elt
|
{
print_tt
(
s
,
*
tt_elt
);
},
ast
::
tt_delim
(
ref
tts
)
=>
print_tts
(
s
,
*
tts
),
ast
::
tt_tok
(
_
,
ref
tk
)
=>
{
match
(
*
tk
)
{
parse
::
token
::
IDENT
(
*
)
=>
{
// don't let idents run together
if
s
.s.token_tree_last_was_ident
{
word
(
s
.s
,
~
" "
)
}
s
.s.token_tree_last_was_ident
=
true
;
}
_
=>
{
s
.s.token_tree_last_was_ident
=
false
;
}
}
word
(
s
.s
,
parse
::
token
::
to_str
(
s
.intr
,
(
*
tk
)));
word
(
s
.s
,
parse
::
token
::
to_str
(
s
.intr
,
(
*
tk
)));
}
ast
::
tt_seq
(
_
,
ref
tts
,
ref
sep
,
zerok
)
=>
{
word
(
s
.s
,
~
"$("
);
...
...
@@ -757,16 +751,25 @@ fn print_tt(s: ps, tt: ast::token_tree) {
None
=>
()
}
word
(
s
.s
,
if
zerok
{
~
"*"
}
else
{
~
"+"
});
s
.s.token_tree_last_was_ident
=
false
;
}
ast
::
tt_nonterminal
(
_
,
name
)
=>
{
word
(
s
.s
,
~
"$"
);
print_ident
(
s
,
name
);
s
.s.token_tree_last_was_ident
=
true
;
}
}
}
fn
print_tts
(
s
:
ps
,
&&
tts
:
&
[
ast
::
token_tree
])
{
ibox
(
s
,
0
);
for
tts
.eachi
|
i
,
tt
|
{
if
i
!=
0
{
space
(
s
.s
);
}
print_tt
(
s
,
*
tt
);
}
end
(
s
);
}
fn
print_variant
(
s
:
ps
,
v
:
ast
::
variant
)
{
print_visibility
(
s
,
v
.node.vis
);
match
v
.node.kind
{
...
...
@@ -1001,7 +1004,7 @@ fn print_mac(s: ps, m: ast::mac) {
print_path
(
s
,
pth
,
false
);
word
(
s
.s
,
~
"!"
);
popen
(
s
);
for
(
*
tts
)
.each
()
|
tt
|
{
print_tt
(
s
,
*
tt
);
}
print_tts
(
s
,
*
tts
);
pclose
(
s
);
}
}
...
...
src/libsyntax/syntax.rc
浏览文件 @
9a4c6698
...
...
@@ -109,9 +109,6 @@ mod ext {
#[path = "ext/concat_idents.rs"]
mod concat_idents;
#[legacy_exports]
#[path = "ext/ident_to_str.rs"]
mod ident_to_str;
#[legacy_exports]
#[path = "ext/log_syntax.rs"]
mod log_syntax;
#[legacy_exports]
...
...
src/test/compile-fail/ext-noname.rs
已删除
100644 → 0
浏览文件 @
e24ae850
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:expected a syntax expander name
fn
main
()
{
#
();
}
src/test/compile-fail/extenv-no-args.rs
浏览文件 @
9a4c6698
...
...
@@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: env! takes
between 1 and 1 arguments
// error-pattern: env! takes
1 argument
fn
main
()
{
env!
();
}
src/test/compile-fail/extenv-too-many-args.rs
浏览文件 @
9a4c6698
...
...
@@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: env! takes
between 1 and 1 arguments
// error-pattern: env! takes
1 argument
fn
main
()
{
env!
(
"one"
,
"two"
);
}
src/test/compile-fail/extfmt-no-args.rs
浏览文件 @
9a4c6698
...
...
@@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:fmt!
needs at least 1 arguments
// error-pattern:fmt!
takes at least 1 argument
fn
main
()
{
fmt!
();
}
src/test/run-pass/class-attributes-1.rs
浏览文件 @
9a4c6698
...
...
@@ -16,7 +16,7 @@ struct cat {
impl
cat
:
Drop
{
#[cat_dropper]
fn
finalize
(
&
self
)
{
error!
(
"%s landed on hir feet"
,
self
.
name
);
}
fn
finalize
(
&
self
)
{
error!
(
"%s landed on hir feet"
,
self
.
name
);
}
}
...
...
src/test/run-pass/syntax-extension-minor.rs
浏览文件 @
9a4c6698
...
...
@@ -13,6 +13,6 @@ fn main() {
let
asdf_fdsa
=
~
"<.<"
;
assert
(
concat_idents!
(
asd
,
f_f
,
dsa
)
==
~
"<.<"
);
assert
(
ident_to_str
!
(
use_mention_distinction
)
==
assert
(
stringify
!
(
use_mention_distinction
)
==
~
"use_mention_distinction"
);
}
src/test/run-pass/syntax-extension-source-utils.rs
浏览文件 @
9a4c6698
...
...
@@ -24,7 +24,7 @@ fn main() {
assert
(
line!
()
==
24
);
assert
(
col!
()
==
11
);
assert
(
file!
()
.ends_with
(
~
"syntax-extension-source-utils.rs"
));
assert
(
stringify!
((
2
*
3
)
+
5
)
==
~
"(
2 * 3
) + 5"
);
assert
(
stringify!
((
2
*
3
)
+
5
)
==
~
"(
2 * 3
) + 5"
);
assert
(
include!
(
"syntax-extension-source-utils-files/includeme.fragment"
)
==
~
"victory robot 6"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录