use crate::unicode_xid::UnicodeXID;
pub static ASCII: [u8; 128] = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
b' ', b'!', b'"', b'#', b'$', b'%', b'&', b'\'',
b'(', b')', b'*', b'+', b',', b'-', b'.', b'/',
b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7',
b'8', b'9', b':', b';', b'<', b'=', b'>', b'?',
b'@', b'A', b'B', b'C', b'D', b'E', b'F', b'G',
b'H', b'I', b'J', b'K', b'L', b'M', b'N', b'O',
b'P', b'Q', b'R', b'S', b'T', b'U', b'V', b'W',
b'X', b'Y', b'Z', b'[', b'\\', b']', b'^', b'_',
b'`', b'a', b'b', b'c', b'd', b'e', b'f', b'g',
b'h', b'i', b'j', b'k', b'l', b'm', b'n', b'o',
b'p', b'q', b'r', b's', b't', b'u', b'v', b'w',
b'x', b'y', b'z', b'{', b'|', b'}', b'~', 0x7f,
];
pub const ZWNJ : char = '\u{200C}';
pub const ZWJ : char = '\u{200D}';
pub const ZWNBSP: char = '\u{FEFF}';
pub const TAB: char = '\u{0009}';
pub const VT: char = '\u{000B}';
pub const FF: char = '\u{000C}';
pub const SP: char = '\u{0020}';
pub const NBSP: char = '\u{00A0}';
pub const CR: char = '\u{000D}';
pub const LF: char = '\u{000A}';
pub const LS: char = '\u{2028}';
pub const PS: char = '\u{2029}';
pub const CR_LF: &[char] = &[ CR, LF, ];
pub const BACKSPACE: char = '\u{0008}';
pub const SLASH: u8 = b'/';
#[derive(Debug)]
pub enum Category {
WhiteSpace,
LineTerminator,
Punctuator,
Identifier,
Numberic,
}
pub trait ESChar {
fn is_es_whitespace(self) -> bool;
fn is_es_line_terminator(self) -> bool;
fn is_es_punctuator_start(self) -> bool;
fn is_es_keyword_start(self) -> bool;
fn is_es_keyword_break(self) -> bool;
fn is_es_identifier_start(self) -> bool;
fn is_es_identifier_part(self) -> bool;
fn is_es_identifier_break(self) -> bool;
fn is_es_binary_digit(self) -> bool;
fn is_es_octal_digit(self) -> bool;
fn is_es_hex_digit(self) -> bool;
fn is_es_decimal_digit(self) -> bool;
fn is_es_digit_break(self) -> bool;
fn is_es_single_escape_character(self) -> bool;
}
impl ESChar for char {
#[inline]
fn is_es_line_terminator(self) -> bool {
match self {
CR | LF | LS | PS => true,
_ => false,
}
}
#[inline]
fn is_es_whitespace(self) -> bool {
match self {
TAB | VT | FF | SP | NBSP | ZWNBSP => true,
_ => {
if self.is_es_line_terminator() {
false
} else {
self.is_whitespace()
}
},
}
}
#[inline]
fn is_es_punctuator_start(self) -> bool {
match self {
'{' | '}' | '(' | ')' | '[' | ']'
| '.' | ';' | ':' | ',' | '?'
| '/' | '!' | '|' | '&' | '^'
| '<' | '>' | '~' | '%' | '='
| '+' | '-' | '*' | '`' | '#' => true,
_ => false,
}
}
#[inline]
fn is_es_keyword_start(self) -> bool {
match self {
'a' | 'b' | 'c' | 'd' | 'e' | 'f'
| 'i' | 'l' | 'n' | 'p' | 'r' | 's'
| 't' | 'v' | 'w' | 'y' => true,
_ => false
}
}
#[inline]
fn is_es_keyword_break(self) -> bool {
self.is_es_identifier_break()
}
#[inline]
fn is_es_identifier_start(self) -> bool {
match self {
'_' | '$' => true,
_ => UnicodeXID::is_xid_start(self),
}
}
#[inline]
fn is_es_identifier_part(self) -> bool {
match self {
'$' | ZWNJ | ZWJ => true,
_ => UnicodeXID::is_xid_continue(self),
}
}
#[inline]
fn is_es_identifier_break(self) -> bool {
if self.is_es_identifier_start() || self.is_es_identifier_part() {
return false;
}
if self.is_es_line_terminator()
|| self.is_es_whitespace()
|| self.is_es_punctuator_start() {
true
} else {
false
}
}
#[inline]
fn is_es_binary_digit(self) -> bool {
self == '0' || self == '1'
}
#[inline]
fn is_es_octal_digit(self) -> bool {
match self {
'0' ... '7' => true,
_ => false,
}
}
#[inline]
fn is_es_hex_digit(self) -> bool {
self.is_ascii_hexdigit()
}
#[inline]
fn is_es_decimal_digit(self) -> bool {
self.is_ascii_digit()
}
#[inline]
fn is_es_digit_break(self) -> bool {
if self.is_es_line_terminator() || self.is_es_whitespace() {
return true;
}
match self {
'\0' | '}' | ')' | ']'
| ';' | ':' | ',' | '?'
| '/' | '|' | '&' | '^'
| '<' | '>' | '='
| '+' | '-' | '*' | '%' => true,
_ => false,
}
}
#[inline]
fn is_es_single_escape_character(self) -> bool {
match self {
'\'' | '"' | '\\' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' => true ,
_ => false,
}
}
}