Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4af7c643
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
4af7c643
编写于
1月 31, 2013
作者:
J
John Clements
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more cleanup
上级
53688add
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
69 addition
and
59 deletion
+69
-59
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+69
-59
未找到文件。
src/libsyntax/parse/parser.rs
浏览文件 @
4af7c643
...
...
@@ -1456,11 +1456,12 @@ fn parse_prefix_expr() -> @expr {
return
self
.mk_expr
(
lo
,
hi
,
ex
);
}
// parse an expression of binops
fn
parse_binops
()
->
@
expr
{
return
self
.parse_more_binops
(
self
.parse_prefix_expr
(),
0
);
self
.parse_more_binops
(
self
.parse_prefix_expr
(),
0
)
}
// parse an expression of binops of at least min_prec precedence
fn
parse_more_binops
(
lhs
:
@
expr
,
min_prec
:
uint
)
->
@
expr
{
if
self
.expr_is_complete
(
lhs
)
{
return
lhs
;
}
...
...
@@ -1468,66 +1469,73 @@ fn parse_more_binops(lhs: @expr, min_prec: uint) ->
if
peeked
==
token
::
BINOP
(
token
::
OR
)
&&
(
self
.restriction
==
RESTRICT_NO_BAR_OP
||
self
.restriction
==
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP
)
{
return
lhs
;
}
if
peeked
==
token
::
OROR
&&
lhs
}
else
if
peeked
==
token
::
OROR
&&
self
.restriction
==
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP
{
return
lhs
;
}
let
cur_opt
=
token_to_binop
(
peeked
);
match
cur_opt
{
Some
(
cur_op
)
=>
{
let
cur_prec
=
operator_prec
(
cur_op
);
if
cur_prec
>
min_prec
{
self
.bump
();
let
expr
=
self
.parse_prefix_expr
();
let
rhs
=
self
.parse_more_binops
(
expr
,
cur_prec
);
self
.get_id
();
// see ast_util::op_expr_callee_id
let
bin
=
self
.mk_expr
(
lhs
.span.lo
,
rhs
.span.hi
,
expr_binary
(
cur_op
,
lhs
,
rhs
));
return
self
.parse_more_binops
(
bin
,
min_prec
);
lhs
}
else
{
let
cur_opt
=
token_to_binop
(
peeked
);
match
cur_opt
{
Some
(
cur_op
)
=>
{
let
cur_prec
=
operator_prec
(
cur_op
);
if
cur_prec
>
min_prec
{
self
.bump
();
let
expr
=
self
.parse_prefix_expr
();
let
rhs
=
self
.parse_more_binops
(
expr
,
cur_prec
);
self
.get_id
();
// see ast_util::op_expr_callee_id
let
bin
=
self
.mk_expr
(
lhs
.span.lo
,
rhs
.span.hi
,
expr_binary
(
cur_op
,
lhs
,
rhs
));
self
.parse_more_binops
(
bin
,
min_prec
)
}
else
{
lhs
}
}
None
=>
{
if
as_prec
>
min_prec
&&
self
.eat_keyword
(
~
"as"
)
{
let
rhs
=
self
.parse_ty
(
true
);
let
_
as
=
self
.mk_expr
(
lhs
.span.lo
,
rhs
.span.hi
,
expr_cast
(
lhs
,
rhs
));
self
.parse_more_binops
(
_
as
,
min_prec
)
}
else
{
lhs
}
}
}
}
_
=>
()
}
if
as_prec
>
min_prec
&&
self
.eat_keyword
(
~
"as"
)
{
let
rhs
=
self
.parse_ty
(
true
);
let
_
as
=
self
.mk_expr
(
lhs
.span.lo
,
rhs
.span.hi
,
expr_cast
(
lhs
,
rhs
));
return
self
.parse_more_binops
(
_
as
,
min_prec
);
}
return
lhs
;
}
// parse an arbitrary expression.
// parse an assignment expression....
// actually, this seems to be the main entry point for
// parsing an arbitrary expression.
fn
parse_assign_expr
()
->
@
expr
{
let
lo
=
self
.span.lo
;
let
lhs
=
self
.parse_binops
();
match
copy
self
.token
{
token
::
EQ
=>
{
self
.bump
();
let
rhs
=
self
.parse_expr
();
return
self
.mk_expr
(
lo
,
rhs
.span.hi
,
expr_assign
(
lhs
,
rhs
));
token
::
EQ
=>
{
self
.bump
();
let
rhs
=
self
.parse_expr
();
self
.mk_expr
(
lo
,
rhs
.span.hi
,
expr_assign
(
lhs
,
rhs
))
}
token
::
BINOPEQ
(
op
)
=>
{
self
.bump
();
let
rhs
=
self
.parse_expr
();
let
mut
aop
;
match
op
{
token
::
PLUS
=>
aop
=
add
,
token
::
MINUS
=>
aop
=
subtract
,
token
::
STAR
=>
aop
=
mul
,
token
::
SLASH
=>
aop
=
div
,
token
::
PERCENT
=>
aop
=
rem
,
token
::
CARET
=>
aop
=
bitxor
,
token
::
AND
=>
aop
=
bitand
,
token
::
OR
=>
aop
=
bitor
,
token
::
SHL
=>
aop
=
shl
,
token
::
SHR
=>
aop
=
shr
}
self
.get_id
();
// see ast_util::op_expr_callee_id
return
self
.mk_expr
(
lo
,
rhs
.span.hi
,
expr_assign_op
(
aop
,
lhs
,
rhs
));
self
.bump
();
let
rhs
=
self
.parse_expr
();
let
mut
aop
;
match
op
{
token
::
PLUS
=>
aop
=
add
,
token
::
MINUS
=>
aop
=
subtract
,
token
::
STAR
=>
aop
=
mul
,
token
::
SLASH
=>
aop
=
div
,
token
::
PERCENT
=>
aop
=
rem
,
token
::
CARET
=>
aop
=
bitxor
,
token
::
AND
=>
aop
=
bitand
,
token
::
OR
=>
aop
=
bitor
,
token
::
SHL
=>
aop
=
shl
,
token
::
SHR
=>
aop
=
shr
}
self
.get_id
();
// see ast_util::op_expr_callee_id
self
.mk_expr
(
lo
,
rhs
.span.hi
,
expr_assign_op
(
aop
,
lhs
,
rhs
))
}
token
::
LARROW
=>
{
self
.obsolete
(
copy
self
.span
,
ObsoleteBinaryMove
);
...
...
@@ -1535,17 +1543,18 @@ fn parse_assign_expr() -> @expr {
self
.bump
();
// <-
self
.bump
();
// rhs
self
.bump
();
// ;
return
self
.mk_expr
(
lo
,
self
.span.hi
,
expr_break
(
None
));
self
.mk_expr
(
lo
,
self
.span.hi
,
expr_break
(
None
))
}
token
::
DARROW
=>
{
self
.bump
();
let
rhs
=
self
.parse_expr
();
return
self
.mk_expr
(
lo
,
rhs
.span.hi
,
expr_swap
(
lhs
,
rhs
));
self
.mk_expr
(
lo
,
rhs
.span.hi
,
expr_swap
(
lhs
,
rhs
))
}
_
=>
{
lhs
}
_
=>
{
/* fall through */
}
}
return
lhs
;
}
fn
parse_if_expr
()
->
@
expr
{
...
...
@@ -1560,7 +1569,7 @@ fn parse_if_expr() -> @expr {
hi
=
elexpr
.span.hi
;
}
let
q
=
{
cond
:
cond
,
then
:
thn
,
els
:
els
,
lo
:
lo
,
hi
:
hi
};
return
self
.mk_expr
(
q
.lo
,
q
.hi
,
expr_if
(
q
.cond
,
q
.then
,
q
.els
));
f
.mk_expr
(
q
.lo
,
q
.hi
,
expr_if
(
q
.cond
,
q
.then
,
q
.els
))
}
fn
parse_fn_expr
(
proto
:
Proto
)
->
@
expr
{
...
...
@@ -1571,8 +1580,9 @@ fn parse_fn_expr(proto: Proto) -> @expr {
let
decl
=
self
.parse_fn_decl
(|
p
|
p
.parse_arg_or_capture_item
());
let
body
=
self
.parse_block
();
return
self
.mk_expr
(
lo
,
body
.span.hi
,
expr_fn
(
proto
,
decl
,
body
,
@
()));
self
.mk_expr
(
lo
,
body
.span.hi
,
expr_fn
(
proto
,
decl
,
body
,
capture_clause
));
}
// `|args| { ... }` like in `do` expressions
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录