Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
71c08734
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,发现更多精彩内容 >>
提交
71c08734
编写于
1月 15, 2018
作者:
E
Esteban Küber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move `ExprPrecedence` to `libsyntax/util/parser.rs`
上级
afe8d13a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
128 addition
and
136 deletion
+128
-136
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+1
-1
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+1
-135
src/libsyntax/util/parser.rs
src/libsyntax/util/parser.rs
+126
-0
未找到文件。
src/librustc/hir/mod.rs
浏览文件 @
71c08734
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
use
syntax
::
symbol
::{
Symbol
,
keywords
};
use
syntax
::
symbol
::{
Symbol
,
keywords
};
use
syntax
::
tokenstream
::
TokenStream
;
use
syntax
::
tokenstream
::
TokenStream
;
use
syntax
::
util
::
ThinVec
;
use
syntax
::
util
::
ThinVec
;
use
syntax
::
ast
::
ExprPrecedence
;
use
syntax
::
util
::
parser
::
ExprPrecedence
;
use
ty
::
AdtKind
;
use
ty
::
AdtKind
;
use
rustc_data_structures
::
indexed_vec
;
use
rustc_data_structures
::
indexed_vec
;
...
...
src/libsyntax/ast.rs
浏览文件 @
71c08734
...
@@ -15,17 +15,7 @@
...
@@ -15,17 +15,7 @@
pub
use
self
::
PathParameters
::
*
;
pub
use
self
::
PathParameters
::
*
;
pub
use
symbol
::{
Ident
,
Symbol
as
Name
};
pub
use
symbol
::{
Ident
,
Symbol
as
Name
};
pub
use
util
::
ThinVec
;
pub
use
util
::
ThinVec
;
pub
use
util
::
parser
::{
pub
use
util
::
parser
::
ExprPrecedence
;
AssocOp
,
PREC_RESET
,
PREC_CLOSURE
,
PREC_JUMP
,
PREC_RANGE
,
PREC_PREFIX
,
PREC_POSTFIX
,
PREC_PAREN
,
PREC_FORCE_PAREN
,
};
use
syntax_pos
::{
Span
,
DUMMY_SP
};
use
syntax_pos
::{
Span
,
DUMMY_SP
};
use
codemap
::{
respan
,
Spanned
};
use
codemap
::{
respan
,
Spanned
};
...
@@ -39,7 +29,6 @@
...
@@ -39,7 +29,6 @@
use
serialize
::{
self
,
Encoder
,
Decoder
};
use
serialize
::{
self
,
Encoder
,
Decoder
};
use
std
::
collections
::
HashSet
;
use
std
::
collections
::
HashSet
;
use
std
::
cmp
::
Ordering
;
use
std
::
fmt
;
use
std
::
fmt
;
use
std
::
rc
::
Rc
;
use
std
::
rc
::
Rc
;
use
std
::
u32
;
use
std
::
u32
;
...
@@ -917,129 +906,6 @@ pub struct Expr {
...
@@ -917,129 +906,6 @@ pub struct Expr {
pub
attrs
:
ThinVec
<
Attribute
>
pub
attrs
:
ThinVec
<
Attribute
>
}
}
#[derive(Debug,
Clone,
Copy,
PartialEq,
Eq)]
pub
enum
ExprPrecedence
{
Closure
,
Break
,
Continue
,
Ret
,
Yield
,
Range
,
Binary
(
BinOpKind
),
InPlace
,
Cast
,
Type
,
Assign
,
AssignOp
,
Box
,
AddrOf
,
Unary
,
Call
,
MethodCall
,
Field
,
TupField
,
Index
,
Try
,
InlineAsm
,
Mac
,
Array
,
Repeat
,
Tup
,
Lit
,
Path
,
Paren
,
If
,
IfLet
,
While
,
WhileLet
,
ForLoop
,
Loop
,
Match
,
Block
,
Catch
,
Struct
,
}
impl
PartialOrd
for
ExprPrecedence
{
fn
partial_cmp
(
&
self
,
other
:
&
Self
)
->
Option
<
Ordering
>
{
Some
(
self
.order
()
.cmp
(
&
other
.order
()))
}
}
impl
Ord
for
ExprPrecedence
{
fn
cmp
(
&
self
,
other
:
&
Self
)
->
Ordering
{
self
.order
()
.cmp
(
&
other
.order
())
}
}
impl
ExprPrecedence
{
pub
fn
order
(
self
)
->
i8
{
match
self
{
ExprPrecedence
::
Closure
=>
PREC_CLOSURE
,
ExprPrecedence
::
Break
|
ExprPrecedence
::
Continue
|
ExprPrecedence
::
Ret
|
ExprPrecedence
::
Yield
=>
PREC_JUMP
,
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
// ensures that `pprust` will add parentheses in the right places to get the desired
// parse.
ExprPrecedence
::
Range
=>
PREC_RANGE
,
// Binop-like expr kinds, handled by `AssocOp`.
ExprPrecedence
::
Binary
(
op
)
=>
AssocOp
::
from_ast_binop
(
op
)
.precedence
()
as
i8
,
ExprPrecedence
::
InPlace
=>
AssocOp
::
Inplace
.precedence
()
as
i8
,
ExprPrecedence
::
Cast
=>
AssocOp
::
As
.precedence
()
as
i8
,
ExprPrecedence
::
Type
=>
AssocOp
::
Colon
.precedence
()
as
i8
,
ExprPrecedence
::
Assign
|
ExprPrecedence
::
AssignOp
=>
AssocOp
::
Assign
.precedence
()
as
i8
,
// Unary, prefix
ExprPrecedence
::
Box
|
ExprPrecedence
::
AddrOf
|
ExprPrecedence
::
Unary
=>
PREC_PREFIX
,
// Unary, postfix
ExprPrecedence
::
Call
|
ExprPrecedence
::
MethodCall
|
ExprPrecedence
::
Field
|
ExprPrecedence
::
TupField
|
ExprPrecedence
::
Index
|
ExprPrecedence
::
Try
|
ExprPrecedence
::
InlineAsm
|
ExprPrecedence
::
Mac
=>
PREC_POSTFIX
,
// Never need parens
ExprPrecedence
::
Array
|
ExprPrecedence
::
Repeat
|
ExprPrecedence
::
Tup
|
ExprPrecedence
::
Lit
|
ExprPrecedence
::
Path
|
ExprPrecedence
::
Paren
|
ExprPrecedence
::
If
|
ExprPrecedence
::
IfLet
|
ExprPrecedence
::
While
|
ExprPrecedence
::
WhileLet
|
ExprPrecedence
::
ForLoop
|
ExprPrecedence
::
Loop
|
ExprPrecedence
::
Match
|
ExprPrecedence
::
Block
|
ExprPrecedence
::
Catch
|
ExprPrecedence
::
Struct
=>
PREC_PAREN
,
}
}
}
impl
Expr
{
impl
Expr
{
/// Wether this expression would be valid somewhere that expects a value, for example, an `if`
/// Wether this expression would be valid somewhere that expects a value, for example, an `if`
/// condition.
/// condition.
...
...
src/libsyntax/util/parser.rs
浏览文件 @
71c08734
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
use
symbol
::
keywords
;
use
symbol
::
keywords
;
use
ast
::{
self
,
BinOpKind
};
use
ast
::{
self
,
BinOpKind
};
use
std
::
cmp
::
Ordering
;
/// Associative operator with precedence.
/// Associative operator with precedence.
///
///
/// This is the enum which specifies operator precedence and fixity to the parser.
/// This is the enum which specifies operator precedence and fixity to the parser.
...
@@ -228,6 +230,130 @@ pub fn to_ast_binop(&self) -> Option<BinOpKind> {
...
@@ -228,6 +230,130 @@ pub fn to_ast_binop(&self) -> Option<BinOpKind> {
pub
const
PREC_PAREN
:
i8
=
99
;
pub
const
PREC_PAREN
:
i8
=
99
;
pub
const
PREC_FORCE_PAREN
:
i8
=
100
;
pub
const
PREC_FORCE_PAREN
:
i8
=
100
;
#[derive(Debug,
Clone,
Copy,
PartialEq,
Eq)]
pub
enum
ExprPrecedence
{
Closure
,
Break
,
Continue
,
Ret
,
Yield
,
Range
,
Binary
(
BinOpKind
),
InPlace
,
Cast
,
Type
,
Assign
,
AssignOp
,
Box
,
AddrOf
,
Unary
,
Call
,
MethodCall
,
Field
,
TupField
,
Index
,
Try
,
InlineAsm
,
Mac
,
Array
,
Repeat
,
Tup
,
Lit
,
Path
,
Paren
,
If
,
IfLet
,
While
,
WhileLet
,
ForLoop
,
Loop
,
Match
,
Block
,
Catch
,
Struct
,
}
impl
PartialOrd
for
ExprPrecedence
{
fn
partial_cmp
(
&
self
,
other
:
&
Self
)
->
Option
<
Ordering
>
{
Some
(
self
.order
()
.cmp
(
&
other
.order
()))
}
}
impl
Ord
for
ExprPrecedence
{
fn
cmp
(
&
self
,
other
:
&
Self
)
->
Ordering
{
self
.order
()
.cmp
(
&
other
.order
())
}
}
impl
ExprPrecedence
{
pub
fn
order
(
self
)
->
i8
{
match
self
{
ExprPrecedence
::
Closure
=>
PREC_CLOSURE
,
ExprPrecedence
::
Break
|
ExprPrecedence
::
Continue
|
ExprPrecedence
::
Ret
|
ExprPrecedence
::
Yield
=>
PREC_JUMP
,
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
// ensures that `pprust` will add parentheses in the right places to get the desired
// parse.
ExprPrecedence
::
Range
=>
PREC_RANGE
,
// Binop-like expr kinds, handled by `AssocOp`.
ExprPrecedence
::
Binary
(
op
)
=>
AssocOp
::
from_ast_binop
(
op
)
.precedence
()
as
i8
,
ExprPrecedence
::
InPlace
=>
AssocOp
::
Inplace
.precedence
()
as
i8
,
ExprPrecedence
::
Cast
=>
AssocOp
::
As
.precedence
()
as
i8
,
ExprPrecedence
::
Type
=>
AssocOp
::
Colon
.precedence
()
as
i8
,
ExprPrecedence
::
Assign
|
ExprPrecedence
::
AssignOp
=>
AssocOp
::
Assign
.precedence
()
as
i8
,
// Unary, prefix
ExprPrecedence
::
Box
|
ExprPrecedence
::
AddrOf
|
ExprPrecedence
::
Unary
=>
PREC_PREFIX
,
// Unary, postfix
ExprPrecedence
::
Call
|
ExprPrecedence
::
MethodCall
|
ExprPrecedence
::
Field
|
ExprPrecedence
::
TupField
|
ExprPrecedence
::
Index
|
ExprPrecedence
::
Try
|
ExprPrecedence
::
InlineAsm
|
ExprPrecedence
::
Mac
=>
PREC_POSTFIX
,
// Never need parens
ExprPrecedence
::
Array
|
ExprPrecedence
::
Repeat
|
ExprPrecedence
::
Tup
|
ExprPrecedence
::
Lit
|
ExprPrecedence
::
Path
|
ExprPrecedence
::
Paren
|
ExprPrecedence
::
If
|
ExprPrecedence
::
IfLet
|
ExprPrecedence
::
While
|
ExprPrecedence
::
WhileLet
|
ExprPrecedence
::
ForLoop
|
ExprPrecedence
::
Loop
|
ExprPrecedence
::
Match
|
ExprPrecedence
::
Block
|
ExprPrecedence
::
Catch
|
ExprPrecedence
::
Struct
=>
PREC_PAREN
,
}
}
}
/// Expressions that syntactically contain an "exterior" struct literal i.e. not surrounded by any
/// Expressions that syntactically contain an "exterior" struct literal i.e. not surrounded by any
/// parens or other delimiters, e.g. `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and
/// parens or other delimiters, e.g. `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and
/// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not.
/// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录