@naanlang/naan 1.0.0 → 1.0.1

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/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Naan for NPM version 1.0.0-1 is released under the MIT License:
1
+ Naan for NPM version 1.0.1-2 is released under the MIT License:
2
2
 
3
3
  Copyright (c) 2017-2022 Zulch Laboratories, Inc.
4
4
 
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  Naan is an async-first software platform for rapid development.
5
5
 
6
6
  #### Release:
7
-      Naan for NPM version 1.0.0-1
7
+      Naan for NPM version 1.0.1-2
8
8
       Copyright (c) 2017-2022 Zulch Laboratories, Inc.
9
9
 
10
10
  #### Features
@@ -33,11 +33,40 @@ For use as a library in the current project:
33
33
 
34
34
  npm install naan
35
35
 
36
- #### Command line usage
36
+ #### Command line execution
37
37
 
38
- naan
38
+ naan [options] [source file] [arguments]
39
39
 
40
- ##### Dependencies:
40
+ With no arguments Naan runs as an interactive REPL using the node.js terminal.
41
+ It can also evaluate an expression or execute a source file.
42
+
43
+ ##### Command line usage
44
+
45
+ -h, --help print usage information
46
+ -e <expression> evaluate an expression
47
+ -i, --interactive use REPL with -e or [source file]
48
+ -v, --version print Naan version
49
+ -vv print Naan version with build number
50
+
51
+ Naan prints the results of evaluating each expression with the REPL, but not
52
+ by default with an expression or source file. The interactive flag overrides
53
+ this to print the result of each expression in all cases.
54
+
55
+ ##### Shell scripting
56
+
57
+ When installed globally, Naan can be used for shell scripts with the [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix))
58
+ mechanism. For example, copy the following text to a file named helloworld:
59
+
60
+ #!/usr/bin/env naan
61
+ printline("Hello World")
62
+
63
+ Now make it executable with chmod:
64
+
65
+ chmod a+x helloworld
66
+
67
+
68
+
69
+ #### Dependencies:
41
70
       We greatfully acknowlege these software packages used with Naan:
42
71
  - [jszip.js](http://stuartk.com/jszip) - read and write zip files
43
72
  - [NodeJS-path](https://nodejs.org/) - NodeJS path utilities
package/bin/index.js ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * index.js
4
+ * Naanlib
5
+ *
6
+ * Naan command line.
7
+ *
8
+ * column positioning: // // !
9
+ *
10
+ * Copyright (c) 2021-2022 by Richard C. Zulch
11
+ *
12
+ */
13
+
14
+ "use strict";
15
+
16
+ /*
17
+ * imports
18
+ *
19
+ */
20
+
21
+ var path = require("path");
22
+ var fs = require("fs");
23
+ var naanOptions;
24
+
25
+ /*
26
+ * Process command-line arguments
27
+ *
28
+ */
29
+
30
+ var cmd_file;
31
+ var eval_text;
32
+ var do_interactive;
33
+ var cmd_text = "nodeparse('node_repl_init.nlg');;\n";
34
+
35
+ process.argv.forEach((val, index) => {
36
+ if (index < 2)
37
+ return;
38
+ if (val == "-e") {
39
+ eval_text = 1;
40
+ return;
41
+ }
42
+ if (val == "-h" || val == "--help") {
43
+ console.log(
44
+ "Usage: naan [options] [source file] [arguments]\n\n" +
45
+ "Options:\n" +
46
+ " -e <expression> evaluate an expression\n" +
47
+ " -i, --interactive use REPL with -e or [source file]\n" +
48
+ " -v, --version print the Naan version\n" +
49
+ " -vv print the version and build\n"
50
+ );
51
+ process.exit(0);
52
+ }
53
+ if (val == "-i" || val == "--interactive") {
54
+ do_interactive = true;
55
+ return;
56
+ }
57
+ if (val == "-v" || val == "--version") {
58
+ console.log("1.0.1");
59
+ process.exit(0);
60
+ }
61
+ if (val == "-vv") {
62
+ console.log("1.0.1-2");
63
+ process.exit(0);
64
+ }
65
+ if (val.substring(0,1) == "-") {
66
+ console.log("naan: bad option: " + val);
67
+ process.exit(9);
68
+ }
69
+ if (eval_text) {
70
+ if (eval_text == 1)
71
+ eval_text = val + '\n';
72
+ return;
73
+ }
74
+ if (!cmd_file) {
75
+ cmd_file = val;
76
+ return;
77
+ }
78
+ // ignore extra arguments
79
+ });
80
+
81
+ if (eval_text == 1) {
82
+ console.log("naan: -e requires an argument");
83
+ process.exit(9);
84
+ }
85
+ if (cmd_file) {
86
+ if (!fs.existsSync(cmd_file)) {
87
+ console.log("naan: file not found: " + cmd_file);
88
+ process.exit(1);
89
+ }
90
+ eval_text = fs.readFileSync(cmd_file, "utf8");
91
+ eval_text = eval_text.replace(/^#!.*\n/, "");
92
+ }
93
+ if (eval_text) {
94
+ if (!do_interactive)
95
+ naanOptions = { replDisable: true };
96
+ cmd_text =
97
+ "closure NodeREPL(local input, error, expr) {\n" +
98
+ (do_interactive ?
99
+ ""
100
+ :
101
+ " sudo(putproc(`exception, false))\n") +
102
+ " input = new(textstream, js.expr)\n" +
103
+ " try {\n" +
104
+ " loop {\n" +
105
+ " `(error, expr) = Dialect.parse(input)\n" +
106
+ " if error {\n" +
107
+ " printline(' ==> parse error: ', Dialect.parseErrorString(error.0))\n" +
108
+ " break\n" +
109
+ " } else\n" +
110
+ (cmd_file && !do_interactive ?
111
+ " eval(expr)\n"
112
+ :
113
+ " {\n" +
114
+ " if input.tokenlast().atom == `;;\n" +
115
+ " eval(expr)\n" +
116
+ " else if input.tokenlast().atom == `;>\n" +
117
+ " printline(eval(expr))\n" +
118
+ " else\n" +
119
+ " printline(Dialect.print(eval(expr)))\n" +
120
+ " }\n") +
121
+ " }\n" +
122
+ " } catch {\n" +
123
+ " if true {\n" +
124
+ " if exception != `(internal, 'end-of-file')\n" +
125
+ " printline(' ==> exception: ', error = exception)\n" +
126
+ " }\n" +
127
+ " } finally {\n" +
128
+ " sleep(1)\n" +
129
+ " exec(quote(js.g.process.exit(if error 1 else 0)))\n" +
130
+ " }\n" +
131
+ "}();;\n";
132
+ }
133
+
134
+
135
+ /*
136
+ * Execute Naan
137
+ *
138
+ */
139
+
140
+ var NaanNodeREPL = require('../lib/env_node.js');
141
+ var naanrepl = new NaanNodeREPL(naanOptions);
142
+ naanrepl.setDirectory(path.join(__dirname, "../lib"));
143
+ if (eval_text)
144
+ naanrepl.setGlobal("expr", eval_text + "\n");
145
+ naanrepl.textCommand(cmd_text);