Changeset 4201

Show
Ignore:
Timestamp:
01/08/08 15:28:39 (5 years ago)
Author:
nshuyo
Message:

lang/javascript/jsruby: fixed a bug...

Location:
lang/javascript/jsruby
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/jsruby/release/jsruby-0.1.js

    r4200 r4201  
    1 if(navigator.userAgent.indexOf("Firefox")<0){Object.prototype.toSource=function(){var B="({";for(var A in this){if(B.length>2){B+=","}B+=A+":";if(this[A]!=null){B+=this[A].toSource()}else{B+="null"}}return B+"})"};Array.prototype.toSource=function(){var A="[";for(var B=0;B<this.length;B++){if(B!=0){A+=","}if(this[B]!=null){A+=this[B].toSource()}else{A+="null"}}return A+"]"};String.prototype.toSource=function(){return'"'+this+'"'};Number.prototype.toSource=Number.prototype.toString;Boolean.prototype.toSource=Boolean.prototype.toString}var RubyEngine={};RubyEngine.FIREFOX=navigator.userAgent.indexOf("Firefox")>=0;RubyEngine.OPERA=navigator.userAgent.indexOf("Opera")>=0;RubyEngine.IE=navigator.userAgent.indexOf("MSIE")>=0;RubyEngine.SAFARI=navigator.userAgent.indexOf("Safari")>=0;RubyEngine.RESERVED={"if":true,"then":true,"elsif":true,"else":true,"end":true,"while":true,"unless":true,"until":true,"def":true,"nil":true};RubyEngine.OPERATORS={"::":1,"[]":2,"**":11,"*":13,"/":13,"%":13,"+":14,"-":14,"<<":15,">>":15,"&":20,"|":21,"^":21,">":22,">=":22,"<":22,"<=":22,"<=>":23,"==":23,"===":23,"!=":23,"=~":23,"!~":23,"&&":24,"||":25,"..":30,"...":30,"?:":31,"=":32,"not":40,"and":41,"or":41};RubyEngine.Node={};RubyEngine.Node.Variable=function(A){this.type="V";this.name=A};RubyEngine.Node.Variable.prototype.toSource=function(){return this.type+"'"+this.name+"'"};RubyEngine.Node.Ref=function(A){this.type="R";this.name=A};RubyEngine.Node.Ref.prototype.toSource=function(){return this.type+"'"+this.name+"'"};RubyEngine.Node.Operator=function(A){this.type="O";this.name=A};RubyEngine.Node.Operator.prototype.toSource=function(){return this.type+"'"+this.name+"'"};RubyEngine.Node.Method=function(B,C,A){this.type="M";this.name=B;this.target=C;this.args=A;this.block=undefined};RubyEngine.Node.Method.prototype.toSource=function(){var A=this.block?this.block.toSource():"";return this.type+"("+(this.target==null?"":this.target.toSource()+".")+this.name+","+(this.args?this.args.toSource():this.args)+")"+A};RubyEngine.Node.Method.prototype.clone=function(){var A=[];for(var B=0;B<this.args.length;B++){A.push(this.args[B])}return new RubyEngine.Node.Method(this.name,this.target,A)};RubyEngine.Node.Block=function(A,B){this.type="B";this.vars=A;this.block=B};RubyEngine.Node.Block.prototype.toSource=function(){return"{|"+(this.vars?this.vars.toSource():this.target)+"| "+(this.block?this.block.toSource():this.block)+"}"};RubyEngine.Node.Expression=function(C){this.type="E";var E=[];var D=[];for(var B=0;B<C.length;B++){var A=C[B];if(RubyEngine.Node.Operator.prototype.isPrototypeOf(A)){while(D.length>0){if(RubyEngine.OPERATORS[D[0].name]>RubyEngine.OPERATORS[A.name]){break}E.push(D.shift())}D.unshift(A)}else{E.push(A)}}while(D.length>0){E.push(D.shift())}this.list=E};RubyEngine.Node.Expression.prototype.toSource=function(){return this.type+"'"+this.list.toSource()+"'"};RubyEngine.RubyObject={};RubyEngine.RubyObject.inherit=function(A,B){B.prototype=new A();B.clz={};B.methods={};B.superclz=A;return B};RubyEngine.RubyObject.call=function(A,D,C,G){var E=A.clz;var H;while(!(H=E.methods[D])){if(!(E=E.superclz)){break}}if(H){return H.apply(this,[A,C,G])}else{if(D!="method_missing"){var F=[new RubyEngine.RubyObject.String(D)];if(C&&C.length>0){F=F.concat(C)}var B=RubyEngine.RubyObject.call.apply(this,[A,"method_missing",F,G]);if(B!=undefined){return B}return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+D+"' for "+A.clz.toString(),D)}}return undefined};RubyEngine.RubyObject._LikeArray={"[object Array]":true,"[object HTMLCollection]":true};RubyEngine.RubyObject.js2r=function(E){if(E==undefined){return E}if(E==null){return E}var D=Object.prototype.toString.call(E);if(D=="[object String]"){return new RubyEngine.RubyObject.String(E)}else{if(D in RubyEngine.RubyObject._LikeArray){var C=[];for(var B=0;B<E.length;B++){C.push(RubyEngine.RubyObject.js2r(E[B]))}var A=new RubyEngine.RubyObject.Array();A.array=C;return A;return new RubyEngine.RubyObject.Array(C)}else{if(D=="[object Number]"){return new RubyEngine.RubyObject.Numeric(E)}else{if(D=="[object Boolean]"){return E}else{return new RubyEngine.RubyObject.JSObject(E)}}}}};RubyEngine.RubyObject.Object=function(){this.clz=RubyEngine.RubyObject.Object};RubyEngine.RubyObject.Object.prototype.toValue=function(){return this};RubyEngine.RubyObject.Object.clz={"methods":{}};RubyEngine.RubyObject.Object.methods={inspect:function(A,B){return A.toString()},dup:function(A,B){return A}};RubyEngine.RubyObject.Numeric=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){this.toValue=function(){return this.num};this.clz=RubyEngine.RubyObject.Numeric;this.num=0;if(arguments.length>0){this.num=arguments[0]}});RubyEngine.RubyObject.Numeric.prototype.toString=function(){return this.num.toString()};RubyEngine.RubyObject.Numeric.prototype.toSource=function(){return this.num.toString()};RubyEngine.RubyObject.Numeric.prototype.neg=function(){return new RubyEngine.RubyObject.Numeric(-this.num)};RubyEngine.RubyObject.Numeric.prototype.add=function(A){return new RubyEngine.RubyObject.Numeric(this.num+A.num)};RubyEngine.RubyObject.Numeric.prototype.sub=function(A){return new RubyEngine.RubyObject.Numeric(this.num-A.num)};RubyEngine.RubyObject.Numeric.prototype.mul=function(A){return new RubyEngine.RubyObject.Numeric(this.num*A.num)};RubyEngine.RubyObject.Numeric.prototype.div=function(A){return new RubyEngine.RubyObject.Numeric(parseInt(this.num/A.num))};RubyEngine.RubyObject.Numeric.prototype.mod=function(A){return new RubyEngine.RubyObject.Numeric(this.num%A.num)};RubyEngine.RubyObject.Numeric.prototype.pow=function(A){return new RubyEngine.RubyObject.Numeric(Math.pow(this.num,A.num))};RubyEngine.RubyObject.Numeric.prototype.eql=function(A){return this.num==A.num};RubyEngine.RubyObject.Numeric.prototype.cmp=function(A){return(this.num==A.num?0:(this.num<A.num?-1:1))};RubyEngine.RubyObject.Numeric.methods={"chr":function(A,B,C){return new RubyEngine.RubyObject.String(String.fromCharCode(A.num))},"to_s":function(A,B,C){return new RubyEngine.RubyObject.String(String(A.num))},"upto":function(B,C,E){if(!E){return null}var A,F=this.run(C[0]).num;if(E.vars){A=E.vars[0].name}this.scope.pushLevel();for(var D=B.num;D<=F;D++){if(A){this.scope.substitute(A,new RubyEngine.RubyObject.Numeric(D))}this.run(E.block)}this.scope.popLevel();return B}};RubyEngine.RubyObject.String=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){this.toValue=function(){return this.str};this.clz=RubyEngine.RubyObject.String;this.str="";if(arguments.length>0){this.str=arguments[0]}});RubyEngine.RubyObject.String.prototype.toString=function(){return this.str};RubyEngine.RubyObject.String.prototype.toSource=function(){return'"'+this.str+'"'};RubyEngine.RubyObject.String.prototype.add=function(A){return new RubyEngine.RubyObject.String(this.str+A.str)};RubyEngine.RubyObject.String.prototype.mul=function(A){var B="";for(var C=0;C<A.num;C++){B+=this.str}return new RubyEngine.RubyObject.String(B)};RubyEngine.RubyObject.String.prototype.eql=function(A){return this.str==A.str};RubyEngine.RubyObject.String.methods={"length":function(A,B,C){return new RubyEngine.RubyObject.Numeric(A.str.length)},"reverse":function(A,C,E){var B="";for(var D=A.str.length-1;D>=0;D--){B+=A.str.charAt(D)}return new RubyEngine.RubyObject.String(B)},"center":function(B,D,F){var A=this.run(D[0]).num;var C="";for(var E=(A-B.str.length-1)/2;E>0;E--){C+=" "}C+=B.str;while(C.length<A){C+=" "}return new RubyEngine.RubyObject.String(C)},"to_i":function(B,C,D){var A=parseInt(B.str);if(isNaN(A)){A=0}return new RubyEngine.RubyObject.Numeric(A)},"[]":function(A,B,C){return new RubyEngine.RubyObject.Numeric(A.str.charCodeAt(this.run(B[0]).num))},"[]=":function(B,C,D){var A=this.run(C[0]).num;if(RubyEngine.RubyObject.Numeric.prototype.isPrototypeOf(C[1])){B.str=B.str.substr(0,A)+String.fromCharCode(C[1].num)+B.str.substr(A+1);return C[1]}else{B.str=B.str.substr(0,A)+this.run(C[1]).toString()+B.str.substr(A+1);return C[1]}}};RubyEngine.RubyObject.Array=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){this.toValue=function(){var A=[];for(var B=0;B<this.array.length;B++){A.push(this.array[B].toValue())}return A};this.clz=RubyEngine.RubyObject.Array;this.array=[]});RubyEngine.RubyObject.Array.toSource=function(){return"Array"};RubyEngine.RubyObject.Array.prototype.toSource=function(){var A="[";for(var B=0;B<this.array.length;B++){if(B>0){A+=","}A+=this.array[B].toSource()}return A+"]"};RubyEngine.RubyObject.Array.prototype.toString=function(){var A="[";for(var B=0;B<this.array.length;B++){if(B>0){A+=","}A+=this.array[B].toString()}return A+"]"};RubyEngine.RubyObject.Array.prototype.sft=function(A){this.array.push(A);return this};RubyEngine.RubyObject.Array.clz.methods={"new":function(A,B,F){var E=new RubyEngine.RubyObject.Array();var D=[];if(B){for(var C=0;C<B.length;C++){D.push(this.run(B[C]))}}E.array=D;return E}};RubyEngine.RubyObject.Array.methods={"[]":function(A,B,C){return A.array[this.run(B[0]).num]},"push":function(A,B,D){if(B){for(var C=0;C<B.length;C++){A.array.push(this.run(B[C]))}}return A},"[]=":function(A,B,C){return A.array[this.run(B[0]).num]=this.run(B[1])},"length":function(A,B,C){return new RubyEngine.RubyObject.Numeric(A.array.length)},"member?":function(B,C,E){var A=this.run(C[0]);for(var D=0;D<B.array.length;D++){if(A.eql(B.array[D])){return true}}return false},"reverse":function(A,C,D){var B=new RubyEngine.RubyObject.Array();B.array=A.array.reverse;return B},"each":function(B,C,E){if(!E){return null}var A;if(E.vars){A=E.vars[0].name}this.scope.pushLevel();for(var D=0;D<B.array.length;D++){if(A){this.scope.substitute(A,B.array[D])}this.run(E.block)}this.scope.popLevel();return B},"inject":function(A,B,F){if(!F){return null}var D=0,E;if(B&&B.length>0){E=this.run(B[0])}else{E=A.array[D++]}while(D<A.array.length){var C={};if(F.vars){if(F.vars.length>0){C[F.vars[0].name]=E}if(F.vars.length>1){C[F.vars[1].name]=A.array[D++]}}this.scope.pushLevel(C);E=this.run(F.block);this.scope.popLevel()}return E},"join":function(A,D,F){var C="",B=(D&&D.length>0?this.run(D[0]).str:"");for(var E=0;E<A.array.length;E++){if(E>0){C+=B}C+=A.array[E].toString()}return new RubyEngine.RubyObject.String(C)}};RubyEngine.RubyObject.Range=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(B,A){this.clz=RubyEngine.RubyObject.Range;this.from=B;this.to=A});RubyEngine.RubyObject.Range.prototype.toString=function(){return"("+this.from+".."+this.to+")"};RubyEngine.RubyObject.Range.prototype.toValue=function(){var B=[];for(var A=this.from;A<=this.to;A++){B.push(A)}return B};RubyEngine.RubyObject.Range.methods={"each":function(B,C,E){if(!E){return null}var A;if(E.vars){A=E.vars[0].name}this.scope.pushLevel();for(var D=B.from;D<=B.to;D++){if(A){this.scope.substitute(A,new RubyEngine.RubyObject.Numeric(D))}this.run(E.block)}this.scope.popLevel();return B}};RubyEngine.RubyObject.JSObject=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(A){this.obj=A;this.clz=RubyEngine.RubyObject.JSObject});RubyEngine.RubyObject.JSObject.prototype.toString=function(){return this.obj.toString()};RubyEngine.RubyObject.JSObject.prototype.toValue=function(){return this.obj};RubyEngine.RubyObject.JSObject.methods={"method_missing":function(self,args,block){var name=this.run(args[0]).str;if(args.length==1){return RubyEngine.RubyObject.js2r(self.obj[name])}else{if(name[name.length-1]=="="){self.obj[name.slice(0,name.length-1)]=this.run(args[1]).toValue()}else{if(name in self.obj){if(RubyEngine.FIREFOX||RubyEngine.OPERA){var jsargs=[];for(var i=1;i<args.length;i++){jsargs.push(this.run(args[i]).toValue())}return RubyEngine.RubyObject.js2r(self.obj[name].apply(self.obj,jsargs))}else{var jsargs=[];for(var i=1;i<args.length;i++){jsargs.push("this.run(args["+i+"]).toValue()")}return RubyEngine.RubyObject.js2r(eval("self.obj[name]("+jsargs.join(",")+")"))}}else{return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+name+"' for "+self.obj.toString(),name)}}}}};RubyEngine.RubyObject.Exception=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){});RubyEngine.RubyObject.Exception.prototype.toString=function(){return this.message};RubyEngine.RubyObject.Exception.prototype.toSource=function(){return this.message};RubyEngine.RubyObject.StandardError=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Exception,function(){});RubyEngine.RubyObject.NameError=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.StandardError,function(){this.toValue=function(){return this};if(arguments.length>0){this.message=arguments[0]}if(arguments.length>1){this.name=arguments[1]}});RubyEngine.Parser=function(){};RubyEngine.Parser.prototype.isfull=function(){return this.body.match(/^\s*$/)};RubyEngine.Parser.prototype.parse=function(A){this.body=A;return this.compstmt()};RubyEngine.Parser.prototype.compstmt=function(){var A;while(this.term()){}if((A=this.stmt())==undefined){return undefined}var B=[A];var C=this.body;while(this.term()){while(this.term()){}if(!(A=this.stmt())){break}C=this.body;B.push(A)}this.body=C;return B};RubyEngine.Parser.prototype.stmt=function(){var A,D;if((A=this.expr())==undefined){return undefined}var B=[A];while(this.body.match(/^[ \t]*(if|unless|while|until)/)){var C=this.body;this.body=RegExp.rightContext;A=RegExp.$1;if(!(D=this.expr())){this.body=C;break}B.unshift(D);B=new RubyEngine.Node.Method(A,null,B)}return B};RubyEngine.Parser.prototype.expr=function(){var A;if((A=this.command())!=undefined){return A}if((A=this.arg())!=undefined){return A}return undefined};RubyEngine.Parser.prototype.command=function(){var A,C;var B=this.body;if(A=this.operation()){if(this.body.match(/^[ \t]+[^\-\+]|^[ \t]*"/)&&(C=this.args())){return new RubyEngine.Node.Method(A,null,C)}this.body=B}return undefined};RubyEngine.Parser.prototype.lhs=function(){var A;var B=this.body;if((A=this.primary())!=undefined){if(RubyEngine.Node.Method.prototype.isPrototypeOf(A)&&A.block==undefined&&(A.name=="[]"||A.args==undefined||A.args.length==0)){return A}this.body=B}if((A=this.varname())!=undefined){return A}return undefined};RubyEngine.Parser.prototype.args=function(){var A,D;if((A=this.arg())==undefined){return undefined}var B=[A];var C=this.body;while((A=this.comma())&&(D=this.arg())){C=this.body;B.push(D)}this.body=C;return B};RubyEngine.Parser.prototype.arg=function(){var A,E,D;var C=this.body;if(A=this.lhs()){if(this.body.match(/^[ \t]*(\+|\-|\*|\/)?\=/)){D=RegExp.$1;this.body=RegExp.rightContext;if((E=this.arg())!=undefined){if(D){E=new RubyEngine.Node.Expression([A,new RubyEngine.Node.Operator(D),E])}if(RubyEngine.Node.Method.prototype.isPrototypeOf(A)){A=A.clone();A.name+="=";if(A.args){A.args.push(E)}else{A.args=[E]}return A}else{return new RubyEngine.Node.Method("*let",null,[A,E])}}}this.body=C}if((A=this.primary())!=undefined){var B=[A];C=this.body;while((A=this.operator())&&((E=this.primary())!=undefined)){C=this.body;B.push(A,E)}this.body=C;if(B.length==1){return B[0]}return new RubyEngine.Node.Expression(B)}return undefined};RubyEngine.Parser.prototype.blockvars=function(){var A=[];var B=this.body;if(this.body.match(/^[ \t]*(\|)/)){this.body=RegExp.rightContext;while((x=this.varname())&&this.body.match(/^[ \t]*(,|\|)/)){A.push(x);this.body=RegExp.rightContext;if(RegExp.$1=="|"){return A}}this.body=B}return undefined};RubyEngine.Parser.prototype.primary=function(){if(this.body.match(/^[ \t]*([-+])/)){var A=RegExp.$1,G;var E=this.body;this.body=RegExp.rightContext;if((G=this.primary())!=undefined){if(A=="+"){return G}return new RubyEngine.Node.Expression([new RubyEngine.Node.Operator("-@"),G])}this.body=E}var B=this.primary2();while(B!=undefined){var G=undefined,F=null,C=undefined;var E=this.body;if(this.body.match(/^[ \t]*(\.|\[)/)){this.body=RegExp.rightContext;C=RegExp.$1}if(C=="["){G=this.args();if(G==undefined||!this.body.match(/^[ \t]*\]/)){this.body=E;break}this.body=RegExp.rightContext;B=new RubyEngine.Node.Method("[]",B,G);continue}if(C=="."&&(G=this.operation())==undefined){this.body=E;break}if(this.body.match(/^[ \t]*(\()/)){E=this.body;this.body=RegExp.rightContext;if(((F=this.args())!=undefined)&&this.body.match(/^[ \t]*(\))/)){this.body=RegExp.rightContext}else{this.body=E;F=null}}if(G!=undefined){B=new RubyEngine.Node.Method(G,B,F)}else{if(C==undefined&&F!=null&&RubyEngine.Node.Ref.prototype.isPrototypeOf(B)){B=new RubyEngine.Node.Method(B.name,null,F)}else{this.body=E;break}}if(this.body.match(/^[ \t]*(\{|do)/)){var D=RegExp.$1;E=this.body;this.body=RegExp.rightContext;G=this.blockvars();F=this.compstmt();if(F==undefined){F=null}if((D=="{"&&this.body.match(/^\s*\}/))||this.body.match(/^\s*end/)){this.body=RegExp.rightContext;B.block=new RubyEngine.Node.Block(G,F)}else{this.body=E}}}var G;if(RubyEngine.Node.Method.prototype.isPrototypeOf(B)&&B.args==null&&B.block==undefined&&this.body.match(/^[ \t]*[^ \t\-\+]/)&&(G=this.args())!=undefined){B.args=G}return B};RubyEngine.Parser.prototype.primary2=function(){var A,G,F;var E=this.body;if(this.body.match(/^[ \t]*(\()/)){this.body=RegExp.rightContext;if((A=this.stmt())&&this.body.match(/^[ \t]*(\))/)){this.body=RegExp.rightContext;return A}this.body=E}if(this.body.match(/^[ \t]*(-?0x[0-9A-F]+|(-?)0b([01]+)|-?0o?[0-7]+|-?(?:0d)?[0-9]+)/i)){this.body=RegExp.rightContext;var C;if(RegExp.$3){C=parseInt(RegExp.$3,2);if(RegExp.$2){C=-C}}else{C=RegExp.$1.replace(/0d/i,"").replace(/0o/i,"0");if(RubyEngine.OPERA&&C.match(/^0[0-7]+$/)){C=parseInt(C,8)}else{C=parseInt(C)}}return new RubyEngine.RubyObject.Numeric(C)}else{if(this.body.match(/^[ \t]*\?(.)/)){this.body=RegExp.rightContext;return new RubyEngine.RubyObject.Numeric(RegExp.$1.charCodeAt(0))}else{if((A=this.strLiteral())!=undefined){return A}else{if((A=this.reference())!=undefined){return new RubyEngine.Node.Ref(A)}}}}if(this.body.match(/^[ \t]*\[/)){this.body=RegExp.rightContext;A=this.args();if(this.body.match(/^[ \t]*\]/)){this.body=RegExp.rightContext;return new RubyEngine.Node.Method("new",RubyEngine.RubyObject.Array,A)}this.body=E}if(this.body.match(/^[ \t]*(if)/)){this.body=RegExp.rightContext;A=RegExp.$1;if((G=this.arg())!=undefined&&this.then()){if(F=this.compstmt()){var B=[G,F];while(this.body.match(/^[ \s]*(elsif)/)){var D=this.body;this.body=RegExp.rightContext;if((G=this.arg())&&this.then()){if(!(F=this.compstmt())){this.body=D;break}B.push(G,F)}}if(this.body.match(/^[ \s]*(else)/)){var D=this.body;this.body=RegExp.rightContext;if(F=this.compstmt()){B.push(true,F)}else{this.body=D}}if(this.body.match(/^[ \s]*(end)/)){this.body=RegExp.rightContext;return new RubyEngine.Node.Method(A,null,B)}}}this.body=E}if(this.body.match(/^[ \t]*def/)){this.body=RegExp.rightContext;A=this.operation();G=this.argdecl();F=this.compstmt();while(this.term()){}if(A!=undefined&&F!=undefined&&this.body.match(/^[ \s]*(end)/)){this.body=RegExp.rightContext;ret=new RubyEngine.Node.Method("def",null,[new RubyEngine.RubyObject.String(A)]);ret.block=new RubyEngine.Node.Block(G,F);return ret}this.body=E}return undefined};RubyEngine.Parser.prototype.strLiteral=function(){var C=this.body;if(this.body.match(/^[ \t]*'((?:[^\\']|\\.)*)'/)){this.body=RegExp.rightContext;return new RubyEngine.RubyObject.String(RegExp.$1)}else{if(this.body.match(/^[ \t]*"/)){this.body=RegExp.rightContext;var B=[],A;while(this.body.match(/^((?:[^\\"]|\\.)*?)#\{/)){this.body=RegExp.rightContext;if((A=RegExp.$1)!=""){B.push(new RubyEngine.RubyObject.String(A))}if((A=this.compstmt())==undefined||!this.body.match(/^\s*}/)){this.body=C;return undefined}this.body=RegExp.rightContext;B.push(A)}if(this.body.match(/^((?:[^\\"]|\\.)*?)"/)){this.body=RegExp.rightContext;if((A=RegExp.$1)!=""){B.push(new RubyEngine.RubyObject.String(A))}if(B.length==1&&RubyEngine.RubyObject.String.prototype.isPrototypeOf(B[0])){return B[0]}else{return new RubyEngine.Node.Method("*concat",null,B)}}}}this.body=C;return undefined};RubyEngine.Parser.prototype.argdecl=function(){var A;var B=this.body;if(this.body.match(/^[ \t]*\(/)){this.body=RegExp.rightContext;if((A=this.arglist())!=undefined&&this.body.match(/^[ \t]*\)/)){this.body=RegExp.rightContext;return A}}else{if((A=this.arglist())!=undefined&&this.term()){return A}}this.body=B;return undefined};RubyEngine.Parser.prototype.arglist=function(){var A;if((A=this.varname())==undefined){return[]}var B=[A],C=this.body;while(this.body.match(/^[ \t]*,/)){this.body=RegExp.rightContext;if((A=this.varname())==undefined){break}B.push(A);C=this.body}this.body=C;return B};RubyEngine.Parser.prototype.then=function(){if(this.body.match(/^\s*(then)/)){this.body=RegExp.rightContext;return"then"}return this.term()};RubyEngine.Parser.prototype.varname=function(){if(this.body.match(/^[ \t]*([A-Za-z_\$][A-Za-z0-9_]*)/)&&!RubyEngine.RESERVED[RegExp.$1]){this.body=RegExp.rightContext;return new RubyEngine.Node.Variable(RegExp.$1)}};RubyEngine.Parser.prototype.term=function(){if(this.body.match(/^[ \t]*(\r?\n|;)/)){this.body=RegExp.rightContext;return RegExp.$1}return undefined};RubyEngine.Parser.prototype.comma=function(){if(this.body.match(/^[ \t]*,/)){this.body=RegExp.rightContext;return","}return undefined};RubyEngine.Parser.prototype.operator=function(){if(this.body.match(/^[ \t]*(\.\.|\+|\-|\*{1,2}|\/|%|==|<<|>>|[<>]=?|&&|\|\|)/)){this.body=RegExp.rightContext;return new RubyEngine.Node.Operator(RegExp.$1)}return undefined};RubyEngine.Parser.prototype.reference=function(){if(this.body.match(/^[ \t]*([A-Za-z_\$][A-Za-z0-9_]*[\!\?]?)/)&&!RubyEngine.RESERVED[RegExp.$1]){this.body=RegExp.rightContext;return RegExp.$1}return undefined};RubyEngine.Parser.prototype.operation=function(){if(this.body.match(/^[ \t]*([A-Za-z_][A-Za-z0-9_]*[\!\?]?)/)&&!RubyEngine.RESERVED[RegExp.$1]){this.body=RegExp.rightContext;return RegExp.$1}return undefined};RubyEngine.Scope=function(){this.clear()};RubyEngine.Scope.prototype.pushScope=function(A){this.stack.push(this.level);this.level=[A||{}]};RubyEngine.Scope.prototype.popScope=function(){this.level=this.stack.pop()};RubyEngine.Scope.prototype.pushLevel=function(A){this.level.push(A||{})};RubyEngine.Scope.prototype.popLevel=function(){this.level.pop()};RubyEngine.Scope.prototype.clear=function(){this.level=[{}];this.stack=[];this.global={};if(typeof (window)!="undefined"){this.global={"$window":new RubyEngine.RubyObject.JSObject(window),"$document":new RubyEngine.RubyObject.JSObject(document)}}for(var A in RubyEngine.Interpreter.KernelMethod){if(A.match(/^[a-z_\*]/)){this.global[A]=RubyEngine.Interpreter.KernelMethod[A]}}for(var A in RubyEngine.RubyObject){if(A.match(/^[A-Z\$]/)){this.global[A]=RubyEngine.RubyObject[A]}}};RubyEngine.Scope.prototype.globalsubstitute=function(A,B){return this.global[A]=B};RubyEngine.Scope.prototype.substitute=function(A,C){if(A.match(/^\$/)){return this.global[A]=C}else{if(A.match(/^[A-Z]/)){if(A in this.global){}return this.global[A]=C}else{for(var B=this.level.length-1;B>=0;B--){if(A in this.level[B]){return this.level[B][A]=C}}return this.level[this.level.length-1][A]=C}}};RubyEngine.Scope.prototype.reference=function(A){for(var B=this.level.length-1;B>=0;B--){if(A in this.level[B]){return this.level[B][A]}}if(A in this.global){return this.global[A]}return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+A+"'",A)};RubyEngine.Scope.prototype.call=function(D,C,H,A){var G=this.scope.reference(D);if(typeof (G)=="function"){return G.apply(this,[C,H])}else{if(RubyEngine.Node.Block.prototype.isPrototypeOf(G)){var H=G;var F={};if(H.vars){for(var E=0;E<H.vars.length;E++){F[H.vars[E].name]=this.run(C[E])}}this.scope.pushScope(F);var B=this.run(H.block);this.scope.popScope();return B}else{if(A){return G}}}return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+node.name+"'",node.name)};RubyEngine.Interpreter=function(){this.context={};this.scope=new RubyEngine.Scope();this.stdout="";this.parser=new RubyEngine.Parser()};RubyEngine.Interpreter.prototype.writeStdout=function(A){this.stdout+=A};RubyEngine.Interpreter.prototype.exec=function(B){if(typeof (B)=="string"){B=this.parser.parse(B)}var A=this.run(B);if(typeof (A)=="object"&&"toValue" in A){return A.toValue()}return A};RubyEngine.Interpreter.prototype.run=function(D){var B=null;if(Array.prototype.isPrototypeOf(D)){for(var A=0;A<D.length;A++){B=this.run(D[A])}}else{if(RubyEngine.Node.Variable.prototype.isPrototypeOf(D)){B=this.scope.reference(D.name)}else{if(RubyEngine.Node.Expression.prototype.isPrototypeOf(D)){B=this.calcExpr(D)}else{if(RubyEngine.Node.Method.prototype.isPrototypeOf(D)||RubyEngine.Node.Ref.prototype.isPrototypeOf(D)){var C=D.type;if(C=="M"&&D.target!=null){B=this.objectMethod(D)}else{return this.scope.call.apply(this,[D.name,D.args,D.block,(C=="R")])}return B}else{B=D}}}}return B};RubyEngine.Interpreter.prototype.calcExpr=function(F){var E=F.list;var D=[];for(var B=0;B<E.length;B++){var A=E[B];if(Array.prototype.isPrototypeOf(A)){D.push(this.run(A))}else{if(RubyEngine.Node.Expression.prototype.isPrototypeOf(A)){D.push(this.calcExpr(A))}else{if(RubyEngine.Node.Variable.prototype.isPrototypeOf(A)){D.push(this.scope.reference(A.name))}else{if(RubyEngine.Node.Ref.prototype.isPrototypeOf(A)){D.push(xx=this.run(A))}else{if(RubyEngine.Node.Method.prototype.isPrototypeOf(A)){D.push(this.run(A))}else{if(RubyEngine.Node.Operator.prototype.isPrototypeOf(A)){switch(A.name){case"-@":D.push(D.pop().neg());break;case"+":var C=D.pop();D.push(D.pop().add(C));break;case"-":var C=D.pop();D.push(D.pop().sub(C));break;case"*":var C=D.pop();D.push(D.pop().mul(C));break;case"/":var C=D.pop();D.push(D.pop().div(C));break;case"%":var C=D.pop();D.push(D.pop().mod(C));break;case"**":var C=D.pop();D.push(D.pop().pow(C));break;case"..":var H=D.pop();var G=D.pop();D.push(new RubyEngine.RubyObject.Range(G.num,H.num));break;case"==":var C=D.pop();D.push(D.pop().eql(C));break;case"<":var C=D.pop();D.push(D.pop().cmp(C)<0);break;case">":var C=D.pop();D.push(D.pop().cmp(C)>0);break;case">=":var C=D.pop();D.push(D.pop().cmp(C)>=0);break;case"<<":var C=D.pop();D.push(D.pop().sft(C));break}}else{D.push(A)}}}}}}}return D.pop()};RubyEngine.Interpreter.prototype.call=function(B,A){var D=[];for(var C=0;C<A.length;C++){D.push(RubyEngine.RubyObject.js2r(A[C]))}return this.scope.call.apply(this,[B,D,null,true]).toValue()};RubyEngine.Interpreter.prototype.kernelMethod=function(A){var B=RubyEngine.Interpreter.KernelMethod[A.name];if(typeof (B)=="function"){return B.apply(this,[A.args,A.block])}else{alert("undefined method: "+A.name)}};RubyEngine.Interpreter.prototype.objectMethod=function(A){var B;if(RubyEngine.Node.Ref.prototype.isPrototypeOf(A.target)){B=this.scope.reference(A.target.name)}else{B=this.run(A.target)}return RubyEngine.RubyObject.call.apply(this,[B,A.name,A.args,A.block])};RubyEngine.Interpreter.KernelMethod={"def":function(B,C){var A=B[0].str;this.scope.globalsubstitute(A,C)},"puts":function(A){if(A&&A.length>0){for(var B=0;B<A.length;B++){this.writeStdout(this.run(A[B])+"\n")}}else{this.writeStdout("\n")}},"if":function(B){for(var A=0;A<B.length;A+=2){var C=this.run(B[A]);if(C||C===0||C===""){return this.run(B[A+1])}}},"*let":function(A){return this.scope.substitute(A[0].name,this.run(A[1]))},"*concat":function(B){var A="";if(B&&B.length>0){for(var C=0;C<B.length;C++){A+=this.run(B[C]).toString()}}return new RubyEngine.RubyObject.String(A)},"p":function(A){if(A&&A.length>0){for(var B=0;B<A.length;B++){this.writeStdout(this.run(A[B]).toSource()+"\n")}}}};RubyEngine.Util={getRubyScriptList:function(){var A=[];var C=document.getElementsByTagName("script");for(var B=0;B<C.length;B++){if(C[B].type=="text/ruby"){A.push(C[B])}}return A},getRubyScript:function(){var B="",C=this.getRubyScriptList();for(var A=0;A<C.length;A++){B+=C[A].text}return B}} 
     1if(navigator.userAgent.indexOf("Firefox")<0){Object.prototype.toSource=function(){var B="({";for(var A in this){if(B.length>2){B+=","}B+=A+":";if(this[A]!=null){B+=this[A].toSource()}else{B+="null"}}return B+"})"};Array.prototype.toSource=function(){var A="[";for(var B=0;B<this.length;B++){if(B!=0){A+=","}if(this[B]!=null){A+=this[B].toSource()}else{A+="null"}}return A+"]"};String.prototype.toSource=function(){return'"'+this+'"'};Number.prototype.toSource=Number.prototype.toString;Boolean.prototype.toSource=Boolean.prototype.toString}var RubyEngine={};RubyEngine.FIREFOX=navigator.userAgent.indexOf("Firefox")>=0;RubyEngine.OPERA=navigator.userAgent.indexOf("Opera")>=0;RubyEngine.IE=navigator.userAgent.indexOf("MSIE")>=0;RubyEngine.SAFARI=navigator.userAgent.indexOf("Safari")>=0;RubyEngine.RESERVED={"if":true,"then":true,"elsif":true,"else":true,"end":true,"while":true,"unless":true,"until":true,"def":true,"nil":true};RubyEngine.OPERATORS={"::":1,"[]":2,"**":11,"*":13,"/":13,"%":13,"+":14,"-":14,"<<":15,">>":15,"&":20,"|":21,"^":21,">":22,">=":22,"<":22,"<=":22,"<=>":23,"==":23,"===":23,"!=":23,"=~":23,"!~":23,"&&":24,"||":25,"..":30,"...":30,"?:":31,"=":32,"not":40,"and":41,"or":41};RubyEngine.Node={};RubyEngine.Node.Variable=function(A){this.type="V";this.name=A};RubyEngine.Node.Variable.prototype.toSource=function(){return this.type+"'"+this.name+"'"};RubyEngine.Node.Ref=function(A){this.type="R";this.name=A};RubyEngine.Node.Ref.prototype.toSource=function(){return this.type+"'"+this.name+"'"};RubyEngine.Node.Operator=function(A){this.type="O";this.name=A};RubyEngine.Node.Operator.prototype.toSource=function(){return this.type+"'"+this.name+"'"};RubyEngine.Node.Method=function(B,C,A){this.type="M";this.name=B;this.target=C;this.args=A;this.block=undefined};RubyEngine.Node.Method.prototype.toSource=function(){var A=this.block?this.block.toSource():"";return this.type+"("+(this.target==null?"":this.target.toSource()+".")+this.name+","+(this.args?this.args.toSource():this.args)+")"+A};RubyEngine.Node.Method.prototype.clone=function(){var A=[];if(this.args){for(var B=0;B<this.args.length;B++){A.push(this.args[B])}}return new RubyEngine.Node.Method(this.name,this.target,A)};RubyEngine.Node.Block=function(A,B){this.type="B";this.vars=A;this.block=B};RubyEngine.Node.Block.prototype.toSource=function(){return"{|"+(this.vars?this.vars.toSource():this.target)+"| "+(this.block?this.block.toSource():this.block)+"}"};RubyEngine.Node.Expression=function(C){this.type="E";var E=[];var D=[];for(var B=0;B<C.length;B++){var A=C[B];if(RubyEngine.Node.Operator.prototype.isPrototypeOf(A)){while(D.length>0){if(RubyEngine.OPERATORS[D[0].name]>RubyEngine.OPERATORS[A.name]){break}E.push(D.shift())}D.unshift(A)}else{E.push(A)}}while(D.length>0){E.push(D.shift())}this.list=E};RubyEngine.Node.Expression.prototype.toSource=function(){return this.type+"'"+this.list.toSource()+"'"};RubyEngine.RubyObject={};RubyEngine.RubyObject.inherit=function(A,B){B.prototype=new A();B.clz={};B.methods={};B.superclz=A;return B};RubyEngine.RubyObject.call=function(A,D,C,G){var E=A.clz;var H;while(!(H=E.methods[D])){if(!(E=E.superclz)){break}}if(H){return H.apply(this,[A,C,G])}else{if(D!="method_missing"){var F=[new RubyEngine.RubyObject.String(D)];if(C&&C.length>0){F=F.concat(C)}var B=RubyEngine.RubyObject.call.apply(this,[A,"method_missing",F,G]);if(B!=undefined){return B}return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+D+"' for "+A.clz.toString(),D)}}return undefined};RubyEngine.RubyObject._LikeArray={"[object Array]":true,"[object HTMLCollection]":true};RubyEngine.RubyObject.js2r=function(E){if(E==undefined){return E}if(E==null){return E}var D=Object.prototype.toString.call(E);if(D=="[object String]"){return new RubyEngine.RubyObject.String(E)}else{if(D in RubyEngine.RubyObject._LikeArray){var C=[];for(var B=0;B<E.length;B++){C.push(RubyEngine.RubyObject.js2r(E[B]))}var A=new RubyEngine.RubyObject.Array();A.array=C;return A;return new RubyEngine.RubyObject.Array(C)}else{if(D=="[object Number]"){return new RubyEngine.RubyObject.Numeric(E)}else{if(D=="[object Boolean]"){return E}else{return new RubyEngine.RubyObject.JSObject(E)}}}}};RubyEngine.RubyObject.Object=function(){this.clz=RubyEngine.RubyObject.Object};RubyEngine.RubyObject.Object.prototype.toValue=function(){return this};RubyEngine.RubyObject.Object.clz={"methods":{}};RubyEngine.RubyObject.Object.methods={inspect:function(A,B){return A.toString()},dup:function(A,B){return A}};RubyEngine.RubyObject.Numeric=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){this.toValue=function(){return this.num};this.clz=RubyEngine.RubyObject.Numeric;this.num=0;if(arguments.length>0){this.num=arguments[0]}});RubyEngine.RubyObject.Numeric.prototype.toString=function(){return this.num.toString()};RubyEngine.RubyObject.Numeric.prototype.toSource=function(){return this.num.toString()};RubyEngine.RubyObject.Numeric.prototype.neg=function(){return new RubyEngine.RubyObject.Numeric(-this.num)};RubyEngine.RubyObject.Numeric.prototype.add=function(A){return new RubyEngine.RubyObject.Numeric(this.num+A.num)};RubyEngine.RubyObject.Numeric.prototype.sub=function(A){return new RubyEngine.RubyObject.Numeric(this.num-A.num)};RubyEngine.RubyObject.Numeric.prototype.mul=function(A){return new RubyEngine.RubyObject.Numeric(this.num*A.num)};RubyEngine.RubyObject.Numeric.prototype.div=function(A){return new RubyEngine.RubyObject.Numeric(parseInt(this.num/A.num))};RubyEngine.RubyObject.Numeric.prototype.mod=function(A){return new RubyEngine.RubyObject.Numeric(this.num%A.num)};RubyEngine.RubyObject.Numeric.prototype.pow=function(A){return new RubyEngine.RubyObject.Numeric(Math.pow(this.num,A.num))};RubyEngine.RubyObject.Numeric.prototype.eql=function(A){return this.num==A.num};RubyEngine.RubyObject.Numeric.prototype.cmp=function(A){return(this.num==A.num?0:(this.num<A.num?-1:1))};RubyEngine.RubyObject.Numeric.methods={"chr":function(A,B,C){return new RubyEngine.RubyObject.String(String.fromCharCode(A.num))},"to_s":function(A,B,C){return new RubyEngine.RubyObject.String(String(A.num))},"upto":function(B,C,E){if(!E){return null}var A,F=this.run(C[0]).num;if(E.vars){A=E.vars[0].name}this.scope.pushLevel();for(var D=B.num;D<=F;D++){if(A){this.scope.substitute(A,new RubyEngine.RubyObject.Numeric(D))}this.run(E.block)}this.scope.popLevel();return B}};RubyEngine.RubyObject.String=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){this.toValue=function(){return this.str};this.clz=RubyEngine.RubyObject.String;this.str="";if(arguments.length>0){this.str=arguments[0]}});RubyEngine.RubyObject.String.prototype.toString=function(){return this.str};RubyEngine.RubyObject.String.prototype.toSource=function(){return'"'+this.str+'"'};RubyEngine.RubyObject.String.prototype.add=function(A){return new RubyEngine.RubyObject.String(this.str+A.str)};RubyEngine.RubyObject.String.prototype.mul=function(A){var B="";for(var C=0;C<A.num;C++){B+=this.str}return new RubyEngine.RubyObject.String(B)};RubyEngine.RubyObject.String.prototype.eql=function(A){return this.str==A.str};RubyEngine.RubyObject.String.methods={"length":function(A,B,C){return new RubyEngine.RubyObject.Numeric(A.str.length)},"reverse":function(A,C,E){var B="";for(var D=A.str.length-1;D>=0;D--){B+=A.str.charAt(D)}return new RubyEngine.RubyObject.String(B)},"center":function(B,D,F){var A=this.run(D[0]).num;var C="";for(var E=(A-B.str.length-1)/2;E>0;E--){C+=" "}C+=B.str;while(C.length<A){C+=" "}return new RubyEngine.RubyObject.String(C)},"to_i":function(B,C,D){var A=parseInt(B.str);if(isNaN(A)){A=0}return new RubyEngine.RubyObject.Numeric(A)},"[]":function(A,B,C){return new RubyEngine.RubyObject.Numeric(A.str.charCodeAt(this.run(B[0]).num))},"[]=":function(B,C,D){var A=this.run(C[0]).num;if(RubyEngine.RubyObject.Numeric.prototype.isPrototypeOf(C[1])){B.str=B.str.substr(0,A)+String.fromCharCode(C[1].num)+B.str.substr(A+1);return C[1]}else{B.str=B.str.substr(0,A)+this.run(C[1]).toString()+B.str.substr(A+1);return C[1]}}};RubyEngine.RubyObject.Array=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){this.toValue=function(){var A=[];for(var B=0;B<this.array.length;B++){A.push(this.array[B].toValue())}return A};this.clz=RubyEngine.RubyObject.Array;this.array=[]});RubyEngine.RubyObject.Array.toSource=function(){return"Array"};RubyEngine.RubyObject.Array.prototype.toSource=function(){var A="[";for(var B=0;B<this.array.length;B++){if(B>0){A+=","}A+=this.array[B].toSource()}return A+"]"};RubyEngine.RubyObject.Array.prototype.toString=function(){var A="[";for(var B=0;B<this.array.length;B++){if(B>0){A+=","}A+=this.array[B].toString()}return A+"]"};RubyEngine.RubyObject.Array.prototype.sft=function(A){this.array.push(A);return this};RubyEngine.RubyObject.Array.clz.methods={"new":function(A,B,F){var E=new RubyEngine.RubyObject.Array();var D=[];if(B){for(var C=0;C<B.length;C++){D.push(this.run(B[C]))}}E.array=D;return E}};RubyEngine.RubyObject.Array.methods={"[]":function(A,B,C){return A.array[this.run(B[0]).num]},"push":function(A,B,D){if(B){for(var C=0;C<B.length;C++){A.array.push(this.run(B[C]))}}return A},"[]=":function(A,B,C){return A.array[this.run(B[0]).num]=this.run(B[1])},"length":function(A,B,C){return new RubyEngine.RubyObject.Numeric(A.array.length)},"member?":function(B,C,E){var A=this.run(C[0]);for(var D=0;D<B.array.length;D++){if(A.eql(B.array[D])){return true}}return false},"reverse":function(A,C,D){var B=new RubyEngine.RubyObject.Array();B.array=A.array.reverse;return B},"each":function(B,C,E){if(!E){return null}var A;if(E.vars){A=E.vars[0].name}this.scope.pushLevel();for(var D=0;D<B.array.length;D++){if(A){this.scope.substitute(A,B.array[D])}this.run(E.block)}this.scope.popLevel();return B},"inject":function(A,B,F){if(!F){return null}var D=0,E;if(B&&B.length>0){E=this.run(B[0])}else{E=A.array[D++]}while(D<A.array.length){var C={};if(F.vars){if(F.vars.length>0){C[F.vars[0].name]=E}if(F.vars.length>1){C[F.vars[1].name]=A.array[D++]}}this.scope.pushLevel(C);E=this.run(F.block);this.scope.popLevel()}return E},"join":function(A,D,F){var C="",B=(D&&D.length>0?this.run(D[0]).str:"");for(var E=0;E<A.array.length;E++){if(E>0){C+=B}C+=A.array[E].toString()}return new RubyEngine.RubyObject.String(C)}};RubyEngine.RubyObject.Range=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(B,A){this.clz=RubyEngine.RubyObject.Range;this.from=B;this.to=A});RubyEngine.RubyObject.Range.prototype.toString=function(){return"("+this.from+".."+this.to+")"};RubyEngine.RubyObject.Range.prototype.toValue=function(){var B=[];for(var A=this.from;A<=this.to;A++){B.push(A)}return B};RubyEngine.RubyObject.Range.methods={"each":function(B,C,E){if(!E){return null}var A;if(E.vars){A=E.vars[0].name}this.scope.pushLevel();for(var D=B.from;D<=B.to;D++){if(A){this.scope.substitute(A,new RubyEngine.RubyObject.Numeric(D))}this.run(E.block)}this.scope.popLevel();return B}};RubyEngine.RubyObject.JSObject=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(A){this.obj=A;this.clz=RubyEngine.RubyObject.JSObject});RubyEngine.RubyObject.JSObject.prototype.toString=function(){return this.obj.toString()};RubyEngine.RubyObject.JSObject.prototype.toValue=function(){return this.obj};RubyEngine.RubyObject.JSObject.methods={"method_missing":function(self,args,block){var name=this.run(args[0]).str;if(args.length==1){return RubyEngine.RubyObject.js2r(self.obj[name])}else{if(name[name.length-1]=="="){self.obj[name.slice(0,name.length-1)]=this.run(args[1]).toValue()}else{if(name in self.obj){if(RubyEngine.FIREFOX||RubyEngine.OPERA){var jsargs=[];for(var i=1;i<args.length;i++){jsargs.push(this.run(args[i]).toValue())}return RubyEngine.RubyObject.js2r(self.obj[name].apply(self.obj,jsargs))}else{var jsargs=[];for(var i=1;i<args.length;i++){jsargs.push("this.run(args["+i+"]).toValue()")}return RubyEngine.RubyObject.js2r(eval("self.obj[name]("+jsargs.join(",")+")"))}}else{return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+name+"' for "+self.obj.toString(),name)}}}}};RubyEngine.RubyObject.Exception=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Object,function(){});RubyEngine.RubyObject.Exception.prototype.toString=function(){return this.message};RubyEngine.RubyObject.Exception.prototype.toSource=function(){return this.message};RubyEngine.RubyObject.StandardError=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.Exception,function(){});RubyEngine.RubyObject.NameError=RubyEngine.RubyObject.inherit(RubyEngine.RubyObject.StandardError,function(){this.toValue=function(){return this};if(arguments.length>0){this.message=arguments[0]}if(arguments.length>1){this.name=arguments[1]}});RubyEngine.Parser=function(){};RubyEngine.Parser.prototype.isfull=function(){return this.body.match(/^\s*$/)};RubyEngine.Parser.prototype.parse=function(A){this.body=A;return this.compstmt()};RubyEngine.Parser.prototype.compstmt=function(){var A;while(this.term()){}if((A=this.stmt())==undefined){return undefined}var B=[A];var C=this.body;while(this.term()){while(this.term()){}if(!(A=this.stmt())){break}C=this.body;B.push(A)}this.body=C;return B};RubyEngine.Parser.prototype.stmt=function(){var A,D;if((A=this.expr())==undefined){return undefined}var B=[A];while(this.body.match(/^[ \t]*(if|unless|while|until)/)){var C=this.body;this.body=RegExp.rightContext;A=RegExp.$1;if(!(D=this.expr())){this.body=C;break}B.unshift(D);B=new RubyEngine.Node.Method(A,null,B)}return B};RubyEngine.Parser.prototype.expr=function(){var A;if((A=this.command())!=undefined){return A}if((A=this.arg())!=undefined){return A}return undefined};RubyEngine.Parser.prototype.command=function(){var A,C;var B=this.body;if(A=this.operation()){if(this.body.match(/^[ \t]+[^\-\+]|^[ \t]*"/)&&(C=this.args())){return new RubyEngine.Node.Method(A,null,C)}this.body=B}return undefined};RubyEngine.Parser.prototype.lhs=function(){var A;var B=this.body;if((A=this.primary())!=undefined){if(RubyEngine.Node.Method.prototype.isPrototypeOf(A)&&A.block==undefined&&(A.name=="[]"||A.args==undefined||A.args.length==0)){return A}this.body=B}if((A=this.varname())!=undefined){return A}return undefined};RubyEngine.Parser.prototype.args=function(){var A,D;if((A=this.arg())==undefined){return undefined}var B=[A];var C=this.body;while((A=this.comma())&&(D=this.arg())){C=this.body;B.push(D)}this.body=C;return B};RubyEngine.Parser.prototype.arg=function(){var A,E,D;var C=this.body;if(A=this.lhs()){if(this.body.match(/^[ \t]*(\+|\-|\*|\/)?\=/)){D=RegExp.$1;this.body=RegExp.rightContext;if((E=this.arg())!=undefined){if(D){E=new RubyEngine.Node.Expression([A,new RubyEngine.Node.Operator(D),E])}if(RubyEngine.Node.Method.prototype.isPrototypeOf(A)){A=A.clone();A.name+="=";if(A.args){A.args.push(E)}else{A.args=[E]}return A}else{return new RubyEngine.Node.Method("*let",null,[A,E])}}}this.body=C}if((A=this.primary())!=undefined){var B=[A];C=this.body;while((A=this.operator())&&((E=this.primary())!=undefined)){C=this.body;B.push(A,E)}this.body=C;if(B.length==1){return B[0]}return new RubyEngine.Node.Expression(B)}return undefined};RubyEngine.Parser.prototype.blockvars=function(){var A=[];var B=this.body;if(this.body.match(/^[ \t]*(\|)/)){this.body=RegExp.rightContext;while((x=this.varname())&&this.body.match(/^[ \t]*(,|\|)/)){A.push(x);this.body=RegExp.rightContext;if(RegExp.$1=="|"){return A}}this.body=B}return undefined};RubyEngine.Parser.prototype.primary=function(){if(this.body.match(/^[ \t]*([-+])/)){var A=RegExp.$1,G;var E=this.body;this.body=RegExp.rightContext;if((G=this.primary())!=undefined){if(A=="+"){return G}return new RubyEngine.Node.Expression([new RubyEngine.Node.Operator("-@"),G])}this.body=E}var B=this.primary2();while(B!=undefined){var G=undefined,F=null,C=undefined;var E=this.body;if(this.body.match(/^[ \t]*(\.|\[)/)){this.body=RegExp.rightContext;C=RegExp.$1}if(C=="["){G=this.args();if(G==undefined||!this.body.match(/^[ \t]*\]/)){this.body=E;break}this.body=RegExp.rightContext;B=new RubyEngine.Node.Method("[]",B,G);continue}if(C=="."&&(G=this.operation())==undefined){this.body=E;break}if(this.body.match(/^[ \t]*(\()/)){E=this.body;this.body=RegExp.rightContext;if(((F=this.args())!=undefined)&&this.body.match(/^[ \t]*(\))/)){this.body=RegExp.rightContext}else{this.body=E;F=null}}if(G!=undefined){B=new RubyEngine.Node.Method(G,B,F)}else{if(C==undefined&&F!=null&&RubyEngine.Node.Ref.prototype.isPrototypeOf(B)){B=new RubyEngine.Node.Method(B.name,null,F)}else{this.body=E;break}}if(this.body.match(/^[ \t]*(\{|do)/)){var D=RegExp.$1;E=this.body;this.body=RegExp.rightContext;G=this.blockvars();F=this.compstmt();if(F==undefined){F=null}if((D=="{"&&this.body.match(/^\s*\}/))||this.body.match(/^\s*end/)){this.body=RegExp.rightContext;B.block=new RubyEngine.Node.Block(G,F)}else{this.body=E}}}var G;if(RubyEngine.Node.Method.prototype.isPrototypeOf(B)&&B.args==null&&B.block==undefined&&this.body.match(/^[ \t]*[^ \t\-\+]/)&&(G=this.args())!=undefined){B.args=G}return B};RubyEngine.Parser.prototype.primary2=function(){var A,G,F;var E=this.body;if(this.body.match(/^[ \t]*(\()/)){this.body=RegExp.rightContext;if((A=this.stmt())&&this.body.match(/^[ \t]*(\))/)){this.body=RegExp.rightContext;return A}this.body=E}if(this.body.match(/^[ \t]*(-?0x[0-9A-F]+|(-?)0b([01]+)|-?0o?[0-7]+|-?(?:0d)?[0-9]+)/i)){this.body=RegExp.rightContext;var C;if(RegExp.$3){C=parseInt(RegExp.$3,2);if(RegExp.$2){C=-C}}else{C=RegExp.$1.replace(/0d/i,"").replace(/0o/i,"0");if(RubyEngine.OPERA&&C.match(/^0[0-7]+$/)){C=parseInt(C,8)}else{C=parseInt(C)}}return new RubyEngine.RubyObject.Numeric(C)}else{if(this.body.match(/^[ \t]*\?(.)/)){this.body=RegExp.rightContext;return new RubyEngine.RubyObject.Numeric(RegExp.$1.charCodeAt(0))}else{if((A=this.strLiteral())!=undefined){return A}else{if((A=this.reference())!=undefined){return new RubyEngine.Node.Ref(A)}}}}if(this.body.match(/^[ \t]*\[/)){this.body=RegExp.rightContext;A=this.args();if(this.body.match(/^[ \t]*\]/)){this.body=RegExp.rightContext;return new RubyEngine.Node.Method("new",RubyEngine.RubyObject.Array,A)}this.body=E}if(this.body.match(/^[ \t]*(if)/)){this.body=RegExp.rightContext;A=RegExp.$1;if((G=this.arg())!=undefined&&this.then()){if(F=this.compstmt()){var B=[G,F];while(this.body.match(/^[ \s]*(elsif)/)){var D=this.body;this.body=RegExp.rightContext;if((G=this.arg())&&this.then()){if(!(F=this.compstmt())){this.body=D;break}B.push(G,F)}}if(this.body.match(/^[ \s]*(else)/)){var D=this.body;this.body=RegExp.rightContext;if(F=this.compstmt()){B.push(true,F)}else{this.body=D}}if(this.body.match(/^[ \s]*(end)/)){this.body=RegExp.rightContext;return new RubyEngine.Node.Method(A,null,B)}}}this.body=E}if(this.body.match(/^[ \t]*def/)){this.body=RegExp.rightContext;A=this.operation();G=this.argdecl();F=this.compstmt();while(this.term()){}if(A!=undefined&&F!=undefined&&this.body.match(/^[ \s]*(end)/)){this.body=RegExp.rightContext;ret=new RubyEngine.Node.Method("def",null,[new RubyEngine.RubyObject.String(A)]);ret.block=new RubyEngine.Node.Block(G,F);return ret}this.body=E}return undefined};RubyEngine.Parser.prototype.strLiteral=function(){var C=this.body;if(this.body.match(/^[ \t]*'((?:[^\\']|\\.)*)'/)){this.body=RegExp.rightContext;return new RubyEngine.RubyObject.String(RegExp.$1)}else{if(this.body.match(/^[ \t]*"/)){this.body=RegExp.rightContext;var B=[],A;while(this.body.match(/^((?:[^\\"]|\\.)*?)#\{/)){this.body=RegExp.rightContext;if((A=RegExp.$1)!=""){B.push(new RubyEngine.RubyObject.String(A))}if((A=this.compstmt())==undefined||!this.body.match(/^\s*}/)){this.body=C;return undefined}this.body=RegExp.rightContext;B.push(A)}if(this.body.match(/^((?:[^\\"]|\\.)*?)"/)){this.body=RegExp.rightContext;if((A=RegExp.$1)!=""){B.push(new RubyEngine.RubyObject.String(A))}if(B.length==1&&RubyEngine.RubyObject.String.prototype.isPrototypeOf(B[0])){return B[0]}else{return new RubyEngine.Node.Method("*concat",null,B)}}}}this.body=C;return undefined};RubyEngine.Parser.prototype.argdecl=function(){var A;var B=this.body;if(this.body.match(/^[ \t]*\(/)){this.body=RegExp.rightContext;if((A=this.arglist())!=undefined&&this.body.match(/^[ \t]*\)/)){this.body=RegExp.rightContext;return A}}else{if((A=this.arglist())!=undefined&&this.term()){return A}}this.body=B;return undefined};RubyEngine.Parser.prototype.arglist=function(){var A;if((A=this.varname())==undefined){return[]}var B=[A],C=this.body;while(this.body.match(/^[ \t]*,/)){this.body=RegExp.rightContext;if((A=this.varname())==undefined){break}B.push(A);C=this.body}this.body=C;return B};RubyEngine.Parser.prototype.then=function(){if(this.body.match(/^\s*(then)/)){this.body=RegExp.rightContext;return"then"}return this.term()};RubyEngine.Parser.prototype.varname=function(){if(this.body.match(/^[ \t]*([A-Za-z_\$][A-Za-z0-9_]*)/)&&!RubyEngine.RESERVED[RegExp.$1]){this.body=RegExp.rightContext;return new RubyEngine.Node.Variable(RegExp.$1)}};RubyEngine.Parser.prototype.term=function(){if(this.body.match(/^[ \t]*(\r?\n|;)/)){this.body=RegExp.rightContext;return RegExp.$1}return undefined};RubyEngine.Parser.prototype.comma=function(){if(this.body.match(/^[ \t]*,/)){this.body=RegExp.rightContext;return","}return undefined};RubyEngine.Parser.prototype.operator=function(){if(this.body.match(/^[ \t]*(\.\.|\+|\-|\*{1,2}|\/|%|==|<<|>>|[<>]=?|&&|\|\|)/)){this.body=RegExp.rightContext;return new RubyEngine.Node.Operator(RegExp.$1)}return undefined};RubyEngine.Parser.prototype.reference=function(){if(this.body.match(/^[ \t]*([A-Za-z_\$][A-Za-z0-9_]*[\!\?]?)/)&&!RubyEngine.RESERVED[RegExp.$1]){this.body=RegExp.rightContext;return RegExp.$1}return undefined};RubyEngine.Parser.prototype.operation=function(){if(this.body.match(/^[ \t]*([A-Za-z_][A-Za-z0-9_]*[\!\?]?)/)&&!RubyEngine.RESERVED[RegExp.$1]){this.body=RegExp.rightContext;return RegExp.$1}return undefined};RubyEngine.Scope=function(){this.clear()};RubyEngine.Scope.prototype.pushScope=function(A){this.stack.push(this.level);this.level=[A||{}]};RubyEngine.Scope.prototype.popScope=function(){this.level=this.stack.pop()};RubyEngine.Scope.prototype.pushLevel=function(A){this.level.push(A||{})};RubyEngine.Scope.prototype.popLevel=function(){this.level.pop()};RubyEngine.Scope.prototype.clear=function(){this.level=[{}];this.stack=[];this.global={};if(typeof (window)!="undefined"){this.global={"$window":new RubyEngine.RubyObject.JSObject(window),"$document":new RubyEngine.RubyObject.JSObject(document)}}for(var A in RubyEngine.Interpreter.KernelMethod){if(A.match(/^[a-z_\*]/)){this.global[A]=RubyEngine.Interpreter.KernelMethod[A]}}for(var A in RubyEngine.RubyObject){if(A.match(/^[A-Z\$]/)){this.global[A]=RubyEngine.RubyObject[A]}}};RubyEngine.Scope.prototype.globalsubstitute=function(A,B){return this.global[A]=B};RubyEngine.Scope.prototype.substitute=function(A,C){if(A.match(/^\$/)){return this.global[A]=C}else{if(A.match(/^[A-Z]/)){if(A in this.global){}return this.global[A]=C}else{for(var B=this.level.length-1;B>=0;B--){if(A in this.level[B]){return this.level[B][A]=C}}return this.level[this.level.length-1][A]=C}}};RubyEngine.Scope.prototype.reference=function(A){for(var B=this.level.length-1;B>=0;B--){if(A in this.level[B]){return this.level[B][A]}}if(A in this.global){return this.global[A]}return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+A+"'",A)};RubyEngine.Scope.prototype.call=function(D,C,H,A){var G=this.scope.reference(D);if(typeof (G)=="function"){return G.apply(this,[C,H])}else{if(RubyEngine.Node.Block.prototype.isPrototypeOf(G)){var H=G;var F={};if(H.vars){for(var E=0;E<H.vars.length;E++){F[H.vars[E].name]=this.run(C[E])}}this.scope.pushScope(F);var B=this.run(H.block);this.scope.popScope();return B}else{if(A){return G}}}return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+node.name+"'",node.name)};RubyEngine.Interpreter=function(){this.context={};this.scope=new RubyEngine.Scope();this.stdout="";this.parser=new RubyEngine.Parser()};RubyEngine.Interpreter.prototype.writeStdout=function(A){this.stdout+=A};RubyEngine.Interpreter.prototype.exec=function(B){if(typeof (B)=="string"){B=this.parser.parse(B)}var A=this.run(B);if(typeof (A)=="object"&&"toValue" in A){return A.toValue()}return A};RubyEngine.Interpreter.prototype.run=function(D){var B=null;if(Array.prototype.isPrototypeOf(D)){for(var A=0;A<D.length;A++){B=this.run(D[A])}}else{if(RubyEngine.Node.Variable.prototype.isPrototypeOf(D)){B=this.scope.reference(D.name)}else{if(RubyEngine.Node.Expression.prototype.isPrototypeOf(D)){B=this.calcExpr(D)}else{if(RubyEngine.Node.Method.prototype.isPrototypeOf(D)||RubyEngine.Node.Ref.prototype.isPrototypeOf(D)){var C=D.type;if(C=="M"&&D.target!=null){B=this.objectMethod(D)}else{return this.scope.call.apply(this,[D.name,D.args,D.block,(C=="R")])}return B}else{B=D}}}}return B};RubyEngine.Interpreter.prototype.calcExpr=function(F){var E=F.list;var D=[];for(var B=0;B<E.length;B++){var A=E[B];if(Array.prototype.isPrototypeOf(A)){D.push(this.run(A))}else{if(RubyEngine.Node.Expression.prototype.isPrototypeOf(A)){D.push(this.calcExpr(A))}else{if(RubyEngine.Node.Variable.prototype.isPrototypeOf(A)){D.push(this.scope.reference(A.name))}else{if(RubyEngine.Node.Ref.prototype.isPrototypeOf(A)){D.push(xx=this.run(A))}else{if(RubyEngine.Node.Method.prototype.isPrototypeOf(A)){D.push(this.run(A))}else{if(RubyEngine.Node.Operator.prototype.isPrototypeOf(A)){switch(A.name){case"-@":D.push(D.pop().neg());break;case"+":var C=D.pop();D.push(D.pop().add(C));break;case"-":var C=D.pop();D.push(D.pop().sub(C));break;case"*":var C=D.pop();D.push(D.pop().mul(C));break;case"/":var C=D.pop();D.push(D.pop().div(C));break;case"%":var C=D.pop();D.push(D.pop().mod(C));break;case"**":var C=D.pop();D.push(D.pop().pow(C));break;case"..":var H=D.pop();var G=D.pop();D.push(new RubyEngine.RubyObject.Range(G.num,H.num));break;case"==":var C=D.pop();D.push(D.pop().eql(C));break;case"<":var C=D.pop();D.push(D.pop().cmp(C)<0);break;case">":var C=D.pop();D.push(D.pop().cmp(C)>0);break;case">=":var C=D.pop();D.push(D.pop().cmp(C)>=0);break;case"<<":var C=D.pop();D.push(D.pop().sft(C));break}}else{D.push(A)}}}}}}}return D.pop()};RubyEngine.Interpreter.prototype.call=function(B,A){var D=[];for(var C=0;C<A.length;C++){D.push(RubyEngine.RubyObject.js2r(A[C]))}return this.scope.call.apply(this,[B,D,null,true]).toValue()};RubyEngine.Interpreter.prototype.kernelMethod=function(A){var B=RubyEngine.Interpreter.KernelMethod[A.name];if(typeof (B)=="function"){return B.apply(this,[A.args,A.block])}else{alert("undefined method: "+A.name)}};RubyEngine.Interpreter.prototype.objectMethod=function(A){var B;if(RubyEngine.Node.Ref.prototype.isPrototypeOf(A.target)){B=this.scope.reference(A.target.name)}else{B=this.run(A.target)}return RubyEngine.RubyObject.call.apply(this,[B,A.name,A.args,A.block])};RubyEngine.Interpreter.KernelMethod={"def":function(B,C){var A=B[0].str;this.scope.globalsubstitute(A,C)},"puts":function(A){if(A&&A.length>0){for(var B=0;B<A.length;B++){this.writeStdout(this.run(A[B])+"\n")}}else{this.writeStdout("\n")}},"if":function(B){for(var A=0;A<B.length;A+=2){var C=this.run(B[A]);if(C||C===0||C===""){return this.run(B[A+1])}}},"*let":function(A){return this.scope.substitute(A[0].name,this.run(A[1]))},"*concat":function(B){var A="";if(B&&B.length>0){for(var C=0;C<B.length;C++){A+=this.run(B[C]).toString()}}return new RubyEngine.RubyObject.String(A)},"p":function(A){if(A&&A.length>0){for(var B=0;B<A.length;B++){this.writeStdout(this.run(A[B]).toSource()+"\n")}}}};RubyEngine.Util={getRubyScriptList:function(){var A=[];var C=document.getElementsByTagName("script");for(var B=0;B<C.length;B++){if(C[B].type=="text/ruby"){A.push(C[B])}}return A},getRubyScript:function(){var B="",C=this.getRubyScriptList();for(var A=0;A<C.length;A++){B+=C[A].text}return B}} 
  • lang/javascript/jsruby/trunk/src/node.js

    r4197 r4201  
    3434RubyEngine.Node.Method.prototype.clone = function(){ 
    3535  var args=[]; 
    36   for(var i=0;i<this.args.length;i++) args.push(this.args[i]); 
     36  if(this.args) for(var i=0;i<this.args.length;i++) args.push(this.args[i]); 
    3737  return new RubyEngine.Node.Method(this.name,this.target,args); 
    3838}