react / wstein / node_modules / jest-cli / node_modules / jasmine-only / node_modules / coffee-script / lib / coffee-script / lexer.js
81146 views// Generated by CoffeeScript 1.6.31(function() {2var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, repeat, starts, throwSyntaxError, _ref, _ref1,3__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };45_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;67_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, repeat = _ref1.repeat, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;89exports.Lexer = Lexer = (function() {10function Lexer() {}1112Lexer.prototype.tokenize = function(code, opts) {13var consumed, i, tag, _ref2;14if (opts == null) {15opts = {};16}17this.literate = opts.literate;18this.indent = 0;19this.indebt = 0;20this.outdebt = 0;21this.indents = [];22this.ends = [];23this.tokens = [];24this.chunkLine = opts.line || 0;25this.chunkColumn = opts.column || 0;26code = this.clean(code);27i = 0;28while (this.chunk = code.slice(i)) {29consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();30_ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];31i += consumed;32}33this.closeIndentation();34if (tag = this.ends.pop()) {35this.error("missing " + tag);36}37if (opts.rewrite === false) {38return this.tokens;39}40return (new Rewriter).rewrite(this.tokens);41};4243Lexer.prototype.clean = function(code) {44if (code.charCodeAt(0) === BOM) {45code = code.slice(1);46}47code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');48if (WHITESPACE.test(code)) {49code = "\n" + code;50this.chunkLine--;51}52if (this.literate) {53code = invertLiterate(code);54}55return code;56};5758Lexer.prototype.identifierToken = function() {59var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;60if (!(match = IDENTIFIER.exec(this.chunk))) {61return 0;62}63input = match[0], id = match[1], colon = match[2];64idLength = id.length;65poppedToken = void 0;66if (id === 'own' && this.tag() === 'FOR') {67this.token('OWN', id);68return id.length;69}70forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');71tag = 'IDENTIFIER';72if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {73tag = id.toUpperCase();74if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {75tag = 'LEADING_WHEN';76} else if (tag === 'FOR') {77this.seenFor = true;78} else if (tag === 'UNLESS') {79tag = 'IF';80} else if (__indexOf.call(UNARY, tag) >= 0) {81tag = 'UNARY';82} else if (__indexOf.call(RELATION, tag) >= 0) {83if (tag !== 'INSTANCEOF' && this.seenFor) {84tag = 'FOR' + tag;85this.seenFor = false;86} else {87tag = 'RELATION';88if (this.value() === '!') {89poppedToken = this.tokens.pop();90id = '!' + id;91}92}93}94}95if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {96if (forcedIdentifier) {97tag = 'IDENTIFIER';98id = new String(id);99id.reserved = true;100} else if (__indexOf.call(RESERVED, id) >= 0) {101this.error("reserved word \"" + id + "\"");102}103}104if (!forcedIdentifier) {105if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {106id = COFFEE_ALIAS_MAP[id];107}108tag = (function() {109switch (id) {110case '!':111return 'UNARY';112case '==':113case '!=':114return 'COMPARE';115case '&&':116case '||':117return 'LOGIC';118case 'true':119case 'false':120return 'BOOL';121case 'break':122case 'continue':123return 'STATEMENT';124default:125return tag;126}127})();128}129tagToken = this.token(tag, id, 0, idLength);130if (poppedToken) {131_ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];132}133if (colon) {134colonOffset = input.lastIndexOf(':');135this.token(':', ':', colonOffset, colon.length);136}137return input.length;138};139140Lexer.prototype.numberToken = function() {141var binaryLiteral, lexedLength, match, number, octalLiteral;142if (!(match = NUMBER.exec(this.chunk))) {143return 0;144}145number = match[0];146if (/^0[BOX]/.test(number)) {147this.error("radix prefix '" + number + "' must be lowercase");148} else if (/E/.test(number) && !/^0x/.test(number)) {149this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");150} else if (/^0\d*[89]/.test(number)) {151this.error("decimal literal '" + number + "' must not be prefixed with '0'");152} else if (/^0\d+/.test(number)) {153this.error("octal literal '" + number + "' must be prefixed with '0o'");154}155lexedLength = number.length;156if (octalLiteral = /^0o([0-7]+)/.exec(number)) {157number = '0x' + parseInt(octalLiteral[1], 8).toString(16);158}159if (binaryLiteral = /^0b([01]+)/.exec(number)) {160number = '0x' + parseInt(binaryLiteral[1], 2).toString(16);161}162this.token('NUMBER', number, 0, lexedLength);163return lexedLength;164};165166Lexer.prototype.stringToken = function() {167var match, octalEsc, string;168switch (this.chunk.charAt(0)) {169case "'":170if (!(match = SIMPLESTR.exec(this.chunk))) {171return 0;172}173string = match[0];174this.token('STRING', string.replace(MULTILINER, '\\\n'), 0, string.length);175break;176case '"':177if (!(string = this.balancedString(this.chunk, '"'))) {178return 0;179}180if (0 < string.indexOf('#{', 1)) {181this.interpolateString(string.slice(1, -1), {182strOffset: 1,183lexedLength: string.length184});185} else {186this.token('STRING', this.escapeLines(string, 0, string.length));187}188break;189default:190return 0;191}192if (octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test(string)) {193this.error("octal escape sequences " + string + " are not allowed");194}195return string.length;196};197198Lexer.prototype.heredocToken = function() {199var doc, heredoc, match, quote;200if (!(match = HEREDOC.exec(this.chunk))) {201return 0;202}203heredoc = match[0];204quote = heredoc.charAt(0);205doc = this.sanitizeHeredoc(match[2], {206quote: quote,207indent: null208});209if (quote === '"' && 0 <= doc.indexOf('#{')) {210this.interpolateString(doc, {211heredoc: true,212strOffset: 3,213lexedLength: heredoc.length214});215} else {216this.token('STRING', this.makeString(doc, quote, true), 0, heredoc.length);217}218return heredoc.length;219};220221Lexer.prototype.commentToken = function() {222var comment, here, match;223if (!(match = this.chunk.match(COMMENT))) {224return 0;225}226comment = match[0], here = match[1];227if (here) {228this.token('HERECOMMENT', this.sanitizeHeredoc(here, {229herecomment: true,230indent: repeat(' ', this.indent)231}), 0, comment.length);232}233return comment.length;234};235236Lexer.prototype.jsToken = function() {237var match, script;238if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {239return 0;240}241this.token('JS', (script = match[0]).slice(1, -1), 0, script.length);242return script.length;243};244245Lexer.prototype.regexToken = function() {246var flags, length, match, prev, regex, _ref2, _ref3;247if (this.chunk.charAt(0) !== '/') {248return 0;249}250if (match = HEREGEX.exec(this.chunk)) {251length = this.heregexToken(match);252return length;253}254prev = last(this.tokens);255if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) {256return 0;257}258if (!(match = REGEX.exec(this.chunk))) {259return 0;260}261_ref3 = match, match = _ref3[0], regex = _ref3[1], flags = _ref3[2];262if (regex.slice(0, 2) === '/*') {263this.error('regular expressions cannot begin with `*`');264}265if (regex === '//') {266regex = '/(?:)/';267}268this.token('REGEX', "" + regex + flags, 0, match.length);269return match.length;270};271272Lexer.prototype.heregexToken = function(match) {273var body, flags, flagsOffset, heregex, plusToken, prev, re, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;274heregex = match[0], body = match[1], flags = match[2];275if (0 > body.indexOf('#{')) {276re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');277if (re.match(/^\*/)) {278this.error('regular expressions cannot begin with `*`');279}280this.token('REGEX', "/" + (re || '(?:)') + "/" + flags, 0, heregex.length);281return heregex.length;282}283this.token('IDENTIFIER', 'RegExp', 0, 0);284this.token('CALL_START', '(', 0, 0);285tokens = [];286_ref2 = this.interpolateString(body, {287regex: true288});289for (_i = 0, _len = _ref2.length; _i < _len; _i++) {290token = _ref2[_i];291tag = token[0], value = token[1];292if (tag === 'TOKENS') {293tokens.push.apply(tokens, value);294} else if (tag === 'NEOSTRING') {295if (!(value = value.replace(HEREGEX_OMIT, ''))) {296continue;297}298value = value.replace(/\\/g, '\\\\');299token[0] = 'STRING';300token[1] = this.makeString(value, '"', true);301tokens.push(token);302} else {303this.error("Unexpected " + tag);304}305prev = last(this.tokens);306plusToken = ['+', '+'];307plusToken[2] = prev[2];308tokens.push(plusToken);309}310tokens.pop();311if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') {312this.token('STRING', '""', 0, 0);313this.token('+', '+', 0, 0);314}315(_ref4 = this.tokens).push.apply(_ref4, tokens);316if (flags) {317flagsOffset = heregex.lastIndexOf(flags);318this.token(',', ',', flagsOffset, 0);319this.token('STRING', '"' + flags + '"', flagsOffset, flags.length);320}321this.token(')', ')', heregex.length - 1, 0);322return heregex.length;323};324325Lexer.prototype.lineToken = function() {326var diff, indent, match, noNewlines, size;327if (!(match = MULTI_DENT.exec(this.chunk))) {328return 0;329}330indent = match[0];331this.seenFor = false;332size = indent.length - 1 - indent.lastIndexOf('\n');333noNewlines = this.unfinished();334if (size - this.indebt === this.indent) {335if (noNewlines) {336this.suppressNewlines();337} else {338this.newlineToken(0);339}340return indent.length;341}342if (size > this.indent) {343if (noNewlines) {344this.indebt = size - this.indent;345this.suppressNewlines();346return indent.length;347}348diff = size - this.indent + this.outdebt;349this.token('INDENT', diff, indent.length - size, size);350this.indents.push(diff);351this.ends.push('OUTDENT');352this.outdebt = this.indebt = 0;353} else {354this.indebt = 0;355this.outdentToken(this.indent - size, noNewlines, indent.length);356}357this.indent = size;358return indent.length;359};360361Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {362var dent, len;363while (moveOut > 0) {364len = this.indents.length - 1;365if (this.indents[len] === void 0) {366moveOut = 0;367} else if (this.indents[len] === this.outdebt) {368moveOut -= this.outdebt;369this.outdebt = 0;370} else if (this.indents[len] < this.outdebt) {371this.outdebt -= this.indents[len];372moveOut -= this.indents[len];373} else {374dent = this.indents.pop() + this.outdebt;375moveOut -= dent;376this.outdebt = 0;377this.pair('OUTDENT');378this.token('OUTDENT', dent, 0, outdentLength);379}380}381if (dent) {382this.outdebt -= moveOut;383}384while (this.value() === ';') {385this.tokens.pop();386}387if (!(this.tag() === 'TERMINATOR' || noNewlines)) {388this.token('TERMINATOR', '\n', outdentLength, 0);389}390return this;391};392393Lexer.prototype.whitespaceToken = function() {394var match, nline, prev;395if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {396return 0;397}398prev = last(this.tokens);399if (prev) {400prev[match ? 'spaced' : 'newLine'] = true;401}402if (match) {403return match[0].length;404} else {405return 0;406}407};408409Lexer.prototype.newlineToken = function(offset) {410while (this.value() === ';') {411this.tokens.pop();412}413if (this.tag() !== 'TERMINATOR') {414this.token('TERMINATOR', '\n', offset, 0);415}416return this;417};418419Lexer.prototype.suppressNewlines = function() {420if (this.value() === '\\') {421this.tokens.pop();422}423return this;424};425426Lexer.prototype.literalToken = function() {427var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;428if (match = OPERATOR.exec(this.chunk)) {429value = match[0];430if (CODE.test(value)) {431this.tagParameters();432}433} else {434value = this.chunk.charAt(0);435}436tag = value;437prev = last(this.tokens);438if (value === '=' && prev) {439if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {440this.error("reserved word \"" + (this.value()) + "\" can't be assigned");441}442if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {443prev[0] = 'COMPOUND_ASSIGN';444prev[1] += '=';445return value.length;446}447}448if (value === ';') {449this.seenFor = false;450tag = 'TERMINATOR';451} else if (__indexOf.call(MATH, value) >= 0) {452tag = 'MATH';453} else if (__indexOf.call(COMPARE, value) >= 0) {454tag = 'COMPARE';455} else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) {456tag = 'COMPOUND_ASSIGN';457} else if (__indexOf.call(UNARY, value) >= 0) {458tag = 'UNARY';459} else if (__indexOf.call(SHIFT, value) >= 0) {460tag = 'SHIFT';461} else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {462tag = 'LOGIC';463} else if (prev && !prev.spaced) {464if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {465if (prev[0] === '?') {466prev[0] = 'FUNC_EXIST';467}468tag = 'CALL_START';469} else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {470tag = 'INDEX_START';471switch (prev[0]) {472case '?':473prev[0] = 'INDEX_SOAK';474}475}476}477switch (value) {478case '(':479case '{':480case '[':481this.ends.push(INVERSES[value]);482break;483case ')':484case '}':485case ']':486this.pair(value);487}488this.token(tag, value);489return value.length;490};491492Lexer.prototype.sanitizeHeredoc = function(doc, options) {493var attempt, herecomment, indent, match, _ref2;494indent = options.indent, herecomment = options.herecomment;495if (herecomment) {496if (HEREDOC_ILLEGAL.test(doc)) {497this.error("block comment cannot contain \"*/\", starting");498}499if (doc.indexOf('\n') < 0) {500return doc;501}502} else {503while (match = HEREDOC_INDENT.exec(doc)) {504attempt = match[1];505if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) {506indent = attempt;507}508}509}510if (indent) {511doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');512}513if (!herecomment) {514doc = doc.replace(/^\n/, '');515}516return doc;517};518519Lexer.prototype.tagParameters = function() {520var i, stack, tok, tokens;521if (this.tag() !== ')') {522return this;523}524stack = [];525tokens = this.tokens;526i = tokens.length;527tokens[--i][0] = 'PARAM_END';528while (tok = tokens[--i]) {529switch (tok[0]) {530case ')':531stack.push(tok);532break;533case '(':534case 'CALL_START':535if (stack.length) {536stack.pop();537} else if (tok[0] === '(') {538tok[0] = 'PARAM_START';539return this;540} else {541return this;542}543}544}545return this;546};547548Lexer.prototype.closeIndentation = function() {549return this.outdentToken(this.indent);550};551552Lexer.prototype.balancedString = function(str, end) {553var continueCount, i, letter, match, prev, stack, _i, _ref2;554continueCount = 0;555stack = [end];556for (i = _i = 1, _ref2 = str.length; 1 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 1 <= _ref2 ? ++_i : --_i) {557if (continueCount) {558--continueCount;559continue;560}561switch (letter = str.charAt(i)) {562case '\\':563++continueCount;564continue;565case end:566stack.pop();567if (!stack.length) {568return str.slice(0, +i + 1 || 9e9);569}570end = stack[stack.length - 1];571continue;572}573if (end === '}' && (letter === '"' || letter === "'")) {574stack.push(end = letter);575} else if (end === '}' && letter === '/' && (match = HEREGEX.exec(str.slice(i)) || REGEX.exec(str.slice(i)))) {576continueCount += match[0].length - 1;577} else if (end === '}' && letter === '{') {578stack.push(end = '}');579} else if (end === '"' && prev === '#' && letter === '{') {580stack.push(end = '}');581}582prev = letter;583}584return this.error("missing " + (stack.pop()) + ", starting");585};586587Lexer.prototype.interpolateString = function(str, options) {588var column, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, rparen, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;589if (options == null) {590options = {};591}592heredoc = options.heredoc, regex = options.regex, offsetInChunk = options.offsetInChunk, strOffset = options.strOffset, lexedLength = options.lexedLength;593offsetInChunk = offsetInChunk || 0;594strOffset = strOffset || 0;595lexedLength = lexedLength || str.length;596if (heredoc && str.length > 0 && str[0] === '\n') {597str = str.slice(1);598strOffset++;599}600tokens = [];601pi = 0;602i = -1;603while (letter = str.charAt(i += 1)) {604if (letter === '\\') {605i += 1;606continue;607}608if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) {609continue;610}611if (pi < i) {612tokens.push(this.makeToken('NEOSTRING', str.slice(pi, i), strOffset + pi));613}614inner = expr.slice(1, -1);615if (inner.length) {616_ref2 = this.getLineAndColumnFromChunk(strOffset + i + 1), line = _ref2[0], column = _ref2[1];617nested = new Lexer().tokenize(inner, {618line: line,619column: column,620rewrite: false621});622popped = nested.pop();623if (((_ref3 = nested[0]) != null ? _ref3[0] : void 0) === 'TERMINATOR') {624popped = nested.shift();625}626if (len = nested.length) {627if (len > 1) {628nested.unshift(this.makeToken('(', '(', strOffset + i + 1, 0));629nested.push(this.makeToken(')', ')', strOffset + i + 1 + inner.length, 0));630}631tokens.push(['TOKENS', nested]);632}633}634i += expr.length;635pi = i + 1;636}637if ((i > pi && pi < str.length)) {638tokens.push(this.makeToken('NEOSTRING', str.slice(pi), strOffset + pi));639}640if (regex) {641return tokens;642}643if (!tokens.length) {644return this.token('STRING', '""', offsetInChunk, lexedLength);645}646if (tokens[0][0] !== 'NEOSTRING') {647tokens.unshift(this.makeToken('NEOSTRING', '', offsetInChunk));648}649if (interpolated = tokens.length > 1) {650this.token('(', '(', offsetInChunk, 0);651}652for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {653token = tokens[i];654tag = token[0], value = token[1];655if (i) {656if (i) {657plusToken = this.token('+', '+');658}659locationToken = tag === 'TOKENS' ? value[0] : token;660plusToken[2] = {661first_line: locationToken[2].first_line,662first_column: locationToken[2].first_column,663last_line: locationToken[2].first_line,664last_column: locationToken[2].first_column665};666}667if (tag === 'TOKENS') {668(_ref4 = this.tokens).push.apply(_ref4, value);669} else if (tag === 'NEOSTRING') {670token[0] = 'STRING';671token[1] = this.makeString(value, '"', heredoc);672this.tokens.push(token);673} else {674this.error("Unexpected " + tag);675}676}677if (interpolated) {678rparen = this.makeToken(')', ')', offsetInChunk + lexedLength, 0);679rparen.stringEnd = true;680this.tokens.push(rparen);681}682return tokens;683};684685Lexer.prototype.pair = function(tag) {686var size, wanted;687if (tag !== (wanted = last(this.ends))) {688if ('OUTDENT' !== wanted) {689this.error("unmatched " + tag);690}691this.indent -= size = last(this.indents);692this.outdentToken(size, true);693return this.pair(tag);694}695return this.ends.pop();696};697698Lexer.prototype.getLineAndColumnFromChunk = function(offset) {699var column, lineCount, lines, string;700if (offset === 0) {701return [this.chunkLine, this.chunkColumn];702}703if (offset >= this.chunk.length) {704string = this.chunk;705} else {706string = this.chunk.slice(0, +(offset - 1) + 1 || 9e9);707}708lineCount = count(string, '\n');709column = this.chunkColumn;710if (lineCount > 0) {711lines = string.split('\n');712column = last(lines).length;713} else {714column += string.length;715}716return [this.chunkLine + lineCount, column];717};718719Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {720var lastCharacter, locationData, token, _ref2, _ref3;721if (offsetInChunk == null) {722offsetInChunk = 0;723}724if (length == null) {725length = value.length;726}727locationData = {};728_ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];729lastCharacter = Math.max(0, length - 1);730_ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];731token = [tag, value, locationData];732return token;733};734735Lexer.prototype.token = function(tag, value, offsetInChunk, length) {736var token;737token = this.makeToken(tag, value, offsetInChunk, length);738this.tokens.push(token);739return token;740};741742Lexer.prototype.tag = function(index, tag) {743var tok;744return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);745};746747Lexer.prototype.value = function(index, val) {748var tok;749return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);750};751752Lexer.prototype.unfinished = function() {753var _ref2;754return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');755};756757Lexer.prototype.escapeLines = function(str, heredoc) {758return str.replace(MULTILINER, heredoc ? '\\n' : '');759};760761Lexer.prototype.makeString = function(body, quote, heredoc) {762if (!body) {763return quote + quote;764}765body = body.replace(/\\([\s\S])/g, function(match, contents) {766if (contents === '\n' || contents === quote) {767return contents;768} else {769return match;770}771});772body = body.replace(RegExp("" + quote, "g"), '\\$&');773return quote + this.escapeLines(body, heredoc) + quote;774};775776Lexer.prototype.error = function(message) {777return throwSyntaxError(message, {778first_line: this.chunkLine,779first_column: this.chunkColumn780});781};782783return Lexer;784785})();786787JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];788789COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];790791COFFEE_ALIAS_MAP = {792and: '&&',793or: '||',794is: '==',795isnt: '!=',796not: '!',797yes: 'true',798no: 'false',799on: 'true',800off: 'false'801};802803COFFEE_ALIASES = (function() {804var _results;805_results = [];806for (key in COFFEE_ALIAS_MAP) {807_results.push(key);808}809return _results;810})();811812COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);813814RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield'];815816STRICT_PROSCRIBED = ['arguments', 'eval'];817818JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED);819820exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED);821822exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED;823824BOM = 65279;825826IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;827828NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;829830HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;831832OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?(\.|::)|\.{2,3})/;833834WHITESPACE = /^[^\n\S]+/;835836COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)$)|^(?:\s*#(?!##[^#]).*)+/;837838CODE = /^[-=]>/;839840MULTI_DENT = /^(?:\n[^\n\S]*)+/;841842SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;843844JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;845846REGEX = /^(\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)([imgy]{0,4})(?!\w)/;847848HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?!\w)/;849850HEREGEX_OMIT = /\s+(?:#.*)?/g;851852MULTILINER = /\n/g;853854HEREDOC_INDENT = /\n+([^\n\S]*)/g;855856HEREDOC_ILLEGAL = /\*\//;857858LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;859860TRAILING_SPACES = /\s+$/;861862COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];863864UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO'];865866LOGIC = ['&&', '||', '&', '|', '^'];867868SHIFT = ['<<', '>>', '>>>'];869870COMPARE = ['==', '!=', '<', '>', '<=', '>='];871872MATH = ['*', '/', '%'];873874RELATION = ['IN', 'OF', 'INSTANCEOF'];875876BOOL = ['TRUE', 'FALSE'];877878NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '++', '--'];879880NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING', ']');881882CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];883884INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL', 'NULL', 'UNDEFINED');885886LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];887888}).call(this);889890891