@@ -12,7 +12,6 @@ use ast::{self, Ident};
1212use syntax_pos:: { self , BytePos , CharPos , Pos , Span } ;
1313use codemap:: CodeMap ;
1414use errors:: { FatalError , DiagnosticBuilder } ;
15- use ext:: tt:: transcribe:: tt_next_token;
1615use parse:: { token, ParseSess } ;
1716use str:: char_at;
1817use symbol:: { Symbol , keywords} ;
@@ -23,53 +22,10 @@ use std::char;
2322use std:: mem:: replace;
2423use std:: rc:: Rc ;
2524
26- pub use ext:: tt:: transcribe:: { TtReader , new_tt_reader} ;
27-
2825pub mod comments;
2926mod tokentrees;
3027mod unicode_chars;
3128
32- pub trait Reader {
33- fn is_eof ( & self ) -> bool ;
34- fn try_next_token ( & mut self ) -> Result < TokenAndSpan , ( ) > ;
35- fn next_token ( & mut self ) -> TokenAndSpan where Self : Sized {
36- let res = self . try_next_token ( ) ;
37- self . unwrap_or_abort ( res)
38- }
39- /// Report a fatal error with the current span.
40- fn fatal ( & self , & str ) -> FatalError ;
41- /// Report a non-fatal error with the current span.
42- fn err ( & self , & str ) ;
43- fn emit_fatal_errors ( & mut self ) ;
44- fn unwrap_or_abort ( & mut self , res : Result < TokenAndSpan , ( ) > ) -> TokenAndSpan {
45- match res {
46- Ok ( tok) => tok,
47- Err ( _) => {
48- self . emit_fatal_errors ( ) ;
49- panic ! ( FatalError ) ;
50- }
51- }
52- }
53- fn peek ( & self ) -> TokenAndSpan ;
54- /// Get a token the parser cares about.
55- fn try_real_token ( & mut self ) -> Result < TokenAndSpan , ( ) > {
56- let mut t = self . try_next_token ( ) ?;
57- loop {
58- match t. tok {
59- token:: Whitespace | token:: Comment | token:: Shebang ( _) => {
60- t = self . try_next_token ( ) ?;
61- }
62- _ => break ,
63- }
64- }
65- Ok ( t)
66- }
67- fn real_token ( & mut self ) -> TokenAndSpan {
68- let res = self . try_real_token ( ) ;
69- self . unwrap_or_abort ( res)
70- }
71- }
72-
7329#[ derive( Clone , PartialEq , Eq , Debug ) ]
7430pub struct TokenAndSpan {
7531 pub tok : token:: Token ,
@@ -182,36 +138,6 @@ impl<'a> StringReader<'a> {
182138 }
183139}
184140
185- impl < ' a > Reader for TtReader < ' a > {
186- fn is_eof ( & self ) -> bool {
187- self . peek ( ) . tok == token:: Eof
188- }
189- fn try_next_token ( & mut self ) -> Result < TokenAndSpan , ( ) > {
190- assert ! ( self . fatal_errs. is_empty( ) ) ;
191- let r = tt_next_token ( self ) ;
192- debug ! ( "TtReader: r={:?}" , r) ;
193- Ok ( r)
194- }
195- fn fatal ( & self , m : & str ) -> FatalError {
196- self . sp_diag . span_fatal ( self . cur_span , m)
197- }
198- fn err ( & self , m : & str ) {
199- self . sp_diag . span_err ( self . cur_span , m) ;
200- }
201- fn emit_fatal_errors ( & mut self ) {
202- for err in & mut self . fatal_errs {
203- err. emit ( ) ;
204- }
205- self . fatal_errs . clear ( ) ;
206- }
207- fn peek ( & self ) -> TokenAndSpan {
208- TokenAndSpan {
209- tok : self . cur_tok . clone ( ) ,
210- sp : self . cur_span ,
211- }
212- }
213- }
214-
215141impl < ' a > StringReader < ' a > {
216142 /// For comments.rs, which hackily pokes into next_pos and ch
217143 pub fn new_raw < ' b > ( sess : & ' a ParseSess , filemap : Rc < syntax_pos:: FileMap > ) -> Self {
0 commit comments