Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9528c347
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,发现更多精彩内容 >>
提交
9528c347
编写于
2月 23, 2011
作者:
B
Brian Anderson
提交者:
Graydon Hoare
3月 02, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Begin implementing #fmt in rustc
上级
e2d36e00
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
141 addition
and
4 deletion
+141
-4
src/comp/front/ast.rs
src/comp/front/ast.rs
+12
-1
src/comp/front/extfmt.rs
src/comp/front/extfmt.rs
+84
-0
src/comp/front/parser.rs
src/comp/front/parser.rs
+34
-1
src/comp/rustc.rc
src/comp/rustc.rc
+1
-0
src/test/run-pass/syntax-extension-fmt.rs
src/test/run-pass/syntax-extension-fmt.rs
+10
-2
未找到文件。
src/comp/front/ast.rs
浏览文件 @
9528c347
...
...
@@ -185,7 +185,7 @@
expr_field
(
@
expr
,
ident
,
ann
);
expr_index
(
@
expr
,
@
expr
,
ann
);
expr_path
(
path
,
option
.t
[
def
],
ann
);
expr_ext
(
path
,
vec
[
@
expr
],
option
.t
[
@
expr
],
ann
);
expr_ext
(
path
,
vec
[
@
expr
],
option
.t
[
@
expr
],
option
.t
[
@
expr
],
ann
);
expr_fail
;
expr_ret
(
option
.t
[
@
expr
]);
expr_put
(
option
.t
[
@
expr
]);
...
...
@@ -363,6 +363,17 @@ fn is_call_expr(@expr e) -> bool {
}
}
fn
is_ext_expr
(
@
expr
e
)
->
bool
{
alt
(
e
.node
)
{
case
(
expr_ext
(
_
,
_
,
_
,
_
,
_
))
{
ret
true
;
}
case
(
_
)
{
ret
false
;
}
}
}
//
// Local Variables:
// mode: rust
...
...
src/comp/front/extfmt.rs
0 → 100644
浏览文件 @
9528c347
/* The 'fmt' extension is modeled on the posix printf system.
*
* A posix conversion ostensibly looks like this:
*
* %[parameter][flags][width][.precision][length]type
*
* Given the different numeric type bestiary we have, we omit the 'length'
* parameter and support slightly different conversions for 'type':
*
* %[parameter][flags][width][.precision]type
*
* we also only support translating-to-rust a tiny subset of the possible
* combinations at the moment.
*/
use
std
;
import
std
.option
;
tag
signedness
{
signed
;
unsigned
;
}
tag
caseness
{
case_upper
;
case_lower
;
}
tag
ty
{
ty_bool
;
ty_str
;
ty_char
;
ty_int
(
signedness
);
ty_bits
;
ty_hex
(
caseness
);
// FIXME: More types
}
tag
flag
{
flag_left_justify
;
flag_left_zero_pad
;
flag_left_space_pad
;
flag_plus_if_positive
;
flag_alternate
;
}
tag
count
{
count_is
(
int
);
count_is_param
(
int
);
count_is_next_param
;
count_implied
;
}
// A formatted conversion from an expression to a string
tag
conv
{
conv_param
(
option
.t
[
int
]);
conv_flags
(
vec
[
flag
]);
conv_width
(
count
);
conv_precision
(
count
);
conv_ty
(
ty
);
}
// A fragment of the output sequence
tag
piece
{
piece_string
(
str
);
piece_conv
(
str
);
}
fn
expand_syntax_ext
(
vec
[
@
ast
.expr
]
args
,
option
.t
[
@
ast
.expr
]
body
)
->
@
ast
.expr
{
fail
;
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//
src/comp/front/parser.rs
浏览文件 @
9528c347
...
...
@@ -656,7 +656,10 @@ fn is_ident(token.token t) -> bool {
some
(
token
.COMMA
),
pf
,
p
);
hi
=
es
.span
;
ex
=
ast
.expr_ext
(
pth
,
es
.node
,
none
[
@
ast
.expr
],
ast
.ann_none
);
ex
=
ast
.expr_ext
(
pth
,
es
.node
,
none
[
@
ast
.expr
],
none
[
@
ast
.expr
],
ast
.ann_none
);
// FIXME: Here is probably not the right place for this
ex
=
expand_syntax_ext
(
p
,
@
spanned
(
lo
,
hi
,
ex
))
.node
;
}
case
(
token
.FAIL
)
{
...
...
@@ -736,6 +739,36 @@ fn is_ident(token.token t) -> bool {
ret
@
spanned
(
lo
,
hi
,
ex
);
}
/*
* FIXME: This is a crude approximation of the syntax-extension system,
* for purposes of prototyping and/or hard-wiring any extensions we
* wish to use while bootstrapping. The eventual aim is to permit
* loading rust crates to process extensions, but this will likely
* require a rust-based frontend, or an ocaml-FFI-based connection to
* rust crates. At the moment we have neither.
*/
impure
fn
expand_syntax_ext
(
parser
p
,
@
ast
.expr
ext
)
->
@
ast
.expr
{
check
(
ast
.is_ext_expr
(
ext
));
alt
(
ext
.node
)
{
case
(
ast
.expr_ext
(
?
path
,
?
args
,
?
body
,
_
,
?
ann
))
{
check
(
_
vec
.len
[
ast
.ident
](
path
.node.idents
)
>
0u
);
auto
extname
=
path
.node.idents
.
(
0
);
if
(
_
str
.eq
(
extname
,
"fmt"
))
{
auto
expanded
=
extfmt
.expand_syntax_ext
(
args
,
body
);
check
(
ast
.is_ext_expr
(
expanded
));
auto
newexpr
=
ast
.expr_ext
(
path
,
args
,
body
,
some
[
@
ast
.expr
](
expanded
),
ann
);
ret
@
spanned
(
ext
.span
,
ext
.span
,
newexpr
);
}
else
{
p
.err
(
"unknown syntax extension"
);
}
}
}
fail
;
}
impure
fn
extend_expr_by_ident
(
parser
p
,
span
lo
,
span
hi
,
@
ast
.expr
e
,
ast
.ident
i
)
->
@
ast
.expr
{
auto
e_
=
e
.node
;
...
...
src/comp/rustc.rc
浏览文件 @
9528c347
...
...
@@ -5,6 +5,7 @@ use std;
mod
front
{
mod
ast
;
mod
extfmt
;
mod
lexer
;
mod
parser
;
mod
token
;
...
...
src/test/run-pass/syntax-extension-fmt.rs
浏览文件 @
9528c347
use
std
;
import
std
._str
;
fn
test
(
str
actual
,
str
expected
)
{
log
actual
;
log
expected
;
check
(
_
str
.eq
(
actual
,
expected
));
}
fn
main
()
{
auto
s
=
#
fmt
(
"hello %d friends and %s things"
,
10
,
"formatted"
);
log
s
;
test
(
#
fmt
(
"hello %d friends and %s things"
,
10
,
"formatted"
),
"hello 10 friends and formatted things"
)
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录