@@ -6,19 +6,19 @@ use crate::diagnostics;
66impl < ' a > Lexer < ' a > {
77 /// 12.9.3 Numeric Literals with `0` prefix
88 pub ( super ) fn read_zero ( & mut self ) -> Kind {
9- match self . peek ( ) {
10- Some ( 'b' | 'B' ) => self . read_non_decimal ( Kind :: Binary ) ,
11- Some ( 'o' | 'O' ) => self . read_non_decimal ( Kind :: Octal ) ,
12- Some ( 'x' | 'X' ) => self . read_non_decimal ( Kind :: Hex ) ,
13- Some ( 'e' | 'E' ) => {
9+ match self . peek_byte ( ) {
10+ Some ( b 'b' | b 'B') => self . read_non_decimal ( Kind :: Binary ) ,
11+ Some ( b 'o' | b 'O') => self . read_non_decimal ( Kind :: Octal ) ,
12+ Some ( b 'x' | b 'X') => self . read_non_decimal ( Kind :: Hex ) ,
13+ Some ( b 'e' | b 'E') => {
1414 self . consume_char ( ) ;
1515 self . read_decimal_exponent ( )
1616 }
17- Some ( '.' ) => {
17+ Some ( b '.') => {
1818 self . consume_char ( ) ;
1919 self . decimal_literal_after_decimal_point_after_digits ( )
2020 }
21- Some ( 'n' ) => {
21+ Some ( b 'n') => {
2222 self . consume_char ( ) ;
2323 self . check_after_numeric_literal ( Kind :: Decimal )
2424 }
@@ -42,23 +42,23 @@ impl<'a> Lexer<'a> {
4242 fn read_non_decimal ( & mut self , kind : Kind ) -> Kind {
4343 self . consume_char ( ) ;
4444
45- if self . peek ( ) . is_some_and ( |c| kind. matches_number_char ( c) ) {
45+ if self . peek_byte ( ) . is_some_and ( |c| kind. matches_number_char ( c) ) {
4646 self . consume_char ( ) ;
4747 } else {
4848 self . unexpected_err ( ) ;
4949 return Kind :: Undetermined ;
5050 }
5151
52- while let Some ( c) = self . peek ( ) {
52+ while let Some ( c) = self . peek_byte ( ) {
5353 match c {
54- '_' => {
54+ b '_' => {
5555 self . consume_char ( ) ;
5656 // NOTE: it looks invalid numeric tokens are still parsed.
5757 // This seems to be a waste. It also requires us to put this
5858 // call here instead of after we ensure the next character
5959 // is a number character
6060 self . token . set_has_separator ( ) ;
61- if self . peek ( ) . is_some_and ( |c| kind. matches_number_char ( c) ) {
61+ if self . peek_byte ( ) . is_some_and ( |c| kind. matches_number_char ( c) ) {
6262 self . consume_char ( ) ;
6363 } else {
6464 self . unexpected_err ( ) ;
@@ -71,35 +71,33 @@ impl<'a> Lexer<'a> {
7171 _ => break ,
7272 }
7373 }
74- if self . peek ( ) == Some ( 'n' ) {
75- self . consume_char ( ) ;
76- }
74+ self . next_ascii_char_eq ( b'n' ) ;
7775 self . check_after_numeric_literal ( kind)
7876 }
7977
8078 fn read_legacy_octal ( & mut self ) -> Kind {
8179 let mut kind = Kind :: Octal ;
8280 loop {
83- match self . peek ( ) {
84- Some ( '0' ..='7' ) => {
81+ match self . peek_byte ( ) {
82+ Some ( b '0' ..=b '7') => {
8583 self . consume_char ( ) ;
8684 }
87- Some ( '8' ..='9' ) => {
85+ Some ( b '8' ..=b '9') => {
8886 self . consume_char ( ) ;
8987 kind = Kind :: Decimal ;
9088 }
9189 _ => break ,
9290 }
9391 }
9492
95- match self . peek ( ) {
93+ match self . peek_byte ( ) {
9694 // allow 08.5 and 09.5
97- Some ( '.' ) if kind == Kind :: Decimal => {
95+ Some ( b '.') if kind == Kind :: Decimal => {
9896 self . consume_char ( ) ;
9997 self . decimal_literal_after_decimal_point_after_digits ( )
10098 }
10199 // allow 08e1 and 09e1
102- Some ( 'e' ) if kind == Kind :: Decimal => {
100+ Some ( b 'e') if kind == Kind :: Decimal => {
103101 self . consume_char ( ) ;
104102 self . read_decimal_exponent ( )
105103 }
@@ -108,12 +106,12 @@ impl<'a> Lexer<'a> {
108106 }
109107
110108 fn read_decimal_exponent ( & mut self ) -> Kind {
111- let kind = match self . peek ( ) {
112- Some ( '-' ) => {
109+ let kind = match self . peek_byte ( ) {
110+ Some ( b '-') => {
113111 self . consume_char ( ) ;
114112 Kind :: NegativeExponential
115113 }
116- Some ( '+' ) => {
114+ Some ( b '+') => {
117115 self . consume_char ( ) ;
118116 Kind :: PositiveExponential
119117 }
@@ -124,7 +122,7 @@ impl<'a> Lexer<'a> {
124122 }
125123
126124 fn read_decimal_digits ( & mut self ) {
127- if self . peek ( ) . is_some_and ( |c| c . is_ascii_digit ( ) ) {
125+ if self . peek_byte ( ) . is_some_and ( |b| b . is_ascii_digit ( ) ) {
128126 self . consume_char ( ) ;
129127 } else {
130128 self . unexpected_err ( ) ;
@@ -135,23 +133,23 @@ impl<'a> Lexer<'a> {
135133 }
136134
137135 fn read_decimal_digits_after_first_digit ( & mut self ) {
138- while let Some ( c ) = self . peek ( ) {
139- match c {
140- '_' => {
136+ while let Some ( b ) = self . peek_byte ( ) {
137+ match b {
138+ b '_' => {
141139 self . consume_char ( ) ;
142140 // NOTE: it looks invalid numeric tokens are still parsed.
143141 // This seems to be a waste. It also requires us to put this
144142 // call here instead of after we ensure the next character
145143 // is an ASCII digit
146144 self . token . set_has_separator ( ) ;
147- if self . peek ( ) . is_some_and ( |c| c . is_ascii_digit ( ) ) {
145+ if self . peek_byte ( ) . is_some_and ( |b| b . is_ascii_digit ( ) ) {
148146 self . consume_char ( ) ;
149147 } else {
150148 self . unexpected_err ( ) ;
151149 return ;
152150 }
153151 }
154- '0' ..='9' => {
152+ b '0' ..=b '9' => {
155153 self . consume_char ( ) ;
156154 }
157155 _ => break ,
@@ -172,16 +170,14 @@ impl<'a> Lexer<'a> {
172170 }
173171
174172 fn optional_decimal_digits ( & mut self ) {
175- if self . peek ( ) . is_some_and ( |c| c . is_ascii_digit ( ) ) {
173+ if self . peek_byte ( ) . is_some_and ( |b| b . is_ascii_digit ( ) ) {
176174 self . consume_char ( ) ;
177- } else {
178- return ;
175+ self . read_decimal_digits_after_first_digit ( ) ;
179176 }
180- self . read_decimal_digits_after_first_digit ( ) ;
181177 }
182178
183179 fn optional_exponent ( & mut self ) -> Option < Kind > {
184- if matches ! ( self . peek ( ) , Some ( 'e' | 'E' ) ) {
180+ if matches ! ( self . peek_byte ( ) , Some ( b 'e' | b 'E') ) {
185181 self . consume_char ( ) ;
186182 return Some ( self . read_decimal_exponent ( ) ) ;
187183 }
@@ -191,12 +187,12 @@ impl<'a> Lexer<'a> {
191187 fn check_after_numeric_literal ( & mut self , kind : Kind ) -> Kind {
192188 let offset = self . offset ( ) ;
193189 // The SourceCharacter immediately following a NumericLiteral must not be an IdentifierStart or DecimalDigit.
194- let c = self . peek ( ) ;
190+ let c = self . peek_char ( ) ;
195191 if c. is_none ( ) || c. is_some_and ( |ch| !ch. is_ascii_digit ( ) && !is_identifier_start ( ch) ) {
196192 return kind;
197193 }
198194 self . consume_char ( ) ;
199- while let Some ( c) = self . peek ( ) {
195+ while let Some ( c) = self . peek_char ( ) {
200196 if is_identifier_start ( c) {
201197 self . consume_char ( ) ;
202198 } else {
0 commit comments