@@ -461,14 +461,6 @@ impl<'a> Lexer<'a> {
461
461
self . tokens . peek ( ) . map ( |i| i. kind )
462
462
}
463
463
464
- /// Returns the second token ahead of the cursor without consuming it. This is slower
465
- /// than [`first`] and should be avoided when possible.
466
- fn second ( & self ) -> Option < raw:: TokenKind > {
467
- let mut tokens = self . tokens . clone ( ) ;
468
- tokens. next ( ) ;
469
- tokens. next ( ) . map ( |i| i. kind )
470
- }
471
-
472
464
/// Consumes the characters while they satisfy `f`. Returns the last character eaten, if any.
473
465
fn eat_while ( & mut self , mut f : impl FnMut ( raw:: TokenKind ) -> bool ) -> Option < raw:: TokenKind > {
474
466
let mut last_eaten: Option < raw:: Token > = None ;
@@ -554,26 +546,31 @@ impl<'a> Lexer<'a> {
554
546
raw:: TokenKind :: Number ( number) => {
555
547
// after reading a decimal number or a float there could be a whitespace
556
548
// followed by a fragment, which will change the type of the literal.
549
+ let numeric_part_hi = self . offset ( ) ;
557
550
self . next_if_eq ( raw:: TokenKind :: Whitespace ) ;
558
551
559
- match self . first ( ) {
560
- Some ( raw:: TokenKind :: LiteralFragment ( fragment) ) => {
561
- use self :: Literal :: { Imaginary , Timing } ;
562
- use TokenKind :: Literal ;
563
-
564
- // Consume the fragment.
565
- self . next ( ) ;
566
-
567
- Ok ( Some ( match fragment {
568
- raw:: LiteralFragmentKind :: Imag => Literal ( Imaginary ) ,
569
- raw:: LiteralFragmentKind :: Dt => Literal ( Timing ( TimingLiteralKind :: Dt ) ) ,
570
- raw:: LiteralFragmentKind :: Ns => Literal ( Timing ( TimingLiteralKind :: Ns ) ) ,
571
- raw:: LiteralFragmentKind :: Us => Literal ( Timing ( TimingLiteralKind :: Us ) ) ,
572
- raw:: LiteralFragmentKind :: Ms => Literal ( Timing ( TimingLiteralKind :: Ms ) ) ,
573
- raw:: LiteralFragmentKind :: S => Literal ( Timing ( TimingLiteralKind :: S ) ) ,
574
- } ) )
575
- }
576
- _ => Ok ( Some ( number. into ( ) ) ) ,
552
+ if let Some ( raw:: TokenKind :: LiteralFragment ( fragment) ) = self . first ( ) {
553
+ use self :: Literal :: { Imaginary , Timing } ;
554
+ use TokenKind :: Literal ;
555
+
556
+ // Consume the fragment.
557
+ self . next ( ) ;
558
+
559
+ Ok ( Some ( match fragment {
560
+ raw:: LiteralFragmentKind :: Imag => Literal ( Imaginary ) ,
561
+ raw:: LiteralFragmentKind :: Dt => Literal ( Timing ( TimingLiteralKind :: Dt ) ) ,
562
+ raw:: LiteralFragmentKind :: Ns => Literal ( Timing ( TimingLiteralKind :: Ns ) ) ,
563
+ raw:: LiteralFragmentKind :: Us => Literal ( Timing ( TimingLiteralKind :: Us ) ) ,
564
+ raw:: LiteralFragmentKind :: Ms => Literal ( Timing ( TimingLiteralKind :: Ms ) ) ,
565
+ raw:: LiteralFragmentKind :: S => Literal ( Timing ( TimingLiteralKind :: S ) ) ,
566
+ } ) )
567
+ } else {
568
+ let kind: TokenKind = number. into ( ) ;
569
+ let span = Span {
570
+ lo : token. offset ,
571
+ hi : numeric_part_hi,
572
+ } ;
573
+ return Ok ( Some ( Token { kind, span } ) ) ;
577
574
}
578
575
}
579
576
raw:: TokenKind :: Single ( Single :: Sharp ) => {
0 commit comments