1
1
use rustc_ast:: ast:: AttrStyle ;
2
2
use rustc_ast:: token:: { self , CommentKind , Token , TokenKind } ;
3
- use rustc_ast:: tokenstream:: IsJoint ;
4
- use rustc_data_structures:: sync:: Lrc ;
5
- use rustc_errors:: { error_code, Applicability , DiagnosticBuilder , FatalError } ;
6
- use rustc_lexer:: Base ;
7
- use rustc_lexer:: { unescape, RawStrError } ;
3
+ use rustc_ast:: tokenstream:: { IsJoint , TokenStream } ;
4
+ use rustc_errors:: { error_code, Applicability , DiagnosticBuilder , FatalError , PResult } ;
5
+ use rustc_lexer:: unescape:: { self , Mode } ;
6
+ use rustc_lexer:: { Base , DocStyle , RawStrError } ;
8
7
use rustc_session:: parse:: ParseSess ;
9
8
use rustc_span:: symbol:: { sym, Symbol } ;
10
9
use rustc_span:: { BytePos , Pos , Span } ;
11
10
12
- use std:: char;
13
11
use tracing:: debug;
14
12
15
13
mod tokentrees;
16
14
mod unescape_error_reporting;
17
15
mod unicode_chars;
18
16
19
- use rustc_lexer:: { unescape:: Mode , DocStyle } ;
20
17
use unescape_error_reporting:: { emit_unescape_error, push_escaped_char} ;
21
18
22
19
#[ derive( Clone , Debug ) ]
@@ -28,7 +25,17 @@ pub struct UnmatchedBrace {
28
25
pub candidate_span : Option < Span > ,
29
26
}
30
27
31
- crate struct StringReader < ' a > {
28
+ crate fn parse_token_trees < ' a > (
29
+ sess : & ' a ParseSess ,
30
+ src : & ' a str ,
31
+ start_pos : BytePos ,
32
+ override_span : Option < Span > ,
33
+ ) -> ( PResult < ' a , TokenStream > , Vec < UnmatchedBrace > ) {
34
+ StringReader { sess, start_pos, pos : start_pos, end_src_index : src. len ( ) , src, override_span }
35
+ . into_token_trees ( )
36
+ }
37
+
38
+ struct StringReader < ' a > {
32
39
sess : & ' a ParseSess ,
33
40
/// Initial position, read-only.
34
41
start_pos : BytePos ,
@@ -37,31 +44,11 @@ crate struct StringReader<'a> {
37
44
/// Stop reading src at this index.
38
45
end_src_index : usize ,
39
46
/// Source text to tokenize.
40
- src : Lrc < String > ,
47
+ src : & ' a str ,
41
48
override_span : Option < Span > ,
42
49
}
43
50
44
51
impl < ' a > StringReader < ' a > {
45
- crate fn new (
46
- sess : & ' a ParseSess ,
47
- source_file : Lrc < rustc_span:: SourceFile > ,
48
- override_span : Option < Span > ,
49
- ) -> Self {
50
- let src = source_file. src . clone ( ) . unwrap_or_else ( || {
51
- sess. span_diagnostic
52
- . bug ( & format ! ( "cannot lex `source_file` without source: {}" , source_file. name) ) ;
53
- } ) ;
54
-
55
- StringReader {
56
- sess,
57
- start_pos : source_file. start_pos ,
58
- pos : source_file. start_pos ,
59
- end_src_index : src. len ( ) ,
60
- src,
61
- override_span,
62
- }
63
- }
64
-
65
52
fn mk_sp ( & self , lo : BytePos , hi : BytePos ) -> Span {
66
53
self . override_span . unwrap_or_else ( || Span :: with_root_ctxt ( lo, hi) )
67
54
}
0 commit comments