"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/coffee-script/lib/coffee-script/lexer.js" (11 Apr 2017, 31130 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Generated by CoffeeScript 1.9.0
    2 (function() {
    3   var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NUMBER, OCTAL_ESCAPE, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, RELATION, RESERVED, Rewriter, SHIFT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, repeat, starts, throwSyntaxError, _ref, _ref1,
    4     __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; };
    5 
    6   _ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
    7 
    8   _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;
    9 
   10   exports.Lexer = Lexer = (function() {
   11     function Lexer() {}
   12 
   13     Lexer.prototype.tokenize = function(code, opts) {
   14       var consumed, end, i, _ref2;
   15       if (opts == null) {
   16         opts = {};
   17       }
   18       this.literate = opts.literate;
   19       this.indent = 0;
   20       this.baseIndent = 0;
   21       this.indebt = 0;
   22       this.outdebt = 0;
   23       this.indents = [];
   24       this.ends = [];
   25       this.tokens = [];
   26       this.chunkLine = opts.line || 0;
   27       this.chunkColumn = opts.column || 0;
   28       code = this.clean(code);
   29       i = 0;
   30       while (this.chunk = code.slice(i)) {
   31         consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
   32         _ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];
   33         i += consumed;
   34         if (opts.untilBalanced && this.ends.length === 0) {
   35           return {
   36             tokens: this.tokens,
   37             index: i
   38           };
   39         }
   40       }
   41       this.closeIndentation();
   42       if (end = this.ends.pop()) {
   43         throwSyntaxError("missing " + end.tag, end.origin[2]);
   44       }
   45       if (opts.rewrite === false) {
   46         return this.tokens;
   47       }
   48       return (new Rewriter).rewrite(this.tokens);
   49     };
   50 
   51     Lexer.prototype.clean = function(code) {
   52       if (code.charCodeAt(0) === BOM) {
   53         code = code.slice(1);
   54       }
   55       code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
   56       if (WHITESPACE.test(code)) {
   57         code = "\n" + code;
   58         this.chunkLine--;
   59       }
   60       if (this.literate) {
   61         code = invertLiterate(code);
   62       }
   63       return code;
   64     };
   65 
   66     Lexer.prototype.identifierToken = function() {
   67       var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
   68       if (!(match = IDENTIFIER.exec(this.chunk))) {
   69         return 0;
   70       }
   71       input = match[0], id = match[1], colon = match[2];
   72       idLength = id.length;
   73       poppedToken = void 0;
   74       if (id === 'own' && this.tag() === 'FOR') {
   75         this.token('OWN', id);
   76         return id.length;
   77       }
   78       if (id === 'from' && this.tag() === 'YIELD') {
   79         this.token('FROM', id);
   80         return id.length;
   81       }
   82       forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');
   83       tag = 'IDENTIFIER';
   84       if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
   85         tag = id.toUpperCase();
   86         if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
   87           tag = 'LEADING_WHEN';
   88         } else if (tag === 'FOR') {
   89           this.seenFor = true;
   90         } else if (tag === 'UNLESS') {
   91           tag = 'IF';
   92         } else if (__indexOf.call(UNARY, tag) >= 0) {
   93           tag = 'UNARY';
   94         } else if (__indexOf.call(RELATION, tag) >= 0) {
   95           if (tag !== 'INSTANCEOF' && this.seenFor) {
   96             tag = 'FOR' + tag;
   97             this.seenFor = false;
   98           } else {
   99             tag = 'RELATION';
  100             if (this.value() === '!') {
  101               poppedToken = this.tokens.pop();
  102               id = '!' + id;
  103             }
  104           }
  105         }
  106       }
  107       if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {
  108         if (forcedIdentifier) {
  109           tag = 'IDENTIFIER';
  110           id = new String(id);
  111           id.reserved = true;
  112         } else if (__indexOf.call(RESERVED, id) >= 0) {
  113           this.error("reserved word \"" + id + "\"");
  114         }
  115       }
  116       if (!forcedIdentifier) {
  117         if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {
  118           id = COFFEE_ALIAS_MAP[id];
  119         }
  120         tag = (function() {
  121           switch (id) {
  122             case '!':
  123               return 'UNARY';
  124             case '==':
  125             case '!=':
  126               return 'COMPARE';
  127             case '&&':
  128             case '||':
  129               return 'LOGIC';
  130             case 'true':
  131             case 'false':
  132               return 'BOOL';
  133             case 'break':
  134             case 'continue':
  135               return 'STATEMENT';
  136             default:
  137               return tag;
  138           }
  139         })();
  140       }
  141       tagToken = this.token(tag, id, 0, idLength);
  142       tagToken.variable = !forcedIdentifier;
  143       if (poppedToken) {
  144         _ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];
  145       }
  146       if (colon) {
  147         colonOffset = input.lastIndexOf(':');
  148         this.token(':', ':', colonOffset, colon.length);
  149       }
  150       return input.length;
  151     };
  152 
  153     Lexer.prototype.numberToken = function() {
  154       var binaryLiteral, lexedLength, match, number, octalLiteral;
  155       if (!(match = NUMBER.exec(this.chunk))) {
  156         return 0;
  157       }
  158       number = match[0];
  159       if (/^0[BOX]/.test(number)) {
  160         this.error("radix prefix '" + number + "' must be lowercase");
  161       } else if (/E/.test(number) && !/^0x/.test(number)) {
  162         this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
  163       } else if (/^0\d*[89]/.test(number)) {
  164         this.error("decimal literal '" + number + "' must not be prefixed with '0'");
  165       } else if (/^0\d+/.test(number)) {
  166         this.error("octal literal '" + number + "' must be prefixed with '0o'");
  167       }
  168       lexedLength = number.length;
  169       if (octalLiteral = /^0o([0-7]+)/.exec(number)) {
  170         number = '0x' + parseInt(octalLiteral[1], 8).toString(16);
  171       }
  172       if (binaryLiteral = /^0b([01]+)/.exec(number)) {
  173         number = '0x' + parseInt(binaryLiteral[1], 2).toString(16);
  174       }
  175       this.token('NUMBER', number, 0, lexedLength);
  176       return lexedLength;
  177     };
  178 
  179     Lexer.prototype.stringToken = function() {
  180       var $, attempt, doc, end, heredoc, i, indent, indentRegex, match, quote, regex, start, token, tokens, _ref2, _ref3;
  181       quote = (STRING_START.exec(this.chunk) || [])[0];
  182       if (!quote) {
  183         return 0;
  184       }
  185       regex = (function() {
  186         switch (quote) {
  187           case "'":
  188             return STRING_SINGLE;
  189           case '"':
  190             return STRING_DOUBLE;
  191           case "'''":
  192             return HEREDOC_SINGLE;
  193           case '"""':
  194             return HEREDOC_DOUBLE;
  195         }
  196       })();
  197       heredoc = quote.length === 3;
  198       start = quote.length;
  199       _ref2 = this.matchWithInterpolations(this.chunk.slice(start), regex, quote, start), tokens = _ref2.tokens, end = _ref2.index;
  200       $ = tokens.length - 1;
  201       if (heredoc) {
  202         indent = null;
  203         doc = ((function() {
  204           var _i, _len, _results;
  205           _results = [];
  206           for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
  207             token = tokens[i];
  208             if (token[0] === 'NEOSTRING') {
  209               _results.push(token[1]);
  210             }
  211           }
  212           return _results;
  213         })()).join('#{}');
  214         while (match = HEREDOC_INDENT.exec(doc)) {
  215           attempt = match[1];
  216           if (indent === null || (0 < (_ref3 = attempt.length) && _ref3 < indent.length)) {
  217             indent = attempt;
  218           }
  219         }
  220         if (indent) {
  221           indentRegex = RegExp("^" + indent, "gm");
  222         }
  223         this.mergeInterpolationTokens(tokens, {
  224           quote: quote[0],
  225           start: start,
  226           end: end
  227         }, (function(_this) {
  228           return function(value, i) {
  229             value = _this.formatString(value);
  230             if (i === 0) {
  231               value = value.replace(LEADING_BLANK_LINE, '');
  232             }
  233             if (i === $) {
  234               value = value.replace(TRAILING_BLANK_LINE, '');
  235             }
  236             value = value.replace(indentRegex, '');
  237             value = value.replace(MULTILINER, '\\n');
  238             return value;
  239           };
  240         })(this));
  241       } else {
  242         this.mergeInterpolationTokens(tokens, {
  243           quote: quote,
  244           start: start,
  245           end: end
  246         }, (function(_this) {
  247           return function(value, i) {
  248             value = _this.formatString(value);
  249             value = value.replace(STRING_OMIT, function(match, offset) {
  250               if ((i === 0 && offset === 0) || (i === $ && offset + match.length === value.length)) {
  251                 return '';
  252               } else {
  253                 return ' ';
  254               }
  255             });
  256             return value;
  257           };
  258         })(this));
  259       }
  260       return end;
  261     };
  262 
  263     Lexer.prototype.commentToken = function() {
  264       var comment, here, match;
  265       if (!(match = this.chunk.match(COMMENT))) {
  266         return 0;
  267       }
  268       comment = match[0], here = match[1];
  269       if (here) {
  270         if (match = HERECOMMENT_ILLEGAL.exec(comment)) {
  271           this.error("block comments cannot contain " + match[0], match.index);
  272         }
  273         if (here.indexOf('\n') >= 0) {
  274           here = here.replace(RegExp("\\n" + (repeat(' ', this.indent)), "g"), '\n');
  275         }
  276         this.token('HERECOMMENT', here, 0, comment.length);
  277       }
  278       return comment.length;
  279     };
  280 
  281     Lexer.prototype.jsToken = function() {
  282       var match, script;
  283       if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
  284         return 0;
  285       }
  286       this.token('JS', (script = match[0]).slice(1, -1), 0, script.length);
  287       return script.length;
  288     };
  289 
  290     Lexer.prototype.regexToken = function() {
  291       var closed, end, flags, index, match, prev, re, regex, rparen, tokens, _ref2, _ref3, _ref4;
  292       switch (false) {
  293         case !(match = REGEX_ILLEGAL.exec(this.chunk)):
  294           this.error("regular expressions cannot begin with " + match[2], match.index + match[1].length);
  295           break;
  296         case this.chunk.slice(0, 3) !== '///':
  297           _ref2 = this.matchWithInterpolations(this.chunk.slice(3), HEREGEX, '///', 3), tokens = _ref2.tokens, index = _ref2.index;
  298           break;
  299         case !(match = REGEX.exec(this.chunk)):
  300           regex = match[0], closed = match[1];
  301           index = regex.length;
  302           prev = last(this.tokens);
  303           if (prev) {
  304             if (prev.spaced && (_ref3 = prev[0], __indexOf.call(CALLABLE, _ref3) >= 0) && !prev.stringEnd && !prev.regexEnd) {
  305               if (!closed || POSSIBLY_DIVISION.test(regex)) {
  306                 return 0;
  307               }
  308             } else if (_ref4 = prev[0], __indexOf.call(NOT_REGEX, _ref4) >= 0) {
  309               return 0;
  310             }
  311           }
  312           if (!closed) {
  313             this.error('missing / (unclosed regex)');
  314           }
  315           break;
  316         default:
  317           return 0;
  318       }
  319       flags = REGEX_FLAGS.exec(this.chunk.slice(index))[0];
  320       end = index + flags.length;
  321       switch (false) {
  322         case !!VALID_FLAGS.test(flags):
  323           this.error("invalid regular expression flags " + flags, index);
  324           break;
  325         case !regex:
  326           this.token('REGEX', "" + regex + flags);
  327           break;
  328         case tokens.length !== 1:
  329           re = this.formatHeregex(tokens[0][1]).replace(/\//g, '\\/');
  330           this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
  331           break;
  332         default:
  333           this.token('IDENTIFIER', 'RegExp', 0, 0);
  334           this.token('CALL_START', '(', 0, 0);
  335           this.mergeInterpolationTokens(tokens, {
  336             quote: '"',
  337             start: 3,
  338             end: end
  339           }, (function(_this) {
  340             return function(value) {
  341               return _this.formatHeregex(value).replace(/\\/g, '\\\\');
  342             };
  343           })(this));
  344           if (flags) {
  345             this.token(',', ',', index, 0);
  346             this.token('STRING', '"' + flags + '"', index, flags.length);
  347           }
  348           rparen = this.token(')', ')', end, 0);
  349           rparen.regexEnd = true;
  350       }
  351       return end;
  352     };
  353 
  354     Lexer.prototype.lineToken = function() {
  355       var diff, indent, match, noNewlines, size;
  356       if (!(match = MULTI_DENT.exec(this.chunk))) {
  357         return 0;
  358       }
  359       indent = match[0];
  360       this.seenFor = false;
  361       size = indent.length - 1 - indent.lastIndexOf('\n');
  362       noNewlines = this.unfinished();
  363       if (size - this.indebt === this.indent) {
  364         if (noNewlines) {
  365           this.suppressNewlines();
  366         } else {
  367           this.newlineToken(0);
  368         }
  369         return indent.length;
  370       }
  371       if (size > this.indent) {
  372         if (noNewlines) {
  373           this.indebt = size - this.indent;
  374           this.suppressNewlines();
  375           return indent.length;
  376         }
  377         if (!this.tokens.length) {
  378           this.baseIndent = this.indent = size;
  379           return indent.length;
  380         }
  381         diff = size - this.indent + this.outdebt;
  382         this.token('INDENT', diff, indent.length - size, size);
  383         this.indents.push(diff);
  384         this.ends.push({
  385           tag: 'OUTDENT'
  386         });
  387         this.outdebt = this.indebt = 0;
  388         this.indent = size;
  389       } else if (size < this.baseIndent) {
  390         this.error('missing indentation', indent.length);
  391       } else {
  392         this.indebt = 0;
  393         this.outdentToken(this.indent - size, noNewlines, indent.length);
  394       }
  395       return indent.length;
  396     };
  397 
  398     Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
  399       var decreasedIndent, dent, lastIndent, _ref2;
  400       decreasedIndent = this.indent - moveOut;
  401       while (moveOut > 0) {
  402         lastIndent = this.indents[this.indents.length - 1];
  403         if (!lastIndent) {
  404           moveOut = 0;
  405         } else if (lastIndent === this.outdebt) {
  406           moveOut -= this.outdebt;
  407           this.outdebt = 0;
  408         } else if (lastIndent < this.outdebt) {
  409           this.outdebt -= lastIndent;
  410           moveOut -= lastIndent;
  411         } else {
  412           dent = this.indents.pop() + this.outdebt;
  413           if (outdentLength && (_ref2 = this.chunk[outdentLength], __indexOf.call(INDENTABLE_CLOSERS, _ref2) >= 0)) {
  414             decreasedIndent -= dent - moveOut;
  415             moveOut = dent;
  416           }
  417           this.outdebt = 0;
  418           this.pair('OUTDENT');
  419           this.token('OUTDENT', moveOut, 0, outdentLength);
  420           moveOut -= dent;
  421         }
  422       }
  423       if (dent) {
  424         this.outdebt -= moveOut;
  425       }
  426       while (this.value() === ';') {
  427         this.tokens.pop();
  428       }
  429       if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
  430         this.token('TERMINATOR', '\n', outdentLength, 0);
  431       }
  432       this.indent = decreasedIndent;
  433       return this;
  434     };
  435 
  436     Lexer.prototype.whitespaceToken = function() {
  437       var match, nline, prev;
  438       if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
  439         return 0;
  440       }
  441       prev = last(this.tokens);
  442       if (prev) {
  443         prev[match ? 'spaced' : 'newLine'] = true;
  444       }
  445       if (match) {
  446         return match[0].length;
  447       } else {
  448         return 0;
  449       }
  450     };
  451 
  452     Lexer.prototype.newlineToken = function(offset) {
  453       while (this.value() === ';') {
  454         this.tokens.pop();
  455       }
  456       if (this.tag() !== 'TERMINATOR') {
  457         this.token('TERMINATOR', '\n', offset, 0);
  458       }
  459       return this;
  460     };
  461 
  462     Lexer.prototype.suppressNewlines = function() {
  463       if (this.value() === '\\') {
  464         this.tokens.pop();
  465       }
  466       return this;
  467     };
  468 
  469     Lexer.prototype.literalToken = function() {
  470       var match, prev, tag, token, value, _ref2, _ref3, _ref4, _ref5;
  471       if (match = OPERATOR.exec(this.chunk)) {
  472         value = match[0];
  473         if (CODE.test(value)) {
  474           this.tagParameters();
  475         }
  476       } else {
  477         value = this.chunk.charAt(0);
  478       }
  479       tag = value;
  480       prev = last(this.tokens);
  481       if (value === '=' && prev) {
  482         if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
  483           this.error("reserved word \"" + (this.value()) + "\" can't be assigned");
  484         }
  485         if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
  486           prev[0] = 'COMPOUND_ASSIGN';
  487           prev[1] += '=';
  488           return value.length;
  489         }
  490       }
  491       if (value === ';') {
  492         this.seenFor = false;
  493         tag = 'TERMINATOR';
  494       } else if (__indexOf.call(MATH, value) >= 0) {
  495         tag = 'MATH';
  496       } else if (__indexOf.call(COMPARE, value) >= 0) {
  497         tag = 'COMPARE';
  498       } else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
  499         tag = 'COMPOUND_ASSIGN';
  500       } else if (__indexOf.call(UNARY, value) >= 0) {
  501         tag = 'UNARY';
  502       } else if (__indexOf.call(UNARY_MATH, value) >= 0) {
  503         tag = 'UNARY_MATH';
  504       } else if (__indexOf.call(SHIFT, value) >= 0) {
  505         tag = 'SHIFT';
  506       } else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
  507         tag = 'LOGIC';
  508       } else if (prev && !prev.spaced) {
  509         if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0) && !prev.stringEnd && !prev.regexEnd) {
  510           if (prev[0] === '?') {
  511             prev[0] = 'FUNC_EXIST';
  512           }
  513           tag = 'CALL_START';
  514         } else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
  515           tag = 'INDEX_START';
  516           switch (prev[0]) {
  517             case '?':
  518               prev[0] = 'INDEX_SOAK';
  519           }
  520         }
  521       }
  522       token = this.makeToken(tag, value);
  523       switch (value) {
  524         case '(':
  525         case '{':
  526         case '[':
  527           this.ends.push({
  528             tag: INVERSES[value],
  529             origin: token
  530           });
  531           break;
  532         case ')':
  533         case '}':
  534         case ']':
  535           this.pair(value);
  536       }
  537       this.tokens.push(token);
  538       return value.length;
  539     };
  540 
  541     Lexer.prototype.tagParameters = function() {
  542       var i, stack, tok, tokens;
  543       if (this.tag() !== ')') {
  544         return this;
  545       }
  546       stack = [];
  547       tokens = this.tokens;
  548       i = tokens.length;
  549       tokens[--i][0] = 'PARAM_END';
  550       while (tok = tokens[--i]) {
  551         switch (tok[0]) {
  552           case ')':
  553             stack.push(tok);
  554             break;
  555           case '(':
  556           case 'CALL_START':
  557             if (stack.length) {
  558               stack.pop();
  559             } else if (tok[0] === '(') {
  560               tok[0] = 'PARAM_START';
  561               return this;
  562             } else {
  563               return this;
  564             }
  565         }
  566       }
  567       return this;
  568     };
  569 
  570     Lexer.prototype.closeIndentation = function() {
  571       return this.outdentToken(this.indent);
  572     };
  573 
  574     Lexer.prototype.matchWithInterpolations = function(str, regex, end, offsetInChunk) {
  575       var close, column, index, line, nested, open, strPart, tokens, _ref2, _ref3, _ref4;
  576       tokens = [];
  577       while (true) {
  578         strPart = regex.exec(str)[0];
  579         tokens.push(this.makeToken('NEOSTRING', strPart, offsetInChunk));
  580         str = str.slice(strPart.length);
  581         offsetInChunk += strPart.length;
  582         if (str.slice(0, 2) !== '#{') {
  583           break;
  584         }
  585         _ref2 = this.getLineAndColumnFromChunk(offsetInChunk + 1), line = _ref2[0], column = _ref2[1];
  586         _ref3 = new Lexer().tokenize(str.slice(1), {
  587           line: line,
  588           column: column,
  589           untilBalanced: true
  590         }), nested = _ref3.tokens, index = _ref3.index;
  591         index += 1;
  592         open = nested[0], close = nested[nested.length - 1];
  593         open[0] = open[1] = '(';
  594         close[0] = close[1] = ')';
  595         close.origin = ['', 'end of interpolation', close[2]];
  596         if (((_ref4 = nested[1]) != null ? _ref4[0] : void 0) === 'TERMINATOR') {
  597           nested.splice(1, 1);
  598         }
  599         tokens.push(['TOKENS', nested]);
  600         str = str.slice(index);
  601         offsetInChunk += index;
  602       }
  603       if (str.slice(0, end.length) !== end) {
  604         this.error("missing " + end);
  605       }
  606       return {
  607         tokens: tokens,
  608         index: offsetInChunk + end.length
  609       };
  610     };
  611 
  612     Lexer.prototype.mergeInterpolationTokens = function(tokens, _arg, fn) {
  613       var converted, end, errorToken, firstEmptyStringIndex, firstIndex, i, interpolated, locationToken, plusToken, quote, rparen, start, tag, token, tokensToPush, value, _i, _len, _ref2;
  614       quote = _arg.quote, start = _arg.start, end = _arg.end;
  615       if (interpolated = tokens.length > 1) {
  616         errorToken = this.makeToken('', 'interpolation', start + tokens[0][1].length, 2);
  617         this.token('(', '(', 0, 0, errorToken);
  618       }
  619       firstIndex = this.tokens.length;
  620       for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
  621         token = tokens[i];
  622         tag = token[0], value = token[1];
  623         switch (tag) {
  624           case 'TOKENS':
  625             if (value.length === 2) {
  626               continue;
  627             }
  628             locationToken = value[0];
  629             tokensToPush = value;
  630             break;
  631           case 'NEOSTRING':
  632             converted = fn(token[1], i);
  633             if (converted.length === 0) {
  634               if (i === 0) {
  635                 firstEmptyStringIndex = this.tokens.length;
  636               } else {
  637                 continue;
  638               }
  639             }
  640             if (i === 2 && (firstEmptyStringIndex != null)) {
  641               this.tokens.splice(firstEmptyStringIndex, 2);
  642             }
  643             token[0] = 'STRING';
  644             token[1] = this.makeString(converted, quote);
  645             locationToken = token;
  646             tokensToPush = [token];
  647         }
  648         if (this.tokens.length > firstIndex) {
  649           plusToken = this.token('+', '+');
  650           plusToken[2] = {
  651             first_line: locationToken[2].first_line,
  652             first_column: locationToken[2].first_column,
  653             last_line: locationToken[2].first_line,
  654             last_column: locationToken[2].first_column
  655           };
  656         }
  657         (_ref2 = this.tokens).push.apply(_ref2, tokensToPush);
  658       }
  659       if (interpolated) {
  660         rparen = this.token(')', ')', end, 0);
  661         return rparen.stringEnd = true;
  662       }
  663     };
  664 
  665     Lexer.prototype.pair = function(tag) {
  666       var wanted, _ref2;
  667       if (tag !== (wanted = (_ref2 = last(this.ends)) != null ? _ref2.tag : void 0)) {
  668         if ('OUTDENT' !== wanted) {
  669           this.error("unmatched " + tag);
  670         }
  671         this.outdentToken(last(this.indents), true);
  672         return this.pair(tag);
  673       }
  674       return this.ends.pop();
  675     };
  676 
  677     Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
  678       var column, lineCount, lines, string;
  679       if (offset === 0) {
  680         return [this.chunkLine, this.chunkColumn];
  681       }
  682       if (offset >= this.chunk.length) {
  683         string = this.chunk;
  684       } else {
  685         string = this.chunk.slice(0, +(offset - 1) + 1 || 9e9);
  686       }
  687       lineCount = count(string, '\n');
  688       column = this.chunkColumn;
  689       if (lineCount > 0) {
  690         lines = string.split('\n');
  691         column = last(lines).length;
  692       } else {
  693         column += string.length;
  694       }
  695       return [this.chunkLine + lineCount, column];
  696     };
  697 
  698     Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
  699       var lastCharacter, locationData, token, _ref2, _ref3;
  700       if (offsetInChunk == null) {
  701         offsetInChunk = 0;
  702       }
  703       if (length == null) {
  704         length = value.length;
  705       }
  706       locationData = {};
  707       _ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];
  708       lastCharacter = Math.max(0, length - 1);
  709       _ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];
  710       token = [tag, value, locationData];
  711       return token;
  712     };
  713 
  714     Lexer.prototype.token = function(tag, value, offsetInChunk, length, origin) {
  715       var token;
  716       token = this.makeToken(tag, value, offsetInChunk, length);
  717       if (origin) {
  718         token.origin = origin;
  719       }
  720       this.tokens.push(token);
  721       return token;
  722     };
  723 
  724     Lexer.prototype.tag = function(index, tag) {
  725       var tok;
  726       return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
  727     };
  728 
  729     Lexer.prototype.value = function(index, val) {
  730       var tok;
  731       return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
  732     };
  733 
  734     Lexer.prototype.unfinished = function() {
  735       var _ref2;
  736       return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === 'UNARY_MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'YIELD' || _ref2 === '**' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
  737     };
  738 
  739     Lexer.prototype.formatString = function(str) {
  740       return str.replace(/\\[^\S\n]*(\n|\\)\s*/g, function(escaped, character) {
  741         if (character === '\n') {
  742           return '';
  743         } else {
  744           return escaped;
  745         }
  746       });
  747     };
  748 
  749     Lexer.prototype.formatHeregex = function(str) {
  750       return str.replace(HEREGEX_OMIT, '$1$2').replace(MULTILINER, '\\n');
  751     };
  752 
  753     Lexer.prototype.makeString = function(body, quote) {
  754       var match;
  755       if (!body) {
  756         return quote + quote;
  757       }
  758       body = body.replace(RegExp("\\\\(" + quote + "|\\\\)", "g"), function(match, contents) {
  759         if (contents === quote) {
  760           return contents;
  761         } else {
  762           return match;
  763         }
  764       });
  765       body = body.replace(RegExp("" + quote, "g"), '\\$&');
  766       if (match = OCTAL_ESCAPE.exec(body)) {
  767         this.error("octal escape sequences are not allowed " + match[2], match.index + match[1].length + 1);
  768       }
  769       return quote + body + quote;
  770     };
  771 
  772     Lexer.prototype.error = function(message, offset) {
  773       var first_column, first_line, _ref2;
  774       if (offset == null) {
  775         offset = 0;
  776       }
  777       _ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
  778       return throwSyntaxError(message, {
  779         first_line: first_line,
  780         first_column: first_column
  781       });
  782     };
  783 
  784     return Lexer;
  785 
  786   })();
  787 
  788   JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'yield', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
  789 
  790   COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
  791 
  792   COFFEE_ALIAS_MAP = {
  793     and: '&&',
  794     or: '||',
  795     is: '==',
  796     isnt: '!=',
  797     not: '!',
  798     yes: 'true',
  799     no: 'false',
  800     on: 'true',
  801     off: 'false'
  802   };
  803 
  804   COFFEE_ALIASES = (function() {
  805     var _results;
  806     _results = [];
  807     for (key in COFFEE_ALIAS_MAP) {
  808       _results.push(key);
  809     }
  810     return _results;
  811   })();
  812 
  813   COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
  814 
  815   RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static'];
  816 
  817   STRICT_PROSCRIBED = ['arguments', 'eval', 'yield*'];
  818 
  819   JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED);
  820 
  821   exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED);
  822 
  823   exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED;
  824 
  825   BOM = 65279;
  826 
  827   IDENTIFIER = /^(?!\d)((?:(?!\s)[$\w\x7f-\uffff])+)([^\n\S]*:(?!:))?/;
  828 
  829   NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
  830 
  831   OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>*\/%])\2=?|\?(\.|::)|\.{2,3})/;
  832 
  833   WHITESPACE = /^[^\n\S]+/;
  834 
  835   COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|###$)|^(?:\s*#(?!##[^#]).*)+/;
  836 
  837   CODE = /^[-=]>/;
  838 
  839   MULTI_DENT = /^(?:\n[^\n\S]*)+/;
  840 
  841   JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
  842 
  843   STRING_START = /^(?:'''|"""|'|")/;
  844 
  845   STRING_SINGLE = /^(?:[^\\']|\\[\s\S])*/;
  846 
  847   STRING_DOUBLE = /^(?:[^\\"#]|\\[\s\S]|\#(?!\{))*/;
  848 
  849   HEREDOC_SINGLE = /^(?:[^\\']|\\[\s\S]|'(?!''))*/;
  850 
  851   HEREDOC_DOUBLE = /^(?:[^\\"#]|\\[\s\S]|"(?!"")|\#(?!\{))*/;
  852 
  853   STRING_OMIT = /\s*\n\s*/g;
  854 
  855   HEREDOC_INDENT = /\n+([^\n\S]*)(?=\S)/g;
  856 
  857   REGEX = /^\/(?!\/)(?:[^[\/\n\\]|\\.|\[(?:\\.|[^\]\n\\])*])*(\/)?/;
  858 
  859   REGEX_FLAGS = /^\w*/;
  860 
  861   VALID_FLAGS = /^(?!.*(.).*\1)[imgy]*$/;
  862 
  863   HEREGEX = /^(?:[^\\\/#]|\\[\s\S]|\/(?!\/\/)|\#(?!\{))*/;
  864 
  865   HEREGEX_OMIT = /((?:\\\\)+)|\\(\s|\/)|\s+(?:#.*)?/g;
  866 
  867   REGEX_ILLEGAL = /^(\/|\/{3}\s*)(\*)/;
  868 
  869   POSSIBLY_DIVISION = /^\/=?\s/;
  870 
  871   MULTILINER = /\n/g;
  872 
  873   HERECOMMENT_ILLEGAL = /\*\//;
  874 
  875   LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;
  876 
  877   OCTAL_ESCAPE = /^((?:\\.|[^\\])*)(\\(?:0[0-7]|[1-7]))/;
  878 
  879   LEADING_BLANK_LINE = /^[^\n\S]*\n/;
  880 
  881   TRAILING_BLANK_LINE = /\n[^\n\S]*$/;
  882 
  883   TRAILING_SPACES = /\s+$/;
  884 
  885   COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=', '**=', '//=', '%%='];
  886 
  887   UNARY = ['NEW', 'TYPEOF', 'DELETE', 'DO'];
  888 
  889   UNARY_MATH = ['!', '~'];
  890 
  891   LOGIC = ['&&', '||', '&', '|', '^'];
  892 
  893   SHIFT = ['<<', '>>', '>>>'];
  894 
  895   COMPARE = ['==', '!=', '<', '>', '<=', '>='];
  896 
  897   MATH = ['*', '/', '%', '//', '%%'];
  898 
  899   RELATION = ['IN', 'OF', 'INSTANCEOF'];
  900 
  901   BOOL = ['TRUE', 'FALSE'];
  902 
  903   CALLABLE = ['IDENTIFIER', ')', ']', '?', '@', 'THIS', 'SUPER'];
  904 
  905   INDEXABLE = CALLABLE.concat(['NUMBER', 'STRING', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '}', '::']);
  906 
  907   NOT_REGEX = INDEXABLE.concat(['++', '--']);
  908 
  909   LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
  910 
  911   INDENTABLE_CLOSERS = [')', '}', ']'];
  912 
  913 }).call(this);