123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- var 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;
- }
- var CATEGORY = new Array(0x80);
- charCodeCategory.Eof = 0x80;
- charCodeCategory.WhiteSpace = 0x82;
- charCodeCategory.Digit = 0x83;
- charCodeCategory.NameStart = 0x84;
- charCodeCategory.NonPrintable = 0x85;
- for (var i = 0; i < CATEGORY.length; i++) {
- switch (true) {
- case isWhiteSpace(i):
- CATEGORY[i] = charCodeCategory.WhiteSpace;
- break;
- case isDigit(i):
- CATEGORY[i] = charCodeCategory.Digit;
- break;
- case isNameStart(i):
- CATEGORY[i] = charCodeCategory.NameStart;
- break;
- case isNonPrintable(i):
- CATEGORY[i] = charCodeCategory.NonPrintable;
- break;
- default:
- CATEGORY[i] = i || charCodeCategory.Eof;
- }
- }
- function charCodeCategory(code) {
- return code < 0x80 ? CATEGORY[code] : charCodeCategory.NameStart;
- };
- module.exports = {
- isDigit: isDigit,
- isHexDigit: isHexDigit,
- isUppercaseLetter: isUppercaseLetter,
- isLowercaseLetter: isLowercaseLetter,
- isLetter: isLetter,
- isNonAscii: isNonAscii,
- isNameStart: isNameStart,
- isName: isName,
- isNonPrintable: isNonPrintable,
- isNewline: isNewline,
- isWhiteSpace: isWhiteSpace,
- isValidEscape: isValidEscape,
- isIdentifierStart: isIdentifierStart,
- isNumberStart: isNumberStart,
- isBOM: isBOM,
- charCodeCategory: charCodeCategory
- };
|