nadesiko3 3.3.63 → 3.3.64
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/batch/command.txt +15 -15
- package/core/package.json +4 -1
- package/core/src/nako3.mjs +5 -2
- package/core/src/nako3.mts +5 -4
- package/core/src/nako_core_version.mjs +2 -2
- package/core/src/nako_core_version.mts +2 -2
- package/core/src/nako_from_dncl.mjs +0 -254
- package/core/src/nako_from_dncl.mts +0 -247
- package/core/src/nako_from_dncl2.mjs +313 -0
- package/core/src/nako_from_dncl2.mts +299 -0
- package/core/src/nako_gen.mjs +1 -1
- package/core/src/nako_gen.mts +1 -1
- package/core/src/nako_indent_inline.mjs +152 -34
- package/core/src/nako_indent_inline.mts +132 -34
- package/core/src/nako_lex_rules.mjs +3 -2
- package/core/src/nako_lex_rules.mts +3 -2
- package/core/src/nako_lexer.mjs +27 -3
- package/core/src/nako_lexer.mts +27 -3
- package/core/src/nako_parser3.mjs +45 -14
- package/core/src/nako_parser3.mts +40 -18
- package/core/src/nako_prepare.mjs +13 -0
- package/core/src/nako_prepare.mts +11 -0
- package/core/src/nako_tools.mjs +53 -0
- package/core/src/nako_tools.mts +46 -0
- package/core/test/basic_test.mjs +16 -8
- package/core/test/dncl2_test.mjs +207 -0
- package/core/test/flow_test.mjs +42 -0
- package/core/test/indent_test.mjs +74 -50
- package/core/test/inline_indent_test.mjs +47 -0
- package/core/test/lex_test.mjs +1 -0
- package/demo/js/a.js +30 -0
- package/package.json +1 -1
- package/release/_hash.txt +16 -16
- package/release/_script-tags.txt +14 -14
- package/release/nako_gen_async.js +1 -1
- package/release/stats.json +1 -1
- package/release/version.js +1 -1
- package/release/wnako3.js +1 -1
- package/release/wnako3webworker.js +1 -1
- package/src/cnako3mod.mjs +43 -33
- package/src/cnako3mod.mts +45 -35
- package/src/nako_version.mjs +2 -2
- package/src/nako_version.mts +2 -2
- package/src/plugin_browser_canvas.mjs +5 -0
package/src/cnako3mod.mjs
CHANGED
|
@@ -59,7 +59,8 @@ export class CNako3 extends NakoCompiler {
|
|
|
59
59
|
.option('-b, --browsers', '対応機器/Webブラウザを表示する')
|
|
60
60
|
.option('-m, --man [command]', 'マニュアルを表示する')
|
|
61
61
|
.option('-p, --speed', 'スピード優先モードの指定')
|
|
62
|
-
.option('-A, --ast', '
|
|
62
|
+
.option('-A, --ast', '構文解析した結果をASTで出力する')
|
|
63
|
+
.option('-X, --lex', '字句解析した結果をJSONで出力する')
|
|
63
64
|
// .option('-h, --help', '使い方を表示する')
|
|
64
65
|
// .option('-v, --version', 'バージョンを表示する')
|
|
65
66
|
.parse(process.argv);
|
|
@@ -94,7 +95,8 @@ export class CNako3 extends NakoCompiler {
|
|
|
94
95
|
test: app.test || false,
|
|
95
96
|
browsers: app.browsers || false,
|
|
96
97
|
speed: app.speed || false,
|
|
97
|
-
ast: app.ast || false
|
|
98
|
+
ast: app.ast || false,
|
|
99
|
+
lex: app.lex || false,
|
|
98
100
|
};
|
|
99
101
|
args.mainfile = app.args[0];
|
|
100
102
|
args.output = app.output;
|
|
@@ -154,6 +156,12 @@ export class CNako3 extends NakoCompiler {
|
|
|
154
156
|
await this.nakoCompile(opt, src, false);
|
|
155
157
|
return;
|
|
156
158
|
}
|
|
159
|
+
// 字句解析の結果をJSONで出力
|
|
160
|
+
if (opt.lex) {
|
|
161
|
+
const lex = this.lex(src, opt.mainfile);
|
|
162
|
+
console.log(this.outputJSON(lex, 0));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
157
165
|
// ASTを出力する
|
|
158
166
|
if (opt.ast) {
|
|
159
167
|
try {
|
|
@@ -287,10 +295,9 @@ export class CNako3 extends NakoCompiler {
|
|
|
287
295
|
}
|
|
288
296
|
}
|
|
289
297
|
/**
|
|
290
|
-
*
|
|
298
|
+
* JSONを出力
|
|
291
299
|
*/
|
|
292
|
-
|
|
293
|
-
const ast = this.parse(src, opt.mainfile);
|
|
300
|
+
outputJSON(ast, level) {
|
|
294
301
|
const makeIndent = (level) => {
|
|
295
302
|
let s = '';
|
|
296
303
|
for (let i = 0; i < level; i++) {
|
|
@@ -299,35 +306,38 @@ export class CNako3 extends NakoCompiler {
|
|
|
299
306
|
return s;
|
|
300
307
|
};
|
|
301
308
|
const trim = (s) => { return s.replace(/(^\s+|\s+$)/g, ''); };
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
if (typeof (ast) === 'number') {
|
|
308
|
-
return makeIndent(level) + ast;
|
|
309
|
-
}
|
|
310
|
-
if (ast instanceof Array) {
|
|
311
|
-
const s = makeIndent(level) + '[\n';
|
|
312
|
-
const sa = [];
|
|
313
|
-
ast.forEach((a) => {
|
|
314
|
-
sa.push(outAST(a, level + 1));
|
|
315
|
-
});
|
|
316
|
-
return s + sa.join(',\n') + '\n' + makeIndent(level) + ']';
|
|
317
|
-
}
|
|
318
|
-
if (ast instanceof Object) {
|
|
319
|
-
const s = makeIndent(level) + '{\n';
|
|
320
|
-
const sa = [];
|
|
321
|
-
for (const key in ast) {
|
|
322
|
-
const sv = trim(outAST(ast[key], level + 1));
|
|
323
|
-
const so = makeIndent(level + 1) + '"' + key + '": ' + sv;
|
|
324
|
-
sa.push(so);
|
|
325
|
-
}
|
|
326
|
-
return s + sa.join(',\n') + '\n' + makeIndent(level) + '}';
|
|
327
|
-
}
|
|
309
|
+
if (typeof (ast) === 'string') {
|
|
310
|
+
return makeIndent(level) + '"' + ast + '"';
|
|
311
|
+
}
|
|
312
|
+
if (typeof (ast) === 'number') {
|
|
328
313
|
return makeIndent(level) + ast;
|
|
329
|
-
}
|
|
330
|
-
|
|
314
|
+
}
|
|
315
|
+
if (ast instanceof Array) {
|
|
316
|
+
const s = makeIndent(level) + '[\n';
|
|
317
|
+
const sa = [];
|
|
318
|
+
ast.forEach((a) => {
|
|
319
|
+
sa.push(this.outputJSON(a, level + 1));
|
|
320
|
+
});
|
|
321
|
+
return s + sa.join(',\n') + '\n' + makeIndent(level) + ']';
|
|
322
|
+
}
|
|
323
|
+
if (ast instanceof Object) {
|
|
324
|
+
const s = makeIndent(level) + '{\n';
|
|
325
|
+
const sa = [];
|
|
326
|
+
for (const key in ast) {
|
|
327
|
+
const sv = trim(this.outputJSON(ast[key], level + 1));
|
|
328
|
+
const so = makeIndent(level + 1) + '"' + key + '": ' + sv;
|
|
329
|
+
sa.push(so);
|
|
330
|
+
}
|
|
331
|
+
return s + sa.join(',\n') + '\n' + makeIndent(level) + '}';
|
|
332
|
+
}
|
|
333
|
+
return makeIndent(level) + ast;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* ASTを出力
|
|
337
|
+
*/
|
|
338
|
+
outputAST(opt, src) {
|
|
339
|
+
const ast = this.parse(src, opt.mainfile);
|
|
340
|
+
console.log(this.outputJSON(ast, 0));
|
|
331
341
|
}
|
|
332
342
|
// REPL(対話実行環境)の場合
|
|
333
343
|
async cnakoRepl(_opt) {
|
package/src/cnako3mod.mts
CHANGED
|
@@ -40,6 +40,7 @@ interface CNako3ArgOptions {
|
|
|
40
40
|
man: string
|
|
41
41
|
browsers: boolean
|
|
42
42
|
ast: boolean
|
|
43
|
+
lex: boolean
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
interface CNako3Options {
|
|
@@ -92,7 +93,8 @@ export class CNako3 extends NakoCompiler {
|
|
|
92
93
|
.option('-b, --browsers', '対応機器/Webブラウザを表示する')
|
|
93
94
|
.option('-m, --man [command]', 'マニュアルを表示する')
|
|
94
95
|
.option('-p, --speed', 'スピード優先モードの指定')
|
|
95
|
-
.option('-A, --ast', '
|
|
96
|
+
.option('-A, --ast', '構文解析した結果をASTで出力する')
|
|
97
|
+
.option('-X, --lex', '字句解析した結果をJSONで出力する')
|
|
96
98
|
// .option('-h, --help', '使い方を表示する')
|
|
97
99
|
// .option('-v, --version', 'バージョンを表示する')
|
|
98
100
|
.parse(process.argv)
|
|
@@ -128,7 +130,8 @@ export class CNako3 extends NakoCompiler {
|
|
|
128
130
|
test: app.test || false,
|
|
129
131
|
browsers: app.browsers || false,
|
|
130
132
|
speed: app.speed || false,
|
|
131
|
-
ast: app.ast || false
|
|
133
|
+
ast: app.ast || false,
|
|
134
|
+
lex: app.lex || false,
|
|
132
135
|
}
|
|
133
136
|
args.mainfile = app.args[0]
|
|
134
137
|
args.output = app.output
|
|
@@ -159,7 +162,7 @@ export class CNako3 extends NakoCompiler {
|
|
|
159
162
|
// 実行する
|
|
160
163
|
async execCommand () {
|
|
161
164
|
// コマンドを解析
|
|
162
|
-
const opt = this.checkArguments()
|
|
165
|
+
const opt: CNako3ArgOptions = this.checkArguments()
|
|
163
166
|
// 使い方の表示か?
|
|
164
167
|
if (opt.man) {
|
|
165
168
|
this.cnakoMan(opt.man)
|
|
@@ -188,7 +191,12 @@ export class CNako3 extends NakoCompiler {
|
|
|
188
191
|
await this.nakoCompile(opt, src, false)
|
|
189
192
|
return
|
|
190
193
|
}
|
|
191
|
-
|
|
194
|
+
// 字句解析の結果をJSONで出力
|
|
195
|
+
if (opt.lex) {
|
|
196
|
+
const lex = this.lex(src, opt.mainfile)
|
|
197
|
+
console.log(this.outputJSON(lex, 0))
|
|
198
|
+
return
|
|
199
|
+
}
|
|
192
200
|
// ASTを出力する
|
|
193
201
|
if (opt.ast) {
|
|
194
202
|
try {
|
|
@@ -318,47 +326,49 @@ export class CNako3 extends NakoCompiler {
|
|
|
318
326
|
}
|
|
319
327
|
}
|
|
320
328
|
}
|
|
321
|
-
|
|
322
329
|
/**
|
|
323
|
-
*
|
|
330
|
+
* JSONを出力
|
|
324
331
|
*/
|
|
325
|
-
|
|
326
|
-
const ast = this.parse(src, opt.mainfile)
|
|
332
|
+
outputJSON (ast: any, level: number): string {
|
|
327
333
|
const makeIndent = (level: number) => {
|
|
328
334
|
let s = ''
|
|
329
335
|
for (let i = 0; i < level; i++) { s += ' ' }
|
|
330
336
|
return s
|
|
331
337
|
}
|
|
332
338
|
const trim = (s: string) => { return s.replace(/(^\s+|\s+$)/g, '') }
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (typeof (ast) === 'number') {
|
|
339
|
-
return makeIndent(level) + ast
|
|
340
|
-
}
|
|
341
|
-
if (ast instanceof Array) {
|
|
342
|
-
const s = makeIndent(level) + '[\n'
|
|
343
|
-
const sa: string[] = []
|
|
344
|
-
ast.forEach((a: Ast) => {
|
|
345
|
-
sa.push(outAST(a, level + 1))
|
|
346
|
-
})
|
|
347
|
-
return s + sa.join(',\n') + '\n' + makeIndent(level) + ']'
|
|
348
|
-
}
|
|
349
|
-
if (ast instanceof Object) {
|
|
350
|
-
const s = makeIndent(level) + '{\n'
|
|
351
|
-
const sa = []
|
|
352
|
-
for (const key in ast) {
|
|
353
|
-
const sv = trim(outAST((ast as any)[key], level + 1))
|
|
354
|
-
const so = makeIndent(level + 1) + '"' + key + '": ' + sv
|
|
355
|
-
sa.push(so)
|
|
356
|
-
}
|
|
357
|
-
return s + sa.join(',\n') + '\n' + makeIndent(level) + '}'
|
|
358
|
-
}
|
|
339
|
+
|
|
340
|
+
if (typeof (ast) === 'string') {
|
|
341
|
+
return makeIndent(level) + '"' + ast + '"'
|
|
342
|
+
}
|
|
343
|
+
if (typeof (ast) === 'number') {
|
|
359
344
|
return makeIndent(level) + ast
|
|
360
345
|
}
|
|
361
|
-
|
|
346
|
+
if (ast instanceof Array) {
|
|
347
|
+
const s = makeIndent(level) + '[\n'
|
|
348
|
+
const sa: string[] = []
|
|
349
|
+
ast.forEach((a: Ast) => {
|
|
350
|
+
sa.push(this.outputJSON(a, level + 1))
|
|
351
|
+
})
|
|
352
|
+
return s + sa.join(',\n') + '\n' + makeIndent(level) + ']'
|
|
353
|
+
}
|
|
354
|
+
if (ast instanceof Object) {
|
|
355
|
+
const s = makeIndent(level) + '{\n'
|
|
356
|
+
const sa = []
|
|
357
|
+
for (const key in ast) {
|
|
358
|
+
const sv = trim(this.outputJSON((ast as any)[key], level + 1))
|
|
359
|
+
const so = makeIndent(level + 1) + '"' + key + '": ' + sv
|
|
360
|
+
sa.push(so)
|
|
361
|
+
}
|
|
362
|
+
return s + sa.join(',\n') + '\n' + makeIndent(level) + '}'
|
|
363
|
+
}
|
|
364
|
+
return makeIndent(level) + ast
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* ASTを出力
|
|
368
|
+
*/
|
|
369
|
+
outputAST (opt: any, src: string) {
|
|
370
|
+
const ast = this.parse(src, opt.mainfile)
|
|
371
|
+
console.log(this.outputJSON(ast, 0))
|
|
362
372
|
}
|
|
363
373
|
|
|
364
374
|
// REPL(対話実行環境)の場合
|
package/src/nako_version.mjs
CHANGED
package/src/nako_version.mts
CHANGED
|
@@ -196,6 +196,7 @@ export default {
|
|
|
196
196
|
fn: function (url, sys) {
|
|
197
197
|
const img = new window.Image()
|
|
198
198
|
img.src = url
|
|
199
|
+
img.crossOrigin = 'Anonymous'
|
|
199
200
|
return img
|
|
200
201
|
}
|
|
201
202
|
},
|
|
@@ -208,6 +209,7 @@ export default {
|
|
|
208
209
|
sys.resolveCount++
|
|
209
210
|
const img = new window.Image()
|
|
210
211
|
img.src = url
|
|
212
|
+
img.crossOrigin = 'Anonymous'
|
|
211
213
|
img.onload = () => {
|
|
212
214
|
sys.__v0['対象'] = img
|
|
213
215
|
sys.resolve()
|
|
@@ -229,6 +231,7 @@ export default {
|
|
|
229
231
|
// 画像を読む
|
|
230
232
|
const img = new window.Image()
|
|
231
233
|
img.src = url
|
|
234
|
+
img.crossOrigin = 'Anonymous'
|
|
232
235
|
img.onload = () => {
|
|
233
236
|
sys.__v0['対象'] = img
|
|
234
237
|
func(sys)
|
|
@@ -260,6 +263,7 @@ export default {
|
|
|
260
263
|
if (typeof img === 'string') {
|
|
261
264
|
const image = new window.Image()
|
|
262
265
|
image.src = img
|
|
266
|
+
image.crossOrigin = 'Anonymous'
|
|
263
267
|
image.onload = () => {
|
|
264
268
|
drawFunc(image, sys.__ctx)
|
|
265
269
|
}
|
|
@@ -311,6 +315,7 @@ export default {
|
|
|
311
315
|
if (typeof img === 'string') {
|
|
312
316
|
const image = new window.Image()
|
|
313
317
|
image.src = img
|
|
318
|
+
image.crossOrigin = 'Anonymous'
|
|
314
319
|
image.onload = () => {
|
|
315
320
|
drawFunc(image, sys.__ctx)
|
|
316
321
|
}
|