grammar: removed extra arrays

This commit is contained in:
satyr 2010-10-11 16:06:29 +09:00
parent fffa01933d
commit 6506f6d99e
3 changed files with 20 additions and 21 deletions

View File

@ -130,7 +130,7 @@
}), o("Param", function() { }), o("Param", function() {
return [$1]; return [$1];
}), o("ParamList , Param", function() { }), o("ParamList , Param", function() {
return $1.concat([$3]); return $1.concat($3);
}) })
], ],
Param: [ Param: [
@ -209,9 +209,9 @@
}), o("AssignObj", function() { }), o("AssignObj", function() {
return [$1]; return [$1];
}), o("AssignList , AssignObj", function() { }), o("AssignList , AssignObj", function() {
return $1.concat([$3]); return $1.concat($3);
}), o("AssignList OptComma TERMINATOR AssignObj", function() { }), o("AssignList OptComma TERMINATOR AssignObj", function() {
return $1.concat([$4]); return $1.concat($4);
}), o("AssignList OptComma INDENT AssignList OptComma OUTDENT", function() { }), o("AssignList OptComma INDENT AssignList OptComma OUTDENT", function() {
return $1.concat($4); return $1.concat($4);
}) })
@ -329,9 +329,9 @@
o("Arg", function() { o("Arg", function() {
return [$1]; return [$1];
}), o("ArgList , Arg", function() { }), o("ArgList , Arg", function() {
return $1.concat([$3]); return $1.concat($3);
}), o("ArgList OptComma TERMINATOR Arg", function() { }), o("ArgList OptComma TERMINATOR Arg", function() {
return $1.concat([$4]); return $1.concat($4);
}), o("INDENT ArgList OptComma OUTDENT", function() { }), o("INDENT ArgList OptComma OUTDENT", function() {
return $2; return $2;
}), o("ArgList OptComma INDENT ArgList OptComma OUTDENT", function() { }), o("ArgList OptComma INDENT ArgList OptComma OUTDENT", function() {
@ -341,7 +341,7 @@
Arg: [o("Expression"), o("Splat")], Arg: [o("Expression"), o("Splat")],
SimpleArgs: [ SimpleArgs: [
o("Expression"), o("SimpleArgs , Expression", function() { o("Expression"), o("SimpleArgs , Expression", function() {
return $1 instanceof Array ? $1.concat([$3]) : [$1].concat([$3]); return [].concat($1, $3);
}) })
], ],
Try: [ Try: [

View File

@ -133,7 +133,7 @@ case 61:this.$ = [];
break; break;
case 62:this.$ = [$$[$0-1+1-1]]; case 62:this.$ = [$$[$0-1+1-1]];
break; break;
case 63:this.$ = $$[$0-3+1-1].concat([$$[$0-3+3-1]]); case 63:this.$ = $$[$0-3+1-1].concat($$[$0-3+3-1]);
break; break;
case 64:this.$ = new yy.Literal($$[$0-1+1-1]); case 64:this.$ = new yy.Literal($$[$0-1+1-1]);
break; break;
@ -199,9 +199,9 @@ case 91:this.$ = [];
break; break;
case 92:this.$ = [$$[$0-1+1-1]]; case 92:this.$ = [$$[$0-1+1-1]];
break; break;
case 93:this.$ = $$[$0-3+1-1].concat([$$[$0-3+3-1]]); case 93:this.$ = $$[$0-3+1-1].concat($$[$0-3+3-1]);
break; break;
case 94:this.$ = $$[$0-4+1-1].concat([$$[$0-4+4-1]]); case 94:this.$ = $$[$0-4+1-1].concat($$[$0-4+4-1]);
break; break;
case 95:this.$ = $$[$0-6+1-1].concat($$[$0-6+4-1]); case 95:this.$ = $$[$0-6+1-1].concat($$[$0-6+4-1]);
break; break;
@ -277,9 +277,9 @@ case 130:this.$ = new yy.ArrayLiteral($$[$0-4+2-1]);
break; break;
case 131:this.$ = [$$[$0-1+1-1]]; case 131:this.$ = [$$[$0-1+1-1]];
break; break;
case 132:this.$ = $$[$0-3+1-1].concat([$$[$0-3+3-1]]); case 132:this.$ = $$[$0-3+1-1].concat($$[$0-3+3-1]);
break; break;
case 133:this.$ = $$[$0-4+1-1].concat([$$[$0-4+4-1]]); case 133:this.$ = $$[$0-4+1-1].concat($$[$0-4+4-1]);
break; break;
case 134:this.$ = $$[$0-4+2-1]; case 134:this.$ = $$[$0-4+2-1];
break; break;
@ -291,7 +291,7 @@ case 137:this.$ = $$[$0-1+1-1];
break; break;
case 138:this.$ = $$[$0-1+1-1]; case 138:this.$ = $$[$0-1+1-1];
break; break;
case 139:this.$ = $$[$0-3+1-1] instanceof Array ? $$[$0-3+1-1].concat([$$[$0-3+3-1]]) : [$$[$0-3+1-1]].concat([$$[$0-3+3-1]]); case 139:this.$ = [].concat($$[$0-3+1-1], $$[$0-3+3-1]);
break; break;
case 140:this.$ = new yy.Try($$[$0-2+2-1]); case 140:this.$ = new yy.Try($$[$0-2+2-1]);
break; break;

View File

@ -195,7 +195,7 @@ grammar =
ParamList: [ ParamList: [
o "", -> [] o "", -> []
o "Param", -> [$1] o "Param", -> [$1]
o "ParamList , Param", -> $1.concat [$3] o "ParamList , Param", -> $1.concat $3
] ]
# A single parameter in a function definition can be ordinary, or a splat # A single parameter in a function definition can be ordinary, or a splat
@ -265,8 +265,8 @@ grammar =
AssignList: [ AssignList: [
o "", -> [] o "", -> []
o "AssignObj", -> [$1] o "AssignObj", -> [$1]
o "AssignList , AssignObj", -> $1.concat [$3] o "AssignList , AssignObj", -> $1.concat $3
o "AssignList OptComma TERMINATOR AssignObj", -> $1.concat [$4] o "AssignList OptComma TERMINATOR AssignObj", -> $1.concat $4
o "AssignList OptComma INDENT AssignList OptComma OUTDENT", -> $1.concat $4 o "AssignList OptComma INDENT AssignList OptComma OUTDENT", -> $1.concat $4
] ]
@ -363,8 +363,8 @@ grammar =
# (i.e. comma-separated expressions). Newlines work as well. # (i.e. comma-separated expressions). Newlines work as well.
ArgList: [ ArgList: [
o "Arg", -> [$1] o "Arg", -> [$1]
o "ArgList , Arg", -> $1.concat [$3] o "ArgList , Arg", -> $1.concat $3
o "ArgList OptComma TERMINATOR Arg", -> $1.concat [$4] o "ArgList OptComma TERMINATOR Arg", -> $1.concat $4
o "INDENT ArgList OptComma OUTDENT", -> $2 o "INDENT ArgList OptComma OUTDENT", -> $2
o "ArgList OptComma INDENT ArgList OptComma OUTDENT", -> $1.concat $4 o "ArgList OptComma INDENT ArgList OptComma OUTDENT", -> $1.concat $4
] ]
@ -380,8 +380,7 @@ grammar =
# having the newlines wouldn't make sense. # having the newlines wouldn't make sense.
SimpleArgs: [ SimpleArgs: [
o "Expression" o "Expression"
o "SimpleArgs , Expression", -> o "SimpleArgs , Expression", -> [].concat $1, $3
if $1 instanceof Array then $1.concat([$3]) else [$1].concat([$3])
] ]
# The variants of *try/catch/finally* exception handling blocks. # The variants of *try/catch/finally* exception handling blocks.
@ -527,8 +526,8 @@ grammar =
# rules are necessary. # rules are necessary.
Operation: [ Operation: [
o "UNARY Expression", -> new Op $1, $2 o "UNARY Expression", -> new Op $1, $2
o("- Expression", (-> new Op('-', $2)), {prec: 'UNARY'}) o "- Expression", (-> new Op '-', $2), prec: 'UNARY'
o("+ Expression", (-> new Op('+', $2)), {prec: 'UNARY'}) o "+ Expression", (-> new Op '+', $2), prec: 'UNARY'
o "-- Expression", -> new Op '--', $2 o "-- Expression", -> new Op '--', $2
o "++ Expression", -> new Op '++', $2 o "++ Expression", -> new Op '++', $2