esr/lexer/
util.rs

1#[inline]
2pub fn legal_in_label(byte: u8) -> bool {
3    // Look up table that marks which ASCII characters are allowed in identifiers
4    const NU: bool = true; // digit
5    const AL: bool = true; // alphabet
6    const DO: bool = true; // dollar sign $
7    const US: bool = true; // underscore
8    const UN: bool = true; // unicode
9    const BS: bool = true; // backslash
10    const __: bool = false;
11
12    static TABLE: [bool; 256] = [
13    // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
14      __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 0
15      __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // 1
16      __, __, __, __, DO, __, __, __, __, __, __, __, __, __, __, __, // 2
17      NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, __, __, __, __, __, __, // 3
18      __, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // 4
19      AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, __, BS, __, __, US, // 5
20      __, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // 6
21      AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, __, __, __, __, __, // 7
22      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // 8
23      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // 9
24      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // A
25      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // B
26      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // C
27      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // D
28      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // E
29      UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, UN, // F
30    ];
31
32    unsafe { *(&TABLE as *const bool).offset(byte as isize) }
33}