Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b4714cdf
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,发现更多精彩内容 >>
提交
b4714cdf
编写于
5月 20, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lexer: Fix span override for the first token in a string
上级
2dca249d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
13 deletion
+15
-13
src/librustdoc/html/highlight.rs
src/librustdoc/html/highlight.rs
+2
-2
src/libsyntax/parse/lexer/comments.rs
src/libsyntax/parse/lexer/comments.rs
+1
-1
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/lexer/mod.rs
+11
-8
src/libsyntax/parse/mod.rs
src/libsyntax/parse/mod.rs
+1
-2
未找到文件。
src/librustdoc/html/highlight.rs
浏览文件 @
b4714cdf
...
...
@@ -48,7 +48,7 @@ pub fn render_with_highlighting(src: &str, class: Option<&str>, id: Option<&str>
}
write_header
(
class
,
id
,
&
mut
out
)
.unwrap
();
let
mut
classifier
=
Classifier
::
new
(
lexer
::
StringReader
::
new
(
&
sess
,
fm
),
sess
.codemap
());
let
mut
classifier
=
Classifier
::
new
(
lexer
::
StringReader
::
new
(
&
sess
,
fm
,
None
),
sess
.codemap
());
if
let
Err
(
_
)
=
classifier
.write_source
(
&
mut
out
)
{
return
format!
(
"<pre>{}</pre>"
,
src
);
}
...
...
@@ -68,7 +68,7 @@ pub fn render_inner_with_highlighting(src: &str) -> io::Result<String> {
let
fm
=
sess
.codemap
()
.new_filemap
(
FileName
::
Custom
(
"stdin"
.to_string
()),
src
.to_string
());
let
mut
out
=
Vec
::
new
();
let
mut
classifier
=
Classifier
::
new
(
lexer
::
StringReader
::
new
(
&
sess
,
fm
),
sess
.codemap
());
let
mut
classifier
=
Classifier
::
new
(
lexer
::
StringReader
::
new
(
&
sess
,
fm
,
None
),
sess
.codemap
());
classifier
.write_source
(
&
mut
out
)
?
;
Ok
(
String
::
from_utf8_lossy
(
&
out
)
.into_owned
())
...
...
src/libsyntax/parse/lexer/comments.rs
浏览文件 @
b4714cdf
...
...
@@ -362,7 +362,7 @@ pub fn gather_comments_and_literals(sess: &ParseSess, path: FileName, srdr: &mut
let
src
=
String
::
from_utf8
(
src
)
.unwrap
();
let
cm
=
CodeMap
::
new
(
sess
.codemap
()
.path_mapping
()
.clone
());
let
filemap
=
cm
.new_filemap
(
path
,
src
);
let
mut
rdr
=
lexer
::
StringReader
::
new_raw
(
sess
,
filemap
);
let
mut
rdr
=
lexer
::
StringReader
::
new_raw
(
sess
,
filemap
,
None
);
let
mut
comments
:
Vec
<
Comment
>
=
Vec
::
new
();
let
mut
literals
:
Vec
<
Literal
>
=
Vec
::
new
();
...
...
src/libsyntax/parse/lexer/mod.rs
浏览文件 @
b4714cdf
...
...
@@ -155,13 +155,15 @@ pub fn peek(&self) -> TokenAndSpan {
impl
<
'a
>
StringReader
<
'a
>
{
/// For comments.rs, which hackily pokes into next_pos and ch
pub
fn
new_raw
(
sess
:
&
'a
ParseSess
,
filemap
:
Lrc
<
syntax_pos
::
FileMap
>
)
->
Self
{
let
mut
sr
=
StringReader
::
new_raw_internal
(
sess
,
filemap
);
pub
fn
new_raw
(
sess
:
&
'a
ParseSess
,
filemap
:
Lrc
<
syntax_pos
::
FileMap
>
,
override_span
:
Option
<
Span
>
)
->
Self
{
let
mut
sr
=
StringReader
::
new_raw_internal
(
sess
,
filemap
,
override_span
);
sr
.bump
();
sr
}
fn
new_raw_internal
(
sess
:
&
'a
ParseSess
,
filemap
:
Lrc
<
syntax_pos
::
FileMap
>
)
->
Self
{
fn
new_raw_internal
(
sess
:
&
'a
ParseSess
,
filemap
:
Lrc
<
syntax_pos
::
FileMap
>
,
override_span
:
Option
<
Span
>
)
->
Self
{
if
filemap
.src
.is_none
()
{
sess
.span_diagnostic
.bug
(
&
format!
(
"Cannot lex filemap without source: {}"
,
filemap
.name
));
...
...
@@ -185,12 +187,13 @@ fn new_raw_internal(sess: &'a ParseSess, filemap: Lrc<syntax_pos::FileMap>) -> S
token
:
token
::
Eof
,
span
:
syntax_pos
::
DUMMY_SP
,
open_braces
:
Vec
::
new
(),
override_span
:
None
,
override_span
,
}
}
pub
fn
new
(
sess
:
&
'a
ParseSess
,
filemap
:
Lrc
<
syntax_pos
::
FileMap
>
)
->
Self
{
let
mut
sr
=
StringReader
::
new_raw
(
sess
,
filemap
);
pub
fn
new
(
sess
:
&
'a
ParseSess
,
filemap
:
Lrc
<
syntax_pos
::
FileMap
>
,
override_span
:
Option
<
Span
>
)
->
Self
{
let
mut
sr
=
StringReader
::
new_raw
(
sess
,
filemap
,
override_span
);
if
sr
.advance_token
()
.is_err
()
{
sr
.emit_fatal_errors
();
FatalError
.raise
();
...
...
@@ -207,7 +210,7 @@ pub fn retokenize(sess: &'a ParseSess, mut span: Span) -> Self {
span
=
span
.shrink_to_lo
();
}
let
mut
sr
=
StringReader
::
new_raw_internal
(
sess
,
begin
.fm
);
let
mut
sr
=
StringReader
::
new_raw_internal
(
sess
,
begin
.fm
,
None
);
// Seek the lexer to the right byte range.
sr
.save_new_lines_and_multibyte
=
false
;
...
...
@@ -1795,7 +1798,7 @@ fn setup<'a>(cm: &CodeMap,
teststr
:
String
)
->
StringReader
<
'a
>
{
let
fm
=
cm
.new_filemap
(
PathBuf
::
from
(
"zebra.rs"
)
.into
(),
teststr
);
StringReader
::
new
(
sess
,
fm
)
StringReader
::
new
(
sess
,
fm
,
None
)
}
#[test]
...
...
src/libsyntax/parse/mod.rs
浏览文件 @
b4714cdf
...
...
@@ -229,8 +229,7 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
/// Given a filemap, produce a sequence of token-trees
pub
fn
filemap_to_stream
(
sess
:
&
ParseSess
,
filemap
:
Lrc
<
FileMap
>
,
override_span
:
Option
<
Span
>
)
->
TokenStream
{
let
mut
srdr
=
lexer
::
StringReader
::
new
(
sess
,
filemap
);
srdr
.override_span
=
override_span
;
let
mut
srdr
=
lexer
::
StringReader
::
new
(
sess
,
filemap
,
override_span
);
srdr
.real_token
();
panictry!
(
srdr
.parse_all_token_trees
())
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录