Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5d72dae1
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,发现更多精彩内容 >>
提交
5d72dae1
编写于
11月 24, 2010
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Parse tag items. Currently segfaults in copy glue.
上级
f55f46af
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
75 addition
and
0 deletion
+75
-0
src/comp/front/ast.rs
src/comp/front/ast.rs
+3
-0
src/comp/front/parser.rs
src/comp/front/parser.rs
+49
-0
src/comp/middle/fold.rs
src/comp/middle/fold.rs
+23
-0
未找到文件。
src/comp/front/ast.rs
浏览文件 @
5d72dae1
...
...
@@ -153,11 +153,14 @@
type
_
mod
=
rec
(
vec
[
@
item
]
items
,
hashmap
[
ident
,
uint
]
index
);
type
variant
=
rec
(
str
name
,
vec
[
@
ty
]
args
);
type
item
=
spanned
[
item_
];
tag
item_
{
item_fn
(
ident
,
_
fn
,
def_id
,
ann
);
item_mod
(
ident
,
_
mod
,
def_id
);
item_ty
(
ident
,
@
ty
,
def_id
,
ann
);
item_tag
(
ident
,
vec
[
variant
],
def_id
);
}
...
...
src/comp/front/parser.rs
浏览文件 @
5d72dae1
...
...
@@ -1019,6 +1019,52 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
ret
tup
(
id
,
@
spanned
(
lo
,
hi
,
item
));
}
impure
fn
parse_item_tag
(
parser
p
)
->
tup
(
ast
.ident
,
@
ast
.item
)
{
auto
lo
=
p
.get_span
();
expect
(
p
,
token
.TAG
);
auto
id
=
parse_ident
(
p
);
let
vec
[
ast
.variant
]
variants
=
vec
();
expect
(
p
,
token
.LBRACE
);
while
(
p
.peek
()
!=
token
.RBRACE
)
{
auto
tok
=
p
.peek
();
alt
(
tok
)
{
case
(
token
.IDENT
(
?
name
))
{
p
.bump
();
auto
args
;
alt
(
p
.peek
())
{
case
(
token
.LPAREN
)
{
auto
f
=
parse_ty
;
auto
tys
=
parse_seq
[
@
ast
.ty
](
token
.LPAREN
,
token
.RPAREN
,
some
(
token
.COMMA
),
f
,
p
);
args
=
tys
.node
;
}
case
(
_
)
{
args
=
vec
();
}
}
expect
(
p
,
token
.SEMI
);
variants
+=
vec
(
rec
(
name
=
name
,
args
=
args
));
}
case
(
token
.RBRACE
)
{
/* empty */
}
case
(
_
)
{
p
.err
(
"expected name of variant or '}' but found "
+
token
.to_str
(
tok
));
}
}
}
p
.bump
();
auto
hi
=
p
.get_span
();
auto
item
=
ast
.item_tag
(
id
,
variants
,
p
.next_def_id
());
ret
tup
(
id
,
@
spanned
(
lo
,
hi
,
item
));
}
impure
fn
parse_item
(
parser
p
)
->
tup
(
ast
.ident
,
@
ast
.item
)
{
alt
(
p
.peek
())
{
case
(
token
.FN
)
{
...
...
@@ -1030,6 +1076,9 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
case
(
token
.TYPE
)
{
ret
parse_item_type
(
p
);
}
case
(
token
.TAG
)
{
ret
parse_item_tag
(
p
);
}
case
(
?
t
)
{
p
.err
(
"expected item but found "
+
token
.to_str
(
t
));
}
...
...
src/comp/middle/fold.rs
浏览文件 @
5d72dae1
...
...
@@ -148,6 +148,10 @@
(
fn
(
&
ENV
e
,
&
span
sp
,
ident
ident
,
@
ty
t
,
def_id
id
,
ann
a
)
->
@
item
)
fold_item_ty
,
(
fn
(
&
ENV
e
,
&
span
sp
,
ident
ident
,
vec
[
ast
.variant
]
variants
,
def_id
id
)
->
@
item
)
fold_item_tag
,
// Additional nodes.
(
fn
(
&
ENV
e
,
&
span
sp
,
&
ast
.block_
)
->
block
)
fold_block
,
...
...
@@ -495,6 +499,18 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
let
@
ast
.ty
ty_
=
fold_ty
[
ENV
](
env_
,
fld
,
ty
);
ret
fld
.fold_item_ty
(
env_
,
i
.span
,
ident
,
ty_
,
id
,
ann
);
}
case
(
ast
.item_tag
(
?
ident
,
?
variants
,
?
id
))
{
let
vec
[
ast
.variant
]
new_variants
=
vec
();
for
(
ast
.variant
v
in
variants
)
{
let
vec
[
@
ast
.ty
]
new_args
=
vec
();
for
(
@
ast
.ty
t
in
v
.args
)
{
new_args
+=
vec
(
fold_ty
[
ENV
](
env_
,
fld
,
t
));
}
new_variants
+=
rec
(
name
=
v
.name
,
args
=
new_args
);
}
ret
fld
.fold_item_tag
(
env_
,
i
.span
,
ident
,
new_variants
,
id
);
}
}
fail
;
...
...
@@ -723,6 +739,12 @@ fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i,
ret
@
respan
(
sp
,
ast
.item_ty
(
i
,
t
,
id
,
a
));
}
fn
identity_fold_item_tag
[
ENV
](
&
ENV
e
,
&
span
sp
,
ident
i
,
vec
[
ast
.variant
]
variants
,
def_id
id
)
->
@
item
{
ret
@
respan
(
sp
,
ast
.item_tag
(
i
,
variants
,
id
));
}
// Additional identities.
...
...
@@ -832,6 +854,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_item_fn
=
bind
identity_fold_item_fn
[
ENV
](
_
,
_
,
_
,
_
,
_
,
_
),
fold_item_mod
=
bind
identity_fold_item_mod
[
ENV
](
_
,
_
,
_
,
_
,
_
),
fold_item_ty
=
bind
identity_fold_item_ty
[
ENV
](
_
,
_
,
_
,
_
,
_
,
_
),
fold_item_tag
=
bind
identity_fold_item_tag
[
ENV
](
_
,
_
,
_
,
_
,
_
),
fold_block
=
bind
identity_fold_block
[
ENV
](
_
,
_
,
_
),
fold_fn
=
bind
identity_fold_fn
[
ENV
](
_
,
_
,
_
,
_
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录