Overview
Comment: | added several file commands, fixed backslash substitutions |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
4f3db7f982775837fa0e627dcee01572 |
User & Date: | suchenwi on 2013-11-23 21:28:45 |
Other Links: | manifest | tags |
Context
2013-11-24
| ||
08:24 | added [file join], [file split] check-in: 07c2ea91bc user: suchenwi tags: trunk | |
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 | |
Changes
Modified tcl053.js from [368d355e33] to [623beb5ebc].
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | + - - + + + - + + - - - - - + + + + + + + - | /* =================================================== -*- C++ -*- * tcl.js "A Tcl implementation in Javascript" * * Released under the same terms as Tcl itself. * (BSD license found at <http://www.tcl.tk/software/tcltk/license.html>) * * Based on Picol by Salvatore Sanfilippo (<http://antirez.com/page/picol>) * (c) Stéphane Arnold 2007 * Richard Suchenwirth 2007, 2013: cleanup, additions * vim: syntax=javascript autoindent softtabwidth=4 */ // 'use strict'; // breaks some tests, like expr 0376, for loop var _step = 0; // set to 1 for debugging if(process.env["DEBUG"] == 1) _step = 1; |
︙ | |||
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | + | } catch (e) { var msg = code.substr(0,128); if(msg.length >= 125) msg += "..."; var msg = e+'\n while executing\n"'+msg+'"'; for(var i = this.level; i > 0; i--) msg += '\n invoked from within\n"'+this.levelcall[i]+'"' this.setVar("::errorInfo", msg); if(_step) puts("e: "+e); throw e; } } this.eval2 = function(code) { this.code = this.OK; var parser = new TclParser(code); var args = []; |
︙ | |||
168 169 170 171 172 173 174 175 176 177 178 179 180 181 | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | + + + + + | args[args.length-1] = args[args.length-1].toString() + text.toString(); } } if (args.length > 0) result = this.call(args); return this.objectify(result); } //---------------------------------- Commands in alphabetical order /*this.registerCommand("after", function (interp, args) { this.arity(args, 3); var code = args[2].toString(); setTimeout(args[1], function(code) {interp.eval(code)}); });*/ this.registerCommand("append", function (interp, args) { this.arity(args, 2, Infinity); var vname = args[1].toString(); try {var str = interp.getVar(vname);} catch(e) {var str = "";} for (var i = 2; i < args.length; i++) str += args[i].toString(); interp.setVar(vname, str); return str; |
︙ | |||
202 203 204 205 206 207 208 | 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | - - + + + + | }); this.registerCommand("continue", function (interp, args) { interp.code = interp.CNT; return; }); this.registerSubCommand("clock", "format", function (interp, args) { var now = new Date(); |
︙ | |||
356 357 358 359 360 361 362 363 | 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | + - + - + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | var sqrt = Math.sqrt; // "publish" other Math.* functions as needed this.registerCommand("expr", function (interp, args) { var expression = args.slice(1).join(" "); return interp.expr(interp, expression); }); this.expr = function (interp, expression) { // also used in for, if, while var mx; try { |
︙ | |||
430 431 432 433 434 435 436 | 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | - + - - - - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + - - | if(fmt=="%x") { var x = new Number(val); return x.toString(16); } else if(fmt=="%X") { var x = new Number(val); return x.toString(16).toUpperCase(); } |
︙ | |||
535 536 537 538 539 540 541 | 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | - + | return interp.mkList(interp.procs); }); this.registerSubCommand("info", "script", function (interp, args) { return interp.script; }); this.registerSubCommand("info", "vars", function (interp, args) { var res = []; |
︙ | |||
597 598 599 600 601 602 603 | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | - + - + | }); this.registerCommand("llength", function (interp, args) { this.arity(args, 2); return args[1].toList().length; }); this.registerCommand("lrange", function (interp, args) { this.arity(args, 4); |
︙ | |||
691 692 693 694 695 696 697 | 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | - + + - + | if (args.length == 3) interp.setVar(name, val); return interp.getVar(name); }); this.registerCommand("source", function (interp, args) { this.arity(args, 2); interp.script = args[1].toString(); try { |
︙ | |||
884 885 886 887 888 889 890 | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | - + | Tcl.isDecimal = new RegExp("^[+\\-]?[1-9][0-9]*$"); Tcl.isHex = new RegExp("^0x[0-9a-fA-F]+$"); Tcl.isOctal = new RegExp("^[+\\-]?0[0-7]*$"); Tcl.isHexSeq = new RegExp("[0-9a-fA-F]*"); Tcl.isOctalSeq = new RegExp("[0-7]*"); Tcl.isList = new RegExp("[\\{\\} ]"); Tcl.isNested = new RegExp("^\\{.*\\}$"); |
︙ | |||
920 921 922 923 924 925 926 | 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | - + - - + | } else if (name == "args") { interp.setVar("args", new TclObject(args.slice(i, args.length))); break; } interp.setVar(name, interp.objectify(args[i])); } if (name == "args" && i+1 < arglist.length) |
︙ | |||
1105 1106 1107 1108 1109 1110 1111 | 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 | - - - + + + | function TclCommand(func, privdata) { if (func == null) throw "No such function"; this.func = func; this.privdata = privdata; this.ensemble = arguments[2]; this.call = function(interp, args) { |
︙ | |||
1137 1138 1139 1140 1141 1142 1143 | 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 | - + - + - + - + | this.len = text.length; this.type = this.EOL; this.cur = this.text.charAt(0); this.getText = function () { return this.text.substring(this.start,this.end+1); } this.parseString = function () { |
︙ | |||
1299 1300 1301 1302 1303 1304 1305 | 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 | - - + | } if (this.cur == "#" && this.type == this.EOL) { this.parseComment(); continue; } return this.parseString(); } |
︙ | |||
1360 1361 1362 1363 1364 1365 1366 | 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 | - + - - + + - + - + + + - - - + + + - - - - - - + + + + - - - | return word; } this.feedcharstart = function () { this.feedchar(); this.start = this.index; } this.setPos = function (index) { |
Modified test_tcljs.tcl from [da8fb3dc27] to [744eb2cb5e].
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | - + + - + - - - - + + + + + - + + + + - | # test suite for TclJS # This file is designed so it can also run in a tclsh. Some JavaScript goodies, # like 1/0, sqrt(-1) were excluded from the tests. # [clock format 0] was excluded because the timezone string differed. set vars [info vars] ;# for later cleanup set version 0.5.3 set total 0 set passed 0 set fail 0 |
︙ | |||
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | + + + + + + - + - - - - + + + + - + | 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 e.g. {file dirname foo/bar/grill} -> foo/bar e.g. {file dirname /foo/bar/grill} -> /foo/bar e.g. {file extension foo.txt} -> .txt e.g. {file extension Makefile} -> "" e.g. {file tail foo/bar/grill} -> grill 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 e.g. {set x 41} -> 41 e.g. {incr x} -> 42 e.g. {incr x 2} -> 44 e.g. {incr x -3} -> 41 |
︙ | |||
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | + - - - - - - - - - - - - + + + + + + + + + + + + + - + + + - - + | 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. {proc f {arg b} {expr $arg*$b}; f 6 7} -> 42 ;# should work with 'args' 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} e.g. {split "a b c d "} -> {a b {} c d {}} e.g. {split usr/local/bin /} -> {usr local bin} e.g. {split /usr/local/bin /} -> {{} usr local bin} e.g. {split abc ""} -> {a b c} |