mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
Merge branch 'unary-new' of http://github.com/satyr/coffee-script
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
__dirname = path.dirname(__filename);
|
||||
return eval(exports.compile(code, options));
|
||||
};
|
||||
lexer = new Lexer();
|
||||
lexer = new Lexer;
|
||||
parser.lexer = {
|
||||
lex: function() {
|
||||
var token;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
exec = _ref.exec;
|
||||
_ref = require('events');
|
||||
EventEmitter = _ref.EventEmitter;
|
||||
helpers.extend(CoffeeScript, new EventEmitter());
|
||||
helpers.extend(CoffeeScript, new EventEmitter);
|
||||
global.CoffeeScript = CoffeeScript;
|
||||
BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee';
|
||||
SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['--no-wrap', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
grammar = {
|
||||
Root: [
|
||||
o("", function() {
|
||||
return new Expressions();
|
||||
return new Expressions;
|
||||
}), o("TERMINATOR", function() {
|
||||
return new Expressions();
|
||||
return new Expressions;
|
||||
}), o("Body"), o("Block TERMINATOR")
|
||||
],
|
||||
Body: [
|
||||
@@ -37,12 +37,12 @@
|
||||
return new LiteralNode($1);
|
||||
})
|
||||
],
|
||||
Expression: [o("Value"), o("Call"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
|
||||
Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
|
||||
Block: [
|
||||
o("INDENT Body OUTDENT", function() {
|
||||
return $2;
|
||||
}), o("INDENT OUTDENT", function() {
|
||||
return new Expressions();
|
||||
return new Expressions;
|
||||
}), o("TERMINATOR Comment", function() {
|
||||
return Expressions.wrap([$2]);
|
||||
})
|
||||
@@ -257,13 +257,6 @@
|
||||
return $2;
|
||||
})
|
||||
],
|
||||
Call: [
|
||||
o("Invocation"), o("NEW Invocation", function() {
|
||||
return $2.newInstance();
|
||||
}), o("NEW Value", function() {
|
||||
return (new CallNode($2, [])).newInstance();
|
||||
})
|
||||
],
|
||||
Extends: [
|
||||
o("SimpleAssignable EXTENDS Value", function() {
|
||||
return new ExtendsNode($1, $3);
|
||||
@@ -611,7 +604,7 @@
|
||||
})
|
||||
]
|
||||
};
|
||||
operators = [["right", '?', 'NEW'], ["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'INSTANCEOF'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||
operators = [["right", '?'], ["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'INSTANCEOF'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||
tokens = [];
|
||||
_ref = grammar;
|
||||
for (name in _ref) {
|
||||
|
||||
14
lib/lexer.js
14
lib/lexer.js
@@ -29,7 +29,7 @@
|
||||
if (o.rewrite === false) {
|
||||
return this.tokens;
|
||||
}
|
||||
return (new Rewriter()).rewrite(this.tokens);
|
||||
return (new Rewriter).rewrite(this.tokens);
|
||||
};
|
||||
Lexer.prototype.identifierToken = function() {
|
||||
var closeIndex, forcedIdentifier, id, match, tag;
|
||||
@@ -185,7 +185,7 @@
|
||||
if (REGEX_INTERPOLATION.test(regex)) {
|
||||
str = regex.slice(1, -1);
|
||||
str = str.replace(REGEX_ESCAPE, '\\$&');
|
||||
this.tokens.push(['(', '('], ['NEW', 'new'], ['IDENTIFIER', 'RegExp'], ['CALL_START', '(']);
|
||||
this.tokens.push(['(', '('], ['IDENTIFIER', 'RegExp'], ['CALL_START', '(']);
|
||||
this.interpolateString("\"" + (str) + "\"", {
|
||||
escapeQuotes: true
|
||||
});
|
||||
@@ -386,12 +386,12 @@
|
||||
}
|
||||
}
|
||||
if (indent) {
|
||||
doc = doc.replace(new RegExp("\\n" + (indent), "g"), '\n');
|
||||
doc = doc.replace(RegExp("\\n" + (indent), "g"), '\n');
|
||||
}
|
||||
if (herecomment) {
|
||||
return doc;
|
||||
}
|
||||
doc = doc.replace(/^\n/, '').replace(new RegExp("" + (options.quote), "g"), '\\$&');
|
||||
doc = doc.replace(/^\n/, '').replace(RegExp("" + (options.quote), "g"), '\\$&');
|
||||
if (options.quote === "'") {
|
||||
doc = this.escapeLines(doc, true);
|
||||
}
|
||||
@@ -485,7 +485,7 @@
|
||||
if (quote !== '"' || str.length < 3) {
|
||||
return this.token('STRING', str);
|
||||
}
|
||||
lexer = new Lexer();
|
||||
lexer = new Lexer;
|
||||
tokens = [];
|
||||
i = (pi = 1);
|
||||
end = str.length - 1;
|
||||
@@ -613,12 +613,12 @@
|
||||
REGEX_END = /^[imgy]{0,4}(?![a-zA-Z])/;
|
||||
REGEX_ESCAPE = /\\[^#]/g;
|
||||
MULTILINER = /\n/g;
|
||||
NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|not|delete|typeof|instanceof)$/;
|
||||
NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;
|
||||
HEREDOC_INDENT = /\n+([ \t]*)/g;
|
||||
ASSIGNED = /^\s*@?[$A-Za-z_][$\w]*[ \t]*?[:=][^:=>]/;
|
||||
NEXT_CHARACTER = /^\s*(\S?)/;
|
||||
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
|
||||
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'TYPEOF', 'DELETE'];
|
||||
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE'];
|
||||
LOGIC = ['&', '|', '^', '&&', '||'];
|
||||
SHIFT = ['<<', '>>', '>>>'];
|
||||
COMPARE = ['<=', '<', '>', '>='];
|
||||
|
||||
12
lib/nodes.js
12
lib/nodes.js
@@ -856,7 +856,7 @@
|
||||
this.variable = literal(o.scope.freeVariable('ctor'));
|
||||
}
|
||||
extension = this.parent && new ExtendsNode(this.variable, this.parent);
|
||||
props = new Expressions();
|
||||
props = new Expressions;
|
||||
o.top = true;
|
||||
me = null;
|
||||
className = this.variable.compile(o);
|
||||
@@ -865,7 +865,7 @@
|
||||
applied = new ValueNode(this.parent, [new AccessorNode(literal('apply'))]);
|
||||
constructor = new CodeNode([], new Expressions([new CallNode(applied, [literal('this'), literal('arguments')])]));
|
||||
} else {
|
||||
constructor = new CodeNode();
|
||||
constructor = new CodeNode;
|
||||
}
|
||||
_ref2 = this.properties;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
@@ -1041,7 +1041,7 @@
|
||||
this.params = _arg;
|
||||
CodeNode.__super__.constructor.call(this);
|
||||
this.params || (this.params = []);
|
||||
this.body || (this.body = new Expressions());
|
||||
this.body || (this.body = (new Expressions));
|
||||
this.bound = tag === 'boundfunc';
|
||||
if (this.bound) {
|
||||
this.context = 'this';
|
||||
@@ -1111,7 +1111,7 @@
|
||||
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
||||
func = ("function(" + (params.join(', ')) + ") {" + (code) + (code && this.tab) + "}");
|
||||
if (this.bound) {
|
||||
return ("" + (utility('bind')) + "(" + (func) + ", " + (this.context) + ")");
|
||||
return ("(" + (utility('bind')) + "(" + (func) + ", " + (this.context) + "))");
|
||||
}
|
||||
return top ? ("(" + (func) + ")") : func;
|
||||
};
|
||||
@@ -1291,6 +1291,8 @@
|
||||
this.flip = !!flip;
|
||||
if (this.first instanceof ValueNode && this.first.base instanceof ObjectNode) {
|
||||
this.first = new ParentheticalNode(this.first);
|
||||
} else if (this.operator === 'new' && this.first instanceof CallNode) {
|
||||
return this.first.newInstance();
|
||||
}
|
||||
this.first.tags.operation = true;
|
||||
if (this.second) {
|
||||
@@ -1309,7 +1311,7 @@
|
||||
};
|
||||
OpNode.prototype.CHAINABLE = ['<', '>', '>=', '<=', '===', '!=='];
|
||||
OpNode.prototype.ASSIGNMENT = ['||=', '&&=', '?='];
|
||||
OpNode.prototype.PREFIX_OPERATORS = ['typeof', 'delete'];
|
||||
OpNode.prototype.PREFIX_OPERATORS = ['new', 'typeof', 'delete'];
|
||||
OpNode.prototype["class"] = 'OpNode';
|
||||
OpNode.prototype.children = ['first', 'second'];
|
||||
OpNode.prototype.isUnary = function() {
|
||||
|
||||
254
lib/parser.js
254
lib/parser.js
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user