@naanlang/naan 1.0.0
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 +21 -0
- package/README.md +46 -0
- package/dist/env_web.js +431 -0
- package/dist/naan.min.js +73 -0
- package/frameworks/browser/browser.nlg +30 -0
- package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
- package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
- package/frameworks/browser/sworker.js +192 -0
- package/frameworks/browser/terminals.nlg +787 -0
- package/frameworks/browser/workers.nlg +386 -0
- package/frameworks/client/apiclient.nlg +183 -0
- package/frameworks/client/client.nlg +29 -0
- package/frameworks/client/psm_client.nlg +572 -0
- package/frameworks/common/common.nlg +464 -0
- package/frameworks/common/preferences.nlg +131 -0
- package/frameworks/common/repltools.nlg +100 -0
- package/frameworks/common/watching.nlg +97 -0
- package/frameworks/node/apiserver.nlg +399 -0
- package/frameworks/node/filesystem.nlg +1012 -0
- package/frameworks/node/gitter.nlg +234 -0
- package/frameworks/node/node.nlg +81 -0
- package/frameworks/node/psm_server.nlg +465 -0
- package/frameworks/node/worker.nlg +560 -0
- package/frameworks/project/build.nlg +1229 -0
- package/frameworks/project/jszip.js +30 -0
- package/frameworks/project/jszip.nlg +87 -0
- package/frameworks/project/proj_cliser.nlg +139 -0
- package/frameworks/project/proj_console.nlg +137 -0
- package/frameworks/project/proj_folder.nlg +143 -0
- package/frameworks/project/proj_lambda.nlg +137 -0
- package/frameworks/project/proj_static.nlg +138 -0
- package/frameworks/project/project.nlg +29 -0
- package/frameworks/project/projects.nlg +587 -0
- package/frameworks/project/uglifyjs.js +1 -0
- package/frameworks/project/uglifyjs.nlg +79 -0
- package/frameworks/running/debugcom.nlg +163 -0
- package/frameworks/running/debugnub.nlg +565 -0
- package/frameworks/running/debugutil.nlg +510 -0
- package/frameworks/running/executors.nlg +767 -0
- package/frameworks/running/running.nlg +151 -0
- package/frameworks/running/sourcecode.nlg +346 -0
- package/frameworks/running/taskexec.nlg +196 -0
- package/frameworks/storage/dbt_pouch.nlg +773 -0
- package/frameworks/storage/file_manager.nlg +772 -0
- package/frameworks/storage/psm.nlg +326 -0
- package/frameworks/storage/psm_dbtables.nlg +814 -0
- package/frameworks/storage/resources.nlg +445 -0
- package/frameworks/storage/storage.nlg +52 -0
- package/lib/browser/env_web.js +431 -0
- package/lib/browser/env_webworker.js +146 -0
- package/lib/browser/require.js +1653 -0
- package/lib/core/naanlib.js +73 -0
- package/lib/env_node.js +282 -0
- package/lib/env_nodeworker.js +165 -0
- package/lib/node_repl.js +25 -0
- package/lib/node_repl_init.nlg +52 -0
- package/package.json +13 -0
- package/plugins/gitClient/clientops.nlg +317 -0
- package/plugins/gitClient/gitClient.nlg +63 -0
- package/plugins/gitClient/gitutils.nlg +1331 -0
- package/plugins/gitClient/minimatch.js +945 -0
- package/plugins/gitClient/minimatch_license.txt +15 -0
- package/plugins/gitClient/minimatch_readme.md +208 -0
- package/plugins/nodeLib/nodeLib.nlg +26 -0
- package/plugins/nodeLib/node_cp.nlg +65 -0
- package/plugins/nodeLib/node_fs.nlg +137 -0
- package/plugins/nodeLib/node_https.nlg +172 -0
- package/plugins/nodeLib/node_util.nlg +180 -0
- package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
- package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
- package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
- package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
- package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
- package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
- package/plugins/serviceAws/aws_cognito.nlg +76 -0
- package/plugins/serviceAws/aws_dynamo.nlg +509 -0
- package/plugins/serviceAws/aws_lambda.nlg +95 -0
- package/plugins/serviceAws/aws_s3.nlg +134 -0
- package/plugins/serviceAws/aws_utils.nlg +86 -0
- package/plugins/serviceAws/dbt_aws.nlg +769 -0
- package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
- package/plugins/serviceAws/psm_aws.nlg +258 -0
- package/plugins/serviceAws/serviceAws.nlg +38 -0
- package/plugins/serviceGitHub/gitops.nlg +522 -0
- package/plugins/serviceGitHub/psm_github.nlg +205 -0
- package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
- package/plugins/serviceGitLab/gitops.nlg +528 -0
- package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
- package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
- package/test/harness.nlg +312 -0
- package/test/node_test.js +33 -0
- package/test/test_01_core.nlg +768 -0
- package/test/test_02_context.nlg +269 -0
- package/test/test_03_jsinterop.nlg +137 -0
- package/test/test_04_numerics.nlg +450 -0
- package/test/test_05_strings.nlg +63 -0
- package/test/test_06_lingoparse.nlg +500 -0
- package/test/test_07_lingo.nlg +623 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* test_06_lingoparse.nlg
|
|
3
|
+
* Test
|
|
4
|
+
*
|
|
5
|
+
* Perform basic unit tests for Naan.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2018-2021 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Test Category 6 - Lingo parse
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
RegisterTestCategory("Lingo parse", [
|
|
20
|
+
[ "4+3;", "7" ], // generic first test
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
//
|
|
24
|
+
// Simple expressions
|
|
25
|
+
//
|
|
26
|
+
|
|
27
|
+
[ "42;", { exprs: "42" } ],
|
|
28
|
+
[ "a;", { exprs: "a" } ],
|
|
29
|
+
[ "`b;", { exprs: "(`` b)" } ],
|
|
30
|
+
[ "`(a b c);", { exprs: "(`` (a b c))" } ],
|
|
31
|
+
|
|
32
|
+
//
|
|
33
|
+
// basic lists and dotted pairs
|
|
34
|
+
//
|
|
35
|
+
|
|
36
|
+
[ "`();>", "false" ],
|
|
37
|
+
[ "`);>", ")" ],
|
|
38
|
+
[ "`(a `.);>", "(a `.)" ],
|
|
39
|
+
[ "`(a `. b);>", "(a `. b)" ],
|
|
40
|
+
[ "`(a ``);>", "(a ``)" ],
|
|
41
|
+
[ "`(a `();>", "(a `()" ],
|
|
42
|
+
[ "`(a `));>", "(a `))" ],
|
|
43
|
+
[ "`(a `,);>", "(a `,)" ],
|
|
44
|
+
[ "`(a . false);>", "(a)" ],
|
|
45
|
+
[ "`(a . b);>", "(a . b)" ],
|
|
46
|
+
[ "`(a b . c);>", "(a b . c)" ],
|
|
47
|
+
[ "`(a . (b c));>", "(a b c)" ],
|
|
48
|
+
[ "`((a b) . (c d));>", "((a b) c d)" ],
|
|
49
|
+
[ "`((a . b) . (c d));>", "((a . b) c d)" ],
|
|
50
|
+
[ "`((a b) . (c . d));>", "((a b) c . d)" ],
|
|
51
|
+
|
|
52
|
+
//
|
|
53
|
+
// Basic operators
|
|
54
|
+
//
|
|
55
|
+
|
|
56
|
+
[ "a or b or c;", { exprs: "(or a b c)" } ],
|
|
57
|
+
[ "4+3*5;", { exprs: "(+ 4 (* 3 5))" } ],
|
|
58
|
+
|
|
59
|
+
//
|
|
60
|
+
// Newline termination
|
|
61
|
+
//
|
|
62
|
+
|
|
63
|
+
[ "4&&3;", { exprs: "(&& 4 3)" } ],
|
|
64
|
+
[ "4\n&&3;", { exprs: "(&& 4 3)" } ],
|
|
65
|
+
[ "4&&\n3;", { exprs: "(&& 4 3)" } ],
|
|
66
|
+
[ "function test0(x, y) { \n x \n y = 3 \n };", { exprs: "(defproc function test0 (x y) x (= y 3))" } ],
|
|
67
|
+
|
|
68
|
+
//
|
|
69
|
+
// Procedure types
|
|
70
|
+
//
|
|
71
|
+
|
|
72
|
+
[ "function test1() { };", { exprs: "(defproc function test1 false)" } ],
|
|
73
|
+
[ "function test1() { a+b };", { exprs: "(defproc function test1 false (+ a b))", text: "==> redefined: test1" } ],
|
|
74
|
+
[ "function test1(x) { };", { exprs: "(defproc function test1 (x))", text: "==> redefined: test1" } ],
|
|
75
|
+
[ "function test1(x) { x };", { exprs: "(defproc function test1 (x) x)", text: "==> redefined: test1" } ],
|
|
76
|
+
[ "function test1 x { };", { exprs: "(defproc function test1 x)", text: "==> redefined: test1" } ],
|
|
77
|
+
[ "function test1 x { x };", { exprs: "(defproc function test1 x x)", text: "==> redefined: test1" } ],
|
|
78
|
+
[ "function () { };", { exprs: "(function lambda false)" } ],
|
|
79
|
+
[ "function () { a+b };", { exprs: "(function lambda false (+ a b))" } ],
|
|
80
|
+
[ "function (x) { x };", { exprs: "(function lambda (x) x)" } ],
|
|
81
|
+
|
|
82
|
+
[ "macro test1() { };", { exprs: "(defproc macro test1 false)", text: "==> redefined: test1" } ],
|
|
83
|
+
[ "macro test1() { a+b };", { exprs: "(defproc macro test1 false (+ a b))", text: "==> redefined: test1" } ],
|
|
84
|
+
[ "macro test1(x) { };", { exprs: "(defproc macro test1 (x))", text: "==> redefined: test1" } ],
|
|
85
|
+
[ "macro test1(x) { x };", { exprs: "(defproc macro test1 (x) x)", text: "==> redefined: test1" } ],
|
|
86
|
+
[ "macro test1 x { };", { exprs: "(defproc macro test1 x)", text: "==> redefined: test1" } ],
|
|
87
|
+
[ "macro test1 x { x };", { exprs: "(defproc macro test1 x x)", text: "==> redefined: test1" } ],
|
|
88
|
+
[ "macro () { };", { exprs: "(macro lambda false)" } ],
|
|
89
|
+
[ "macro () { a+b };", { exprs: "(macro lambda false (+ a b))" } ],
|
|
90
|
+
[ "macro (x) { x };", { exprs: "(macro lambda (x) x)" } ],
|
|
91
|
+
|
|
92
|
+
[ "closure test1() { };", { exprs: "(defproc closure test1 false)", text: "==> redefined: test1" } ],
|
|
93
|
+
[ "closure test1() { a+b };", { exprs: "(defproc closure test1 false (+ a b))", text: "==> redefined: test1" } ],
|
|
94
|
+
[ "closure test1(x) { };", { exprs: "(defproc closure test1 (x))", text: "==> redefined: test1" } ],
|
|
95
|
+
[ "closure test1(x) { x };", { exprs: "(defproc closure test1 (x) x)", text: "==> redefined: test1" } ],
|
|
96
|
+
[ "closure test1 x { };", { exprs: "(defproc closure test1 x)", text: "==> redefined: test1" } ],
|
|
97
|
+
[ "closure test1 x { x };", { exprs: "(defproc closure test1 x x)", text: "==> redefined: test1" } ],
|
|
98
|
+
[ "closure () { };", { exprs: "(closure lambda false)" } ],
|
|
99
|
+
[ "closure () { a+b };", { exprs: "(closure lambda false (+ a b))" } ],
|
|
100
|
+
[ "closure (x) { x };", { exprs: "(closure lambda (x) x)" } ],
|
|
101
|
+
|
|
102
|
+
[ "function false() { };", { text: "cannot define function false in Namespace<Test-Lingo parse>" } ],
|
|
103
|
+
[ "function false(x) { x };", { text: "cannot define function false in Namespace<Test-Lingo parse>" } ],
|
|
104
|
+
[ "function false x { x };", { text: "cannot define function false in Namespace<Test-Lingo parse>" } ],
|
|
105
|
+
|
|
106
|
+
[ "function lambda() { };", { exprs: "(function lambda false)" } ],
|
|
107
|
+
[ "function lambda(x) { x };", { exprs: "(function lambda (x) x)" } ],
|
|
108
|
+
[ "function lambda x { x };", { exprs: "(function lambda x x)" } ],
|
|
109
|
+
|
|
110
|
+
[ "`(function test99);", { exprs: "(`` (function test99))" } ],
|
|
111
|
+
[ "`(macro test99);", { exprs: "(`` (macro test99))" } ],
|
|
112
|
+
[ "`(closure test99);", { exprs: "(`` (closure test99))" } ],
|
|
113
|
+
[ "`(a function test1);", { exprs: "(`` (a function test1))" } ],
|
|
114
|
+
[ "`(b macro test1);", { exprs: "(`` (b macro test1))" } ],
|
|
115
|
+
[ "`(c closure test1);", { exprs: "(`` (c closure test1))" } ],
|
|
116
|
+
|
|
117
|
+
[ "function () { function(x) { x+1 }() };", { exprs: "(function lambda false (call (function lambda (x) (+ x 1))))" } ],
|
|
118
|
+
|
|
119
|
+
//
|
|
120
|
+
// Defining procedures
|
|
121
|
+
//
|
|
122
|
+
|
|
123
|
+
[ "function true(a,b) { a+b };", { text: "cannot define function true in Namespace<Test-Lingo parse>" } ],
|
|
124
|
+
[ "macro true(a,b) { a+b };", { text: "cannot define macro true in Namespace<Test-Lingo parse>" } ],
|
|
125
|
+
[ "closure true(a,b) { a+b };", { text: "cannot define closure true in Namespace<Test-Lingo parse>" } ],
|
|
126
|
+
[ "function test() {\n"
|
|
127
|
+
" f(),\n" // ### remove comma to break everything
|
|
128
|
+
" (a - b) / 3\n"
|
|
129
|
+
"};\n", "test" ],
|
|
130
|
+
|
|
131
|
+
[ "function(){{spawn:function(){[{ok:true}]}}};", "function () {\n"
|
|
132
|
+
" {\n"
|
|
133
|
+
" spawn: function () {\n"
|
|
134
|
+
" [\n"
|
|
135
|
+
" { ok: true }]\n"
|
|
136
|
+
" }\n"
|
|
137
|
+
" }\n"
|
|
138
|
+
"}" ],
|
|
139
|
+
|
|
140
|
+
//
|
|
141
|
+
// Printing procedures
|
|
142
|
+
//
|
|
143
|
+
|
|
144
|
+
[ "quote(function () { function(x) { x+1 }() });", "function () {\n"
|
|
145
|
+
" function (x) {\n"
|
|
146
|
+
" x + 1\n"
|
|
147
|
+
" } ()\n"
|
|
148
|
+
"}" ],
|
|
149
|
+
[ "quote(function (a) { function(x) { x+1 }(a) });", "function (a) {\n"
|
|
150
|
+
" function (x) {\n"
|
|
151
|
+
" x + 1\n"
|
|
152
|
+
" } (a)\n"
|
|
153
|
+
"}" ],
|
|
154
|
+
|
|
155
|
+
//
|
|
156
|
+
// quoting
|
|
157
|
+
//
|
|
158
|
+
|
|
159
|
+
[ "`(a . b);", "(a . b)" ],
|
|
160
|
+
[ "`(a . b);", { exprs: "(`` (a . b))" } ],
|
|
161
|
+
[ "quote(`(a . b));", "`(a . b)" ],
|
|
162
|
+
[ "function() { `(a . b) };", { exprs: "(function lambda false (`` (a . b)))" } ],
|
|
163
|
+
[ "function() { `(c . d) };", "function () {\n"
|
|
164
|
+
" `(c . d)\n"
|
|
165
|
+
"}" ],
|
|
166
|
+
|
|
167
|
+
//
|
|
168
|
+
// and/or/not
|
|
169
|
+
//
|
|
170
|
+
|
|
171
|
+
[ "function (x,y) { if 1 <= 2 or 3 <= 4 or (y = 5) or 6 7 };",
|
|
172
|
+
{ exprs: "(function lambda (x y) ((or (<= 1 2) (<= 3 4) (= y 5) 6) 7))" } ],
|
|
173
|
+
[ "a or b or c or d;", { exprs: "(or a b c d)" } ],
|
|
174
|
+
[ "a or b or c or d or e;", { exprs: "(or a b c d e)" } ],
|
|
175
|
+
[ "a or b or (c or d) or e;", { exprs: "(or a b c d e)" } ],
|
|
176
|
+
[ "a or (b or c) or d or e;", { exprs: "(or a b c d e)" } ],
|
|
177
|
+
[ "(a or (b or c)) or d or e;", { exprs: "(or a b c d e)" } ],
|
|
178
|
+
[ "a or ((b or c) or d) or e;", { exprs: "(or a b c d e)" } ],
|
|
179
|
+
|
|
180
|
+
//
|
|
181
|
+
// if/else
|
|
182
|
+
//
|
|
183
|
+
|
|
184
|
+
[ "if a 1;", { exprs: "(cond ((identity a) 1))" } ],
|
|
185
|
+
[ "if a, -1;", { exprs: "(cond ((identity a) -1))" } ],
|
|
186
|
+
|
|
187
|
+
[ "function (){if c, (3) else if d 5};", { exprs: "(function lambda false ((identity c) 3) ((identity d) 5))" } ],
|
|
188
|
+
|
|
189
|
+
[ "function(expr) { if 1 expr };", { exprs: "(function lambda (expr) ((identity 1) expr))" } ],
|
|
190
|
+
|
|
191
|
+
[ "function () { if (1) {} else 2 };", { exprs: "(function lambda false ((identity 1)) 2)" } ],
|
|
192
|
+
|
|
193
|
+
[ "function (x) { if atom(x) { x = x + 1, x } };", { exprs: "(function lambda (x) ((atom x) (= x (+ x 1)) x))" } ],
|
|
194
|
+
|
|
195
|
+
[ "function test2(x) { if x > 9 print("big1") };",
|
|
196
|
+
{ exprs: "(defproc function test2 (x) ((> x 9) (print "big1")))" } ],
|
|
197
|
+
|
|
198
|
+
[ "function test2(x) { if x > 9 print("big2"), print(x) };",
|
|
199
|
+
{ exprs: "(defproc function test2 (x) (((> x 9) (print "big2"))) (print x))",
|
|
200
|
+
text: "==> redefined: test2" } ],
|
|
201
|
+
|
|
202
|
+
[ "function test2(x) { if x > 9 print("big3") else if x > 1 print("small") };",
|
|
203
|
+
{ exprs: "(defproc function test2 (x) ((> x 9) (print "big3")) ((> x 1) (print "small")))",
|
|
204
|
+
text: "==> redefined: test2" } ],
|
|
205
|
+
|
|
206
|
+
[ "function test2(x) { if x > 9 print("big4") else if x > 1 print("small"), print(x) };",
|
|
207
|
+
{ exprs: "(defproc function test2 (x) (((> x 9) (print "big4")) ((> x 1) (print "small"))) (print x))",
|
|
208
|
+
text: "==> redefined: test2" } ],
|
|
209
|
+
|
|
210
|
+
[ "function test2(x) { if x > 9 { print("big5"), print("bigger") } else if x > 1 print("small") };",
|
|
211
|
+
{ exprs: "(defproc function test2 (x) ((> x 9) (print "big5") (print "bigger")) ((> x 1) (print "small")))",
|
|
212
|
+
text: "==> redefined: test2" } ],
|
|
213
|
+
|
|
214
|
+
[ "function test2(x) { if x > 9 print("big6") else if x > 1 { print("small"), print("smaller") }};",
|
|
215
|
+
{ exprs: "(defproc function test2 (x) ((> x 9) (print "big6")) ((> x 1) (print "small") (print "smaller")))",
|
|
216
|
+
text: "==> redefined: test2" } ],
|
|
217
|
+
|
|
218
|
+
[ "function test2(x) { if x > 9 { print("big7"), print("bigger") } else if x > 1 { print("small"), print("smaller") }};",
|
|
219
|
+
{ exprs: "(defproc function test2 (x) ((> x 9) (print "big7") (print "bigger")) ((> x 1) (print "small") (print "smaller")))",
|
|
220
|
+
text: "==> redefined: test2" } ],
|
|
221
|
+
|
|
222
|
+
[ "function () { if 1 2 };",
|
|
223
|
+
{ exprs: "(function lambda false ((identity 1) 2))" } ],
|
|
224
|
+
|
|
225
|
+
[ "function () { if 1 2 else 3 };",
|
|
226
|
+
{ exprs: "(function lambda false ((identity 1) 2) 3)" } ],
|
|
227
|
+
|
|
228
|
+
[ "function () { if 1 { 2 } else 3 };",
|
|
229
|
+
{ exprs: "(function lambda false ((identity 1) 2) 3)" } ],
|
|
230
|
+
|
|
231
|
+
[ "function () { if 1 2 else { 3 } };",
|
|
232
|
+
{ exprs: "(function lambda false ((identity 1) 2) 3)" } ],
|
|
233
|
+
|
|
234
|
+
[ "function () { if 1 { 2 } else { 3 } };",
|
|
235
|
+
{ exprs: "(function lambda false ((identity 1) 2) 3)" } ],
|
|
236
|
+
|
|
237
|
+
[ "function () { if 1 2 else if 3 4 };",
|
|
238
|
+
{ exprs: "(function lambda false ((identity 1) 2) ((identity 3) 4))" } ],
|
|
239
|
+
|
|
240
|
+
[ "function () { if 1 2 else if 3 { 4 } };",
|
|
241
|
+
{ exprs: "(function lambda false ((identity 1) 2) ((identity 3) 4))" } ],
|
|
242
|
+
|
|
243
|
+
[ "function () { if 1 2 else if 3 4 else 5 };",
|
|
244
|
+
{ exprs: "(function lambda false ((identity 1) 2) ((identity 3) 4) 5)" } ],
|
|
245
|
+
|
|
246
|
+
[ "function () { if 1 2 else if 3 4 else 5, 6 };",
|
|
247
|
+
{ exprs: "(function lambda false (((identity 1) 2) ((identity 3) 4) 5) 6)" } ],
|
|
248
|
+
|
|
249
|
+
[ "function() { if 1 2 else { if 3 4, 5} };",
|
|
250
|
+
{ exprs: "(function lambda false ((identity 1) 2) (((identity 3) 4)) 5)" } ],
|
|
251
|
+
|
|
252
|
+
[ "function() { if 1 2 else { if 3 4, 5}, 6 };",
|
|
253
|
+
{ exprs: "(function lambda false (((identity 1) 2) (((identity 3) 4)) 5) 6)" } ],
|
|
254
|
+
|
|
255
|
+
[ "function () { if 1 if 2 3 };",
|
|
256
|
+
{ exprs: "(function lambda false ((identity 1) ((identity 2) 3)))" } ],
|
|
257
|
+
|
|
258
|
+
[ "function () { if 1 if 2 3 else 4 };",
|
|
259
|
+
{ exprs: "(function lambda false ((identity 1) ((identity 2) 3) 4))" } ],
|
|
260
|
+
|
|
261
|
+
[ "function() { if 1 { } else f({ root: 2 }) };",
|
|
262
|
+
{ exprs: "(function lambda false ((identity 1)) (f Dictionary{1}))" } ],
|
|
263
|
+
|
|
264
|
+
[ "function(a,b) {if a>b {-1} else 0};",
|
|
265
|
+
{ exprs: "(function lambda (a b) ((> a b) -1) 0)" } ],
|
|
266
|
+
|
|
267
|
+
[ "function() { if 1 2 else { if 3 4, 5}, 6 };",
|
|
268
|
+
"function () {\n"
|
|
269
|
+
" if 1\n"
|
|
270
|
+
" 2\n"
|
|
271
|
+
" else {\n"
|
|
272
|
+
" if 3\n"
|
|
273
|
+
" 4\n"
|
|
274
|
+
" 5 }\n"
|
|
275
|
+
" 6\n"
|
|
276
|
+
"}" ],
|
|
277
|
+
|
|
278
|
+
//
|
|
279
|
+
// loop
|
|
280
|
+
//
|
|
281
|
+
|
|
282
|
+
[ "loop{if 1 break};",
|
|
283
|
+
{ exprs: "(loop false ((identity 1)))" } ],
|
|
284
|
+
[ "function(){loop{if 1 break}};",
|
|
285
|
+
{ exprs: "(function lambda false (loop false ((identity 1))))" } ],
|
|
286
|
+
|
|
287
|
+
[ "loop{if 1 break else 2};",
|
|
288
|
+
{ exprs: "(loop false (((identity 1) (break)) 2))" } ],
|
|
289
|
+
[ "function(){loop{if 1 break else 2}};",
|
|
290
|
+
{ exprs: "(function lambda false (loop false (((identity 1) (break)) 2)))" } ],
|
|
291
|
+
|
|
292
|
+
[ "function test2(x) { loop { if x > 3 break, printline(\"loop \", x), x = x+1 } };",
|
|
293
|
+
{ exprs: "(defproc function test2 (x) (loop false ((> x 3)) (printline \"loop \" x) (= x (+ x 1))))",
|
|
294
|
+
text: "==> redefined: test2" } ],
|
|
295
|
+
|
|
296
|
+
[ "function test2(x) { loop { if x > 3 { print(\"done\"), break }, printline(\"loop \", x), x = x+1 } };",
|
|
297
|
+
{ exprs: "(defproc function test2 (x) (loop false ((> x 3) (print \"done\")) (printline \"loop \" x) (= x (+ x 1))))",
|
|
298
|
+
text: "==> redefined: test2" } ],
|
|
299
|
+
|
|
300
|
+
[ "function test2(x) { loop { if x > 3 print(\"done\"), break, printline(\"loop \", x), x = x+1 } };",
|
|
301
|
+
{ exprs: "(defproc function test2 (x) (loop false (((> x 3) (print \"done\"))) (break) (printline \"loop \" x) (= x (+ x 1))))",
|
|
302
|
+
text: "==> redefined: test2" } ],
|
|
303
|
+
|
|
304
|
+
[ "function test2(x) { loop { if x > 3 if x > 2 { print(\"done\"), break }, printline(\"loop \", x), x = x+1 } };",
|
|
305
|
+
{ exprs: "(defproc function test2 (x) (loop false (((> x 3) ((> x 2) (print \"done\") (break)))) (printline \"loop \" x) (= x (+ x 1))))",
|
|
306
|
+
text: "==> redefined: test2" } ],
|
|
307
|
+
|
|
308
|
+
[ "function test2(x) { loop { if x > 4 {print(\"done\"), break}, printline(\"loop \", x), x = x+1, print(\" \")} };",
|
|
309
|
+
{ exprs: "(defproc function test2 (x) (loop false ((> x 4) (print \"done\")) (printline \"loop \" x) (= x (+ x 1)) (print \" \")))",
|
|
310
|
+
text: "==> redefined: test2" } ],
|
|
311
|
+
|
|
312
|
+
[ "function test2(x) { loop { if x > 3 { if x > 2 print(\"done\"), break }, printline(\"loop \", x), x = x+1 } };",
|
|
313
|
+
{ exprs: "(defproc function test2 (x) (loop false (((> x 3) (((> x 2) (print \"done\"))) (break))) (printline \"loop \" x) (= x (+ x 1))))",
|
|
314
|
+
text: "==> redefined: test2" } ],
|
|
315
|
+
|
|
316
|
+
[ "function test2(x) { loop { if x <= 3 print(\" \") else break, printline(\"loop \", x), x = x+1 } };",
|
|
317
|
+
{ exprs: "(defproc function test2 (x) (loop false (((<= x 3) (print \" \")) (break)) (printline \"loop \" x) (= x (+ x 1))))",
|
|
318
|
+
text: "==> redefined: test2" } ],
|
|
319
|
+
|
|
320
|
+
[ "function test2(x) { loop { if x > 3 { if x > 2 { print(\"done\"), break }, print(\" \")} , printline(\"loop \", x), x = x+1 } };",
|
|
321
|
+
{ exprs: "(defproc function test2 (x) (loop false (((> x 3) (((> x 2) (print \"done\") (break))) (print \" \"))) (printline \"loop \" x) (= x (+ x 1))))",
|
|
322
|
+
text: "==> redefined: test2" } ],
|
|
323
|
+
|
|
324
|
+
[ "function test3() { loop { if 1 < 2 3 else break, print }};",
|
|
325
|
+
{ exprs: "(defproc function test3 false (loop false (((< 1 2) 3) (break)) print))" } ],
|
|
326
|
+
|
|
327
|
+
[ "function test3() { loop { if 1 < 2 3 else continue, print }};",
|
|
328
|
+
{ exprs: "(defproc function test3 false (loop false (((< 1 2) 3) (continue)) print))",
|
|
329
|
+
text: "==> redefined: test3" } ],
|
|
330
|
+
|
|
331
|
+
[ "function test4() { loop { if 1 < 2 break, 4 }};",
|
|
332
|
+
{ exprs: "(defproc function test4 false (loop false ((< 1 2)) 4))" } ],
|
|
333
|
+
|
|
334
|
+
[ "function test4() { loop { if 1 < 2 { 3, break }, 4 }};",
|
|
335
|
+
{ exprs: "(defproc function test4 false (loop false ((< 1 2) 3) 4))",
|
|
336
|
+
text: "==> redefined: test4" } ],
|
|
337
|
+
|
|
338
|
+
[ "function() { loop { if 1 break, 2} };",
|
|
339
|
+
{ exprs: "(function lambda false (loop false ((identity 1)) 2))" } ],
|
|
340
|
+
[ "function(x) { x = loop { if 1 break, 2 } };",
|
|
341
|
+
{ exprs: "(function lambda (x) (= x (loop false ((identity 1)) 2)))" } ],
|
|
342
|
+
|
|
343
|
+
[ "function(x) { if x 2 else if y 3 };",
|
|
344
|
+
{ exprs: "(function lambda (x) ((identity x) 2) ((identity y) 3))" } ],
|
|
345
|
+
|
|
346
|
+
[ "function(x) { loop { if x 2 else if y 3 } };",
|
|
347
|
+
{ exprs: "(function lambda (x) (loop false (((identity x) 2) ((identity y) 3))))" } ],
|
|
348
|
+
|
|
349
|
+
[ "function() { if 1 { 2, loop { if 3 4 }, 5 } };",
|
|
350
|
+
{ exprs: "(function lambda false ((identity 1) 2 (loop false (((identity 3) 4))) 5))" } ],
|
|
351
|
+
[ "function() { if 1 { 2, loop { if 3 4 }, 5 } };",
|
|
352
|
+
"function () {\n"
|
|
353
|
+
" if 1 {\n"
|
|
354
|
+
" 2\n"
|
|
355
|
+
" loop\n"
|
|
356
|
+
" if 3\n"
|
|
357
|
+
" 4\n"
|
|
358
|
+
" 5 }\n"
|
|
359
|
+
"}" ],
|
|
360
|
+
|
|
361
|
+
//
|
|
362
|
+
// while
|
|
363
|
+
//
|
|
364
|
+
|
|
365
|
+
[ "function () { while 1 2 };",
|
|
366
|
+
{ exprs: "(function lambda false (while false ((not 1)) 2))" } ],
|
|
367
|
+
|
|
368
|
+
[ "function () { while 1 { 2 } };",
|
|
369
|
+
{ exprs: "(function lambda false (while false ((not 1)) 2))" } ],
|
|
370
|
+
|
|
371
|
+
[ "function () { while 1 A() };",
|
|
372
|
+
{ exprs: "(function lambda false (while false ((not 1)) (A)))" } ],
|
|
373
|
+
|
|
374
|
+
[ "function () { while 1 { A() } };",
|
|
375
|
+
{ exprs: "(function lambda false (while false ((not 1)) (A)))" } ],
|
|
376
|
+
|
|
377
|
+
[ "function () { while:tag 1 { A() } };",
|
|
378
|
+
{ exprs: "(function lambda false (while tag ((not 1)) (A)))" } ],
|
|
379
|
+
|
|
380
|
+
[ "function wtest(n local x) { x = 0, while x <= n { print(x), x=x+1 }};",
|
|
381
|
+
{ exprs: "(defproc function wtest (n false x) (= x 0) (while false ((not (<= x n))) (print x) (= x (+ x 1))))" } ],
|
|
382
|
+
|
|
383
|
+
[ "while x < 10 { print(x++, space), if x==8 break };",
|
|
384
|
+
{ exprs: "(while false ((not (< x 10))) (print (postadjust x + 1) space) (((== x 8) (break))))" } ],
|
|
385
|
+
|
|
386
|
+
[ "quote(while x < 10 { print(x++, space), if x==8 break });",
|
|
387
|
+
"while x < 10 {\n"
|
|
388
|
+
" print(x++, space)\n"
|
|
389
|
+
" if x == 8\n"
|
|
390
|
+
" break\n"
|
|
391
|
+
"}" ],
|
|
392
|
+
|
|
393
|
+
[ "quote(while x < 10 print(x++, space));",
|
|
394
|
+
"while x < 10\n"
|
|
395
|
+
" print(x++, space)" ],
|
|
396
|
+
|
|
397
|
+
//
|
|
398
|
+
// for
|
|
399
|
+
//
|
|
400
|
+
|
|
401
|
+
[ "for x in `(a b c) print(x);",
|
|
402
|
+
{ exprs: "(for (let lambda (iter) (= iter (iterate (`` (a b c)) (`` x))) (loop false ((`. iter \"next\" (iter)) (`. iter \"final\" (iter))) (= x (`. iter \"value\")) (print x))))",
|
|
403
|
+
text: "abc" } ],
|
|
404
|
+
|
|
405
|
+
[ "for:gg x in `(a b c) print(x);",
|
|
406
|
+
{ exprs: "(for (let lambda (iter) (= iter (iterate (`` (a b c)) (`` x))) (loop gg ((`. iter \"next\" (iter)) (`. iter \"final\" (iter))) (= x (`. iter \"value\")) (print x))))",
|
|
407
|
+
text: "abc" } ],
|
|
408
|
+
|
|
409
|
+
[ "for:gg x in `(a b c) {print(x),print(y)};",
|
|
410
|
+
{ exprs: "(for (let lambda (iter) (= iter (iterate (`` (a b c)) (`` x))) (loop gg ((`. iter \"next\" (iter)) (`. iter \"final\" (iter))) (= x (`. iter \"value\")) (print x) (print y))))",
|
|
411
|
+
text: "aybycy" } ],
|
|
412
|
+
[ "quote(for:gg x in `(a b c) {print(x),print(y)});",
|
|
413
|
+
"for :gg x in `(a, b, c) {\n"
|
|
414
|
+
" print(x)\n"
|
|
415
|
+
" print(y)\n"
|
|
416
|
+
"}" ],
|
|
417
|
+
|
|
418
|
+
//
|
|
419
|
+
// Return/continue/break
|
|
420
|
+
//
|
|
421
|
+
|
|
422
|
+
[ "return;", { exprs: "(return)" } ],
|
|
423
|
+
[ "return (777);", { exprs: "(return 777)" } ],
|
|
424
|
+
[ "function test4() { loop :dumb { if 1 < 2 { 3, break :dumb }, 4 }};",
|
|
425
|
+
{ exprs: "(defproc function test4 false (loop dumb (((< 1 2) 3 (break dumb))) 4))",
|
|
426
|
+
text: "==> redefined: test4" } ],
|
|
427
|
+
[ "function test4() { loop :smart { if 1 < 2 { 3, continue :smart }, 4 }};",
|
|
428
|
+
{ exprs: "(defproc function test4 false (loop smart (((< 1 2) 3 (continue smart))) 4))",
|
|
429
|
+
text: "==> redefined: test4" } ],
|
|
430
|
+
|
|
431
|
+
//
|
|
432
|
+
// Try/catch/throw
|
|
433
|
+
//
|
|
434
|
+
|
|
435
|
+
[ "try { print(\"try\") } finally { print(\"finally\") };",
|
|
436
|
+
{ exprs: "(catch ((print \"try\")) false ((print \"finally\")))",
|
|
437
|
+
text: "tryfinally" } ],
|
|
438
|
+
[ "try{nest()}finally{};",
|
|
439
|
+
{ exprs: "(catch ((nest)) false false)" } ],
|
|
440
|
+
[ "try{nest()}catch{}finally{};",
|
|
441
|
+
{ exprs: "(catch ((nest)) (((identity true))) false)" } ],
|
|
442
|
+
[ "function test1() { try { nest() } finally { } };",
|
|
443
|
+
{ exprs: "(defproc function test1 false (catch ((nest)) false false))",
|
|
444
|
+
text: "==> redefined: test1" } ],
|
|
445
|
+
[ "function(){try{nest()}catch{},if(1)2};",
|
|
446
|
+
{ exprs: "(function lambda false (catch ((nest)) (((identity true))) false) ((identity 1) 2))" } ],
|
|
447
|
+
[ "function(x) { try {} catch { if true { 4 } } };",
|
|
448
|
+
{ exprs: "(function lambda (x) (catch false (((identity true) 4)) false))" } ],
|
|
449
|
+
|
|
450
|
+
//
|
|
451
|
+
// cond
|
|
452
|
+
//
|
|
453
|
+
|
|
454
|
+
[ "cond(if 1 2);",
|
|
455
|
+
{ exprs: "(cond ((identity 1) 2))" } ],
|
|
456
|
+
[ "cond(if 1 2, if 3 4);",
|
|
457
|
+
{ exprs: "(cond ((identity 1) 2) ((identity 3) 4))" } ],
|
|
458
|
+
|
|
459
|
+
//
|
|
460
|
+
// dereference
|
|
461
|
+
//
|
|
462
|
+
|
|
463
|
+
[ "a[b,c];>", "(Lib::dereflist a (b c))" ],
|
|
464
|
+
[ "a[b,c];", "a[b,c]" ],
|
|
465
|
+
|
|
466
|
+
//
|
|
467
|
+
// parser/unparser ambiguities
|
|
468
|
+
//
|
|
469
|
+
|
|
470
|
+
[ "function() {test()[3]};>", "(function lambda false (deref (test) 3))"],
|
|
471
|
+
[ "function() {test()\n[3]};>", "(function lambda false (deref (test) 3))"],
|
|
472
|
+
[ "function() {test(),\n[3]};>", "(function lambda false (test) Array[1])"],
|
|
473
|
+
[ "function() {test(),\n[3]};", "function () {\n"
|
|
474
|
+
" test(),\n" // need comma before array
|
|
475
|
+
" [3]\n"
|
|
476
|
+
"}"],
|
|
477
|
+
[ "function(){\n[3]};", "function () {\n"
|
|
478
|
+
" [3]\n" // don't need comma before array
|
|
479
|
+
"}"],
|
|
480
|
+
[ "function() {if 1 { { a:3 } } };", "function () {\n"
|
|
481
|
+
" if 1 {\n"
|
|
482
|
+
" { a: 3 } }\n" // need braces around dictionary
|
|
483
|
+
"}" ],
|
|
484
|
+
[ "function() {if 1 2 };", "function () {\n"
|
|
485
|
+
" if 1\n"
|
|
486
|
+
" 2\n"
|
|
487
|
+
"}" ],
|
|
488
|
+
[ "function() {if 1 2 else 3 };", "function () {\n"
|
|
489
|
+
" if 1\n"
|
|
490
|
+
" 2\n"
|
|
491
|
+
" else\n"
|
|
492
|
+
" 3\n"
|
|
493
|
+
"}" ],
|
|
494
|
+
[ "function() {if 1 2 else { { a:3 } } };", "function () {\n"
|
|
495
|
+
" if 1\n"
|
|
496
|
+
" 2\n"
|
|
497
|
+
" else {\n"
|
|
498
|
+
" { a: 3 } }\n" // need braces around dictionary
|
|
499
|
+
"}" ],
|
|
500
|
+
]);
|