feat: generate charCodes
Vim 🖤
This commit is contained in:
parent
a2ed843636
commit
8b206b2c3b
@ -28,26 +28,26 @@ import State from "./state";
|
||||
const forbiddenNumericSeparatorSiblings = {
|
||||
decBinOct: [
|
||||
charCodes.dot,
|
||||
charCodes.letterUpperB,
|
||||
charCodes.letterUpperE,
|
||||
charCodes.letterUpperO,
|
||||
charCodes.uppercaseB,
|
||||
charCodes.uppercaseE,
|
||||
charCodes.uppercaseO,
|
||||
charCodes.underscore, // multiple separators are not allowed
|
||||
charCodes.letterLowerB,
|
||||
charCodes.letterLowerE,
|
||||
charCodes.letterLowerO,
|
||||
charCodes.lowercaseB,
|
||||
charCodes.lowercaseE,
|
||||
charCodes.lowercaseO,
|
||||
],
|
||||
hex: [
|
||||
charCodes.dot,
|
||||
charCodes.letterUpperX,
|
||||
charCodes.uppercaseX,
|
||||
charCodes.underscore, // multiple separators are not allowed
|
||||
charCodes.letterLowerX,
|
||||
charCodes.lowercaseX,
|
||||
],
|
||||
};
|
||||
|
||||
const allowedNumericSeparatorSiblings = {};
|
||||
allowedNumericSeparatorSiblings.bin = [
|
||||
// 0 - 1
|
||||
48,
|
||||
charCodes.digit0,
|
||||
49,
|
||||
];
|
||||
allowedNumericSeparatorSiblings.oct = [
|
||||
@ -64,7 +64,7 @@ allowedNumericSeparatorSiblings.dec = [
|
||||
// 0 - 9
|
||||
...allowedNumericSeparatorSiblings.oct,
|
||||
56,
|
||||
57,
|
||||
charCodes.digit9,
|
||||
];
|
||||
|
||||
allowedNumericSeparatorSiblings.hex = [
|
||||
@ -72,17 +72,17 @@ allowedNumericSeparatorSiblings.hex = [
|
||||
...allowedNumericSeparatorSiblings.dec,
|
||||
// A - F
|
||||
65,
|
||||
charCodes.letterUpperB,
|
||||
charCodes.uppercaseB,
|
||||
67,
|
||||
68,
|
||||
charCodes.letterUpperE,
|
||||
charCodes.uppercaseE,
|
||||
70,
|
||||
// a - f
|
||||
97,
|
||||
charCodes.letterLowerB,
|
||||
charCodes.lowercaseB,
|
||||
99,
|
||||
100,
|
||||
charCodes.letterLowerE,
|
||||
charCodes.lowercaseE,
|
||||
102,
|
||||
];
|
||||
|
||||
@ -401,7 +401,7 @@ export default class Tokenizer extends LocationParser {
|
||||
//
|
||||
readToken_dot(): void {
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next >= 48 && next <= 57) {
|
||||
if (next >= charCodes.digit0 && next <= charCodes.digit9) {
|
||||
this.readNumber(true);
|
||||
return;
|
||||
}
|
||||
@ -589,7 +589,10 @@ export default class Tokenizer extends LocationParser {
|
||||
if (next === charCodes.questionMark) {
|
||||
// '??'
|
||||
this.finishOp(tt.nullishCoalescing, 2);
|
||||
} else if (next === charCodes.dot && !(next2 >= 48 && next2 <= 57)) {
|
||||
} else if (
|
||||
next === charCodes.dot &&
|
||||
!(next2 >= charCodes.digit0 && next2 <= charCodes.digit9)
|
||||
) {
|
||||
// '.' not followed by a number
|
||||
this.state.pos += 2;
|
||||
this.finishToken(tt.questionDot);
|
||||
@ -692,30 +695,21 @@ export default class Tokenizer extends LocationParser {
|
||||
this.finishToken(tt.backQuote);
|
||||
return;
|
||||
|
||||
case 48: {
|
||||
case charCodes.digit0: {
|
||||
// '0'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
// '0x', '0X' - hex number
|
||||
if (
|
||||
next === charCodes.letterLowerX ||
|
||||
next === charCodes.letterUpperX
|
||||
) {
|
||||
if (next === charCodes.lowercaseX || next === charCodes.uppercaseX) {
|
||||
this.readRadixNumber(16);
|
||||
return;
|
||||
}
|
||||
// '0o', '0O' - octal number
|
||||
if (
|
||||
next === charCodes.letterLowerO ||
|
||||
next === charCodes.letterUpperO
|
||||
) {
|
||||
if (next === charCodes.lowercaseO || next === charCodes.uppercaseO) {
|
||||
this.readRadixNumber(8);
|
||||
return;
|
||||
}
|
||||
// '0b', '0B' - binary number
|
||||
if (
|
||||
next === charCodes.letterLowerB ||
|
||||
next === charCodes.letterUpperB
|
||||
) {
|
||||
if (next === charCodes.lowercaseB || next === charCodes.uppercaseB) {
|
||||
this.readRadixNumber(2);
|
||||
return;
|
||||
}
|
||||
@ -730,7 +724,7 @@ export default class Tokenizer extends LocationParser {
|
||||
case 54:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57: // 1-9
|
||||
case charCodes.digit9: // 1-9
|
||||
this.readNumber(false);
|
||||
return;
|
||||
|
||||
@ -888,7 +882,7 @@ export default class Tokenizer extends LocationParser {
|
||||
} else if (code >= 65) {
|
||||
val = code - 65 + 10; // A
|
||||
} else if (charCodes.isDigit(code)) {
|
||||
val = code - 48; // 0-9
|
||||
val = code - charCodes.digit0; // 0-9
|
||||
} else {
|
||||
val = Infinity;
|
||||
}
|
||||
@ -1128,7 +1122,7 @@ export default class Tokenizer extends LocationParser {
|
||||
return "\n"; // 'n' -> '\n'
|
||||
case 114:
|
||||
return "\r"; // 'r' -> '\r'
|
||||
case charCodes.letterLowerX: {
|
||||
case charCodes.lowercaseX: {
|
||||
const code = this.readHexChar(2, throwOnInvalid);
|
||||
return code === null ? null : String.fromCharCode(code);
|
||||
}
|
||||
@ -1139,7 +1133,7 @@ export default class Tokenizer extends LocationParser {
|
||||
}
|
||||
case 116:
|
||||
return "\t"; // 't' -> '\t'
|
||||
case charCodes.letterLowerB:
|
||||
case charCodes.lowercaseB:
|
||||
return "\b"; // 'b' -> '\b'
|
||||
case 118:
|
||||
return "\u000b"; // 'v' -> '\u000b'
|
||||
@ -1152,7 +1146,7 @@ export default class Tokenizer extends LocationParser {
|
||||
++this.state.curLine;
|
||||
return "";
|
||||
default:
|
||||
if (ch >= 48 && ch <= 55) {
|
||||
if (ch >= charCodes.digit0 && ch <= 55) {
|
||||
const codePos = this.state.pos - 1;
|
||||
// $FlowFixMe
|
||||
let octalStr = this.input
|
||||
|
||||
@ -14,30 +14,97 @@ export const paragraphSeparator = 8233;
|
||||
export const asterisk = 42; // '*'
|
||||
export const dot = 46; // '.'
|
||||
export const slash = 47; // '/'
|
||||
export const underscore = 95; // '_'
|
||||
|
||||
export const letterUpperB = 66; // 'B'
|
||||
export const letterUpperE = 69; // 'E'
|
||||
export const letterUpperO = 79; // 'O'
|
||||
export const letterUpperX = 88; // 'X'
|
||||
|
||||
export const letterLowerN = 110; // 'n'
|
||||
export const letterLowerB = 98; // 'b'
|
||||
export const letterLowerE = 101; // 'e'
|
||||
export const letterLowerO = 111; // 'o'
|
||||
export const letterLowerX = 120; // 'x'
|
||||
|
||||
export const dash = 45; // '-'
|
||||
export const exclamationMark = 33; // '!'
|
||||
export const quotationMark = 34; // '"'
|
||||
export const numberSign = 35; // '#'
|
||||
export const dollarSign = 36; // '$'
|
||||
export const percentSign = 37; // '%'
|
||||
export const ampersand = 38; // '&'
|
||||
export const apostrophe = 39; // '''
|
||||
export const leftParenthesis = 40; // '('
|
||||
export const rightParenthesis = 41; // ')'
|
||||
export const plusSign = 43; // '+'
|
||||
export const comma = 44; // ','
|
||||
export const digit0 = 48; // '0'
|
||||
export const digit1 = 49; // '1'
|
||||
export const digit2 = 50; // '2'
|
||||
export const digit3 = 51; // '3'
|
||||
export const digit4 = 52; // '4'
|
||||
export const digit5 = 53; // '5'
|
||||
export const digit6 = 54; // '6'
|
||||
export const digit7 = 55; // '7'
|
||||
export const digit8 = 56; // '8'
|
||||
export const digit9 = 57; // '9'
|
||||
|
||||
export const colon = 58; // ':'
|
||||
export const semicolon = 59; // ';'
|
||||
export const lessThan = 60; // '<'
|
||||
export const equalsTo = 61; // '='
|
||||
export const greaterThan = 62; // '>'
|
||||
export const questionMark = 63; // '?'
|
||||
export const at = 64; // '@'
|
||||
|
||||
export const exclamationMark = 33; // '!'
|
||||
export const dash = 45; // '-'
|
||||
export const atSign = 64; // '@'
|
||||
export const uppercaseA = 65; // 'A'
|
||||
export const uppercaseB = 66; // 'B'
|
||||
export const uppercaseC = 67; // 'C'
|
||||
export const uppercaseD = 68; // 'D'
|
||||
export const uppercaseE = 69; // 'E'
|
||||
export const uppercaseF = 70; // 'F'
|
||||
export const uppercaseG = 71; // 'G'
|
||||
export const uppercaseH = 72; // 'H'
|
||||
export const uppercaseI = 73; // 'I'
|
||||
export const uppercaseJ = 74; // 'J'
|
||||
export const uppercaseK = 75; // 'K'
|
||||
export const uppercaseL = 76; // 'L'
|
||||
export const uppercaseM = 77; // 'M'
|
||||
export const uppercaseN = 78; // 'N'
|
||||
export const uppercaseO = 79; // 'O'
|
||||
export const uppercaseP = 80; // 'P'
|
||||
export const uppercaseQ = 81; // 'Q'
|
||||
export const uppercaseR = 82; // 'R'
|
||||
export const uppercaseS = 83; // 'S'
|
||||
export const uppercaseT = 84; // 'T'
|
||||
export const uppercaseU = 85; // 'U'
|
||||
export const uppercaseV = 86; // 'V'
|
||||
export const uppercaseW = 87; // 'W'
|
||||
export const uppercaseX = 88; // 'X'
|
||||
export const uppercaseY = 89; // 'Y'
|
||||
export const uppercaseZ = 90; // 'Z'
|
||||
export const leftSquareBracket = 91; // '['
|
||||
export const backslash = 92; // '\ '
|
||||
export const rightSquareBracket = 93; // ']'
|
||||
export const caret = 94; // '^'
|
||||
export const underscore = 95; // '_'
|
||||
export const graveAccent = 96; // '`'
|
||||
export const lowercaseA = 97; // 'a'
|
||||
export const lowercaseB = 98; // 'b'
|
||||
export const lowercaseC = 99; // 'c'
|
||||
export const lowercaseD = 100; // 'd'
|
||||
export const lowercaseE = 101; // 'e'
|
||||
export const lowercaseF = 102; // 'f'
|
||||
export const lowercaseG = 103; // 'g'
|
||||
export const lowercaseH = 104; // 'h'
|
||||
export const lowercaseI = 105; // 'i'
|
||||
export const lowercaseJ = 106; // 'j'
|
||||
export const lowercaseK = 107; // 'k'
|
||||
export const lowercaseL = 108; // 'l'
|
||||
export const lowercaseM = 109; // 'm'
|
||||
export const lowercaseN = 110; // 'n'
|
||||
export const lowercaseO = 111; // 'o'
|
||||
export const lowercaseP = 112; // 'p'
|
||||
export const lowercaseQ = 113; // 'q'
|
||||
export const lowercaseR = 114; // 'r'
|
||||
export const lowercaseS = 115; // 's'
|
||||
export const lowercaseT = 116; // 't'
|
||||
export const lowercaseU = 117; // 'u'
|
||||
export const lowercaseV = 118; // 'v'
|
||||
export const lowercaseW = 119; // 'w'
|
||||
export const lowercaseX = 120; // 'x'
|
||||
export const lowercaseY = 121; // 'y'
|
||||
export const lowercaseZ = 122; // 'z'
|
||||
export const leftCurlyBrace = 123; // '{'
|
||||
export const verticalBar = 124; // '|'
|
||||
export const rightCurlyBrace = 125; // '}'
|
||||
export const tilde = 126; // '~'
|
||||
|
||||
export function isDigit(code: Char): boolean {
|
||||
return code >= digit0 && code <= digit9;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user