1 // Generated by CoffeeScript 1.8.0
3 var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, 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, UNARY_MATH, 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; };
6 _ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
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;
10 exports.Lexer = Lexer = (function() {
13 Lexer.prototype.tokenize = function(code, opts) {
14 var consumed, i, tag, _ref2;
18 this.literate = opts.literate;
26 this.chunkLine = opts.line || 0;
27 this.chunkColumn = opts.column || 0;
28 code = this.clean(code);
30 while (this.chunk = code.slice(i)) {
31 consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
32 _ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];
35 this.closeIndentation();
36 if (tag = this.ends.pop()) {
37 this.error("missing " + tag);
39 if (opts.rewrite === false) {
42 return (new Rewriter).rewrite(this.tokens);
45 Lexer.prototype.clean = function(code) {
46 if (code.charCodeAt(0) === BOM) {
49 code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
50 if (WHITESPACE.test(code)) {
55 code = invertLiterate(code);
60 Lexer.prototype.identifierToken = function() {
61 var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
62 if (!(match = IDENTIFIER.exec(this.chunk))) {
65 input = match[0], id = match[1], colon = match[2];
68 if (id === 'own' && this.tag() === 'FOR') {
69 this.token('OWN', id);
72 forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');
74 if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
75 tag = id.toUpperCase();
76 if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
78 } else if (tag === 'FOR') {
80 } else if (tag === 'UNLESS') {
82 } else if (__indexOf.call(UNARY, tag) >= 0) {
84 } else if (__indexOf.call(RELATION, tag) >= 0) {
85 if (tag !== 'INSTANCEOF' && this.seenFor) {
90 if (this.value() === '!') {
91 poppedToken = this.tokens.pop();
97 if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {
98 if (forcedIdentifier) {
102 } else if (__indexOf.call(RESERVED, id) >= 0) {
103 this.error("reserved word \"" + id + "\"");
106 if (!forcedIdentifier) {
107 if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {
108 id = COFFEE_ALIAS_MAP[id];
131 tagToken = this.token(tag, id, 0, idLength);
133 _ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];
136 colonOffset = input.lastIndexOf(':');
137 this.token(':', ':', colonOffset, colon.length);
142 Lexer.prototype.numberToken = function() {
143 var binaryLiteral, lexedLength, match, number, octalLiteral;
144 if (!(match = NUMBER.exec(this.chunk))) {
148 if (/^0[BOX]/.test(number)) {
149 this.error("radix prefix '" + number + "' must be lowercase");
150 } else if (/E/.test(number) && !/^0x/.test(number)) {
151 this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
152 } else if (/^0\d*[89]/.test(number)) {
153 this.error("decimal literal '" + number + "' must not be prefixed with '0'");
154 } else if (/^0\d+/.test(number)) {
155 this.error("octal literal '" + number + "' must be prefixed with '0o'");
157 lexedLength = number.length;
158 if (octalLiteral = /^0o([0-7]+)/.exec(number)) {
159 number = '0x' + parseInt(octalLiteral[1], 8).toString(16);
161 if (binaryLiteral = /^0b([01]+)/.exec(number)) {
162 number = '0x' + parseInt(binaryLiteral[1], 2).toString(16);
164 this.token('NUMBER', number, 0, lexedLength);
168 Lexer.prototype.stringToken = function() {
169 var inner, innerLen, numBreak, octalEsc, pos, quote, string, trimmed;
170 switch (quote = this.chunk.charAt(0)) {
172 string = (SIMPLESTR.exec(this.chunk) || [])[0];
175 string = this.balancedString(this.chunk, '"');
180 inner = string.slice(1, -1);
181 trimmed = this.removeNewlines(inner);
182 if (quote === '"' && 0 < string.indexOf('#{', 1)) {
184 innerLen = inner.length;
185 while (inner.charAt(pos++) === '\n' && pos < innerLen) {
188 this.interpolateString(trimmed, {
189 strOffset: 1 + numBreak,
190 lexedLength: string.length
193 this.token('STRING', quote + this.escapeLines(trimmed) + quote, 0, string.length);
195 if (octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test(string)) {
196 this.error("octal escape sequences " + string + " are not allowed");
198 return string.length;
201 Lexer.prototype.heredocToken = function() {
202 var doc, heredoc, match, quote, strOffset;
203 if (!(match = HEREDOC.exec(this.chunk))) {
207 quote = heredoc.charAt(0);
208 doc = this.sanitizeHeredoc(match[2], {
212 if (quote === '"' && 0 <= doc.indexOf('#{')) {
213 strOffset = match[2].charAt(0) === '\n' ? 4 : 3;
214 this.interpolateString(doc, {
216 strOffset: strOffset,
217 lexedLength: heredoc.length
220 this.token('STRING', this.makeString(doc, quote, true), 0, heredoc.length);
222 return heredoc.length;
225 Lexer.prototype.commentToken = function() {
226 var comment, here, match;
227 if (!(match = this.chunk.match(COMMENT))) {
230 comment = match[0], here = match[1];
232 this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
234 indent: repeat(' ', this.indent)
235 }), 0, comment.length);
237 return comment.length;
240 Lexer.prototype.jsToken = function() {
242 if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
245 this.token('JS', (script = match[0]).slice(1, -1), 0, script.length);
246 return script.length;
249 Lexer.prototype.regexToken = function() {
250 var flags, length, match, prev, regex, _ref2, _ref3;
251 if (this.chunk.charAt(0) !== '/') {
254 if (length = this.heregexToken()) {
257 prev = last(this.tokens);
258 if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) {
261 if (!(match = REGEX.exec(this.chunk))) {
264 _ref3 = match, match = _ref3[0], regex = _ref3[1], flags = _ref3[2];
265 if (regex === '//') {
268 if (regex.slice(0, 2) === '/*') {
269 this.error('regular expressions cannot begin with `*`');
271 this.token('REGEX', "" + regex + flags, 0, match.length);
275 Lexer.prototype.heregexToken = function() {
276 var body, flags, flagsOffset, heregex, match, plusToken, prev, re, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
277 if (!(match = HEREGEX.exec(this.chunk))) {
280 heregex = match[0], body = match[1], flags = match[2];
281 if (0 > body.indexOf('#{')) {
282 re = this.escapeLines(body.replace(HEREGEX_OMIT, '$1$2').replace(/\//g, '\\/'), true);
283 if (re.match(/^\*/)) {
284 this.error('regular expressions cannot begin with `*`');
286 this.token('REGEX', "/" + (re || '(?:)') + "/" + flags, 0, heregex.length);
287 return heregex.length;
289 this.token('IDENTIFIER', 'RegExp', 0, 0);
290 this.token('CALL_START', '(', 0, 0);
292 _ref2 = this.interpolateString(body, {
296 for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
298 tag = token[0], value = token[1];
299 if (tag === 'TOKENS') {
300 tokens.push.apply(tokens, value);
301 } else if (tag === 'NEOSTRING') {
302 if (!(value = value.replace(HEREGEX_OMIT, '$1$2'))) {
305 value = value.replace(/\\/g, '\\\\');
307 token[1] = this.makeString(value, '"', true);
310 this.error("Unexpected " + tag);
312 prev = last(this.tokens);
313 plusToken = ['+', '+'];
314 plusToken[2] = prev[2];
315 tokens.push(plusToken);
318 if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') {
319 this.token('STRING', '""', 0, 0);
320 this.token('+', '+', 0, 0);
322 (_ref4 = this.tokens).push.apply(_ref4, tokens);
324 flagsOffset = heregex.lastIndexOf(flags);
325 this.token(',', ',', flagsOffset, 0);
326 this.token('STRING', '"' + flags + '"', flagsOffset, flags.length);
328 this.token(')', ')', heregex.length - 1, 0);
329 return heregex.length;
332 Lexer.prototype.lineToken = function() {
333 var diff, indent, match, noNewlines, size;
334 if (!(match = MULTI_DENT.exec(this.chunk))) {
338 this.seenFor = false;
339 size = indent.length - 1 - indent.lastIndexOf('\n');
340 noNewlines = this.unfinished();
341 if (size - this.indebt === this.indent) {
343 this.suppressNewlines();
345 this.newlineToken(0);
347 return indent.length;
349 if (size > this.indent) {
351 this.indebt = size - this.indent;
352 this.suppressNewlines();
353 return indent.length;
355 if (!this.tokens.length) {
356 this.baseIndent = this.indent = size;
357 return indent.length;
359 diff = size - this.indent + this.outdebt;
360 this.token('INDENT', diff, indent.length - size, size);
361 this.indents.push(diff);
362 this.ends.push('OUTDENT');
363 this.outdebt = this.indebt = 0;
365 } else if (size < this.baseIndent) {
366 this.error('missing indentation', indent.length);
369 this.outdentToken(this.indent - size, noNewlines, indent.length);
371 return indent.length;
374 Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
375 var decreasedIndent, dent, lastIndent, _ref2;
376 decreasedIndent = this.indent - moveOut;
377 while (moveOut > 0) {
378 lastIndent = this.indents[this.indents.length - 1];
381 } else if (lastIndent === this.outdebt) {
382 moveOut -= this.outdebt;
384 } else if (lastIndent < this.outdebt) {
385 this.outdebt -= lastIndent;
386 moveOut -= lastIndent;
388 dent = this.indents.pop() + this.outdebt;
389 if (outdentLength && (_ref2 = this.chunk[outdentLength], __indexOf.call(INDENTABLE_CLOSERS, _ref2) >= 0)) {
390 decreasedIndent -= dent - moveOut;
394 this.pair('OUTDENT');
395 this.token('OUTDENT', moveOut, 0, outdentLength);
400 this.outdebt -= moveOut;
402 while (this.value() === ';') {
405 if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
406 this.token('TERMINATOR', '\n', outdentLength, 0);
408 this.indent = decreasedIndent;
412 Lexer.prototype.whitespaceToken = function() {
413 var match, nline, prev;
414 if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
417 prev = last(this.tokens);
419 prev[match ? 'spaced' : 'newLine'] = true;
422 return match[0].length;
428 Lexer.prototype.newlineToken = function(offset) {
429 while (this.value() === ';') {
432 if (this.tag() !== 'TERMINATOR') {
433 this.token('TERMINATOR', '\n', offset, 0);
438 Lexer.prototype.suppressNewlines = function() {
439 if (this.value() === '\\') {
445 Lexer.prototype.literalToken = function() {
446 var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
447 if (match = OPERATOR.exec(this.chunk)) {
449 if (CODE.test(value)) {
450 this.tagParameters();
453 value = this.chunk.charAt(0);
456 prev = last(this.tokens);
457 if (value === '=' && prev) {
458 if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
459 this.error("reserved word \"" + (this.value()) + "\" can't be assigned");
461 if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
462 prev[0] = 'COMPOUND_ASSIGN';
468 this.seenFor = false;
470 } else if (__indexOf.call(MATH, value) >= 0) {
472 } else if (__indexOf.call(COMPARE, value) >= 0) {
474 } else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
475 tag = 'COMPOUND_ASSIGN';
476 } else if (__indexOf.call(UNARY, value) >= 0) {
478 } else if (__indexOf.call(UNARY_MATH, value) >= 0) {
480 } else if (__indexOf.call(SHIFT, value) >= 0) {
482 } else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
484 } else if (prev && !prev.spaced) {
485 if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {
486 if (prev[0] === '?') {
487 prev[0] = 'FUNC_EXIST';
490 } else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
494 prev[0] = 'INDEX_SOAK';
502 this.ends.push(INVERSES[value]);
509 this.token(tag, value);
513 Lexer.prototype.sanitizeHeredoc = function(doc, options) {
514 var attempt, herecomment, indent, match, _ref2;
515 indent = options.indent, herecomment = options.herecomment;
517 if (HEREDOC_ILLEGAL.test(doc)) {
518 this.error("block comment cannot contain \"*/\", starting");
520 if (doc.indexOf('\n') < 0) {
524 while (match = HEREDOC_INDENT.exec(doc)) {
526 if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) {
532 doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
535 doc = doc.replace(/^\n/, '');
540 Lexer.prototype.tagParameters = function() {
541 var i, stack, tok, tokens;
542 if (this.tag() !== ')') {
546 tokens = this.tokens;
548 tokens[--i][0] = 'PARAM_END';
549 while (tok = tokens[--i]) {
558 } else if (tok[0] === '(') {
559 tok[0] = 'PARAM_START';
569 Lexer.prototype.closeIndentation = function() {
570 return this.outdentToken(this.indent);
573 Lexer.prototype.balancedString = function(str, end) {
574 var continueCount, i, letter, match, prev, stack, _i, _ref2;
577 for (i = _i = 1, _ref2 = str.length; 1 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 1 <= _ref2 ? ++_i : --_i) {
582 switch (letter = str.charAt(i)) {
589 return str.slice(0, +i + 1 || 9e9);
591 end = stack[stack.length - 1];
594 if (end === '}' && (letter === '"' || letter === "'")) {
595 stack.push(end = letter);
596 } else if (end === '}' && letter === '/' && (match = HEREGEX.exec(str.slice(i)) || REGEX.exec(str.slice(i)))) {
597 continueCount += match[0].length - 1;
598 } else if (end === '}' && letter === '{') {
599 stack.push(end = '}');
600 } else if (end === '"' && prev === '#' && letter === '{') {
601 stack.push(end = '}');
605 return this.error("missing " + (stack.pop()) + ", starting");
608 Lexer.prototype.interpolateString = function(str, options) {
609 var column, errorToken, 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;
610 if (options == null) {
613 heredoc = options.heredoc, regex = options.regex, offsetInChunk = options.offsetInChunk, strOffset = options.strOffset, lexedLength = options.lexedLength;
614 offsetInChunk || (offsetInChunk = 0);
615 strOffset || (strOffset = 0);
616 lexedLength || (lexedLength = str.length);
620 while (letter = str.charAt(i += 1)) {
621 if (letter === '\\') {
625 if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) {
629 tokens.push(this.makeToken('NEOSTRING', str.slice(pi, i), strOffset + pi));
632 errorToken = this.makeToken('', 'string interpolation', offsetInChunk + i + 1, 2);
634 inner = expr.slice(1, -1);
636 _ref2 = this.getLineAndColumnFromChunk(strOffset + i + 2), line = _ref2[0], column = _ref2[1];
637 nested = new Lexer().tokenize(inner, {
642 popped = nested.pop();
643 if (((_ref3 = nested[0]) != null ? _ref3[0] : void 0) === 'TERMINATOR') {
644 popped = nested.shift();
646 if (len = nested.length) {
648 nested.unshift(this.makeToken('(', '(', strOffset + i + 1, 0));
649 nested.push(this.makeToken(')', ')', strOffset + i + 1 + inner.length, 0));
651 tokens.push(['TOKENS', nested]);
657 if ((i > pi && pi < str.length)) {
658 tokens.push(this.makeToken('NEOSTRING', str.slice(pi), strOffset + pi));
663 if (!tokens.length) {
664 return this.token('STRING', '""', offsetInChunk, lexedLength);
666 if (tokens[0][0] !== 'NEOSTRING') {
667 tokens.unshift(this.makeToken('NEOSTRING', '', offsetInChunk));
669 if (interpolated = tokens.length > 1) {
670 this.token('(', '(', offsetInChunk, 0, errorToken);
672 for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
674 tag = token[0], value = token[1];
677 plusToken = this.token('+', '+');
679 locationToken = tag === 'TOKENS' ? value[0] : token;
681 first_line: locationToken[2].first_line,
682 first_column: locationToken[2].first_column,
683 last_line: locationToken[2].first_line,
684 last_column: locationToken[2].first_column
687 if (tag === 'TOKENS') {
688 (_ref4 = this.tokens).push.apply(_ref4, value);
689 } else if (tag === 'NEOSTRING') {
691 token[1] = this.makeString(value, '"', heredoc);
692 this.tokens.push(token);
694 this.error("Unexpected " + tag);
698 rparen = this.makeToken(')', ')', offsetInChunk + lexedLength, 0);
699 rparen.stringEnd = true;
700 this.tokens.push(rparen);
705 Lexer.prototype.pair = function(tag) {
707 if (tag !== (wanted = last(this.ends))) {
708 if ('OUTDENT' !== wanted) {
709 this.error("unmatched " + tag);
711 this.outdentToken(last(this.indents), true);
712 return this.pair(tag);
714 return this.ends.pop();
717 Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
718 var column, lineCount, lines, string;
720 return [this.chunkLine, this.chunkColumn];
722 if (offset >= this.chunk.length) {
725 string = this.chunk.slice(0, +(offset - 1) + 1 || 9e9);
727 lineCount = count(string, '\n');
728 column = this.chunkColumn;
730 lines = string.split('\n');
731 column = last(lines).length;
733 column += string.length;
735 return [this.chunkLine + lineCount, column];
738 Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
739 var lastCharacter, locationData, token, _ref2, _ref3;
740 if (offsetInChunk == null) {
743 if (length == null) {
744 length = value.length;
747 _ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];
748 lastCharacter = Math.max(0, length - 1);
749 _ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];
750 token = [tag, value, locationData];
754 Lexer.prototype.token = function(tag, value, offsetInChunk, length, origin) {
756 token = this.makeToken(tag, value, offsetInChunk, length);
758 token.origin = origin;
760 this.tokens.push(token);
764 Lexer.prototype.tag = function(index, tag) {
766 return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
769 Lexer.prototype.value = function(index, val) {
771 return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
774 Lexer.prototype.unfinished = function() {
776 return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === 'UNARY_MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === '**' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
779 Lexer.prototype.removeNewlines = function(str) {
780 return str.replace(/^\s*\n\s*/, '').replace(/([^\\]|\\\\)\s*\n\s*$/, '$1');
783 Lexer.prototype.escapeLines = function(str, heredoc) {
784 str = str.replace(/\\[^\S\n]*(\n|\\)\s*/g, function(escaped, character) {
785 if (character === '\n') {
792 return str.replace(MULTILINER, '\\n');
794 return str.replace(/\s*\n\s*/g, ' ');
798 Lexer.prototype.makeString = function(body, quote, heredoc) {
800 return quote + quote;
802 body = body.replace(RegExp("\\\\(" + quote + "|\\\\)", "g"), function(match, contents) {
803 if (contents === quote) {
809 body = body.replace(RegExp("" + quote, "g"), '\\$&');
810 return quote + this.escapeLines(body, heredoc) + quote;
813 Lexer.prototype.error = function(message, offset) {
814 var first_column, first_line, _ref2;
815 if (offset == null) {
818 _ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
819 return throwSyntaxError(message, {
820 first_line: first_line,
821 first_column: first_column
829 JS_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'];
831 COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
845 COFFEE_ALIASES = (function() {
848 for (key in COFFEE_ALIAS_MAP) {
854 COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
856 RESERVED = ['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'];
858 STRICT_PROSCRIBED = ['arguments', 'eval'];
860 JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED);
862 exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED);
864 exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED;
868 IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;
870 NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
872 HEREDOC = /^("""|''')((?:\\[\s\S]|[^\\])*?)(?:\n[^\n\S]*)?\1/;
874 OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>*\/%])\2=?|\?(\.|::)|\.{2,3})/;
876 WHITESPACE = /^[^\n\S]+/;
878 COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|###$)|^(?:\s*#(?!##[^#]).*)+/;
882 MULTI_DENT = /^(?:\n[^\n\S]*)+/;
884 SIMPLESTR = /^'[^\\']*(?:\\[\s\S][^\\']*)*'/;
886 JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
888 REGEX = /^(\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)([imgy]{0,4})(?!\w)/;
890 HEREGEX = /^\/{3}((?:\\?[\s\S])+?)\/{3}([imgy]{0,4})(?!\w)/;
892 HEREGEX_OMIT = /((?:\\\\)+)|\\(\s|\/)|\s+(?:#.*)?/g;
896 HEREDOC_INDENT = /\n+([^\n\S]*)/g;
898 HEREDOC_ILLEGAL = /\*\//;
900 LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;
902 TRAILING_SPACES = /\s+$/;
904 COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=', '**=', '//=', '%%='];
906 UNARY = ['NEW', 'TYPEOF', 'DELETE', 'DO'];
908 UNARY_MATH = ['!', '~'];
910 LOGIC = ['&&', '||', '&', '|', '^'];
912 SHIFT = ['<<', '>>', '>>>'];
914 COMPARE = ['==', '!=', '<', '>', '<=', '>='];
916 MATH = ['*', '/', '%', '//', '%%'];
918 RELATION = ['IN', 'OF', 'INSTANCEOF'];
920 BOOL = ['TRUE', 'FALSE'];
922 NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '++', '--'];
924 NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING', ']');
926 CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
928 INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL', 'NULL', 'UNDEFINED');
930 LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
932 INDENTABLE_CLOSERS = [')', '}', ']'];