Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2c0cb901
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,发现更多精彩内容 >>
提交
2c0cb901
编写于
4月 17, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
syntax: Begin moving functions from mod parser to mod classify
上级
d51973a6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
37 deletion
+41
-37
src/librustsyntax/parse/classify.rs
src/librustsyntax/parse/classify.rs
+31
-0
src/librustsyntax/parse/parser.rs
src/librustsyntax/parse/parser.rs
+4
-35
src/librustsyntax/print/pprust.rs
src/librustsyntax/print/pprust.rs
+2
-2
src/librustsyntax/rustsyntax.rc
src/librustsyntax/rustsyntax.rc
+4
-0
未找到文件。
src/librustsyntax/parse/classify.rs
0 → 100644
浏览文件 @
2c0cb901
// FIXME: There are a bunch of similar functions in pprust that
// likely belong here
fn
expr_requires_semi_to_be_stmt
(
e
:
@
ast
::
expr
)
->
bool
{
alt
e
.node
{
ast
::
expr_if
(
_
,
_
,
_
)
|
ast
::
expr_if_check
(
_
,
_
,
_
)
|
ast
::
expr_alt
(
_
,
_
,
_
)
|
ast
::
expr_block
(
_
)
|
ast
::
expr_do_while
(
_
,
_
)
|
ast
::
expr_while
(
_
,
_
)
|
ast
::
expr_loop
(
_
)
|
ast
::
expr_call
(
_
,
_
,
true
)
{
false
}
_
{
true
}
}
}
fn
stmt_ends_with_semi
(
stmt
:
ast
::
stmt
)
->
bool
{
alt
stmt
.node
{
ast
::
stmt_decl
(
d
,
_
)
{
ret
alt
d
.node
{
ast
::
decl_local
(
_
)
{
true
}
ast
::
decl_item
(
_
)
{
false
}
}
}
ast
::
stmt_expr
(
e
,
_
)
{
ret
expr_requires_semi_to_be_stmt
(
e
);
}
ast
::
stmt_semi
(
e
,
_
)
{
ret
false
;
}
}
}
src/librustsyntax/parse/parser.rs
浏览文件 @
2c0cb901
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
import
lexer
::
reader
;
import
lexer
::
reader
;
import
prec
::{
op_spec
,
binop_prec_table
,
as_prec
};
import
prec
::{
op_spec
,
binop_prec_table
,
as_prec
};
export
expr_requires_semi_to_be_stmt
;
export
file_type
;
export
file_type
;
export
mk_item
;
export
mk_item
;
export
next_node_id
;
export
next_node_id
;
...
@@ -31,7 +30,6 @@
...
@@ -31,7 +30,6 @@
export
parse_sess
;
export
parse_sess
;
export
parse_stmt
;
export
parse_stmt
;
export
parse_ty
;
export
parse_ty
;
export
stmt_ends_with_semi
;
enum
restriction
{
enum
restriction
{
UNRESTRICTED
,
UNRESTRICTED
,
...
@@ -1776,38 +1774,9 @@ fn check_expected_item(p: parser, current_attrs: [ast::attribute]) {
...
@@ -1776,38 +1774,9 @@ fn check_expected_item(p: parser, current_attrs: [ast::attribute]) {
fn
expr_is_complete
(
p
:
parser
,
e
:
pexpr
)
->
bool
{
fn
expr_is_complete
(
p
:
parser
,
e
:
pexpr
)
->
bool
{
log
(
debug
,
(
"expr_is_complete"
,
p
.restriction
,
log
(
debug
,
(
"expr_is_complete"
,
p
.restriction
,
print
::
pprust
::
expr_to_str
(
*
e
),
print
::
pprust
::
expr_to_str
(
*
e
),
expr_requires_semi_to_be_stmt
(
*
e
)));
classify
::
expr_requires_semi_to_be_stmt
(
*
e
)));
ret
p
.restriction
==
RESTRICT_STMT_EXPR
&&
ret
p
.restriction
==
RESTRICT_STMT_EXPR
&&
!
expr_requires_semi_to_be_stmt
(
*
e
);
!
classify
::
expr_requires_semi_to_be_stmt
(
*
e
);
}
fn
expr_requires_semi_to_be_stmt
(
e
:
@
ast
::
expr
)
->
bool
{
alt
e
.node
{
ast
::
expr_if
(
_
,
_
,
_
)
|
ast
::
expr_if_check
(
_
,
_
,
_
)
|
ast
::
expr_alt
(
_
,
_
,
_
)
|
ast
::
expr_block
(
_
)
|
ast
::
expr_do_while
(
_
,
_
)
|
ast
::
expr_while
(
_
,
_
)
|
ast
::
expr_loop
(
_
)
|
ast
::
expr_call
(
_
,
_
,
true
)
{
false
}
_
{
true
}
}
}
fn
stmt_ends_with_semi
(
stmt
:
ast
::
stmt
)
->
bool
{
alt
stmt
.node
{
ast
::
stmt_decl
(
d
,
_
)
{
ret
alt
d
.node
{
ast
::
decl_local
(
_
)
{
true
}
ast
::
decl_item
(
_
)
{
false
}
}
}
ast
::
stmt_expr
(
e
,
_
)
{
ret
expr_requires_semi_to_be_stmt
(
e
);
}
ast
::
stmt_semi
(
e
,
_
)
{
ret
false
;
}
}
}
}
fn
parse_block
(
p
:
parser
)
->
ast
::
blk
{
fn
parse_block
(
p
:
parser
)
->
ast
::
blk
{
...
@@ -1890,7 +1859,7 @@ fn parse_block_tail_(p: parser, lo: uint, s: ast::blk_check_mode,
...
@@ -1890,7 +1859,7 @@ fn parse_block_tail_(p: parser, lo: uint, s: ast::blk_check_mode,
expr
=
some
(
e
);
expr
=
some
(
e
);
}
}
t
{
t
{
if
stmt_ends_with_semi
(
*
stmt
)
{
if
classify
::
stmt_ends_with_semi
(
*
stmt
)
{
p
.fatal
(
"expected ';' or '}' after expression but
\
p
.fatal
(
"expected ';' or '}' after expression but
\
found '"
+
token_to_str
(
p
.reader
,
t
)
+
found '"
+
token_to_str
(
p
.reader
,
t
)
+
"'"
);
"'"
);
...
@@ -1903,7 +1872,7 @@ fn parse_block_tail_(p: parser, lo: uint, s: ast::blk_check_mode,
...
@@ -1903,7 +1872,7 @@ fn parse_block_tail_(p: parser, lo: uint, s: ast::blk_check_mode,
_
{
// All other kinds of statements:
_
{
// All other kinds of statements:
stmts
+=
[
stmt
];
stmts
+=
[
stmt
];
if
stmt_ends_with_semi
(
*
stmt
)
{
if
classify
::
stmt_ends_with_semi
(
*
stmt
)
{
expect
(
p
,
token
::
SEMI
);
expect
(
p
,
token
::
SEMI
);
}
}
}
}
...
...
src/librustsyntax/print/pprust.rs
浏览文件 @
2c0cb901
...
@@ -685,7 +685,7 @@ fn print_stmt(s: ps, st: ast::stmt) {
...
@@ -685,7 +685,7 @@ fn print_stmt(s: ps, st: ast::stmt) {
word
(
s
.s
,
";"
);
word
(
s
.s
,
";"
);
}
}
}
}
if
parse
::
parser
::
stmt_ends_with_semi
(
st
)
{
word
(
s
.s
,
";"
);
}
if
parse
::
classify
::
stmt_ends_with_semi
(
st
)
{
word
(
s
.s
,
";"
);
}
maybe_print_trailing_comment
(
s
,
st
.span
,
none
::
<
uint
>
);
maybe_print_trailing_comment
(
s
,
st
.span
,
none
::
<
uint
>
);
}
}
...
@@ -1508,7 +1508,7 @@ fn need_parens(expr: @ast::expr, outer_prec: int) -> bool {
...
@@ -1508,7 +1508,7 @@ fn need_parens(expr: @ast::expr, outer_prec: int) -> bool {
ast
::
expr_assert
(
_
)
{
true
}
ast
::
expr_assert
(
_
)
{
true
}
ast
::
expr_check
(
_
,
_
)
{
true
}
ast
::
expr_check
(
_
,
_
)
{
true
}
ast
::
expr_log
(
_
,
_
,
_
)
{
true
}
ast
::
expr_log
(
_
,
_
,
_
)
{
true
}
_
{
!
parse
::
parser
::
expr_requires_semi_to_be_stmt
(
expr
)
}
_
{
!
parse
::
classify
::
expr_requires_semi_to_be_stmt
(
expr
)
}
}
}
}
}
...
...
src/librustsyntax/rustsyntax.rc
浏览文件 @
2c0cb901
...
@@ -27,6 +27,7 @@ mod parse {
...
@@ -27,6 +27,7 @@ mod parse {
export lexer;
export lexer;
export comments;
export comments;
export prec;
export prec;
export classify;
mod eval;
mod eval;
mod lexer;
mod lexer;
...
@@ -36,6 +37,9 @@ mod parse {
...
@@ -36,6 +37,9 @@ mod parse {
#[doc = "Functions dealing with operator precedence"]
#[doc = "Functions dealing with operator precedence"]
mod prec;
mod prec;
#[doc = "Routines the parser uses to classify AST nodes"]
mod classify;
}
}
mod print {
mod print {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录