Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
33b342e8
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,发现更多精彩内容 >>
提交
33b342e8
编写于
1月 20, 2011
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Teach ast and parser about linear for expressions.
上级
9d3ebd6a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
28 deletion
+56
-28
src/comp/front/ast.rs
src/comp/front/ast.rs
+1
-0
src/comp/front/parser.rs
src/comp/front/parser.rs
+55
-28
未找到文件。
src/comp/front/ast.rs
浏览文件 @
33b342e8
...
...
@@ -150,6 +150,7 @@
expr_cast
(
@
expr
,
@
ty
,
ann
);
expr_if
(
@
expr
,
block
,
option
.t
[
block
],
ann
);
expr_while
(
@
expr
,
block
,
ann
);
expr_for
(
@
local
,
@
expr
,
block
,
ann
);
expr_do_while
(
block
,
@
expr
,
ann
);
expr_alt
(
@
expr
,
vec
[
arm
],
ann
);
expr_block
(
block
,
ann
);
...
...
src/comp/front/parser.rs
浏览文件 @
33b342e8
...
...
@@ -891,6 +891,29 @@ fn append_dot_ident_to_expr(span lo, span hi,
ret
@
spanned
(
lo
,
hi
,
ast
.expr_if
(
cond
,
thn
,
els
,
ast
.ann_none
));
}
impure
fn
parse_for_expr
(
parser
p
)
->
@
ast
.expr
{
auto
lo
=
p
.get_span
();
auto
hi
=
lo
;
expect
(
p
,
token
.FOR
);
expect
(
p
,
token
.LPAREN
);
let
@
ast
.local
local
;
if
(
p
.peek
()
==
token
.AUTO
)
{
p
.bump
();
local
=
parse_auto_local
(
p
);
}
else
{
local
=
parse_typed_local
(
p
);
}
expect
(
p
,
token
.IN
);
auto
seq
=
parse_expr
(
p
);
expect
(
p
,
token
.RPAREN
);
auto
body
=
parse_block
(
p
);
hi
=
body
.span
;
ret
@
spanned
(
lo
,
hi
,
ast
.expr_for
(
local
,
seq
,
body
,
ast
.ann_none
));
}
impure
fn
parse_while_expr
(
parser
p
)
->
@
ast
.expr
{
auto
lo
=
p
.get_span
();
auto
hi
=
lo
;
...
...
@@ -979,6 +1002,9 @@ fn append_dot_ident_to_expr(span lo, span hi,
case
(
token
.IF
)
{
ret
parse_if_expr
(
p
);
}
case
(
token
.FOR
)
{
ret
parse_for_expr
(
p
);
}
case
(
token
.WHILE
)
{
ret
parse_while_expr
(
p
);
}
...
...
@@ -1052,43 +1078,40 @@ fn append_dot_ident_to_expr(span lo, span hi,
ret
@
spanned
(
lo
,
hi
,
pat
);
}
impure
fn
parse_let
(
parser
p
)
->
@
ast
.decl
{
auto
lo
=
p
.get_span
();
expect
(
p
,
token
.LET
);
auto
ty
=
parse_ty
(
p
);
impure
fn
parse_local
(
&
option
.t
[
@
ast
.ty
]
tyopt
,
parser
p
)
->
@
ast
.local
{
auto
ident
=
parse_ident
(
p
);
auto
init
=
parse_initializer
(
p
);
ret
@
rec
(
ty
=
tyopt
,
infer
=
false
,
ident
=
ident
,
init
=
init
,
id
=
p
.next_def_id
(),
ann
=
ast
.ann_none
);
}
auto
hi
=
p
.get_span
();
impure
fn
parse_typed_local
(
parser
p
)
->
@
ast
.local
{
auto
ty
=
parse_ty
(
p
);
ret
parse_local
(
some
(
ty
),
p
);
}
let
ast
.local
local
=
rec
(
ty
=
some
(
ty
),
infer
=
false
,
ident
=
ident
,
init
=
init
,
id
=
p
.next_def_id
(),
ann
=
ast
.ann_none
);
impure
fn
parse_auto_local
(
parser
p
)
->
@
ast
.local
{
ret
parse_local
(
none
[
@
ast
.ty
],
p
);
}
ret
@
spanned
(
lo
,
hi
,
ast
.decl_local
(
@
local
));
impure
fn
parse_let
(
parser
p
)
->
@
ast
.decl
{
auto
lo
=
p
.get_span
();
expect
(
p
,
token
.LET
);
auto
local
=
parse_typed_local
(
p
);
auto
hi
=
p
.get_span
();
ret
@
spanned
(
lo
,
hi
,
ast
.decl_local
(
local
));
}
impure
fn
parse_auto
(
parser
p
)
->
@
ast
.decl
{
auto
lo
=
p
.get_span
();
expect
(
p
,
token
.AUTO
);
auto
ident
=
parse_ident
(
p
);
auto
init
=
parse_initializer
(
p
);
auto
local
=
parse_auto_local
(
p
);
auto
hi
=
p
.get_span
();
let
ast
.local
local
=
rec
(
ty
=
none
[
@
ast
.ty
],
infer
=
true
,
ident
=
ident
,
init
=
init
,
id
=
p
.next_def_id
(),
ann
=
ast
.ann_none
);
ret
@
spanned
(
lo
,
hi
,
ast
.decl_local
(
@
local
));
ret
@
spanned
(
lo
,
hi
,
ast
.decl_local
(
local
));
}
impure
fn
parse_stmt
(
parser
p
)
->
@
ast
.stmt
{
...
...
@@ -1150,6 +1173,11 @@ fn append_dot_ident_to_expr(span lo, span hi,
ret
@
spanned
(
lo
,
e
.span
,
ast
.stmt_expr
(
e
));
}
case
(
token
.FOR
)
{
auto
e
=
parse_expr
(
p
);
ret
@
spanned
(
lo
,
e
.span
,
ast
.stmt_expr
(
e
));
}
case
(
token
.WHILE
)
{
auto
e
=
parse_expr
(
p
);
ret
@
spanned
(
lo
,
e
.span
,
ast
.stmt_expr
(
e
));
...
...
@@ -1279,6 +1307,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
case
(
ast
.expr_lit
(
_
,
_
))
{
ret
true
;
}
case
(
ast
.expr_cast
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
ast
.expr_if
(
_
,
_
,
_
,
_
))
{
ret
false
;
}
case
(
ast
.expr_for
(
_
,
_
,
_
,
_
))
{
ret
false
;
}
case
(
ast
.expr_while
(
_
,
_
,
_
))
{
ret
false
;
}
case
(
ast
.expr_do_while
(
_
,
_
,
_
))
{
ret
false
;
}
case
(
ast
.expr_alt
(
_
,
_
,
_
))
{
ret
false
;
}
...
...
@@ -1289,10 +1318,8 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
case
(
ast
.expr_field
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
ast
.expr_index
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
ast
.expr_path
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
_
)
{
fail
;
}
}
}
case
(
_
)
{
fail
;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录