@@ -450,6 +450,7 @@ where
450450 }
451451
452452 /// Lex a single comment.
453+ #[ cfg( feature = "full-lexer" ) ]
453454 fn lex_comment ( & mut self ) -> LexResult {
454455 let start_pos = self . get_pos ( ) ;
455456 let mut value = String :: new ( ) ;
@@ -465,6 +466,20 @@ where
465466 }
466467 }
467468
469+ /// Discard comment if full-lexer is not enabled.
470+ #[ cfg( not( feature = "full-lexer" ) ) ]
471+ fn lex_comment ( & mut self ) {
472+ loop {
473+ match self . window [ 0 ] {
474+ Some ( '\n' | '\r' ) | None => {
475+ return ;
476+ }
477+ Some ( _) => { }
478+ }
479+ self . next_char ( ) . unwrap ( ) ;
480+ }
481+ }
482+
468483 /// Lex a string literal.
469484 fn lex_string ( & mut self , kind : StringKind ) -> LexResult {
470485 let start_pos = self . get_pos ( ) ;
@@ -611,8 +626,9 @@ where
611626 tabs += 1 ;
612627 }
613628 Some ( '#' ) => {
614- let comment = self . lex_comment ( ) ?;
615- self . emit ( comment) ;
629+ let _comment = self . lex_comment ( ) ;
630+ #[ cfg( feature = "full-lexer" ) ]
631+ self . emit ( _comment?) ;
616632 spaces = 0 ;
617633 tabs = 0 ;
618634 }
@@ -753,8 +769,9 @@ where
753769 self . emit ( number) ;
754770 }
755771 '#' => {
756- let comment = self . lex_comment ( ) ?;
757- self . emit ( comment) ;
772+ let _comment = self . lex_comment ( ) ;
773+ #[ cfg( feature = "full-lexer" ) ]
774+ self . emit ( _comment?) ;
758775 }
759776 '"' | '\'' => {
760777 let string = self . lex_string ( StringKind :: String ) ?;
@@ -1101,6 +1118,7 @@ where
11011118 self . at_begin_of_line = true ;
11021119 self . emit ( ( Tok :: Newline , TextRange :: new ( tok_start, tok_end) ) ) ;
11031120 } else {
1121+ #[ cfg( feature = "full-lexer" ) ]
11041122 self . emit ( ( Tok :: NonLogicalNewline , TextRange :: new ( tok_start, tok_end) ) ) ;
11051123 }
11061124 }
@@ -1408,6 +1426,7 @@ mod tests {
14081426 ( $( $name: ident: $eol: expr, ) * ) => {
14091427 $(
14101428 #[ test]
1429+ #[ cfg( feature = "full-lexer" ) ]
14111430 fn $name( ) {
14121431 let source = format!( r"99232 # {}" , $eol) ;
14131432 let tokens = lex_source( & source) ;
@@ -1428,6 +1447,7 @@ mod tests {
14281447 ( $( $name: ident: $eol: expr, ) * ) => {
14291448 $(
14301449 #[ test]
1450+ #[ cfg( feature = "full-lexer" ) ]
14311451 fn $name( ) {
14321452 let source = format!( "123 # Foo{}456" , $eol) ;
14331453 let tokens = lex_source( & source) ;
@@ -1607,6 +1627,7 @@ mod tests {
16071627 ( $( $name: ident: $eol: expr, ) * ) => {
16081628 $(
16091629 #[ test]
1630+ #[ cfg( feature = "full-lexer" ) ]
16101631 fn $name( ) {
16111632 let source = r"x = [
16121633
@@ -1669,6 +1690,7 @@ mod tests {
16691690 }
16701691
16711692 #[ test]
1693+ #[ cfg( feature = "full-lexer" ) ]
16721694 fn test_non_logical_newline_in_string_continuation ( ) {
16731695 let source = r"(
16741696 'a'
@@ -1698,6 +1720,7 @@ mod tests {
16981720 }
16991721
17001722 #[ test]
1723+ #[ cfg( feature = "full-lexer" ) ]
17011724 fn test_logical_newline_line_comment ( ) {
17021725 let source = "#Hello\n #World" ;
17031726 let tokens = lex_source ( source) ;
0 commit comments