@@ -84,7 +84,7 @@ impl<'src> SourceReader<'src> {
8484 let mut tokens = Vec :: new ( ) ;
8585 let mut errors = Vec :: new ( ) ;
8686
87- while let Some ( & c) = self . peek ( ) {
87+ while let Some ( c) = self . peek ( ) {
8888 match c {
8989 ' ' | '\r' | '\n' | '\t' => {
9090 self . next_char ( ) ;
@@ -133,11 +133,11 @@ impl<'src> SourceReader<'src> {
133133 }
134134 continue ;
135135 }
136- Some ( & c) => {
136+ Some ( c) => {
137137 if is_ident_start ( c) {
138138 loop {
139139 self . next_char ( ) ;
140- let Some ( & c) = self . peek ( ) else { break } ;
140+ let Some ( c) = self . peek ( ) else { break } ;
141141 if !is_xid_continue ( c) {
142142 break ;
143143 }
@@ -491,9 +491,9 @@ impl<'src> SourceReader<'src> {
491491
492492 self . next_char ( ) ;
493493 let ( base, alt) = match self . peek ( ) {
494- Some ( & 'x' ) => ( 16 , true ) ,
495- Some ( & 'o' ) => ( 8 , true ) ,
496- Some ( & 'b' ) => ( 2 , true ) ,
494+ Some ( 'x' ) => ( 16 , true ) ,
495+ Some ( 'o' ) => ( 8 , true ) ,
496+ Some ( 'b' ) => ( 2 , true ) ,
497497 _ => ( 10 , false ) ,
498498 } ;
499499 if alt {
@@ -502,7 +502,7 @@ impl<'src> SourceReader<'src> {
502502
503503 // Now pointing to the first digit.
504504 let mut end = self . index ;
505- while let Some ( & ch) = self . peek ( ) {
505+ while let Some ( ch) = self . peek ( ) {
506506 if ch. is_digit ( base as _ ) {
507507 self . next_char ( ) ;
508508 end += 1 ;
@@ -513,7 +513,7 @@ impl<'src> SourceReader<'src> {
513513 base,
514514 loc : ( self . index , 1 ) . into ( ) ,
515515 } ) ;
516- while self . peek ( ) . map_or ( false , char :: is_ascii_digit) {
516+ while self . peek ( ) . map_or ( false , |c| c . is_ascii_digit ( ) ) {
517517 self . next_char ( ) ;
518518 }
519519 }
@@ -523,9 +523,27 @@ impl<'src> SourceReader<'src> {
523523
524524 // Now pointing to the last digit before the non-digit.
525525
526- if !alt && self . peek ( ) == Some ( & '.' ) {
527- self . next_char ( ) ;
528- end += 1 ;
526+ if !alt && self . peek ( ) == Some ( '.' ) {
527+ let idx = self . index ;
528+ if loop {
529+ match self . next_char ( ) {
530+ Some ( '_' | '@' ) => break true ,
531+ Some ( c) if is_xid_start ( c) => break true ,
532+ Some ( c) if !c. is_whitespace ( ) => break false ,
533+ _ => { }
534+ }
535+ } {
536+ self . index = idx;
537+ tokens. push ( Token {
538+ kind : TokenKind :: Literal ( LiteralToken :: Int (
539+ & self . source [ start..end] ,
540+ ) ) ,
541+ span : ( start..end) . into ( ) ,
542+ } ) ;
543+ continue ;
544+ } else {
545+ end += 1 ;
546+ }
529547 } else {
530548 // Not a float.
531549 tokens. push ( Token {
@@ -572,9 +590,34 @@ impl<'src> SourceReader<'src> {
572590
573591 // Now pointing to the last digit before the non-digit.
574592
575- if self . peek ( ) == Some ( & '.' ) {
593+ if self . peek ( ) == Some ( '.' ) {
594+ let idx = self . index ;
576595 self . next_char ( ) ;
577- num_len += 1 ;
596+ let old_len = num_len;
597+ // num_len += 1;
598+ if loop {
599+ match {
600+ let ch = self . next_char ( ) ;
601+ num_len += ch. map_or ( 0 , |c| c. len_utf8 ( ) ) ;
602+ ch
603+ } {
604+ Some ( '_' | '@' ) => break true ,
605+ Some ( c) if is_xid_start ( c) => break true ,
606+ Some ( c) if !c. is_whitespace ( ) => break false ,
607+ None => break false ,
608+ _ => { }
609+ }
610+ } {
611+ self . index = idx;
612+ tokens. push ( Token {
613+ kind : TokenKind :: Literal ( LiteralToken :: Int (
614+ self . slice_backward ( old_len) ,
615+ ) ) ,
616+ span : self . source_span_backward ( old_len) ,
617+ } ) ;
618+ continue ;
619+ }
620+ self . index = idx + 1 ;
578621 } else {
579622 // Not a float.
580623 tokens. push ( Token {
@@ -618,14 +661,14 @@ impl<'src> SourceReader<'src> {
618661 self . next_char ( ) ;
619662
620663 match self . peek ( ) {
621- Some ( & '?' ) => {
664+ Some ( '?' ) => {
622665 self . next_char ( ) ;
623666 tokens. push ( Token {
624667 kind : TokenKind :: BinOp ( BinOpToken :: Colonq ) ,
625668 span : self . source_span_backward ( 2 ) ,
626669 } ) ;
627670 }
628- Some ( & ':' ) => {
671+ Some ( ':' ) => {
629672 self . next_char ( ) ;
630673 tokens. push ( Token {
631674 kind : TokenKind :: ColonColon ,
@@ -659,7 +702,7 @@ impl<'src> SourceReader<'src> {
659702 let span_start = self . index ;
660703 self . next_char ( ) ;
661704
662- if let Some ( & c) = self . peek ( ) {
705+ if let Some ( c) = self . peek ( ) {
663706 if !is_ident_start ( c) {
664707 errors. push ( CobaltError :: ExpectedFound {
665708 ex : "start of identifier" ,
@@ -704,7 +747,7 @@ impl<'src> SourceReader<'src> {
704747 // --- Optional param.
705748
706749 match self . peek ( ) {
707- Some ( & '(' ) => { }
750+ Some ( '(' ) => { }
708751 _ => {
709752 tokens. push ( Token {
710753 kind : TokenKind :: Annotation ( ( name, None ) ) ,
@@ -718,7 +761,7 @@ impl<'src> SourceReader<'src> {
718761 }
719762
720763 // Eat the '('.
721- assert_eq ! ( self . peek( ) , Some ( & '(' ) ) ;
764+ assert_eq ! ( self . peek( ) , Some ( '(' ) ) ;
722765 self . next_char ( ) ;
723766
724767 let arg_span_start = self . index ;
@@ -777,13 +820,13 @@ impl<'src> SourceReader<'src> {
777820 }
778821 let c = c. unwrap ( ) ;
779822
780- if c == & '\\' {
823+ if c == '\\' {
781824 last_was_escape = !last_was_escape;
782825 self . next_char ( ) ;
783826 continue ;
784827 }
785828
786- if c == & '\'' && !last_was_escape {
829+ if c == '\'' && !last_was_escape {
787830 break ;
788831 }
789832
@@ -834,7 +877,7 @@ impl<'src> SourceReader<'src> {
834877 fn eat_ident ( & mut self ) -> Result < Token < ' src > , CobaltError < ' src > > {
835878 let start_idx = self . index ;
836879
837- if let Some ( & c) = self . peek ( ) {
880+ if let Some ( c) = self . peek ( ) {
838881 if !( is_xid_start ( c) || c == '_' ) {
839882 self . next_char ( ) ;
840883 let err = CobaltError :: ExpectedFound {
@@ -858,7 +901,7 @@ impl<'src> SourceReader<'src> {
858901 // The reader is now pointing at the first character of the identifier.
859902
860903 while let Some ( c) = self . peek ( ) {
861- if !is_xid_continue ( * c) {
904+ if !is_xid_continue ( c) {
862905 break ;
863906 }
864907
@@ -940,13 +983,13 @@ impl<'src> SourceReader<'src> {
940983 }
941984 let c = c. unwrap ( ) ;
942985
943- if c == & '\\' {
986+ if c == '\\' {
944987 last_was_escape = !last_was_escape;
945988 self . next_char ( ) ;
946989 continue ;
947990 }
948991
949- if c == & '"' && !last_was_escape {
992+ if c == '"' && !last_was_escape {
950993 break ;
951994 }
952995
0 commit comments