int Lexer::hexEscape(int n) { mark = idx; if (!hexDigits(n)) compiler->syntaxError(lineno, "Wrong number of hexadecimal digits; expected %d", n); return (int)parseInt(16); }
int Lexer::unicodeEscape() { if (*idx == '{') { idx++; mark = idx; if (!hexDigits(-1) || *idx != '}') compiler->syntaxError(lineno, "Invalid variable-length unicode escape"); int n = (int)parseInt(16); idx++; return n; } return hexEscape(4); }
static bool hexFractionalPart() { char c; if (!next(c) || (c != '.')) return false; return hexDigits(); }
int Lexer::escapeSequence() { switch (*idx) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': return octalOrNulEscape (); case 'x': idx++; // Compatibility fallback, handle \x<whatever> as "x" followed by <whatever> mark = idx; if (hexDigits(2)) { idx = mark; return hexEscape(2); } idx = mark; return 'x'; case 'u': idx++; // Compatibility fallback, handle \u<whatever> as "u" followed by <whatever> mark = idx; if (hexDigits(4)) { idx = mark; return unicodeEscape (); } idx = mark; return 'u'; case 'b': idx++; return '\b'; case 'f': idx++; return '\f'; case 'n': idx++; return '\n'; case 'r': idx++; return '\r'; case 't': idx++; return '\t'; case 'v': idx++; return '\v'; case '\'': case '"': case '\\': return *idx++; case 0: if (idx+1 >= limit) compiler->syntaxError(lineno, "End of input in escape sequence"); idx++; return 0; case '\n': case '\r': case UNICHAR_LS: case UNICHAR_PS: compiler->syntaxError(lineno, "Illegal line terminator in escape sequence"); default: return *idx++; } }
static bool hexInt() { if (!str("0x")) return false; int x; if (!hexDigit(x)) return false; return hexDigits(); }