Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
eaf9e056
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,发现更多精彩内容 >>
提交
eaf9e056
编写于
11月 02, 2011
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make 'lambda(...) -> ...' parse as a type
上级
4e9b8a28
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
26 deletion
+10
-26
doc/tutorial/func.md
doc/tutorial/func.md
+1
-4
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+9
-22
未找到文件。
doc/tutorial/func.md
浏览文件 @
eaf9e056
...
...
@@ -25,13 +25,10 @@ expected to return.
## Closures
FIXME Either move entirely to fn~/fn@ nomenclature, or fix compiler to
accept lambda as a type
Normal Rust functions (declared with
`fn`
) do not close over their
environment. A
`lambda`
expression can be used to create a closure.
fn make_plus_function(x: int) ->
fn@
(int) -> int {
fn make_plus_function(x: int) ->
lambda
(int) -> int {
lambda(y: int) -> int { x + y }
}
let plus_two = make_plus_function(2);
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
eaf9e056
...
...
@@ -299,7 +299,7 @@ fn parse_fn_input_ty(p: parser) -> ast::ty_arg {
ret
ast
::
ty_fn
(
proto
,
inputs
.node
,
ret_ty
,
ret_style
,
constrs
);
}
fn
parse_ty_obj
(
p
:
parser
,
&
hi
:
uint
)
->
ast
::
ty_
{
fn
parse_ty_obj
(
p
:
parser
)
->
ast
::
ty_
{
fn
parse_method_sig
(
p
:
parser
)
->
ast
::
ty_method
{
let
flo
=
p
.get_lo_pos
();
let
proto
:
ast
::
proto
=
parse_method_proto
(
p
);
...
...
@@ -320,7 +320,6 @@ fn parse_method_sig(p: parser) -> ast::ty_method {
}
let
meths
=
parse_seq
(
token
::
LBRACE
,
token
::
RBRACE
,
none
,
parse_method_sig
,
p
);
hi
=
meths
.span.hi
;
ret
ast
::
ty_obj
(
meths
.node
);
}
...
...
@@ -475,7 +474,6 @@ fn parse_ret_ty(p: parser, n_args: uint) -> (ast::ret_style, @ast::ty) {
fn
parse_ty
(
p
:
parser
,
colons_before_params
:
bool
)
->
@
ast
::
ty
{
let
lo
=
p
.get_lo_pos
();
let
hi
=
lo
;
let
t
:
ast
::
ty_
;
// FIXME: do something with this
...
...
@@ -518,7 +516,6 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
}
else
if
p
.peek
()
==
token
::
LPAREN
{
p
.bump
();
if
p
.peek
()
==
token
::
RPAREN
{
hi
=
p
.get_hi_pos
();
p
.bump
();
t
=
ast
::
ty_nil
;
}
else
{
...
...
@@ -530,54 +527,44 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
if
vec
::
len
(
ts
)
==
1u
{
t
=
ts
[
0
]
.node
;
}
else
{
t
=
ast
::
ty_tup
(
ts
);
}
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
RPAREN
);
}
}
else
if
p
.peek
()
==
token
::
AT
{
p
.bump
();
let
mt
=
parse_mt
(
p
);
hi
=
mt
.ty.span.hi
;
t
=
ast
::
ty_box
(
mt
);
t
=
ast
::
ty_box
(
parse_mt
(
p
));
}
else
if
p
.peek
()
==
token
::
TILDE
{
p
.bump
();
let
mt
=
parse_mt
(
p
);
hi
=
mt
.ty.span.hi
;
t
=
ast
::
ty_uniq
(
mt
);
t
=
ast
::
ty_uniq
(
parse_mt
(
p
));
}
else
if
p
.peek
()
==
token
::
BINOP
(
token
::
STAR
)
{
p
.bump
();
let
mt
=
parse_mt
(
p
);
hi
=
mt
.ty.span.hi
;
t
=
ast
::
ty_ptr
(
mt
);
t
=
ast
::
ty_ptr
(
parse_mt
(
p
));
}
else
if
p
.peek
()
==
token
::
LBRACE
{
let
elems
=
parse_seq
(
token
::
LBRACE
,
token
::
RBRACE
,
some
(
token
::
COMMA
),
parse_ty_field
,
p
);
hi
=
elems
.span.hi
;
let
hi
=
elems
.span.hi
;
t
=
ast
::
ty_rec
(
elems
.node
);
if
p
.peek
()
==
token
::
COLON
{
p
.bump
();
t
=
ast
::
ty_constr
(
@
spanned
(
lo
,
hi
,
t
),
t
=
ast
::
ty_constr
(
@
spanned
(
lo
,
hi
,
t
),
parse_type_constraints
(
p
));
}
}
else
if
p
.peek
()
==
token
::
LBRACKET
{
expect
(
p
,
token
::
LBRACKET
);
t
=
ast
::
ty_vec
(
parse_mt
(
p
));
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
RBRACKET
);
}
else
if
eat_word
(
p
,
"fn"
)
{
let
proto
=
parse_fn_ty_proto
(
p
);
t
=
parse_ty_fn
(
proto
,
p
);
alt
t
{
ast
::
ty_fn
(
_
,
_
,
out
,
_
,
_
)
{
hi
=
out
.span.hi
;
}
}
}
else
if
eat_word
(
p
,
"block"
)
{
t
=
parse_ty_fn
(
ast
::
proto_block
,
p
);
alt
t
{
ast
::
ty_fn
(
_
,
_
,
out
,
_
,
_
)
{
hi
=
out
.span.hi
;
}
}
}
else
if
eat_word
(
p
,
"lambda"
)
{
t
=
parse_ty_fn
(
ast
::
proto_shared
(
ast
::
sugar_sexy
),
p
);
}
else
if
eat_word
(
p
,
"obj"
)
{
t
=
parse_ty_obj
(
p
,
hi
);
t
=
parse_ty_obj
(
p
);
}
else
if
p
.peek
()
==
token
::
MOD_SEP
||
is_ident
(
p
.peek
())
{
let
path
=
parse_path
(
p
);
t
=
ast
::
ty_path
(
path
,
p
.get_id
());
hi
=
path
.span.hi
;
}
else
{
p
.fatal
(
"expecting type"
);
}
ret
parse_ty_postfix
(
t
,
p
,
colons_before_params
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录