nadesiko3 3.7.13 → 3.7.14
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 +473 -473
- package/batch/jsplugin2text.nako3 +2 -0
- package/core/package.json +1 -1
- package/core/src/nako3.mjs +0 -4
- package/core/src/nako3.mts +55 -55
- package/core/src/nako_ast.mjs +0 -1
- package/core/src/nako_ast.mts +1 -1
- package/core/src/nako_colors.mjs +0 -1
- package/core/src/nako_colors.mts +1 -1
- package/core/src/nako_core_version.mjs +2 -2
- package/core/src/nako_core_version.mts +2 -2
- package/core/src/nako_csv.mjs +0 -1
- package/core/src/nako_csv.mts +9 -9
- package/core/src/nako_errors.mts +8 -8
- package/core/src/nako_from_dncl.mts +5 -5
- package/core/src/nako_from_dncl2.mjs +0 -1
- package/core/src/nako_from_dncl2.mts +5 -5
- package/core/src/nako_gen.mjs +13 -15
- package/core/src/nako_gen.mts +224 -220
- package/core/src/nako_global.mts +11 -11
- package/core/src/nako_indent.mts +92 -92
- package/core/src/nako_indent_chars.mts +1 -1
- package/core/src/nako_indent_inline.mjs +11 -11
- package/core/src/nako_indent_inline.mts +20 -20
- package/core/src/nako_lex_rules.mjs +0 -1
- package/core/src/nako_lex_rules.mts +8 -8
- package/core/src/nako_lexer.mjs +0 -1
- package/core/src/nako_lexer.mts +23 -23
- package/core/src/nako_logger.mjs +1 -1
- package/core/src/nako_logger.mts +38 -38
- package/core/src/nako_parser3.mjs +4 -5
- package/core/src/nako_parser3.mts +79 -79
- package/core/src/nako_parser_base.mjs +1 -1
- package/core/src/nako_parser_base.mts +68 -68
- package/core/src/nako_parser_const.mjs +0 -1
- package/core/src/nako_parser_const.mts +1 -1
- package/core/src/nako_prepare.mts +12 -12
- package/core/src/nako_source_mapping.mts +9 -9
- package/core/src/nako_token.mjs +0 -1
- package/core/src/nako_token.mts +2 -2
- package/core/src/nako_tools.mjs +0 -1
- package/core/src/nako_tools.mts +4 -4
- package/core/src/nako_types.mjs +0 -1
- package/core/src/nako_types.mts +3 -3
- package/core/src/plugin_api.mjs +0 -1
- package/core/src/plugin_api.mts +1 -1
- package/core/src/plugin_csv.mjs +0 -1
- package/core/src/plugin_csv.mts +7 -7
- package/core/src/plugin_math.mjs +0 -1
- package/core/src/plugin_math.mts +39 -40
- package/core/src/plugin_promise.mjs +1 -1
- package/core/src/plugin_promise.mts +9 -9
- package/core/src/plugin_system.mjs +1 -10
- package/core/src/plugin_system.mts +319 -321
- package/core/src/plugin_test.mjs +0 -2
- package/core/src/plugin_test.mts +6 -6
- package/core/src/plugin_toml.mjs +1 -1
- package/core/src/plugin_toml.mts +4 -4
- package/core/test/flow_test.mjs +22 -0
- package/package.json +31 -34
- package/release/_hash.txt +24 -24
- package/release/_script-tags.txt +16 -16
- package/release/command_cnako3.json +1 -1
- package/release/edit_main.js +33 -21
- package/release/edit_main.js.map +4 -4
- package/release/editor.js +33 -21
- package/release/plugin_keigo.js.map +2 -2
- package/release/plugin_turtle.js.map +2 -2
- package/release/plugin_weykturtle3d.js.map +2 -2
- package/release/version.js +29 -17
- package/release/version_main.js +29 -17
- package/release/version_main.js.map +4 -4
- package/release/wnako3.js +51 -44
- package/release/wnako3.js.map +3 -3
- package/release/wnako3webworker.js +45 -38
- package/release/wnako3webworker.js.map +2 -2
- package/src/cnako3.mts +1 -1
- package/src/cnako3mod.mjs +4 -7
- package/src/cnako3mod.mts +24 -24
- package/src/commander_ja.mts +8 -8
- package/src/deno_wrapper.mjs +0 -1
- package/src/deno_wrapper.mts +5 -5
- package/src/nako_version.mjs +2 -2
- package/src/nako_version.mts +2 -2
- package/src/plugin_browser.mjs +21 -29
- package/src/plugin_browser.mts +30 -35
- package/src/plugin_browser_ajax.mts +27 -27
- package/src/plugin_browser_audio.mjs +0 -1
- package/src/plugin_browser_audio.mts +11 -11
- package/src/plugin_browser_camera.mts +8 -8
- package/src/plugin_browser_canvas.mjs +0 -2
- package/src/plugin_browser_canvas.mts +34 -34
- package/src/plugin_browser_chart.mjs +0 -1
- package/src/plugin_browser_chart.mts +13 -13
- package/src/plugin_browser_color.mts +2 -2
- package/src/plugin_browser_crypto.mts +5 -5
- package/src/plugin_browser_dialog.mts +4 -4
- package/src/plugin_browser_dom_basic.mts +42 -42
- package/src/plugin_browser_dom_event.mjs +0 -1
- package/src/plugin_browser_dom_event.mts +27 -28
- package/src/plugin_browser_dom_parts.mjs +0 -2
- package/src/plugin_browser_dom_parts.mts +31 -31
- package/src/plugin_browser_geolocation.mts +3 -3
- package/src/plugin_browser_hotkey.mts +3 -3
- package/src/plugin_browser_html.mts +4 -4
- package/src/plugin_browser_in_worker.mts +1 -1
- package/src/plugin_browser_location.mts +2 -2
- package/src/plugin_browser_speech.mts +7 -7
- package/src/plugin_browser_storage.mts +11 -11
- package/src/plugin_browser_system.mts +2 -2
- package/src/plugin_browser_websocket.mts +6 -6
- package/src/plugin_httpserver.mts +17 -17
- package/src/plugin_keigo.mts +5 -5
- package/src/plugin_node.mjs +7 -48
- package/src/plugin_node.mts +114 -145
- package/src/plugin_turtle.mts +143 -143
- package/src/plugin_weykturtle3d.mjs +0 -3
- package/src/plugin_weykturtle3d.mts +135 -135
- package/src/plugin_weykturtle3d_three.mjs +0 -1
- package/src/plugin_weykturtle3d_three.mts +1 -1
- package/src/plugin_weykturtle3d_threeutil.mts +3 -3
- package/src/wnako3.mjs +0 -1
- package/src/wnako3.mts +1 -1
- package/src/wnako3_editor.mjs +0 -2
- package/src/wnako3_editor.mts +132 -132
- package/src/wnako3mod.mjs +0 -5
- package/src/wnako3mod.mts +19 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import { NakoLogger } from './nako_logger.mjs'
|
|
3
3
|
import { FuncList, FuncListItem, SourceMap, NewEmptyToken, ExportMap } from './nako_types.mjs'
|
|
4
4
|
import { Ast, AstBlocks, AstOperator, AstConst, AstStrValue } from './nako_ast.mjs'
|
|
@@ -33,7 +33,7 @@ export class NakoParserBase {
|
|
|
33
33
|
protected isExportStack: boolean[]
|
|
34
34
|
protected isModifiedNodes: boolean
|
|
35
35
|
|
|
36
|
-
constructor
|
|
36
|
+
constructor(logger: NakoLogger) {
|
|
37
37
|
this.logger = logger
|
|
38
38
|
this.stackList = [] // 関数定義の際にスタックが混乱しないように整理する
|
|
39
39
|
this.tokens = []
|
|
@@ -83,13 +83,13 @@ export class NakoParserBase {
|
|
|
83
83
|
this.init()
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
init
|
|
86
|
+
init() {
|
|
87
87
|
this.funclist = new Map() // 関数の一覧
|
|
88
88
|
this.moduleExport = new Map()
|
|
89
89
|
this.reset()
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
reset
|
|
92
|
+
reset() {
|
|
93
93
|
this.tokens = [] // 字句解析済みのトークンの一覧を保存
|
|
94
94
|
this.index = 0 // tokens[] のどこまで読んだかを管理する
|
|
95
95
|
this.stack = [] // 計算用のスタック ... 直接は操作せず、pushStack() popStack() を介して使う
|
|
@@ -97,11 +97,11 @@ export class NakoParserBase {
|
|
|
97
97
|
this.genMode = 'sync' // #637, #1056
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
setFuncList
|
|
100
|
+
setFuncList(funclist: FuncList) {
|
|
101
101
|
this.funclist = funclist
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
setModuleExport
|
|
104
|
+
setModuleExport(moduleexport: ExportMap) {
|
|
105
105
|
this.moduleExport = moduleexport
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -109,7 +109,7 @@ export class NakoParserBase {
|
|
|
109
109
|
* 特定の助詞を持つ要素をスタックから一つ下ろす、指定がなければ末尾を下ろす
|
|
110
110
|
* @param {string[]} josiList 下ろしたい助詞の配列
|
|
111
111
|
*/
|
|
112
|
-
popStack
|
|
112
|
+
popStack(josiList: string[]|undefined = undefined): Ast | null {
|
|
113
113
|
if (!josiList) {
|
|
114
114
|
const t = this.stack.pop()
|
|
115
115
|
if (t) { return t }
|
|
@@ -133,12 +133,12 @@ export class NakoParserBase {
|
|
|
133
133
|
* saveStack と loadStack は対で使う。
|
|
134
134
|
* 関数定義などでスタックが混乱しないように配慮するためのもの
|
|
135
135
|
*/
|
|
136
|
-
saveStack
|
|
136
|
+
saveStack() {
|
|
137
137
|
this.stackList.push(this.stack)
|
|
138
138
|
this.stack = []
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
loadStack
|
|
141
|
+
loadStack() {
|
|
142
142
|
this.stack = this.stackList.pop()
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -146,7 +146,7 @@ export class NakoParserBase {
|
|
|
146
146
|
* @param {string} name
|
|
147
147
|
* @returns {any}変数名の情報
|
|
148
148
|
*/
|
|
149
|
-
findVar
|
|
149
|
+
findVar(name: string): any {
|
|
150
150
|
// ローカル変数?
|
|
151
151
|
if (this.localvars.get(name)) {
|
|
152
152
|
return {
|
|
@@ -201,7 +201,7 @@ export class NakoParserBase {
|
|
|
201
201
|
/**
|
|
202
202
|
* 計算用に要素をスタックに積む
|
|
203
203
|
*/
|
|
204
|
-
pushStack
|
|
204
|
+
pushStack(item: any) {
|
|
205
205
|
this.logger.trace('PUSH:' + JSON.stringify(item))
|
|
206
206
|
this.stack.push(item)
|
|
207
207
|
}
|
|
@@ -209,18 +209,18 @@ export class NakoParserBase {
|
|
|
209
209
|
/**
|
|
210
210
|
* トークンの末尾に達したか
|
|
211
211
|
*/
|
|
212
|
-
isEOF
|
|
212
|
+
isEOF(): boolean {
|
|
213
213
|
return (this.index >= this.tokens.length)
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
getIndex
|
|
216
|
+
getIndex(): number {
|
|
217
217
|
return this.index
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
221
|
* カーソル位置にある単語の型を確かめる
|
|
222
222
|
*/
|
|
223
|
-
check
|
|
223
|
+
check(ttype: string): boolean {
|
|
224
224
|
return (this.tokens[this.index].type === ttype)
|
|
225
225
|
}
|
|
226
226
|
|
|
@@ -228,7 +228,7 @@ export class NakoParserBase {
|
|
|
228
228
|
* カーソル位置以降にある単語の型を確かめる 2単語以上に対応
|
|
229
229
|
* @param a [単語1の型, 単語2の型, ... ]
|
|
230
230
|
*/
|
|
231
|
-
check2
|
|
231
|
+
check2(a: any[]): boolean {
|
|
232
232
|
for (let i = 0; i < a.length; i++) {
|
|
233
233
|
const idx = i + this.index
|
|
234
234
|
if (this.tokens.length <= idx) { return false }
|
|
@@ -246,7 +246,7 @@ export class NakoParserBase {
|
|
|
246
246
|
/**
|
|
247
247
|
* カーソル位置の型を確認するが、複数の種類を確かめられる
|
|
248
248
|
*/
|
|
249
|
-
checkTypes
|
|
249
|
+
checkTypes(a: TokenType[]): boolean {
|
|
250
250
|
const type = this.tokens[this.index].type
|
|
251
251
|
return (a.indexOf(type) >= 0)
|
|
252
252
|
}
|
|
@@ -255,7 +255,7 @@ export class NakoParserBase {
|
|
|
255
255
|
* check2の高度なやつ、型名の他にコールバック関数を指定できる
|
|
256
256
|
* 型にマッチしなければ false を返し、カーソルを巻き戻す
|
|
257
257
|
*/
|
|
258
|
-
accept
|
|
258
|
+
accept(types: any[]): boolean {
|
|
259
259
|
const y = []
|
|
260
260
|
const tmpIndex = this.index
|
|
261
261
|
const rollback = () => {
|
|
@@ -265,7 +265,7 @@ export class NakoParserBase {
|
|
|
265
265
|
for (let i = 0; i < types.length; i++) {
|
|
266
266
|
if (this.isEOF()) { return rollback() }
|
|
267
267
|
const type = types[i]
|
|
268
|
-
if (type
|
|
268
|
+
if (type === null) { return rollback() }
|
|
269
269
|
if (typeof type === 'string') {
|
|
270
270
|
const token = this.get()
|
|
271
271
|
if (token && token.type !== type) { return rollback() }
|
|
@@ -293,31 +293,31 @@ export class NakoParserBase {
|
|
|
293
293
|
/**
|
|
294
294
|
* カーソル語句を取得して、カーソルを後ろに移動する
|
|
295
295
|
*/
|
|
296
|
-
get
|
|
296
|
+
get(): Token | null {
|
|
297
297
|
if (this.isEOF()) { return null }
|
|
298
298
|
return this.tokens[this.index++]
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
/** カーソル語句を取得してカーソルを進める、取得できなければエラーを出す */
|
|
302
|
-
getCur
|
|
302
|
+
getCur(): Token {
|
|
303
303
|
if (this.isEOF()) { throw new Error('トークンが取得できません。') }
|
|
304
304
|
const t = this.tokens[this.index++]
|
|
305
305
|
if (!t) { throw new Error('トークンが取得できません。') }
|
|
306
306
|
return t
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
unget
|
|
309
|
+
unget() {
|
|
310
310
|
if (this.index > 0) { this.index-- }
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
/** 解析中のトークンを返す */
|
|
314
|
-
peek
|
|
314
|
+
peek(i = 0): Token|null {
|
|
315
315
|
if (this.isEOF()) { return null }
|
|
316
316
|
return this.tokens[this.index + i]
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
/** 解析中のトークンを返す、無理なら def を返す */
|
|
320
|
-
peekDef
|
|
320
|
+
peekDef(def: Token|null = null): Token {
|
|
321
321
|
if (this.isEOF()) {
|
|
322
322
|
if (!def) { def = NewEmptyToken() }
|
|
323
323
|
return def
|
|
@@ -328,7 +328,7 @@ export class NakoParserBase {
|
|
|
328
328
|
/**
|
|
329
329
|
* 現在のカーソル語句のソースコード上の位置を取得する。
|
|
330
330
|
*/
|
|
331
|
-
peekSourceMap
|
|
331
|
+
peekSourceMap(t: Token|undefined = undefined): SourceMap {
|
|
332
332
|
const token = (t === undefined) ? this.peek() : t
|
|
333
333
|
if (token === null) {
|
|
334
334
|
return { startOffset: undefined, endOffset: undefined, file: undefined, line: 0, column: 0 }
|
|
@@ -342,57 +342,57 @@ export class NakoParserBase {
|
|
|
342
342
|
* @param {{ depth: number, typeName?: string }} opts
|
|
343
343
|
* @param {boolean} debugMode
|
|
344
344
|
*/
|
|
345
|
-
nodeToStr
|
|
345
|
+
nodeToStr(node: Ast|Token|null, opts: {depth: number, typeName?: string}, debugMode: boolean): string {
|
|
346
346
|
const depth = opts.depth - 1
|
|
347
347
|
const typeName = (name: string) => (opts.typeName !== undefined) ? opts.typeName : name
|
|
348
348
|
const debug = debugMode ? (' debug: ' + JSON.stringify(node, null, 2)) : ''
|
|
349
349
|
if (!node) { return '(NULL)' }
|
|
350
350
|
switch (node.type) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
case 'op': {
|
|
359
|
-
const node2: AstOperator = node as AstOperator
|
|
360
|
-
let operator: string = node2.operator || ''
|
|
361
|
-
const table:{[key: string]: string} = { eq: '=', not: '!', gt: '>', lt: '<', and: 'かつ', or: 'または' }
|
|
362
|
-
if (operator in table) {
|
|
363
|
-
operator = table[operator]
|
|
364
|
-
}
|
|
365
|
-
if (depth >= 0) {
|
|
366
|
-
const left: string = this.nodeToStr(node2.blocks[0], { depth }, debugMode)
|
|
367
|
-
const right: string = this.nodeToStr(node2.blocks[1], { depth }, debugMode)
|
|
368
|
-
if (node2.operator === 'eq') {
|
|
369
|
-
return `${typeName('')}『${left}と${right}が等しいかどうかの比較${debug}』`
|
|
370
|
-
}
|
|
371
|
-
return `${typeName('')}『${left}と${right}に演算子『${operator}』を適用した式${debug}』`
|
|
372
|
-
} else {
|
|
373
|
-
return `${typeName('演算子')}『${operator}${debug}』`
|
|
374
|
-
}
|
|
351
|
+
case 'not':
|
|
352
|
+
if (depth >= 0) {
|
|
353
|
+
const subNode: Ast = (node as AstBlocks).blocks[0]
|
|
354
|
+
return `${typeName('')}『${this.nodeToStr(subNode, { depth }, debugMode)}に演算子『not』を適用した式${debug}』`
|
|
355
|
+
} else {
|
|
356
|
+
return `${typeName('演算子')}『not』`
|
|
375
357
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
case 'word':
|
|
383
|
-
return `${typeName('単語')}『${(node as AstStrValue).value}${debug}』`
|
|
384
|
-
case 'func':
|
|
385
|
-
return `${typeName('関数')}『${node.name || (node as AstStrValue).value}${debug}』`
|
|
386
|
-
case 'eol':
|
|
387
|
-
return '行の末尾'
|
|
388
|
-
case 'eof':
|
|
389
|
-
return 'ファイルの末尾'
|
|
390
|
-
default: {
|
|
391
|
-
let name:any = node.name
|
|
392
|
-
if (name) { name = (node as AstStrValue).value }
|
|
393
|
-
if (typeof name !== 'string') { name = node.type }
|
|
394
|
-
return `${typeName('')}『${name}${debug}』`
|
|
358
|
+
case 'op': {
|
|
359
|
+
const node2: AstOperator = node as AstOperator
|
|
360
|
+
let operator: string = node2.operator || ''
|
|
361
|
+
const table:{[key: string]: string} = { eq: '=', not: '!', gt: '>', lt: '<', and: 'かつ', or: 'または' }
|
|
362
|
+
if (operator in table) {
|
|
363
|
+
operator = table[operator]
|
|
395
364
|
}
|
|
365
|
+
if (depth >= 0) {
|
|
366
|
+
const left: string = this.nodeToStr(node2.blocks[0], { depth }, debugMode)
|
|
367
|
+
const right: string = this.nodeToStr(node2.blocks[1], { depth }, debugMode)
|
|
368
|
+
if (node2.operator === 'eq') {
|
|
369
|
+
return `${typeName('')}『${left}と${right}が等しいかどうかの比較${debug}』`
|
|
370
|
+
}
|
|
371
|
+
return `${typeName('')}『${left}と${right}に演算子『${operator}』を適用した式${debug}』`
|
|
372
|
+
} else {
|
|
373
|
+
return `${typeName('演算子')}『${operator}${debug}』`
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
case 'number':
|
|
377
|
+
return `${typeName('数値')}${(node as AstConst).value}`
|
|
378
|
+
case 'bigint':
|
|
379
|
+
return `${typeName('巨大整数')}${(node as AstConst).value}`
|
|
380
|
+
case 'string':
|
|
381
|
+
return `${typeName('文字列')}『${(node as AstConst).value}${debug}』`
|
|
382
|
+
case 'word':
|
|
383
|
+
return `${typeName('単語')}『${(node as AstStrValue).value}${debug}』`
|
|
384
|
+
case 'func':
|
|
385
|
+
return `${typeName('関数')}『${node.name || (node as AstStrValue).value}${debug}』`
|
|
386
|
+
case 'eol':
|
|
387
|
+
return '行の末尾'
|
|
388
|
+
case 'eof':
|
|
389
|
+
return 'ファイルの末尾'
|
|
390
|
+
default: {
|
|
391
|
+
let name:any = node.name
|
|
392
|
+
if (name) { name = (node as AstStrValue).value }
|
|
393
|
+
if (typeof name !== 'string') { name = node.type }
|
|
394
|
+
return `${typeName('')}『${name}${debug}』`
|
|
395
|
+
}
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
}
|
|
@@ -7,7 +7,7 @@ class ReplaceHistory {
|
|
|
7
7
|
from: number
|
|
8
8
|
to: number
|
|
9
9
|
index: number
|
|
10
|
-
constructor
|
|
10
|
+
constructor(from: number, to: number, index: number) {
|
|
11
11
|
this.from = from
|
|
12
12
|
this.to = to
|
|
13
13
|
this.index = index
|
|
@@ -17,7 +17,7 @@ class ReplaceHistory {
|
|
|
17
17
|
export class ConvertResult {
|
|
18
18
|
public text: string
|
|
19
19
|
public sourcePosition: number
|
|
20
|
-
constructor
|
|
20
|
+
constructor(text: string, sourcePosition: number) {
|
|
21
21
|
this.text = text
|
|
22
22
|
this.sourcePosition = sourcePosition
|
|
23
23
|
}
|
|
@@ -29,16 +29,16 @@ export class ConvertResult {
|
|
|
29
29
|
export class Replace {
|
|
30
30
|
history: ReplaceHistory[]
|
|
31
31
|
private code: string
|
|
32
|
-
constructor
|
|
32
|
+
constructor(code: string) {
|
|
33
33
|
this.history = []
|
|
34
34
|
this.code = code
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
getText
|
|
37
|
+
getText(): string {
|
|
38
38
|
return this.code
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
replaceAll
|
|
41
|
+
replaceAll(from: string, to: string) {
|
|
42
42
|
while (true) {
|
|
43
43
|
const index = this.getText().indexOf(from)
|
|
44
44
|
if (index === -1) {
|
|
@@ -51,7 +51,7 @@ export class Replace {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
getSourcePosition
|
|
54
|
+
getSourcePosition(i: number): number {
|
|
55
55
|
// 少し遅い。パース時間1.4秒に対して0.15秒かかる。iが単調増加することを利用して高速化できるはず。
|
|
56
56
|
for (const item of this.history) {
|
|
57
57
|
if (i >= item.index + item.to) { // 置換範囲より後ろ
|
|
@@ -77,10 +77,10 @@ export class Replace {
|
|
|
77
77
|
*/
|
|
78
78
|
export class NakoPrepare {
|
|
79
79
|
// 唯一のインスタンス
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
private static _instance: NakoPrepare
|
|
82
82
|
/** 唯一のインスタンスを返す */
|
|
83
|
-
public static getInstance
|
|
83
|
+
public static getInstance(): NakoPrepare {
|
|
84
84
|
if (!NakoPrepare._instance) {
|
|
85
85
|
NakoPrepare._instance = new NakoPrepare()
|
|
86
86
|
}
|
|
@@ -88,7 +88,7 @@ export class NakoPrepare {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
private convertTable: Map<number, string>
|
|
91
|
-
private constructor
|
|
91
|
+
private constructor() {
|
|
92
92
|
// 単純な変換テーブル
|
|
93
93
|
this.convertTable = new Map([
|
|
94
94
|
// ハイフンへの変換
|
|
@@ -150,7 +150,7 @@ export class NakoPrepare {
|
|
|
150
150
|
/**
|
|
151
151
|
* @param {string} ch
|
|
152
152
|
*/
|
|
153
|
-
public convert1ch
|
|
153
|
+
public convert1ch(ch: string): string {
|
|
154
154
|
if (!ch) { return '' }
|
|
155
155
|
const c: number = ch.codePointAt(0) || 0
|
|
156
156
|
// テーブルによる変換
|
|
@@ -167,7 +167,7 @@ export class NakoPrepare {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/** convert code */
|
|
170
|
-
convert
|
|
170
|
+
convert(code: string): ConvertResult[] {
|
|
171
171
|
if (!code) { return [] }
|
|
172
172
|
const src = new Replace(code)
|
|
173
173
|
|
|
@@ -321,7 +321,7 @@ export class NakoPrepare {
|
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
/** なでしこのソースコードのモード(!インデント構文など)が設定されているか調べる */
|
|
324
|
-
export function checkNakoMode
|
|
324
|
+
export function checkNakoMode(code: string, modeNames: string[]): boolean {
|
|
325
325
|
// 先頭の256文字について調べる
|
|
326
326
|
code = code.substring(0, 256)
|
|
327
327
|
// 全角半角の揺れを吸収
|
|
@@ -14,7 +14,7 @@ export class SourceMappingOfTokenization {
|
|
|
14
14
|
* @param {number} sourceCodeLength
|
|
15
15
|
* @param {PreprocessItem[]} preprocessed
|
|
16
16
|
*/
|
|
17
|
-
constructor
|
|
17
|
+
constructor(sourceCodeLength: number, preprocessed: PreprocessItem[]) {
|
|
18
18
|
/** @private @readonly */
|
|
19
19
|
this.sourceCodeLength = sourceCodeLength
|
|
20
20
|
|
|
@@ -40,7 +40,7 @@ export class SourceMappingOfTokenization {
|
|
|
40
40
|
* @param {number} preprocessedCodePosition
|
|
41
41
|
* @returns {number}
|
|
42
42
|
*/
|
|
43
|
-
map
|
|
43
|
+
map(preprocessedCodePosition: number): number {
|
|
44
44
|
const i = this.findIndex(preprocessedCodePosition)
|
|
45
45
|
return Math.min(
|
|
46
46
|
this.preprocessed[i].sourcePosition + (preprocessedCodePosition - this.cumulativeSum[i]),
|
|
@@ -52,7 +52,7 @@ export class SourceMappingOfTokenization {
|
|
|
52
52
|
* @param {number} preprocessedCodePosition
|
|
53
53
|
* @returns {number}
|
|
54
54
|
*/
|
|
55
|
-
findIndex
|
|
55
|
+
findIndex(preprocessedCodePosition: number): number {
|
|
56
56
|
// 連続アクセスに対する高速化
|
|
57
57
|
if (preprocessedCodePosition < this.lastPreprocessedCodePosition) {
|
|
58
58
|
this.lastIndex = 0
|
|
@@ -82,7 +82,7 @@ export class SourceMappingOfIndentSyntax {
|
|
|
82
82
|
* @param {readonly number[]} linesInsertedByIndentationSyntax
|
|
83
83
|
* @param {readonly { lineNumber: number, len: number }[]} linesDeletedByIndentationSyntax
|
|
84
84
|
*/
|
|
85
|
-
constructor
|
|
85
|
+
constructor(
|
|
86
86
|
codeAfterProcessingIndentationSyntax: string,
|
|
87
87
|
linesInsertedByIndentationSyntax: number[],
|
|
88
88
|
linesDeletedByIndentationSyntax: { lineNumber: number, len: number }[]
|
|
@@ -113,7 +113,7 @@ export class SourceMappingOfIndentSyntax {
|
|
|
113
113
|
* @param {number | null} endOffset
|
|
114
114
|
* @returns {{ startOffset: number | null, endOffset: number | null }}
|
|
115
115
|
*/
|
|
116
|
-
map
|
|
116
|
+
map(startOffset: number | null, endOffset:number | null): { startOffset: number | null, endOffset: number | null } {
|
|
117
117
|
if (startOffset === null) {
|
|
118
118
|
return { startOffset, endOffset }
|
|
119
119
|
}
|
|
@@ -159,7 +159,7 @@ export class SourceMappingOfIndentSyntax {
|
|
|
159
159
|
* @returns {number}
|
|
160
160
|
* @private
|
|
161
161
|
*/
|
|
162
|
-
getLineNumber
|
|
162
|
+
getLineNumber(offset: number): number {
|
|
163
163
|
// 連続アクセスに対する高速化
|
|
164
164
|
if (offset < this.lastOffset) {
|
|
165
165
|
this.lastLineNumber = 0
|
|
@@ -186,7 +186,7 @@ export class OffsetToLineColumn {
|
|
|
186
186
|
/**
|
|
187
187
|
* @param {string} code
|
|
188
188
|
*/
|
|
189
|
-
constructor
|
|
189
|
+
constructor(code: string) {
|
|
190
190
|
/** @private @type {number[]} */
|
|
191
191
|
this.lineOffsets = []
|
|
192
192
|
|
|
@@ -208,7 +208,7 @@ export class OffsetToLineColumn {
|
|
|
208
208
|
* @param {boolean} oneBasedLineNumber trueのときlineを1から始める
|
|
209
209
|
* @returns {{ line: number, column: number }}
|
|
210
210
|
*/
|
|
211
|
-
map
|
|
211
|
+
map(offset: number, oneBasedLineNumber: boolean):{ line: number, column: number } {
|
|
212
212
|
// 連続アクセスに対する高速化
|
|
213
213
|
if (offset < this.lastOffset) {
|
|
214
214
|
this.lastLineNumber = 0
|
|
@@ -237,7 +237,7 @@ export class OffsetToLineColumn {
|
|
|
237
237
|
* preCodeの分、ソースマップのoffset、行数、列数を減らす。
|
|
238
238
|
* @type {<T extends {line?: number, column?: number, startOffset: number | null, endOffset: number | null }>(sourceMap: T, preCode: string) => T}
|
|
239
239
|
*/
|
|
240
|
-
export function subtractSourceMapByPreCodeLength
|
|
240
|
+
export function subtractSourceMapByPreCodeLength(sourceMap: any, preCode: string) {
|
|
241
241
|
// offsetは単純に引くだけでよい
|
|
242
242
|
if (typeof sourceMap.startOffset === 'number') {
|
|
243
243
|
sourceMap.startOffset -= preCode.length
|
package/core/src/nako_token.mjs
CHANGED
package/core/src/nako_token.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
|
|
3
3
|
import { FuncListItem, Ast } from './nako_types.mjs'
|
|
4
4
|
|
|
@@ -121,7 +121,7 @@ export interface Token {
|
|
|
121
121
|
tag?: string;
|
|
122
122
|
preprocessedCodeOffset?: number | undefined;
|
|
123
123
|
preprocessedCodeLength?: number | undefined;
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
name?: Token | Ast; // NakoPaserBase.nodeToStrの問題を回避するため
|
|
126
126
|
start?: number;
|
|
127
127
|
end?: number;
|
package/core/src/nako_tools.mjs
CHANGED
package/core/src/nako_tools.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
/**
|
|
3
3
|
* よく使う処理をまとめたもの
|
|
4
4
|
*/
|
|
@@ -10,7 +10,7 @@ import { TokenType } from './nako_token.mjs'
|
|
|
10
10
|
* @param tokens トークンの一覧
|
|
11
11
|
* @returns 文字列
|
|
12
12
|
*/
|
|
13
|
-
export function debugTokens
|
|
13
|
+
export function debugTokens(tokens: Token[]) {
|
|
14
14
|
const result = []
|
|
15
15
|
for (let i = 0; i < tokens.length; i++) {
|
|
16
16
|
const t = tokens[i]
|
|
@@ -30,7 +30,7 @@ export function debugTokens (tokens: Token[]) {
|
|
|
30
30
|
return result.join('\n')
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function makeIndent
|
|
33
|
+
export function makeIndent(n: number): string {
|
|
34
34
|
let s = ''
|
|
35
35
|
for (let i = 0; i < n; i++) {
|
|
36
36
|
s += ' '
|
|
@@ -39,7 +39,7 @@ export function makeIndent (n: number): string {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
let lastTokenInfo = NewEmptyToken()
|
|
42
|
-
export function newToken
|
|
42
|
+
export function newToken(type: TokenType, value: any, templateToken: Token|undefined = undefined): Token {
|
|
43
43
|
if (templateToken) {
|
|
44
44
|
lastTokenInfo = templateToken
|
|
45
45
|
}
|
package/core/src/nako_types.mjs
CHANGED
package/core/src/nako_types.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
/**
|
|
3
3
|
* なでしこ3 の TypeScript のための型定義
|
|
4
4
|
*/
|
|
@@ -26,7 +26,7 @@ export interface FuncListItem {
|
|
|
26
26
|
funcPointers?: any[];
|
|
27
27
|
asyncFn?: boolean;
|
|
28
28
|
isExport?: null|boolean;
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
return_none?: boolean;
|
|
31
31
|
pure?: boolean;
|
|
32
32
|
name?: string;
|
|
@@ -46,7 +46,7 @@ export interface TokenMeta {
|
|
|
46
46
|
funcPointers: any[] | undefined;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export function NewEmptyToken
|
|
49
|
+
export function NewEmptyToken(type: TokenType = '?', value: any = '', indent = -1, line = 0, file = 'main.nako3'): Token {
|
|
50
50
|
return {
|
|
51
51
|
type,
|
|
52
52
|
value,
|
package/core/src/plugin_api.mjs
CHANGED
package/core/src/plugin_api.mts
CHANGED
package/core/src/plugin_csv.mjs
CHANGED
package/core/src/plugin_csv.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import { CSVOptions, options, parse, stringify } from './nako_csv.mjs'
|
|
3
3
|
|
|
4
4
|
const PluginCSV = {
|
|
@@ -16,7 +16,7 @@ const PluginCSV = {
|
|
|
16
16
|
type: 'func',
|
|
17
17
|
josi: [],
|
|
18
18
|
pure: true,
|
|
19
|
-
fn: function
|
|
19
|
+
fn: function(): void {
|
|
20
20
|
// 基本的に初期化不要
|
|
21
21
|
}
|
|
22
22
|
},
|
|
@@ -25,7 +25,7 @@ const PluginCSV = {
|
|
|
25
25
|
type: 'func',
|
|
26
26
|
josi: [['を', 'の', 'で']],
|
|
27
27
|
pure: true,
|
|
28
|
-
fn: function
|
|
28
|
+
fn: function(str: string): (string | number)[][] {
|
|
29
29
|
options.delimiter = ','
|
|
30
30
|
return parse(str)
|
|
31
31
|
}
|
|
@@ -34,7 +34,7 @@ const PluginCSV = {
|
|
|
34
34
|
type: 'func',
|
|
35
35
|
josi: [['を', 'の', 'で']],
|
|
36
36
|
pure: true,
|
|
37
|
-
fn: function
|
|
37
|
+
fn: function(str: string): (string|number)[][] {
|
|
38
38
|
options.delimiter = '\t'
|
|
39
39
|
return parse(str)
|
|
40
40
|
}
|
|
@@ -43,7 +43,7 @@ const PluginCSV = {
|
|
|
43
43
|
type: 'func',
|
|
44
44
|
josi: [['を']],
|
|
45
45
|
pure: true,
|
|
46
|
-
fn: function
|
|
46
|
+
fn: function(a: string[][]): string {
|
|
47
47
|
options.delimiter = ','
|
|
48
48
|
return stringify(a)
|
|
49
49
|
}
|
|
@@ -52,7 +52,7 @@ const PluginCSV = {
|
|
|
52
52
|
type: 'func',
|
|
53
53
|
josi: [['を']],
|
|
54
54
|
pure: true,
|
|
55
|
-
fn: function
|
|
55
|
+
fn: function(a: string[][]): string {
|
|
56
56
|
options.delimiter = '\t'
|
|
57
57
|
return stringify(a)
|
|
58
58
|
}
|
|
@@ -61,7 +61,7 @@ const PluginCSV = {
|
|
|
61
61
|
type: 'func',
|
|
62
62
|
josi: [['を', 'で']],
|
|
63
63
|
pure: true,
|
|
64
|
-
fn: function
|
|
64
|
+
fn: function(obj: { [key: string]: unknown }): void {
|
|
65
65
|
for (const key in obj) {
|
|
66
66
|
const value: unknown = obj[key]
|
|
67
67
|
if (key === 'delimiter' || key === '区切文字') {
|
package/core/src/plugin_math.mjs
CHANGED