|
'use strict'; |
|
|
|
const EOF = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
function isDigit(code) { |
|
return code >= 0x0030 && code <= 0x0039; |
|
} |
|
|
|
|
|
|
|
|
|
function isHexDigit(code) { |
|
return ( |
|
isDigit(code) || |
|
(code >= 0x0041 && code <= 0x0046) || |
|
(code >= 0x0061 && code <= 0x0066) |
|
); |
|
} |
|
|
|
|
|
|
|
function isUppercaseLetter(code) { |
|
return code >= 0x0041 && code <= 0x005A; |
|
} |
|
|
|
|
|
|
|
function isLowercaseLetter(code) { |
|
return code >= 0x0061 && code <= 0x007A; |
|
} |
|
|
|
|
|
|
|
function isLetter(code) { |
|
return isUppercaseLetter(code) || isLowercaseLetter(code); |
|
} |
|
|
|
|
|
|
|
function isNonAscii(code) { |
|
return code >= 0x0080; |
|
} |
|
|
|
|
|
|
|
function isNameStart(code) { |
|
return isLetter(code) || isNonAscii(code) || code === 0x005F; |
|
} |
|
|
|
|
|
|
|
function isName(code) { |
|
return isNameStart(code) || isDigit(code) || code === 0x002D; |
|
} |
|
|
|
|
|
|
|
|
|
function isNonPrintable(code) { |
|
return ( |
|
(code >= 0x0000 && code <= 0x0008) || |
|
(code === 0x000B) || |
|
(code >= 0x000E && code <= 0x001F) || |
|
(code === 0x007F) |
|
); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isNewline(code) { |
|
return code === 0x000A || code === 0x000D || code === 0x000C; |
|
} |
|
|
|
|
|
|
|
function isWhiteSpace(code) { |
|
return isNewline(code) || code === 0x0020 || code === 0x0009; |
|
} |
|
|
|
|
|
function isValidEscape(first, second) { |
|
|
|
if (first !== 0x005C) { |
|
return false; |
|
} |
|
|
|
|
|
if (isNewline(second) || second === EOF) { |
|
return false; |
|
} |
|
|
|
|
|
return true; |
|
} |
|
|
|
|
|
function isIdentifierStart(first, second, third) { |
|
|
|
|
|
|
|
if (first === 0x002D) { |
|
|
|
|
|
return ( |
|
isNameStart(second) || |
|
second === 0x002D || |
|
isValidEscape(second, third) |
|
); |
|
} |
|
|
|
|
|
if (isNameStart(first)) { |
|
|
|
return true; |
|
} |
|
|
|
|
|
if (first === 0x005C) { |
|
|
|
return isValidEscape(first, second); |
|
} |
|
|
|
|
|
|
|
return false; |
|
} |
|
|
|
|
|
function isNumberStart(first, second, third) { |
|
|
|
|
|
|
|
|
|
if (first === 0x002B || first === 0x002D) { |
|
|
|
if (isDigit(second)) { |
|
return 2; |
|
} |
|
|
|
|
|
|
|
|
|
return second === 0x002E && isDigit(third) ? 3 : 0; |
|
} |
|
|
|
|
|
if (first === 0x002E) { |
|
|
|
return isDigit(second) ? 2 : 0; |
|
} |
|
|
|
|
|
if (isDigit(first)) { |
|
|
|
return 1; |
|
} |
|
|
|
|
|
|
|
return 0; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function isBOM(code) { |
|
|
|
if (code === 0xFEFF) { |
|
return 1; |
|
} |
|
|
|
|
|
if (code === 0xFFFE) { |
|
return 1; |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
|
|
|
|
const CATEGORY = new Array(0x80); |
|
const EofCategory = 0x80; |
|
const WhiteSpaceCategory = 0x82; |
|
const DigitCategory = 0x83; |
|
const NameStartCategory = 0x84; |
|
const NonPrintableCategory = 0x85; |
|
|
|
for (let i = 0; i < CATEGORY.length; i++) { |
|
CATEGORY[i] = |
|
isWhiteSpace(i) && WhiteSpaceCategory || |
|
isDigit(i) && DigitCategory || |
|
isNameStart(i) && NameStartCategory || |
|
isNonPrintable(i) && NonPrintableCategory || |
|
i || EofCategory; |
|
} |
|
|
|
function charCodeCategory(code) { |
|
return code < 0x80 ? CATEGORY[code] : NameStartCategory; |
|
} |
|
|
|
exports.DigitCategory = DigitCategory; |
|
exports.EofCategory = EofCategory; |
|
exports.NameStartCategory = NameStartCategory; |
|
exports.NonPrintableCategory = NonPrintableCategory; |
|
exports.WhiteSpaceCategory = WhiteSpaceCategory; |
|
exports.charCodeCategory = charCodeCategory; |
|
exports.isBOM = isBOM; |
|
exports.isDigit = isDigit; |
|
exports.isHexDigit = isHexDigit; |
|
exports.isIdentifierStart = isIdentifierStart; |
|
exports.isLetter = isLetter; |
|
exports.isLowercaseLetter = isLowercaseLetter; |
|
exports.isName = isName; |
|
exports.isNameStart = isNameStart; |
|
exports.isNewline = isNewline; |
|
exports.isNonAscii = isNonAscii; |
|
exports.isNonPrintable = isNonPrintable; |
|
exports.isNumberStart = isNumberStart; |
|
exports.isUppercaseLetter = isUppercaseLetter; |
|
exports.isValidEscape = isValidEscape; |
|
exports.isWhiteSpace = isWhiteSpace; |
|
|