Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
596face2
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,发现更多精彩内容 >>
提交
596face2
编写于
3月 04, 2011
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Parse (and generally ignore) constraints and constrained types.
上级
95c0cefd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
1 deletion
+76
-1
src/comp/front/ast.rs
src/comp/front/ast.rs
+9
-0
src/comp/front/parser.rs
src/comp/front/parser.rs
+67
-1
未找到文件。
src/comp/front/ast.rs
浏览文件 @
596face2
...
...
@@ -231,8 +231,17 @@
ty_path
(
path
,
option
.t
[
def
]);
ty_mutable
(
@
ty
);
ty_type
;
ty_constr
(
@
ty
,
vec
[
@
constr
]);
}
tag
constr_arg_
{
carg_base
;
carg_ident
(
ident
);
}
type
constr_arg
=
spanned
[
constr_arg_
];
type
constr_
=
rec
(
path
path
,
vec
[
@
constr_arg
]
args
);
type
constr
=
spanned
[
constr_
];
type
arg
=
rec
(
mode
mode
,
@
ty
ty
,
ident
ident
,
def_id
id
);
type
fn_decl
=
rec
(
effect
effect
,
vec
[
arg
]
inputs
,
...
...
src/comp/front/parser.rs
浏览文件 @
596face2
...
...
@@ -199,6 +199,10 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
auto
inputs
=
parse_seq
[
rec
(
ast
.mode
mode
,
@
ast
.ty
ty
)](
token
.LPAREN
,
token
.RPAREN
,
some
(
token
.COMMA
),
f
,
p
);
// FIXME: dropping constrs on the floor at the moment.
// pick them up when they're used by typestate pass.
parse_constrs
(
p
);
let
@
ast
.ty
output
;
if
(
p
.peek
()
==
token
.RARROW
)
{
p
.bump
();
...
...
@@ -254,6 +258,62 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
ret
rec
(
ident
=
id
,
ty
=
ty
);
}
impure
fn
parse_constr_arg
(
parser
p
)
->
@
ast
.constr_arg
{
auto
lo
=
p
.get_span
();
auto
carg
=
ast
.carg_base
;
if
(
p
.peek
()
==
token
.BINOP
(
token
.STAR
))
{
p
.bump
();
}
else
{
carg
=
ast
.carg_ident
(
parse_ident
(
p
));
}
ret
@
spanned
(
lo
,
lo
,
carg
);
}
impure
fn
parse_ty_constr
(
parser
p
)
->
@
ast
.constr
{
auto
lo
=
p
.get_span
();
auto
path
=
parse_path
(
p
,
GREEDY
);
auto
pf
=
parse_constr_arg
;
auto
args
=
parse_seq
[
@
ast
.constr_arg
](
token
.LPAREN
,
token
.RPAREN
,
some
(
token
.COMMA
),
pf
,
p
);
auto
hi
=
args
.span
;
ret
@
spanned
(
lo
,
hi
,
rec
(
path
=
path
,
args
=
args
.node
));
}
impure
fn
parse_constrs
(
parser
p
)
->
common
.spanned
[
vec
[
@
ast
.constr
]]
{
auto
lo
=
p
.get_span
();
auto
hi
=
lo
;
let
vec
[
@
ast
.constr
]
constrs
=
vec
();
if
(
p
.peek
()
==
token
.COLON
)
{
p
.bump
();
let
bool
more
=
true
;
while
(
more
)
{
alt
(
p
.peek
())
{
case
(
token
.IDENT
(
_
))
{
auto
constr
=
parse_ty_constr
(
p
);
hi
=
constr
.span
;
append
[
@
ast
.constr
](
constrs
,
constr
);
if
(
p
.peek
()
==
token
.COMMA
)
{
p
.bump
();
more
=
false
;
}
}
case
(
_
)
{
more
=
false
;
}
}
}
}
ret
spanned
(
lo
,
hi
,
constrs
);
}
impure
fn
parse_ty_constrs
(
@
ast
.ty
t
,
parser
p
)
->
@
ast
.ty
{
if
(
p
.peek
()
==
token
.COLON
)
{
auto
constrs
=
parse_constrs
(
p
);
ret
@
spanned
(
t
.span
,
constrs
.span
,
ast
.ty_constr
(
t
,
constrs
.node
));
}
ret
t
;
}
impure
fn
parse_ty
(
parser
p
)
->
@
ast
.ty
{
auto
lo
=
p
.get_span
();
auto
hi
=
lo
;
...
...
@@ -368,7 +428,8 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
fail
;
}
}
ret
@
spanned
(
lo
,
hi
,
t
);
ret
parse_ty_constrs
(
@
spanned
(
lo
,
hi
,
t
),
p
);
}
impure
fn
parse_arg
(
parser
p
)
->
ast
.arg
{
...
...
@@ -1676,6 +1737,11 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
pf
,
p
);
let
@
ast
.ty
output
;
// FIXME: dropping constrs on the floor at the moment.
// pick them up when they're used by typestate pass.
parse_constrs
(
p
);
if
(
p
.peek
()
==
token
.RARROW
)
{
p
.bump
();
output
=
parse_ty
(
p
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录