@@ -28,11 +28,13 @@ pub mod unescape;
2828#[ cfg( test) ]
2929mod tests;
3030
31+ pub use crate :: literals:: { Base , LiteralKind , RawStrError } ;
32+
3133use self :: TokenKind :: * ;
3234use crate :: cursor:: Cursor ;
3335use crate :: literals:: {
3436 double_quoted_string, eat_literal_suffix, lifetime_or_char, number, raw_double_quoted_string,
35- single_quoted_string, LiteralKind ,
37+ single_quoted_string,
3638} ;
3739
3840/// Parsed token.
@@ -165,12 +167,6 @@ pub fn strip_shebang(input: &str) -> Option<usize> {
165167 None
166168}
167169
168- /// Parses the first token from the provided input string.
169- pub fn first_token ( input : & str ) -> Token {
170- debug_assert ! ( !input. is_empty( ) ) ;
171- advance_token ( & mut Cursor :: new ( input) )
172- }
173-
174170/// Creates an iterator that produces tokens from the input string.
175171pub fn tokenize ( mut input : & str ) -> impl Iterator < Item = Token > + ' _ {
176172 std:: iter:: from_fn ( move || {
@@ -250,8 +246,11 @@ pub fn is_ident(string: &str) -> bool {
250246 }
251247}
252248
253- /// Parses a token from the input string.
254- fn advance_token ( cursor : & mut Cursor ) -> Token {
249+ /// Parses the first token from the provided input string.
250+ pub fn first_token ( input : & str ) -> Token {
251+ debug_assert ! ( !input. is_empty( ) ) ;
252+ let cursor = & mut Cursor :: new ( input) ;
253+
255254 let first_char = cursor. bump ( ) . unwrap ( ) ;
256255 let token_kind = match first_char {
257256 // Slash, comment or block comment.
@@ -262,11 +261,21 @@ fn advance_token(cursor: &mut Cursor) -> Token {
262261 } ,
263262
264263 // Whitespace sequence.
265- c if is_whitespace ( c) => whitespace ( cursor) ,
264+ c if is_whitespace ( c) => {
265+ cursor. bump_while ( is_whitespace) ;
266+ Whitespace
267+ }
266268
267269 // Raw identifier, raw string literal or identifier.
268270 'r' => match ( cursor. peek ( ) , cursor. peek_second ( ) ) {
269- ( '#' , c1) if is_id_start ( c1) => raw_ident ( cursor) ,
271+ ( '#' , c1) if is_id_start ( c1) => {
272+ // Eat "#" symbol.
273+ cursor. bump ( ) ;
274+ // Eat the identifier part of RawIdent.
275+ cursor. bump ( ) ;
276+ ident ( cursor) ;
277+ RawIdent
278+ }
270279 ( '#' , _) | ( '"' , _) => {
271280 let ( n_hashes, err) = raw_double_quoted_string ( cursor, 1 ) ;
272281 let suffix_start = cursor. len_consumed ( ) ;
@@ -425,34 +434,9 @@ fn block_comment(cursor: &mut Cursor) -> TokenKind {
425434 BlockComment { doc_style, terminated : depth == 0 }
426435}
427436
428- fn whitespace ( cursor : & mut Cursor ) -> TokenKind {
429- debug_assert ! ( is_whitespace( cursor. prev( ) ) ) ;
430- cursor. bump_while ( is_whitespace) ;
431- Whitespace
432- }
433-
434- fn raw_ident ( cursor : & mut Cursor ) -> TokenKind {
435- debug_assert ! ( cursor. prev( ) == 'r' && cursor. peek( ) == '#' && is_id_start( cursor. peek_second( ) ) ) ;
436- // Eat "#" symbol.
437- cursor. bump ( ) ;
438- // Eat the identifier part of RawIdent.
439- eat_identifier ( cursor) ;
440- RawIdent
441- }
442-
443- fn ident ( cursor : & mut Cursor ) -> TokenKind {
437+ /// Start is already eaten, eat the rest of identifier.
438+ pub ( crate ) fn ident ( cursor : & mut Cursor ) -> TokenKind {
444439 debug_assert ! ( is_id_start( cursor. prev( ) ) ) ;
445- // Start is already eaten, eat the rest of identifier.
446440 cursor. bump_while ( is_id_continue) ;
447441 Ident
448442}
449-
450- /// Eats one identifier.
451- pub ( crate ) fn eat_identifier ( cursor : & mut Cursor ) {
452- if !is_id_start ( cursor. peek ( ) ) {
453- return ;
454- }
455- cursor. bump ( ) ;
456-
457- cursor. bump_while ( is_id_continue) ;
458- }
0 commit comments