Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
33a3206d
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,发现更多精彩内容 >>
提交
33a3206d
编写于
5月 23, 2019
作者:
N
Nicholas Nethercote
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use `Symbol` equality in `may_begin_with` and `parse_nt`.
上级
15789a97
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
34 addition
and
27 deletion
+34
-27
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/ext/tt/macro_parser.rs
+27
-27
src/libsyntax_pos/symbol.rs
src/libsyntax_pos/symbol.rs
+7
-0
未找到文件。
src/libsyntax/ext/tt/macro_parser.rs
浏览文件 @
33a3206d
...
...
@@ -80,7 +80,7 @@
use
crate
::
parse
::
parser
::{
Parser
,
PathStyle
};
use
crate
::
parse
::
token
::{
self
,
DocComment
,
Nonterminal
,
Token
};
use
crate
::
print
::
pprust
;
use
crate
::
symbol
::
kw
;
use
crate
::
symbol
::
{
kw
,
sym
,
Symbol
}
;
use
crate
::
tokenstream
::{
DelimSpan
,
TokenStream
};
use
errors
::
FatalError
;
...
...
@@ -598,7 +598,7 @@ fn inner_parse_loop<'root, 'tt>(
TokenTree
::
MetaVarDecl
(
_
,
_
,
id
)
=>
{
// Built-in nonterminals never start with these tokens,
// so we can eliminate them from consideration.
if
may_begin_with
(
&*
id
.as_str
()
,
token
)
{
if
may_begin_with
(
id
.name
,
token
)
{
bb_items
.push
(
item
);
}
}
...
...
@@ -791,7 +791,7 @@ pub fn parse(
let
match_cur
=
item
.match_cur
;
item
.push_match
(
match_cur
,
MatchedNonterminal
(
Lrc
::
new
(
parse_nt
(
&
mut
parser
,
span
,
&
ident
.as_str
()
))),
MatchedNonterminal
(
Lrc
::
new
(
parse_nt
(
&
mut
parser
,
span
,
ident
.name
))),
);
item
.idx
+=
1
;
item
.match_cur
+=
1
;
...
...
@@ -819,7 +819,7 @@ fn get_macro_ident(token: &Token) -> Option<(Ident, bool)> {
///
/// Returning `false` is a *stability guarantee* that such a matcher will *never* begin with that
/// token. Be conservative (return true) if not sure.
fn
may_begin_with
(
name
:
&
str
,
token
:
&
Token
)
->
bool
{
fn
may_begin_with
(
name
:
Symbol
,
token
:
&
Token
)
->
bool
{
/// Checks whether the non-terminal may contain a single (non-keyword) identifier.
fn
may_be_ident
(
nt
:
&
token
::
Nonterminal
)
->
bool
{
match
*
nt
{
...
...
@@ -829,16 +829,16 @@ fn may_be_ident(nt: &token::Nonterminal) -> bool {
}
match
name
{
"expr"
=>
token
.can_begin_expr
(),
"ty"
=>
token
.can_begin_type
(),
"ident"
=>
get_macro_ident
(
token
)
.is_some
(),
"literal"
=>
token
.can_begin_literal_or_bool
(),
"vis"
=>
match
*
token
{
sym
::
expr
=>
token
.can_begin_expr
(),
sym
::
ty
=>
token
.can_begin_type
(),
sym
::
ident
=>
get_macro_ident
(
token
)
.is_some
(),
sym
::
literal
=>
token
.can_begin_literal_or_bool
(),
sym
::
vis
=>
match
*
token
{
// The follow-set of :vis + "priv" keyword + interpolated
Token
::
Comma
|
Token
::
Ident
(
..
)
|
Token
::
Interpolated
(
_
)
=>
true
,
_
=>
token
.can_begin_type
(),
},
"block"
=>
match
*
token
{
sym
::
block
=>
match
*
token
{
Token
::
OpenDelim
(
token
::
Brace
)
=>
true
,
Token
::
Interpolated
(
ref
nt
)
=>
match
**
nt
{
token
::
NtItem
(
_
)
...
...
@@ -852,7 +852,7 @@ fn may_be_ident(nt: &token::Nonterminal) -> bool {
},
_
=>
false
,
},
"path"
|
"meta"
=>
match
*
token
{
sym
::
path
|
sym
::
meta
=>
match
*
token
{
Token
::
ModSep
|
Token
::
Ident
(
..
)
=>
true
,
Token
::
Interpolated
(
ref
nt
)
=>
match
**
nt
{
token
::
NtPath
(
_
)
|
token
::
NtMeta
(
_
)
=>
true
,
...
...
@@ -860,7 +860,7 @@ fn may_be_ident(nt: &token::Nonterminal) -> bool {
},
_
=>
false
,
},
"pat"
=>
match
*
token
{
sym
::
pat
=>
match
*
token
{
Token
::
Ident
(
..
)
|
// box, ref, mut, and other identifiers (can stricten)
Token
::
OpenDelim
(
token
::
Paren
)
|
// tuple pattern
Token
::
OpenDelim
(
token
::
Bracket
)
|
// slice pattern
...
...
@@ -876,7 +876,7 @@ fn may_be_ident(nt: &token::Nonterminal) -> bool {
Token
::
Interpolated
(
ref
nt
)
=>
may_be_ident
(
nt
),
_
=>
false
,
},
"lifetime"
=>
match
*
token
{
sym
::
lifetime
=>
match
*
token
{
Token
::
Lifetime
(
_
)
=>
true
,
Token
::
Interpolated
(
ref
nt
)
=>
match
**
nt
{
token
::
NtLifetime
(
_
)
|
token
::
NtTT
(
_
)
=>
true
,
...
...
@@ -903,34 +903,34 @@ fn may_be_ident(nt: &token::Nonterminal) -> bool {
/// # Returns
///
/// The parsed non-terminal.
fn
parse_nt
<
'a
>
(
p
:
&
mut
Parser
<
'a
>
,
sp
:
Span
,
name
:
&
str
)
->
Nonterminal
{
if
name
==
"tt"
{
fn
parse_nt
<
'a
>
(
p
:
&
mut
Parser
<
'a
>
,
sp
:
Span
,
name
:
Symbol
)
->
Nonterminal
{
if
name
==
sym
::
tt
{
return
token
::
NtTT
(
p
.parse_token_tree
());
}
// check at the beginning and the parser checks after each bump
p
.process_potential_macro_variable
();
match
name
{
"item"
=>
match
panictry!
(
p
.parse_item
())
{
sym
::
item
=>
match
panictry!
(
p
.parse_item
())
{
Some
(
i
)
=>
token
::
NtItem
(
i
),
None
=>
{
p
.fatal
(
"expected an item keyword"
)
.emit
();
FatalError
.raise
();
}
},
"block"
=>
token
::
NtBlock
(
panictry!
(
p
.parse_block
())),
"stmt"
=>
match
panictry!
(
p
.parse_stmt
())
{
sym
::
block
=>
token
::
NtBlock
(
panictry!
(
p
.parse_block
())),
sym
::
stmt
=>
match
panictry!
(
p
.parse_stmt
())
{
Some
(
s
)
=>
token
::
NtStmt
(
s
),
None
=>
{
p
.fatal
(
"expected a statement"
)
.emit
();
FatalError
.raise
();
}
},
"pat"
=>
token
::
NtPat
(
panictry!
(
p
.parse_pat
(
None
))),
"expr"
=>
token
::
NtExpr
(
panictry!
(
p
.parse_expr
())),
"literal"
=>
token
::
NtLiteral
(
panictry!
(
p
.parse_literal_maybe_minus
())),
"ty"
=>
token
::
NtTy
(
panictry!
(
p
.parse_ty
())),
sym
::
pat
=>
token
::
NtPat
(
panictry!
(
p
.parse_pat
(
None
))),
sym
::
expr
=>
token
::
NtExpr
(
panictry!
(
p
.parse_expr
())),
sym
::
literal
=>
token
::
NtLiteral
(
panictry!
(
p
.parse_literal_maybe_minus
())),
sym
::
ty
=>
token
::
NtTy
(
panictry!
(
p
.parse_ty
())),
// this could be handled like a token, since it is one
"ident"
=>
if
let
Some
((
ident
,
is_raw
))
=
get_macro_ident
(
&
p
.token
)
{
sym
::
ident
=>
if
let
Some
((
ident
,
is_raw
))
=
get_macro_ident
(
&
p
.token
)
{
let
span
=
p
.span
;
p
.bump
();
token
::
NtIdent
(
Ident
::
new
(
ident
.name
,
span
),
is_raw
)
...
...
@@ -939,10 +939,10 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
p
.fatal
(
&
format!
(
"expected ident, found {}"
,
&
token_str
))
.emit
();
FatalError
.raise
()
}
"path"
=>
token
::
NtPath
(
panictry!
(
p
.parse_path
(
PathStyle
::
Type
))),
"meta"
=>
token
::
NtMeta
(
panictry!
(
p
.parse_meta_item
())),
"vis"
=>
token
::
NtVis
(
panictry!
(
p
.parse_visibility
(
true
))),
"lifetime"
=>
if
p
.check_lifetime
()
{
sym
::
path
=>
token
::
NtPath
(
panictry!
(
p
.parse_path
(
PathStyle
::
Type
))),
sym
::
meta
=>
token
::
NtMeta
(
panictry!
(
p
.parse_meta_item
())),
sym
::
vis
=>
token
::
NtVis
(
panictry!
(
p
.parse_visibility
(
true
))),
sym
::
lifetime
=>
if
p
.check_lifetime
()
{
token
::
NtLifetime
(
p
.expect_lifetime
()
.ident
)
}
else
{
let
token_str
=
pprust
::
token_to_string
(
&
p
.token
);
...
...
src/libsyntax_pos/symbol.rs
浏览文件 @
33a3206d
...
...
@@ -252,6 +252,7 @@
existential_type
,
expected
,
export_name
,
expr
,
extern_absolute_paths
,
external_doc
,
extern_crate_item_prelude
,
...
...
@@ -329,6 +330,7 @@
issue
,
issue_5723_bootstrap
,
issue_tracker_base_url
,
item
,
item_like_imports
,
iter
,
Iterator
,
...
...
@@ -339,6 +341,7 @@
lang
,
lang_items
,
lib
,
lifetime
,
link
,
linkage
,
link_args
,
...
...
@@ -347,6 +350,7 @@
link_name
,
link_section
,
lint_reasons
,
literal
,
local_inner_macros
,
log_syntax
,
loop_break_value
,
...
...
@@ -435,6 +439,7 @@
partial_cmp
,
PartialOrd
,
passes
,
pat
,
path
,
pattern_parentheses
,
Pending
,
...
...
@@ -578,6 +583,7 @@
static_recursion
,
std
,
str
,
stmt
,
stmt_expr_attributes
,
stop_after_dataflow
,
struct_field_attributes
,
...
...
@@ -610,6 +616,7 @@
Try
,
try_blocks
,
try_trait
,
tt
,
tuple_indexing
,
ty
,
type_alias_enum_variants
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录