Changeset 2339
- Timestamp:
- 12/03/07 16:43:25 (5 years ago)
- Location:
- lang/javascript/jsruby/trunk
- Files:
-
- 4 modified
-
src/builtinobjects.js (modified) (1 diff)
-
src/interpreter.js (modified) (1 diff)
-
src/parse.js (modified) (1 diff)
-
tests/string.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/jsruby/trunk/src/builtinobjects.js
r2328 r2339 81 81 for(var i=self.str.length-1;i>=0;i--) st += self.str.charAt(i); 82 82 return new RubyEngine.RubyObject.String(st); 83 }, 84 "[]": function(self, args, block) { 85 return new RubyEngine.RubyObject.Numeric(self.str.charCodeAt(args[0])); 83 86 } 84 87 }; -
lang/javascript/jsruby/trunk/src/interpreter.js
r2328 r2339 121 121 return method.apply(this, [obj, node.args, node.block]); 122 122 } else { 123 alert("undefined method :" + obj.toSource() + "." + node tree[idx].toSource());123 alert("undefined method :" + obj.toSource() + "." + node[idx].toSource()); 124 124 } 125 125 } -
lang/javascript/jsruby/trunk/src/parse.js
r2337 r2339 134 134 } 135 135 136 // Primary : Primary2 ('.'Operation ('(' Args ')')? ('{' ('|'Varname'|')? CompStmt '}')? )* 136 // Primary : Primary2 ( '[' Args ']' | '.'Operation ('(' Args ')')? ('{' ('|'Varname'|')? CompStmt '}')? )* 137 // # for removing left recursions of Primary in BNF of Ruby 137 138 RubyEngine.Parser.prototype.primary = function() { 138 139 //console.log(this.body);console.trace();if(!confirm("continue?")) exit(); 139 140 var prim = this.primary2(); 140 141 while(prim != undefined) { 141 if (!this.body.match(/^[ \t]*\./)) return prim;142 143 142 var y, z; 144 143 var prebody = this.body; 145 this.body = RegExp.rightContext; 144 145 if (!this.body.match(/^[ \t]*(\.|\[)/)) return prim; 146 this.body = RegExp.rightContext; 147 148 // '[' Args ']' 149 if (RegExp.$1=='[') { 150 y = this.args(); 151 if (y==undefined || !this.body.match(/^[ \t]*\]/)) { 152 this.body = prebody; 153 return prim; 154 } 155 this.body = RegExp.rightContext; 156 prim = new RubyEngine.Node.Method('[]', prim, y); 157 continue; 158 } 146 159 147 160 // '.'Operation -
lang/javascript/jsruby/trunk/tests/string.html
r2328 r2339 37 37 } 38 38 39 function testBrackett() { 40 assertEquals("string[nth] 1", ruby.exec(' "ABC"[0] '), 65); 41 assertEquals("string[nth] 2", ruby.exec(' "ABC"[1] '), 66); 42 //assertEquals("string[nth] 3", ruby.exec(' "ABC"[-1] '), 67); 43 } 44 39 45 </script> 40 46 </head>
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)