diff --git a/lib/coffee_script/grammar.js b/lib/coffee_script/grammar.js index 42fcdaac..30d17a61 100644 --- a/lib/coffee_script/grammar.js +++ b/lib/coffee_script/grammar.js @@ -564,7 +564,7 @@ // Save the parser to a file. // puts parser.generate() posix = require('posix'); - posix.open('parser.js', process.O_CREAT | process.O_WRONLY, 0755).addCallback(function(fd) { + posix.open('lib/coffee_script/parser.js', process.O_CREAT | process.O_WRONLY, 0755).addCallback(function(fd) { return posix.write(fd, parser.generate()); }); })(); \ No newline at end of file diff --git a/lib/coffee_script/nodes.js b/lib/coffee_script/nodes.js index b6d1907a..efc1cd50 100644 --- a/lib/coffee_script/nodes.js +++ b/lib/coffee_script/nodes.js @@ -847,7 +847,7 @@ return this; }, compile_node: function compile_node(o) { - var __a, __b, code, func, inner, name_part, param, shared_scope, splat, top; + var __a, __b, __c, __d, __e, code, func, inner, name_part, param, params, shared_scope, splat, top; shared_scope = del(o, 'shared_scope'); top = del(o, 'top'); o.scope = shared_scope || new Scope(o.scope, this.body, this); @@ -861,14 +861,22 @@ splat.index = this.params.length; this.body.unshift(splat); } - __a = this.params; - for (__b = 0; __b < __a.length; __b++) { - param = __a[__b]; + params = ((function() { + __a = []; __b = this.params; + for (__c = 0; __c < __b.length; __c++) { + param = __b[__c]; + __a.push(param.compile(o)); + } + return __a; + }).call(this)); + __d = params; + for (__e = 0; __e < __d.length; __e++) { + param = __d[__e]; (o.scope.parameter(param)); } code = this.body.expressions.length ? '\n' + this.body.compile_with_declarations(o) + '\n' : ''; name_part = this.name ? ' ' + this.name : ''; - func = 'function' + (this.bound ? '' : name_part) + '(' + this.params.join(', ') + ') {' + code + this.idt(this.bound ? 1 : 0) + '}'; + func = 'function' + (this.bound ? '' : name_part) + '(' + params.join(', ') + ') {' + code + this.idt(this.bound ? 1 : 0) + '}'; if (top && !this.bound) { func = '(' + func + ')'; } diff --git a/lib/coffee_script/parser.js b/lib/coffee_script/parser.js index c500a757..54c2389e 100755 --- a/lib/coffee_script/parser.js +++ b/lib/coffee_script/parser.js @@ -209,7 +209,7 @@ case 99:this.$ = [$$[$0-1+1-1]]; break; case 100:this.$ = $$[$0-3+1-1].concat([$$[$0-3+3-1]]); break; -case 101:this.$ = yytext; +case 101:this.$ = new LiteralNode(yytext); break; case 102:this.$ = new SplatNode($$[$0-4+1-1]); break; @@ -436,8 +436,6 @@ parse: function parse(input) { var symbol, state, action, a, r, yyval={},p,len,ip=0,newState, expected; symbol = lex(); while (true) { - // this.trace('stack:',JSON.stringify(stack), '\n\t\t\tinput:', this.lexer._input); - // this.trace('vstack:',JSON.stringify(vstack)); // set first input state = stack[stack.length-1]; // read action for current state and first input @@ -448,13 +446,11 @@ parse: function parse(input) { for (p in table[state]) if (this.terminals_[p] && p != 1) { expected.push("'"+this.terminals_[p]+"'"); } - self.trace("stack:",JSON.stringify(stack), 'symbol:',symbol, 'input', this.lexer.upcomingInput()); - if (this.lexer.upcomingInput) self.trace('input', this.lexer.upcomingInput()); parseError('Parse error on line '+(yylineno+1)+'. Expecting: '+expected.join(', ')+"\n"+(this.lexer.showPosition && this.lexer.showPosition()), {text: this.lexer.match, token: symbol, line: this.lexer.yylineno}); } - // this.trace('action:',action); + this.trace('action:',action); // this shouldn't happen, unless resolve defaults are off if (action.length > 1) { @@ -481,7 +477,6 @@ parse: function parse(input) { reductions++; len = this.productions_[a[1]][1]; - // this.trace('reduce by: ', this.productions ? this.productions[a[1]] : a[1]); // perform semantic action yyval.$ = vstack[vstack.length-len]; // default to $$ = $1 @@ -491,11 +486,8 @@ parse: function parse(input) { return r; } - // this.trace('yyval=',JSON.stringify(yyval.$)); - // pop off stack if (len) { - // this.trace('production length:',len); stack = stack.slice(0,-1*len*2); vstack = vstack.slice(0, -1*len); } @@ -509,10 +501,8 @@ parse: function parse(input) { case 3: // accept - // this.trace('stack:',stack, '\n\tinput:', this.lexer._input); - // this.trace('vstack:',JSON.stringify(vstack)); - // this.trace('Total reductions:', reductions); - // this.trace('Total shifts:', shifts); + this.reductionCount = reductions; + this.shiftCount = shifts; return true; } diff --git a/src/grammar.coffee b/src/grammar.coffee index 7d4bff8d..f0cceba8 100644 --- a/src/grammar.coffee +++ b/src/grammar.coffee @@ -463,5 +463,5 @@ parser: new Parser({tokens: tokens, bnf: bnf, operators: operators.reverse(), st # Save the parser to a file. # puts parser.generate() posix: require 'posix' -posix.open('parser.js', process.O_CREAT | process.O_WRONLY, 0755).addCallback (fd) -> +posix.open('lib/coffee_script/parser.js', process.O_CREAT | process.O_WRONLY, 0755).addCallback (fd) -> posix.write(fd, parser.generate()) diff --git a/src/nodes.coffee b/src/nodes.coffee index 949ac2b9..49538bad 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -664,10 +664,11 @@ CodeNode: exports.CodeNode: inherit Node, { splat: @params.pop() splat.index: @params.length @body.unshift(splat) - (o.scope.parameter(param)) for param in @params + params: (param.compile(o) for param in @params) + (o.scope.parameter(param)) for param in params code: if @body.expressions.length then '\n' + @body.compile_with_declarations(o) + '\n' else '' name_part: if @name then ' ' + @name else '' - func: 'function' + (if @bound then '' else name_part) + '(' + @params.join(', ') + ') {' + code + @idt(if @bound then 1 else 0) + '}' + func: 'function' + (if @bound then '' else name_part) + '(' + params.join(', ') + ') {' + code + @idt(if @bound then 1 else 0) + '}' func: '(' + func + ')' if top and not @bound return func unless @bound inner: '(function' + name_part + '() {\n' + @idt(2) + 'return __func.apply(__this, arguments);\n' + @idt(1) + '});' diff --git a/vendor/jison/lib/jison.js b/vendor/jison/lib/jison.js index e46ea203..5130ae6c 100644 --- a/vendor/jison/lib/jison.js +++ b/vendor/jison/lib/jison.js @@ -737,7 +737,6 @@ lrGeneratorMixin.parseTable = function parseTable (itemSets) { if (action.length) { var sol = resolveConflict(item.production, op, [r,item.production.id], action[0]); self.resolutions.push([k,stackSymbol,sol]); - //self.trace(sol.msg); if (sol.bydefault) { self.conflicts++; if (!self.DEBUG) { @@ -753,7 +752,6 @@ lrGeneratorMixin.parseTable = function parseTable (itemSets) { action.push([r,item.production.id]); } if (action && action.length) { - //self.trace(k, stackSymbol, action); state[self.symbols_[stackSymbol]] = action; } }); @@ -893,12 +891,12 @@ var lrGeneratorDebug = { afterparseTable: function () { var self = this; if (this.conflicts > 0) { - this.trace("\n"+this.conflicts+" Conflict(s) found in grammar:"); this.resolutions.forEach(function (r, i) { if (r[2].bydefault) { - self.warn('State:',r[0], ', Token:',r[1], "\n ", printAction(r[2].r, self), "\n ", printAction(r[2].s, self)); + self.warn('Conflict at state:',r[0], ', Token:',r[1], "\n ", printAction(r[2].r, self), "\n ", printAction(r[2].s, self)); } }); + this.trace("\n"+this.conflicts+" Conflict(s) found in grammar."); } this.trace("Done."); }, @@ -976,8 +974,6 @@ parser.parse = function parse (input) { var symbol, state, action, a, r, yyval={},p,len,ip=0,newState, expected; symbol = lex(); while (true) { - this.trace('stack:',JSON.stringify(stack), '\n\t\t\tinput:', this.lexer._input); - this.trace('vstack:',JSON.stringify(vstack)); // set first input state = stack[stack.length-1]; // read action for current state and first input @@ -988,8 +984,6 @@ parser.parse = function parse (input) { for (p in table[state]) if (this.terminals_[p] && p != 1) { expected.push("'"+this.terminals_[p]+"'"); } - self.trace("stack:",JSON.stringify(stack), 'symbol:',symbol, 'input', this.lexer.upcomingInput()); - if (this.lexer.upcomingInput) self.trace('input', this.lexer.upcomingInput()); parseError('Parse error on line '+(yylineno+1)+'. Expecting: '+expected.join(', ')+"\n"+(this.lexer.showPosition && this.lexer.showPosition()), {text: this.lexer.match, token: symbol, line: this.lexer.yylineno}); } @@ -1021,7 +1015,6 @@ parser.parse = function parse (input) { reductions++; len = this.productions_[a[1]][1]; - this.trace('reduce by: ', this.productions ? this.productions[a[1]] : a[1]); // perform semantic action yyval.$ = vstack[vstack.length-len]; // default to $$ = $1 @@ -1031,11 +1024,8 @@ parser.parse = function parse (input) { return r; } - this.trace('yyval=',JSON.stringify(yyval.$)); - // pop off stack if (len) { - this.trace('production length:',len); stack = stack.slice(0,-1*len*2); vstack = vstack.slice(0, -1*len); } @@ -1049,10 +1039,8 @@ parser.parse = function parse (input) { case 3: // accept - this.trace('stack:',stack, '\n\tinput:', this.lexer._input); - this.trace('vstack:',JSON.stringify(vstack)); - this.trace('Total reductions:', reductions); - this.trace('Total shifts:', shifts); + this.reductionCount = reductions; + this.shiftCount = shifts; return true; } @@ -1392,7 +1380,6 @@ exports.main = function main (args) { } var opt = grammar.options || {}; - opt.debug = true; // lexer file if (args[2]) {