@naanlang/naan 1.0.14 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/env_node.js CHANGED
@@ -37,6 +37,7 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
37
37
  if (typeof(options) != 'object')
38
38
  options = { };
39
39
  var repl = require('repl');
40
+ var replServer;
40
41
  var process = require('process');
41
42
  var Naan = require('./core/naanlib');
42
43
  var naanlib = new Naan.Naanlib();
@@ -69,6 +70,14 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
69
70
  outEnable = true;
70
71
  naanlib.textLine(cmd);
71
72
  };
73
+
74
+ this.setPrompt = function setPrompt(prompt) {
75
+ if (replServer) {
76
+ replServer.setPrompt(prompt);
77
+ return (prompt);
78
+ }
79
+ return (false);
80
+ };
72
81
 
73
82
 
74
83
  //==========================================================================
@@ -85,9 +94,9 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
85
94
 
86
95
  if (!options.replDisable)
87
96
  {
88
- var nprompt = repl.start({ prompt: 'Naan> ', eval: myEval});
97
+ replServer = repl.start({ prompt: 'Naan> ', eval: myEval});
89
98
 
90
- nprompt.on('line', function(cmd) { // process raw command line
99
+ replServer.on('line', function(cmd) { // process raw command line
91
100
  if (cmd.charAt(0) != ".") {
92
101
  textToRemoteTerm(cmd);
93
102
  naanlib.textLine(cmd + "\n");
@@ -98,7 +107,7 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
98
107
  // Hook the ^C interrupt
99
108
  //
100
109
 
101
- nprompt._events.SIGINT = function () {
110
+ replServer._events.SIGINT = function () {
102
111
  naanlib.escape();
103
112
  };
104
113
 
@@ -106,7 +115,7 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
106
115
  // Hook an exit command
107
116
  //
108
117
 
109
- nprompt.on('exit', function() {
118
+ replServer.on('exit', function() {
110
119
  process.exit();
111
120
  });
112
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naanlang/naan",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "author": "Richard C. Zulch",
5
5
  "description": "Naan™ software platform",
6
6
  "main": "./lib/core/naanlib.js",
@@ -357,12 +357,16 @@ RegisterTestCategory("core", [
357
357
  [ "print(testcore=`testcore);", "testcore|testcore" ],
358
358
  [ "print(testcore=42);", "42|42" ],
359
359
 
360
- [ "cond();", { errors: "cond( requires if expression at (1, 6) found )" } ],
360
+ [ "cond();", "false" ],
361
+ [ "cond(true);",
362
+ { errors: "if expression required at (1, 6) found true" } ],
361
363
  [ "quote(cond(if false 3 else if true 4));>", "(cond ((identity false) 3) ((identity true) 4))" ],
362
364
  [ "cond(if false 3 else if true 4);", "4" ],
363
365
  [ "cond (if 1 and\n 2, 3);", "3" ],
364
366
  [ "cond(print(false),print(\"hi\"));",
365
- { errors: "cond( requires if expression at (1, 6) found print" } ],
367
+ { errors: "if expression required at (1, 6) found print" } ],
368
+ [ "cond(if 3 4, print(5));",
369
+ { errors: "if expression required at (1, 14) found print" } ],
366
370
 
367
371
  [ "body();", "false" ],
368
372
  [ "quote(body(if false 3 else if true 4));>", "(body ((identity false) 3) ((identity true) 4))" ],
@@ -370,8 +374,10 @@ RegisterTestCategory("core", [
370
374
  [ "body(print(\"hi\"), print(\" there\"),4+3);>", "hi there|7" ],
371
375
  [ "body(print(false),print(\"hi\"));", "falsehi|\"hi\"" ],
372
376
 
373
- [ "push();>", { errors: "attempt to modify constant false" } ],
374
- [ "push(true);>", { errors: "attempt to modify constant false" } ],
377
+ [ "push();>",
378
+ { errors: "attempt to modify constant false" } ],
379
+ [ "push(true);>",
380
+ { errors: "attempt to modify constant false" } ],
375
381
  [ "push(true, 3);>", "false" ],
376
382
  [ "testcore=false;", "false" ],
377
383
  [ "push(11, testcore);>", "(11)" ],
@@ -427,6 +433,8 @@ RegisterTestCategory("core", [
427
433
  [ "temp(2, `(1 2 3));>", "(2 3)|(2 3)" ],
428
434
  [ "function (ex1, lex1) { ex1+pop(lex1), print(lex1), lex1 }(2, `(1 2 3));>", "(2 3)|(2 3)" ],
429
435
  [ "quote(function (a)\n { f(b)-\ng(c) * h(d)\n });>", "(function lambda (a) (- (f b) (* (g c) (h d))))" ],
436
+ [ "quote(function (a)\n { f(b)\n-g(c) * h(d)\n });>",
437
+ { errors: "ambiguous newline (use \\ or ,) at (3, 1) found -" }],
430
438
  [ "quote(function (a)\n { f(b)\\\n-g(c) * h(d)\n });>", "(function lambda (a) (- (f b) (* (g c) (h d))))" ],
431
439
 
432
440
  [ "tempo = temp.proc;>", "(function temp (ex1 lex1) (+ ex1 (pop lex1)) (print lex1) lex1)" ],
@@ -35,11 +35,11 @@ RegisterTestCategory("JSinterop", [
35
35
 
36
36
  [ "o(3);", {
37
37
  "dev": { errors: "xcall \"[object Object]\": TypeError: object.apply is not a function" }
38
- "prod": { errors: "xcall \"[object Object]\": TypeError: e[3].apply is not a function" }
38
+ "prod": { errors: "xcall \"[object Object]\": TypeError: r[3].apply is not a function" }
39
39
  }[ "prod"]],
40
40
  [ "o(Number);", {
41
41
  "dev": { errors: "xcall \"[object Object]\": TypeError: object.apply is not a function" }
42
- "prod": { errors: "xcall \"[object Object]\": TypeError: e[3].apply is not a function" }
42
+ "prod": { errors: "xcall \"[object Object]\": TypeError: r[3].apply is not a function" }
43
43
  }[ "prod"]],
44
44
  [ "Number(3);", "[Number 3]" ],
45
45
  [ "Number(3).toString();", "\"3\"" ],
@@ -71,6 +71,12 @@ RegisterTestCategory("JSinterop", [
71
71
  ["Array([3]);", "[Array [3]]"],
72
72
  ["Array([3]).0;", "[Array 3]"],
73
73
  ["Array([3]).0.0;", "3"],
74
+ ["[].concat([])", "[]"],
75
+ ["[].concat(3)", "[3]"],
76
+ ["[].concat([3])", "[3]"],
77
+ ["[].concat(Array())", "[]"],
78
+ ["[].concat(Array(a))", '["a"]'],
79
+ ["[].concat(xnew())", "[[object Object]]"],
74
80
 
75
81
 
76
82
  //
@@ -61,7 +61,7 @@ RegisterTestCategory("Lingo parse", [
61
61
  //
62
62
 
63
63
  [ "4&&3;", { exprs: "(&& 4 3)" } ],
64
- [ "4\\\n&&3;", { exprs: "(&& 4 3)" } ],
64
+ [ "4\n&&3;", { exprs: "(&& 4 3)" } ],
65
65
  [ "4&&\n3;", { exprs: "(&& 4 3)" } ],
66
66
  [ "function test0(x, y) { \n y = 3\n x \n };", { exprs: "(defproc function test0 (x y) (= y 3) x)" } ],
67
67
 
@@ -438,15 +438,18 @@ RegisterTestCategory("Lingo parse", [
438
438
  [ "try{nest()}finally{};",
439
439
  { exprs: "(catch ((nest)) false false)" } ],
440
440
  [ "try{nest()}catch{}finally{};",
441
- { exprs: "(catch ((nest)) (((identity true))) false)" } ],
441
+ { exprs: "(catch ((nest)) (((identity true) false)) false)" } ],
442
442
  [ "function test1() { try { nest() } finally { } };",
443
443
  { exprs: "(defproc function test1 false (catch ((nest)) false false))",
444
444
  text: "==> redefined: test1" } ],
445
445
  [ "function(){try{nest()}catch{},if(1)2};",
446
- { exprs: "(function lambda false (catch ((nest)) (((identity true))) false) ((identity 1) 2))" } ],
446
+ { exprs: "(function lambda false (catch ((nest)) (((identity true) false)) false) ((identity 1) 2))" } ],
447
447
  [ "function(x) { try {} catch { if true { 4 } } };",
448
448
  { exprs: "(function lambda (x) (catch false (((identity true) 4)) false))" } ],
449
-
449
+ [ "try { throw(green) } catch { printline(4) };",
450
+ { exprs: "(catch ((throw green)) (((identity true) (printline 4))) false)",
451
+ text: "4" } ],
452
+
450
453
  //
451
454
  // cond
452
455
  //
@@ -514,11 +517,25 @@ RegisterTestCategory("Lingo parse", [
514
517
  " if 1 - 2\n"
515
518
  " 3\n"
516
519
  "}" ],
520
+ [ "function(x) {if x\n[2]\n3 };",
521
+ { errors: "ambiguous newline (use \\ or ,) at (2, 1) found [" } ],
522
+ [ "function(x) {if x,\n[2]\n3 };",
523
+ "function (x) {\n"
524
+ " if x\n"
525
+ " [2]\n"
526
+ " 3\n"
527
+ "}" ],
528
+ [ "function(x) {if x\\\n[2]\n3 };",
529
+ "function (x) {\n"
530
+ " if x[2]\n"
531
+ " 3\n"
532
+ "}" ],
533
+ [ "function(x) {if x\n(2)\n3 };",
534
+ { errors: "ambiguous newline (use \\ or ,) at (2, 1) found (" } ],
517
535
  [ "function() { else };",
518
536
  { errors: "stray keyword at (1, 14) found else" } ],
519
537
  [ "function() { if 1 else 3 };",
520
- { errors: "stray keyword at (1, 19) found else"
521
- "|mismatched delimiter at (1, 24) found 3 expected } starting with { at (1, 12)" } ],
538
+ { errors: "stray keyword at (1, 19) found else" } ],
522
539
 
523
540
  //
524
541
  // semantic validity
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * column positioning: // // !
8
8
  *
9
- * Copyright (c) 2018-2021 by Richard C. Zulch
9
+ * Copyright (c) 2018-2023 by Richard C. Zulch
10
10
  *
11
11
  */
12
12
 
@@ -297,6 +297,27 @@ RegisterTestCategory("Lingo", [
297
297
  [ "aa[1] /= 2;", "3" ],
298
298
 
299
299
 
300
+ //
301
+ // catch
302
+ //
303
+
304
+ [ "try { throw(green) } catch { printline(4) };", "4|4" ],
305
+ [ "try { throw(blue) } catch { false(),printline(5) };", "5|5" ],
306
+ [ "try { 1/0 } catch {};", "false"],
307
+ [ "try { 1/0 } catch { 0 };", "0"],
308
+ [ "try { 1/0 } catch { exception };", '(internal, "divide by zero")'],
309
+ [ "try { 1/0 } catch { if exception == 3 4, printline(5) };",
310
+ { errors: "if expression required at (1, 42) found printline"} ],
311
+ [ "try { throw(blue) } catch { if exception == blue printline(blue) };", "blue|blue"],
312
+ [ "try { throw(green) } catch { if exception == blue printline(blue) };",
313
+ { errors: "exception: green" } ],
314
+ [ "try { throw(green) } catch { if exception == blue printline(blue),"
315
+ "if exception == green printline(green) };", "green|green"],
316
+ [ "try { throw(red) } catch { if exception == blue printline(blue),"
317
+ "if exception == green printline(green) };",
318
+ { errors: "exception: red" } ],
319
+
320
+
300
321
  //
301
322
  // if else
302
323
  //