Overview
Comment: | added [catch] |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
3d61c6fe53bb2dc412187dd18ec9a28f |
User & Date: | suchenwi on 2013-11-20 20:58:57 |
Other Links: | manifest | tags |
Context
2013-11-23
| ||
21:28 | added several file commands, fixed backslash substitutions check-in: 4f3db7f982 user: suchenwi tags: trunk | |
2013-11-20
| ||
20:58 | added [catch] check-in: 3d61c6fe53 user: suchenwi tags: trunk | |
2013-11-19
| ||
20:21 | now passing all 105 tests check-in: c9965b6d9d user: suchenwi tags: trunk | |
Changes
Modified tcl053.js from [7793cfca8e] to [368d355e33].
︙ | |||
98 99 100 101 102 103 104 | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | - + | } this.eval = function (code) { try { return this.eval2(code); } catch (e) { var msg = code.substr(0,128); if(msg.length >= 125) msg += "..."; |
︙ | |||
179 180 181 182 183 184 185 186 187 188 189 190 191 192 | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | + + + + + + + + + | for (var i = 2; i < args.length; i++) str += args[i].toString(); interp.setVar(vname, str); return str; }); this.registerCommand("break", function (interp, args) { interp.code = interp.BRK; return; }); this.registerCommand("catch", function (interp, args) { this.arity(args, 2, 3); var code = args[1].toString(); var res; var rc = 0; try {res = interp.eval(code);} catch(e) {res = e; rc = 1;} if(args.length == 3) interp.setVar(args[2], res); return rc; }); this.registerCommand("cd", function (interp, args) { this.arity(args, 1, 2); var dir = process.env.HOME; if (args.length == 2) dir = args[1].toString(); process.chdir(dir); return; |
︙ | |||
674 675 676 677 678 679 680 | 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | + - + - + + - + - - + - - - + + + | var r = args[1]; interp.code = interp.RET; return r; }); this.registerCommand("set", function (interp, args) { this.arity(args, 2, 3); var name = args[1]; var val = eval(args[2]); |
︙ | |||
816 817 818 819 820 821 822 | 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | return; } base = cmd[0].toString(); cmd.shift(); interp.registerSubCommand(base, cmd.join(" "), eval(args[2].toString())); return; }); |
︙ | |||
1176 1177 1178 1179 1180 1181 1182 | 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | - - + + - + | this.start = this.index; while (true) { if (this.len == 0) { this.end = this.index-1; this.type = this.ESC; return this.OK; } |
︙ | |||
1207 1208 1209 1210 1211 1212 1213 | 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 | - + - + | while (true) { if (this.len == 0) { this.end = this.index; this.type = this.EOL; return; } switch (this.cur) { |
︙ | |||
1250 1251 1252 1253 1254 1255 1256 | 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 | - - + + | while (true) { if (this.len == 0) break; if (this.cur == "[" && blevel == 0) level++; else if (this.cur == "]" && blevel == 0) { level--; if (level == 0) break; |
︙ | |||
1279 1280 1281 1282 1283 1284 1285 | 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 | - + + - + | this.setPos(this.end+1); return this.OK; } this.parseBrace = function () { var level = 1; this.feedcharstart(); while (true) { |
︙ | |||
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 | 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 | + - + + - - + + + | } if (this.cur == "#" && this.type == this.EOL) { this.parseComment(); continue; } return this.parseString(); } puts("unreachable?"); return this.OK; // unreached } this.feedSequence = function () { //return; if (this.cur != "\\") throw "Invalid escape sequence"; var cur = this.steal(1); |
︙ |
Modified test_tcljs.tcl from [c15ca09a61] to [da8fb3dc27].
︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | + + + + + | e.g. {append x bar} -> foobar proc sum args {expr [join $args +]} e.g. {sum 1 2 3} -> 6 #native sum2 {function (interp, args) {return eval(args.join("+"));}} #e.g. {sum2 2 3 4} -> 9 e.g. {catch foo msg} -> 1 e.g. {set msg} -> {invalid command name "foo"} e.g. {catch {expr 7*6}} -> 0 e.g. {catch {expr 7*6} msg; set msg} -> 42 e.g. {concat {a b} {c d}} -> {a b c d} e.g. {set d [dict create a 1 b 2 c 3]} -> {a 1 b 2 c 3} e.g. {dict exists $d c} -> 1 e.g. {dict exists $d x} -> 0 e.g. {dict get $d b} -> 2 e.g. {dict keys $d} -> {a b c} |
︙ | |||
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | + + + + + + + | e.g. {set x 0xFF; expr {$x+0}} -> 255 e.g. {expr 0376} -> 254 e.g. {set x 0375; expr $x} -> 253 e.g. {expr {$x}} -> 253 e.g. {expr 6 * 7} -> 42 e.g. {expr 1 == 2} -> 0 e.g. {expr 1 < 2} -> 1 e.g. {expr 1 > 2} -> 0 e.g. {expr 1 != 2} -> 1 e.g. {expr 1 <= 2} -> 1 e.g. {expr 1 >= 2} -> 0 e.g. {expr !0} -> 1 e.g. {expr !42} -> 0 e.g. {set x 3} -> 3 e.g. {expr $x+1} -> 4 e.g. {expr {$x+1}} -> 4 e.g. {set x a; set y b; expr {$x == $y}} -> 0 e.g. {expr {$x != $y}} -> 1 e.g. {expr 43 % 5} -> 3 e.g. {set x -44; expr {-$x}} -> 44 e.g. {expr 1<<3} -> 8 set forres "" e.g. {for {set i 0} {$i < 5} {incr i} {append forres $i}; set forres} -> 01234 e.g. {foreach i {a b c d e} {append foreachres $i}; set foreachres} -> abcde e.g. {format %x 255} -> ff e.g. {format %X 254} -> FE |
︙ | |||
121 122 123 124 125 126 127 128 129 130 131 132 133 134 | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | + + + + + | e.g. {llength $x} -> 4 e.g. {lindex $x 2} -> c e.g. {lrange $x 1 2} -> {b c} e.g. {lreverse {a b c}} -> {c b a} e.g. {lsearch $x b} -> 1 e.g. {lsearch $x y} -> -1 e.g. {lsort {z x y}} -> {x y z} e.g. {proc f args {expr [join $args +]}} -> "" e.g. {f 1} -> 1 e.g. {f 1 2} -> 3 e.g. {f 1 2 3} -> 6 e.g. {regexp {X[ABC]Y} XAY} -> 1 e.g. {regexp {X[ABC]Y} XDY} -> 0 e.g. {regsub {[A-C]+} uBAAD x} -> uxD e.g. {split "a b c d"} -> {a b {} c d} e.g. {split " a b c d"} -> {{} a b {} c d} |
︙ | |||
146 147 148 149 150 151 152 | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | - + | e.g. {string length ""} -> 0 e.g. {string length foo} -> 3 e.g. {string range hello 1 3} -> ell e.g. {string tolower Tcl} -> tcl e.g. {string toupper Tcl} -> TCL e.g. {string trim " foo "} -> foo |