@@ -20,26 +20,6 @@ const num_sep = `_`
2020const b_lf = 10
2121const b_cr = 13
2222const backslash = `\\ `
23- const digit_table = get_digit_table ()
24- const letter_table = get_letter_table ()
25-
26- @[direct_array_access]
27- fn get_digit_table () [256 ]bool {
28- mut res := [256 ]bool {}
29- for c in 0 .. 256 {
30- res[c] = u8 (c).is_digit ()
31- }
32- return res
33- }
34-
35- @[direct_array_access]
36- fn get_letter_table () [256 ]bool {
37- mut res := [256 ]bool {}
38- for c in 0 .. 256 {
39- res[c] = u8 (c).is_letter ()
40- }
41- return res
42- }
4323
4424@[minify]
4525pub struct Scanner {
@@ -293,7 +273,6 @@ fn (s &Scanner) num_lit(start int, end int) string {
293273 }
294274}
295275
296- @[direct_array_access]
297276fn (mut s Scanner) ident_bin_number () string {
298277 mut has_wrong_digit := false
299278 mut first_wrong_digit_pos := 0
@@ -309,7 +288,7 @@ fn (mut s Scanner) ident_bin_number() string {
309288 s.error ('cannot use `_` consecutively' )
310289 }
311290 if ! c.is_bin_digit () && c != num_sep {
312- if (! digit_table[c] && ! letter_table[c] ) || s.is_inside_string || s.is_nested_string {
291+ if (! c. is_digit () && ! c. is_letter () ) || s.is_inside_string || s.is_nested_string {
313292 break
314293 } else if ! has_wrong_digit {
315294 has_wrong_digit = true
@@ -353,7 +332,7 @@ fn (mut s Scanner) ident_hex_number() string {
353332 s.error ('cannot use `_` consecutively' )
354333 }
355334 if ! c.is_hex_digit () && c != num_sep {
356- if ! letter_table[c] || s.is_inside_string || s.is_nested_string {
335+ if ! c. is_letter () || s.is_inside_string || s.is_nested_string {
357336 break
358337 } else if ! has_wrong_digit {
359338 has_wrong_digit = true
@@ -378,7 +357,6 @@ fn (mut s Scanner) ident_hex_number() string {
378357 return number
379358}
380359
381- @[direct_array_access]
382360fn (mut s Scanner) ident_oct_number () string {
383361 mut has_wrong_digit := false
384362 mut first_wrong_digit_pos := 0
@@ -394,7 +372,7 @@ fn (mut s Scanner) ident_oct_number() string {
394372 s.error ('cannot use `_` consecutively' )
395373 }
396374 if ! c.is_oct_digit () && c != num_sep {
397- if (! digit_table[c] && ! letter_table[c] ) || s.is_inside_string || s.is_nested_string {
375+ if (! c. is_digit () && ! c. is_letter () ) || s.is_inside_string || s.is_nested_string {
398376 break
399377 } else if ! has_wrong_digit {
400378 has_wrong_digit = true
@@ -431,8 +409,8 @@ fn (mut s Scanner) ident_dec_number() string {
431409 if c == num_sep && s.text[s.pos - 1 ] == num_sep {
432410 s.error ('cannot use `_` consecutively' )
433411 }
434- if ! digit_table[c] && c != num_sep {
435- if ! letter_table[c] || c in [`e` , `E` ] || s.is_inside_string || s.is_nested_string {
412+ if ! c. is_digit () && c != num_sep {
413+ if ! c. is_letter () || c in [`e` , `E` ] || s.is_inside_string || s.is_nested_string {
436414 break
437415 } else if ! has_wrong_digit {
438416 has_wrong_digit = true
@@ -453,14 +431,14 @@ fn (mut s Scanner) ident_dec_number() string {
453431 s.pos++
454432 if s.pos < s.text.len {
455433 // 5.5, 5.5.str()
456- if digit_table[ s.text[s.pos]] {
434+ if s.text[s.pos]. is_digit () {
457435 for s.pos < s.text.len {
458436 c := s.text[s.pos]
459- if ! digit_table[c] {
460- if ! letter_table[c] || c in [`e` , `E` ] || s.is_inside_string
437+ if ! c. is_digit () {
438+ if ! c. is_letter () || c in [`e` , `E` ] || s.is_inside_string
461439 || s.is_nested_string {
462440 // 5.5.str()
463- if c == `.` && s.pos + 1 < s.text.len && letter_table[ s.text[s.pos + 1 ]] {
441+ if c == `.` && s.pos + 1 < s.text.len && s.text[s.pos + 1 ]. is_letter () {
464442 call_method = true
465443 }
466444 break
@@ -478,14 +456,14 @@ fn (mut s Scanner) ident_dec_number() string {
478456 s.pos--
479457 } else if s.text[s.pos] in [`e` , `E` ] {
480458 // 5.e5
481- } else if letter_table[ s.text[s.pos]] {
459+ } else if s.text[s.pos]. is_letter () {
482460 // 5.str()
483461 call_method = true
484462 s.pos--
485463 } else {
486464 // 5.
487465 mut symbol_length := 0
488- for i := s.pos - 2 ; i > 0 && digit_table[ s.text[i - 1 ]] ; i-- {
466+ for i := s.pos - 2 ; i > 0 && s.text[i - 1 ]. is_digit () ; i-- {
489467 symbol_length++
490468 }
491469 float_symbol := s.text[s.pos - 2 - symbol_length..s.pos - 1 ]
@@ -503,10 +481,10 @@ fn (mut s Scanner) ident_dec_number() string {
503481 }
504482 for s.pos < s.text.len {
505483 c := s.text[s.pos]
506- if ! digit_table[c] {
507- if ! letter_table[c] || s.is_inside_string || s.is_nested_string {
484+ if ! c. is_digit () {
485+ if ! c. is_letter () || s.is_inside_string || s.is_nested_string {
508486 // 5e5.str()
509- if c == `.` && s.pos + 1 < s.text.len && letter_table[ s.text[s.pos + 1 ]] {
487+ if c == `.` && s.pos + 1 < s.text.len && s.text[s.pos + 1 ]. is_letter () {
510488 call_method = true
511489 }
512490 break
@@ -735,7 +713,7 @@ pub fn (mut s Scanner) text_scan() token.Token {
735713 s.is_inter_start = false
736714 }
737715 return s.new_token (.name, name, name.len)
738- } else if digit_table[c] || (c == `.` && digit_table[ nextc] ) {
716+ } else if c. is_digit () || (c == `.` && nextc. is_digit () ) {
739717 // `123`, `.123`
740718 if ! s.is_inside_string {
741719 // In C ints with `0` prefix are octal (in V they're decimal), so discarding heading zeros is needed.
@@ -745,7 +723,7 @@ pub fn (mut s Scanner) text_scan() token.Token {
745723 }
746724 mut prefix_zero_num := start_pos - s.pos // how many prefix zeros should be jumped
747725 // for 0b, 0o, 0x the heading zero shouldn't be jumped
748- if start_pos == s.text.len || (c == `0` && ! digit_table[ s.text[start_pos]] ) {
726+ if start_pos == s.text.len || (c == `0` && ! s.text[start_pos]. is_digit () ) {
749727 prefix_zero_num--
750728 }
751729 s.pos + = prefix_zero_num // jump these zeros
@@ -1287,7 +1265,7 @@ pub fn (mut s Scanner) ident_string() string {
12871265 s.u32_ escapes_pos << s.pos - 1
12881266 }
12891267 // Unknown escape sequence
1290- if ! util.is_escape_sequence (c) && ! digit_table[c] && c != `\n ` {
1268+ if ! util.is_escape_sequence (c) && ! c. is_digit () && c != `\n ` {
12911269 s.error ('`${c .ascii_str ()}` unknown escape sequence' )
12921270 }
12931271 }
@@ -1631,7 +1609,7 @@ pub fn (mut s Scanner) ident_char() string {
16311609 s.error_with_pos ('invalid character literal, use \` \\ n\` instead' , lspos)
16321610 } else if c.len > len {
16331611 ch := c[c.len - 1 ]
1634- if ! util.is_escape_sequence (ch) && ! digit_table[ch] {
1612+ if ! util.is_escape_sequence (ch) && ! ch. is_digit () {
16351613 s.error ('`${ch .ascii_str ()}` unknown escape sequence' )
16361614 }
16371615 }
0 commit comments