Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
476d5a09
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,发现更多精彩内容 >>
提交
476d5a09
编写于
4月 17, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
syntax: Extract prec mod from parser mod
上级
aa4278a3
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
52 addition
and
40 deletion
+52
-40
src/librustsyntax/parse/parser.rs
src/librustsyntax/parse/parser.rs
+4
-36
src/librustsyntax/parse/prec.rs
src/librustsyntax/parse/prec.rs
+40
-0
src/librustsyntax/print/pprust.rs
src/librustsyntax/print/pprust.rs
+4
-4
src/librustsyntax/rustsyntax.rc
src/librustsyntax/rustsyntax.rc
+4
-0
未找到文件。
src/librustsyntax/parse/parser.rs
浏览文件 @
476d5a09
...
...
@@ -7,8 +7,8 @@
import
ast
::{
node_id
,
spanned
};
import
ast_util
::{
mk_sp
,
ident_to_path
};
import
lexer
::
reader
;
import
prec
::{
op_spec
,
binop_prec_table
,
as_prec
};
export
as_prec
;
export
expr_requires_semi_to_be_stmt
;
export
file_type
;
export
mk_item
;
...
...
@@ -31,9 +31,7 @@
export
parse_sess
;
export
parse_stmt
;
export
parse_ty
;
export
prec_table
;
export
stmt_ends_with_semi
;
export
unop_prec
;
enum
restriction
{
UNRESTRICTED
,
...
...
@@ -71,7 +69,7 @@ fn next_node_id(sess: parse_sess) -> node_id {
mut
buffer
:
[{
tok
:
token
::
token
,
span
:
span
}],
mut
restriction
:
restriction
,
reader
:
reader
,
precs
:
@
[
op_spec
],
binop_
precs
:
@
[
op_spec
],
bad_expr_words
:
hashmap
<
str
,
()
>
};
...
...
@@ -161,7 +159,7 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
mut
buffer
:
[],
mut
restriction
:
UNRESTRICTED
,
reader
:
rdr
,
precs
:
prec_table
(),
binop_precs
:
binop_
prec_table
(),
bad_expr_words
:
bad_expr_word_table
()}
}
...
...
@@ -1301,41 +1299,11 @@ fn parse_prefix_expr(p: parser) -> pexpr {
ret
mk_pexpr
(
p
,
lo
,
hi
,
ex
);
}
type
op_spec
=
{
tok
:
token
::
token
,
op
:
ast
::
binop
,
prec
:
int
};
// FIXME make this a const, don't store it in parser state
fn
prec_table
()
->
@
[
op_spec
]
{
ret
@
[{
tok
:
token
::
BINOP
(
token
::
STAR
),
op
:
ast
::
mul
,
prec
:
12
},
{
tok
:
token
::
BINOP
(
token
::
SLASH
),
op
:
ast
::
div
,
prec
:
12
},
{
tok
:
token
::
BINOP
(
token
::
PERCENT
),
op
:
ast
::
rem
,
prec
:
12
},
// 'as' sits between here with 11
{
tok
:
token
::
BINOP
(
token
::
PLUS
),
op
:
ast
::
add
,
prec
:
10
},
{
tok
:
token
::
BINOP
(
token
::
MINUS
),
op
:
ast
::
subtract
,
prec
:
10
},
{
tok
:
token
::
BINOP
(
token
::
LSL
),
op
:
ast
::
lsl
,
prec
:
9
},
{
tok
:
token
::
BINOP
(
token
::
LSR
),
op
:
ast
::
lsr
,
prec
:
9
},
{
tok
:
token
::
BINOP
(
token
::
ASR
),
op
:
ast
::
asr
,
prec
:
9
},
{
tok
:
token
::
BINOP
(
token
::
AND
),
op
:
ast
::
bitand
,
prec
:
8
},
{
tok
:
token
::
BINOP
(
token
::
CARET
),
op
:
ast
::
bitxor
,
prec
:
7
},
{
tok
:
token
::
BINOP
(
token
::
OR
),
op
:
ast
::
bitor
,
prec
:
6
},
{
tok
:
token
::
LT
,
op
:
ast
::
lt
,
prec
:
4
},
{
tok
:
token
::
LE
,
op
:
ast
::
le
,
prec
:
4
},
{
tok
:
token
::
GE
,
op
:
ast
::
ge
,
prec
:
4
},
{
tok
:
token
::
GT
,
op
:
ast
::
gt
,
prec
:
4
},
{
tok
:
token
::
EQEQ
,
op
:
ast
::
eq
,
prec
:
3
},
{
tok
:
token
::
NE
,
op
:
ast
::
ne
,
prec
:
3
},
{
tok
:
token
::
ANDAND
,
op
:
ast
::
and
,
prec
:
2
},
{
tok
:
token
::
OROR
,
op
:
ast
::
or
,
prec
:
1
}];
}
fn
parse_binops
(
p
:
parser
)
->
@
ast
::
expr
{
ret
parse_more_binops
(
p
,
parse_prefix_expr
(
p
),
0
);
}
const
unop_prec
:
int
=
100
;
const
as_prec
:
int
=
11
;
fn
parse_more_binops
(
p
:
parser
,
plhs
:
pexpr
,
min_prec
:
int
)
->
@
ast
::
expr
{
let
lhs
=
to_expr
(
plhs
);
...
...
@@ -1343,7 +1311,7 @@ fn parse_more_binops(p: parser, plhs: pexpr, min_prec: int) ->
let
peeked
=
p
.token
;
if
peeked
==
token
::
BINOP
(
token
::
OR
)
&&
p
.restriction
==
RESTRICT_NO_BAR_OP
{
ret
lhs
;
}
for
vec
::
each
(
*
p
.precs
)
{|
cur
|
for
vec
::
each
(
*
p
.
binop_
precs
)
{|
cur
|
if
cur
.prec
>
min_prec
&&
cur
.tok
==
peeked
{
p
.bump
();
let
expr
=
parse_prefix_expr
(
p
);
...
...
src/librustsyntax/parse/prec.rs
0 → 100644
浏览文件 @
476d5a09
export
as_prec
;
export
unop_prec
;
export
binop_prec_table
;
export
op_spec
;
#[doc
=
"Unary operators have higher precedence than binary"
]
const
unop_prec
:
int
=
100
;
#[doc
=
"
Precedence of the `as` operator, which is a binary operator
but is not represented in the precedence table.
"
]
const
as_prec
:
int
=
11
;
type
op_spec
=
{
tok
:
token
::
token
,
op
:
ast
::
binop
,
prec
:
int
};
// FIXME make this a const, don't store it in parser state
#[doc
=
"The precedence of binary operators"
]
fn
binop_prec_table
()
->
@
[
op_spec
]
{
ret
@
[{
tok
:
token
::
BINOP
(
token
::
STAR
),
op
:
ast
::
mul
,
prec
:
12
},
{
tok
:
token
::
BINOP
(
token
::
SLASH
),
op
:
ast
::
div
,
prec
:
12
},
{
tok
:
token
::
BINOP
(
token
::
PERCENT
),
op
:
ast
::
rem
,
prec
:
12
},
// 'as' sits between here with 11
{
tok
:
token
::
BINOP
(
token
::
PLUS
),
op
:
ast
::
add
,
prec
:
10
},
{
tok
:
token
::
BINOP
(
token
::
MINUS
),
op
:
ast
::
subtract
,
prec
:
10
},
{
tok
:
token
::
BINOP
(
token
::
LSL
),
op
:
ast
::
lsl
,
prec
:
9
},
{
tok
:
token
::
BINOP
(
token
::
LSR
),
op
:
ast
::
lsr
,
prec
:
9
},
{
tok
:
token
::
BINOP
(
token
::
ASR
),
op
:
ast
::
asr
,
prec
:
9
},
{
tok
:
token
::
BINOP
(
token
::
AND
),
op
:
ast
::
bitand
,
prec
:
8
},
{
tok
:
token
::
BINOP
(
token
::
CARET
),
op
:
ast
::
bitxor
,
prec
:
7
},
{
tok
:
token
::
BINOP
(
token
::
OR
),
op
:
ast
::
bitor
,
prec
:
6
},
{
tok
:
token
::
LT
,
op
:
ast
::
lt
,
prec
:
4
},
{
tok
:
token
::
LE
,
op
:
ast
::
le
,
prec
:
4
},
{
tok
:
token
::
GE
,
op
:
ast
::
ge
,
prec
:
4
},
{
tok
:
token
::
GT
,
op
:
ast
::
gt
,
prec
:
4
},
{
tok
:
token
::
EQEQ
,
op
:
ast
::
eq
,
prec
:
3
},
{
tok
:
token
::
NE
,
op
:
ast
::
ne
,
prec
:
3
},
{
tok
:
token
::
ANDAND
,
op
:
ast
::
and
,
prec
:
2
},
{
tok
:
token
::
OROR
,
op
:
ast
::
or
,
prec
:
1
}];
}
src/librustsyntax/print/pprust.rs
浏览文件 @
476d5a09
...
...
@@ -934,7 +934,7 @@ fn print_opt(s: ps, expr: option<@ast::expr>) {
}
ast
::
expr_unary
(
op
,
expr
)
{
word
(
s
.s
,
ast_util
::
unop_to_str
(
op
));
print_op_maybe_parens
(
s
,
expr
,
parse
::
p
arser
::
unop_prec
);
print_op_maybe_parens
(
s
,
expr
,
parse
::
p
rec
::
unop_prec
);
}
ast
::
expr_addr_of
(
m
,
expr
)
{
word
(
s
.s
,
"&"
);
...
...
@@ -943,7 +943,7 @@ fn print_opt(s: ps, expr: option<@ast::expr>) {
}
ast
::
expr_lit
(
lit
)
{
print_literal
(
s
,
lit
);
}
ast
::
expr_cast
(
expr
,
ty
)
{
print_op_maybe_parens
(
s
,
expr
,
parse
::
p
arser
::
as_prec
);
print_op_maybe_parens
(
s
,
expr
,
parse
::
p
rec
::
as_prec
);
space
(
s
.s
);
word_space
(
s
,
"as"
);
print_type
(
s
,
ty
);
...
...
@@ -1488,7 +1488,7 @@ fn print_view_item(s: ps, item: @ast::view_item) {
// FIXME: The fact that this builds up the table anew for every call is
// not good. Eventually, table should be a const.
fn
operator_prec
(
op
:
ast
::
binop
)
->
int
{
for
vec
::
each
(
*
parse
::
p
arser
::
prec_table
())
{|
spec
|
for
vec
::
each
(
*
parse
::
p
rec
::
binop_
prec_table
())
{|
spec
|
if
spec
.op
==
op
{
ret
spec
.prec
;
}
}
core
::
unreachable
();
...
...
@@ -1497,7 +1497,7 @@ fn operator_prec(op: ast::binop) -> int {
fn
need_parens
(
expr
:
@
ast
::
expr
,
outer_prec
:
int
)
->
bool
{
alt
expr
.node
{
ast
::
expr_binary
(
op
,
_
,
_
)
{
operator_prec
(
op
)
<
outer_prec
}
ast
::
expr_cast
(
_
,
_
)
{
parse
::
p
arser
::
as_prec
<
outer_prec
}
ast
::
expr_cast
(
_
,
_
)
{
parse
::
p
rec
::
as_prec
<
outer_prec
}
// This may be too conservative in some cases
ast
::
expr_assign
(
_
,
_
)
{
true
}
ast
::
expr_move
(
_
,
_
)
{
true
}
...
...
src/librustsyntax/rustsyntax.rc
浏览文件 @
476d5a09
...
...
@@ -26,12 +26,16 @@ mod parse {
export parser;
export lexer;
export comments;
export prec;
mod eval;
mod lexer;
mod parser;
mod token;
mod comments;
#[doc = "Functions dealing with operator precedence"]
mod prec;
}
mod print {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录