11use rustc_ast:: ast:: AttrStyle ;
22use 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 } ;
87use rustc_session:: parse:: ParseSess ;
98use rustc_span:: symbol:: { sym, Symbol } ;
109use rustc_span:: { BytePos , Pos , Span } ;
1110
12- use std:: char;
1311use tracing:: debug;
1412
1513mod tokentrees;
1614mod unescape_error_reporting;
1715mod unicode_chars;
1816
19- use rustc_lexer:: { unescape:: Mode , DocStyle } ;
2017use unescape_error_reporting:: { emit_unescape_error, push_escaped_char} ;
2118
2219#[ derive( Clone , Debug ) ]
@@ -28,7 +25,17 @@ pub struct UnmatchedBrace {
2825 pub candidate_span : Option < Span > ,
2926}
3027
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 > {
3239 sess : & ' a ParseSess ,
3340 /// Initial position, read-only.
3441 start_pos : BytePos ,
@@ -37,31 +44,11 @@ crate struct StringReader<'a> {
3744 /// Stop reading src at this index.
3845 end_src_index : usize ,
3946 /// Source text to tokenize.
40- src : Lrc < String > ,
47+ src : & ' a str ,
4148 override_span : Option < Span > ,
4249}
4350
4451impl < ' 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-
6552 fn mk_sp ( & self , lo : BytePos , hi : BytePos ) -> Span {
6653 self . override_span . unwrap_or_else ( || Span :: with_root_ctxt ( lo, hi) )
6754 }
0 commit comments