efront 4.10.0 → 4.10.2
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/coms/basic/shallowClone.js +6 -2
- package/coms/basic/sortRegister.js +16 -0
- package/coms/basic_/nullish_.js +1 -1
- package/coms/compile/Html.js +5 -1
- package/coms/compile/Html_test.js +5 -0
- package/coms/compile/Javascript.js +141 -92
- package/coms/compile/Javascript_test.js +73 -3
- package/coms/compile/Program.js +351 -98
- package/coms/compile/audit.js +1 -1
- package/coms/compile/autoenum.js +6 -1
- package/coms/compile/cloneNode.js +2 -0
- package/coms/compile/common.js +134 -69
- package/coms/compile/downLevel.js +137 -54
- package/coms/compile/downLevel_test.js +12 -2
- package/coms/compile/formatcode.js +1 -1
- package/coms/compile/powermap.js +7 -24
- package/coms/compile/unstruct.js +10 -7
- package/coms/compile/unstruct_test.js +3 -3
- package/coms/docs/codecolor.js +47 -14
- package/coms/docs/codetext.xht +86 -11
- package/coms/frame/route.js +15 -15
- package/coms/maps/gaode.js +1 -1
- package/coms/zimoli/render.js +1 -1
- package/coms/zimoli/tree.js +21 -20
- package/docs//347/273/204/344/273/266.xht +1 -0
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/compile/Program.js
CHANGED
|
@@ -15,11 +15,7 @@ const {
|
|
|
15
15
|
number_reg,
|
|
16
16
|
} = require("./common");
|
|
17
17
|
var combine = require("../basic/combine");
|
|
18
|
-
var
|
|
19
|
-
if (a.indexOf(b) >= 0) return -1;
|
|
20
|
-
if (b.indexOf(a) >= 0) return 1;
|
|
21
|
-
return 0;
|
|
22
|
-
};
|
|
18
|
+
var sortRegster = require("../basic/sortRegister");
|
|
23
19
|
var createQuotedMap = function (entry) {
|
|
24
20
|
var map = {};
|
|
25
21
|
var end = {};
|
|
@@ -83,6 +79,7 @@ try {
|
|
|
83
79
|
spaceDefined.pop();
|
|
84
80
|
spaceDefined.pop();
|
|
85
81
|
}
|
|
82
|
+
var powermap = require("./powermap");
|
|
86
83
|
class Program {
|
|
87
84
|
quotes = [
|
|
88
85
|
[/'/, /'/, /\\[\s\S]/],
|
|
@@ -91,7 +88,7 @@ class Program {
|
|
|
91
88
|
["`", "`", /\\[\s\S]/, ["${", "}"]],
|
|
92
89
|
]
|
|
93
90
|
tags = [
|
|
94
|
-
[["<", "</"], /\/?>/, /\\[\s\S]
|
|
91
|
+
[["<", "</"], /\/?>/, /\\[\s\S]|\=\>/, "'", '"', "<!--", ["${", "}"]]
|
|
95
92
|
];
|
|
96
93
|
scriptTags = [];
|
|
97
94
|
ignoreTags = ["STYLE", "SCRIPT"];
|
|
@@ -105,19 +102,35 @@ class Program {
|
|
|
105
102
|
["[", "]"],
|
|
106
103
|
["{", "}"],
|
|
107
104
|
]
|
|
108
|
-
stamps = "
|
|
105
|
+
stamps = "/=+;|:?<>-!~%^&*,.".split("")
|
|
109
106
|
value_reg = /^(false|true|null)$/
|
|
110
107
|
number_reg = number_reg;
|
|
111
108
|
Code = Array;
|
|
112
|
-
|
|
109
|
+
powermap = powermap;
|
|
110
|
+
transive_reg = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|default|instanceof|throw|extends|import|from)$/;
|
|
113
111
|
straps = "if,for".split(',');
|
|
114
112
|
forceend_reg = /^(return|break|continue)$/;
|
|
115
|
-
|
|
116
|
-
extends_reg = /^(extends)$/;
|
|
113
|
+
funcstrap_reg = /^(class|function|fn|func|async|interface|struct|enum|impl|pub)$/;
|
|
114
|
+
extends_reg = /^(extends|implements)$/;
|
|
115
|
+
structstrap_reg = /^(class|interface|struct|enum)$/;
|
|
116
|
+
control_reg = /^(if|else|switch|case|do|while|for|loop|break|continue|default|import|from|as|export|try|catch|finally|throw|await|yield|return)$/;
|
|
117
|
+
type_reg = /^(var|let|const|function|fn|func|class|interface|type|struct|enum|impl)$/;
|
|
117
118
|
spaces = spaceDefined;
|
|
118
119
|
nocase = false
|
|
119
120
|
keepspace = false;
|
|
120
121
|
lastIndex = 0
|
|
122
|
+
twain(o1, o2) {
|
|
123
|
+
if (o1.istype || o1.needle || o2.needle) return;
|
|
124
|
+
o2.istype = true;
|
|
125
|
+
}
|
|
126
|
+
compile2(s) {
|
|
127
|
+
return s.replace(/\\[\s\S]|[\[\]\(\)\{\}\+\.\*\?\$\^\|\\\/\s\?]/g, function (m) {
|
|
128
|
+
if (m.length > 1) {
|
|
129
|
+
return m;
|
|
130
|
+
}
|
|
131
|
+
return "\\" + m;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
121
134
|
compile(s) {
|
|
122
135
|
return s.replace(/\\[\s\S]|[\[\]\(\)\{\}\+\.\-\*\?\$\^\|\\\/ ]/g, function (m) {
|
|
123
136
|
if (m.length > 1) {
|
|
@@ -129,9 +142,11 @@ class Program {
|
|
|
129
142
|
createRegExp(source, g) {
|
|
130
143
|
source = source.map(s => {
|
|
131
144
|
if (s instanceof RegExp) return s.source;
|
|
132
|
-
if (s instanceof Array) return s.slice().
|
|
133
|
-
return this.
|
|
145
|
+
if (s instanceof Array) return s.slice().map(s => this.compile2(s));
|
|
146
|
+
return this.compile2(s);
|
|
134
147
|
});
|
|
148
|
+
source = [].concat(...source);
|
|
149
|
+
sortRegster(source);
|
|
135
150
|
var flag = this.nocase ? "i" : "";
|
|
136
151
|
var s = source.join("|");
|
|
137
152
|
if (g) return new RegExp(`${s}`, "g" + flag);
|
|
@@ -150,10 +165,34 @@ class Program {
|
|
|
150
165
|
var Code = this.Code;
|
|
151
166
|
var queue = new Code();
|
|
152
167
|
queue.type = this.type;
|
|
168
|
+
queue.inExpress = this.inExpress;
|
|
169
|
+
if (this.type === ELEMENT) {
|
|
170
|
+
queue.entry = this.tags[0].tag[0];
|
|
171
|
+
}
|
|
153
172
|
var origin = queue;
|
|
154
173
|
var forceend_reg = this.forceend_reg;
|
|
155
174
|
var program = this;
|
|
156
|
-
var
|
|
175
|
+
var quote_map = this.quote_map;
|
|
176
|
+
var space_reg = this.space_reg;
|
|
177
|
+
var strap_reg = this.strap_reg;
|
|
178
|
+
var stamp_reg = this.stamp_reg;
|
|
179
|
+
var scope_entry = this.scope_entry;
|
|
180
|
+
var express_reg = this.express_reg;
|
|
181
|
+
var value_reg = this.value_reg;
|
|
182
|
+
var extends_reg = this.extends_reg;
|
|
183
|
+
var funcstrap_reg = this.funcstrap_reg;
|
|
184
|
+
var entry_reg = this.entry_reg;
|
|
185
|
+
var type_reg = this.type_reg;
|
|
186
|
+
var comment_entry = this.comment_entry;
|
|
187
|
+
var rowsOf = m => m.replace(/[^\r\n\u2028\u2029]+/g, ';').replace(/\r\n|\r|\n|\u2028|\u2029/g, ' ').replace(/;/g, '').length;
|
|
188
|
+
var setRows = m => {
|
|
189
|
+
row += rowsOf(m);
|
|
190
|
+
colstart = start + m.length - m.replace(/^[\s\S]*?([^\r\n\u2028\u2029]*)$/, '$1').length - 1;
|
|
191
|
+
};
|
|
192
|
+
var queue_push = (scope) => {
|
|
193
|
+
if (scope.type & (SPACE | COMMENT | PIECE | QUOTED)) {
|
|
194
|
+
if (scope.text) setRows(scope.text);
|
|
195
|
+
}
|
|
157
196
|
var last = queue.last;
|
|
158
197
|
Object.defineProperty(scope, 'queue', { value: queue, enumerable: false, configurable: true });
|
|
159
198
|
scope.prev = last;
|
|
@@ -172,7 +211,16 @@ class Program {
|
|
|
172
211
|
last = queue.last, scope.prev = last;
|
|
173
212
|
if (last) last.text = text.slice(last.start, last.end);
|
|
174
213
|
}
|
|
175
|
-
if (
|
|
214
|
+
if (queue.isClass && scope.isprop) scope.isend = false;
|
|
215
|
+
if (last) {
|
|
216
|
+
last.next = scope;
|
|
217
|
+
if (queue[queue.length - 1] === last && last.type === scope.type && last.type & (EXPRESS | PROPERTY)) {
|
|
218
|
+
this.twain(last, scope);
|
|
219
|
+
}
|
|
220
|
+
if (last.type === STAMP && last.text === "*") {
|
|
221
|
+
if (scope.type === STRAP) last.unary = false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
176
224
|
queue.last = scope;
|
|
177
225
|
for (var cx = queue.length - 1; cx >= 0; cx--) {
|
|
178
226
|
var o = queue[cx];
|
|
@@ -181,49 +229,101 @@ class Program {
|
|
|
181
229
|
}
|
|
182
230
|
if (!queue.first) queue.first = scope;
|
|
183
231
|
}
|
|
184
|
-
scope.row = row;
|
|
185
|
-
scope.col = scope.start - colstart;
|
|
186
232
|
queue.push(scope);
|
|
187
233
|
};
|
|
188
234
|
var row = 1, colstart = -1;
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
235
|
+
var cache_stamp = null;
|
|
236
|
+
var powermap = this.powermap;
|
|
237
|
+
var push_stamp = function () {
|
|
238
|
+
var last = queue.last;
|
|
239
|
+
var o = cache_stamp;
|
|
240
|
+
if (last?.istype && last.prev?.isarg) {
|
|
241
|
+
o.unary = true;
|
|
242
|
+
}
|
|
243
|
+
else if (!last || last.type === STAMP && (!(last.text in powermap)) && !last.istype) {
|
|
244
|
+
if (!queue.istype && powermap[o.text] > powermap["="]) o.unary = true;
|
|
245
|
+
}
|
|
246
|
+
else if (last.type === STRAP && !last.isend || last.type === STAMP && !last.istype && !/^(\+\+|\-\-)$/.test(last.text) || last.type === SCOPED && /^[\{\[]$/.test(last.entry) && !last.isExpress) {
|
|
247
|
+
o.unary = /^[^=;,\:]$/.test(o.text);
|
|
248
|
+
if (o.unary && /^(\+|\-)$/.test(o.text) && last && last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) o.unary = !!last.unary;
|
|
249
|
+
}
|
|
250
|
+
if (/^(\+\+|\-\-)$/.test(o.text)) {
|
|
251
|
+
var i = 1;
|
|
252
|
+
var p = queue[queue.length - i];
|
|
253
|
+
if (p === o) p = queue[queue.length - ++i];
|
|
254
|
+
while (p && p.type & (SPACE | COMMENT)) {
|
|
255
|
+
if (p.type === SPACE && /[\r\n\u2028\u2029]/.test(p.text)) break;
|
|
256
|
+
p = queue[queue.length - ++i];
|
|
206
257
|
}
|
|
258
|
+
o.unary = !p || p.type & (SPACE | STAMP | STRAP) || p.type === EXPRESS && p.prev && p.prev.type === STAMP && /^(\+\+|\-\-)$/.test(p.prev.text) && p.prev.unary;
|
|
207
259
|
}
|
|
208
260
|
|
|
261
|
+
if (!o.unary && /^(\.\.\.|\*)$/.test(o.text)) {
|
|
262
|
+
if (powermap[o.text] === powermap.new) o.unary = true;
|
|
263
|
+
if (last?.isarg || last?.isargl || last?.isprop) {
|
|
264
|
+
o.unary = true;
|
|
265
|
+
o.istype = true;
|
|
266
|
+
}
|
|
267
|
+
else if (queue.istype || o.isprop) o.unary = true;
|
|
268
|
+
else {
|
|
269
|
+
if (last?.isprop && !last.isend) o.unary = true;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (powermap[o.text] >= powermap["."]) {
|
|
273
|
+
o.needle = true;
|
|
274
|
+
}
|
|
275
|
+
if (o.needle);
|
|
276
|
+
else if (powermap[o.text] > powermap.new && !o.unary) {
|
|
277
|
+
o.needle = true;
|
|
278
|
+
}
|
|
279
|
+
queue_push(cache_stamp);
|
|
280
|
+
if (cache_stamp.istype && cache_stamp.unary && powermap[cache_stamp.text] == powermap[":"]) cache_stamp.unary = false;
|
|
281
|
+
if (cache_stamp === queue.last && cache_stamp.isExpress && cache_stamp.text in powermap && !cache_stamp.needle) queue.inExpress = true;
|
|
282
|
+
lasttype = cache_stamp.type;
|
|
283
|
+
cache_stamp = null;
|
|
284
|
+
}
|
|
285
|
+
var save = (type) => {
|
|
286
|
+
if (type === STAMP) {
|
|
287
|
+
if (cache_stamp) {
|
|
288
|
+
var stamp = cache_stamp.text;
|
|
289
|
+
if (!stamp) stamp = m;
|
|
290
|
+
else stamp += m;
|
|
291
|
+
if (stamp in powermap) {
|
|
292
|
+
cache_stamp.text = stamp;
|
|
293
|
+
cache_stamp.end = end;
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
push_stamp();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
if (cache_stamp) push_stamp();
|
|
301
|
+
}
|
|
209
302
|
var scope = {
|
|
210
303
|
type,
|
|
211
304
|
start,
|
|
212
305
|
end,
|
|
306
|
+
row,
|
|
307
|
+
col: start - colstart,
|
|
213
308
|
isExpress: queue.inExpress,
|
|
214
309
|
text: m
|
|
310
|
+
};
|
|
311
|
+
lasttype = type;
|
|
312
|
+
if (type === STAMP) {
|
|
313
|
+
cache_stamp = scope;
|
|
314
|
+
scope.prev = queue.last;
|
|
315
|
+
return;
|
|
215
316
|
}
|
|
216
317
|
if (type === STRAP) {
|
|
217
318
|
if (forceend_reg.test(m)) scope.isend = false, queue.inExpress = false;
|
|
218
|
-
if (this.transive_reg.test(m)) scope.transive = true, queue.inExpress = true;
|
|
219
319
|
}
|
|
220
320
|
if (isdigit) scope.isdigit = true;
|
|
221
|
-
lasttype = type;
|
|
222
321
|
queue_push(scope);
|
|
223
322
|
};
|
|
224
323
|
var space_exp = this.space_exp;
|
|
225
324
|
var scriptTags = this.scriptTags;
|
|
226
325
|
var ignoreTags = this.ignoreTags;
|
|
326
|
+
var structstrap_reg = this.structstrap_reg;
|
|
227
327
|
var openTag = function () {
|
|
228
328
|
var m1 = text.slice(start, match.index);
|
|
229
329
|
var s = space_exp.exec(m1);
|
|
@@ -253,6 +353,9 @@ class Program {
|
|
|
253
353
|
scope.entry = queue.tag_entry;
|
|
254
354
|
scope.tag_leave = queue.tag_leave;
|
|
255
355
|
scope.tag = tag;
|
|
356
|
+
scope.row = row;
|
|
357
|
+
scope.col = scope.start - colstart;
|
|
358
|
+
|
|
256
359
|
scope.inTag = true;
|
|
257
360
|
scope.type = ELEMENT;
|
|
258
361
|
}
|
|
@@ -290,11 +393,25 @@ class Program {
|
|
|
290
393
|
queue.last = null;
|
|
291
394
|
return true;
|
|
292
395
|
};
|
|
396
|
+
var isTypedColon = function (qp) {
|
|
397
|
+
var istype = false;
|
|
398
|
+
if (qp?.type === STAMP && qp.text === ':' && !qp.isExpress) {
|
|
399
|
+
if (qp.istype) return true;
|
|
400
|
+
var qpp = qp.prev;
|
|
401
|
+
if (qpp.type === SCOPED && qpp.entry === '(') {
|
|
402
|
+
var qppp = qpp.prev;
|
|
403
|
+
if (qppp && (qppp.isprop)) {
|
|
404
|
+
istype = true;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return istype;
|
|
409
|
+
}
|
|
293
410
|
var closeTag = function () {
|
|
294
411
|
queue.inTag = false;
|
|
295
412
|
if (queue.closed) return;
|
|
296
413
|
if (queue.length) queue.attributes = queue.splice(0, queue.length);
|
|
297
|
-
if (/^\//.test(m)) return queue.short = true, queue.closed = true;
|
|
414
|
+
if (/^\//.test(m) || queue.istype) return queue.short = true, queue.closed = true;
|
|
298
415
|
return false;
|
|
299
416
|
};
|
|
300
417
|
var push_quote = function () {
|
|
@@ -309,35 +426,65 @@ class Program {
|
|
|
309
426
|
push_parents(scope);
|
|
310
427
|
};
|
|
311
428
|
var push_parents = function (scope) {
|
|
429
|
+
if (cache_stamp) push_stamp();
|
|
312
430
|
scope.queue = queue;
|
|
313
431
|
scope.prev = queue.last;
|
|
432
|
+
scope.row = row;
|
|
433
|
+
scope.col = match.index - colstart;
|
|
314
434
|
parents.push(queue);
|
|
315
435
|
queue = scope;
|
|
316
436
|
lasttype = null;
|
|
317
437
|
}
|
|
318
438
|
var pop_parents = function () {
|
|
439
|
+
if (cache_stamp) push_stamp();
|
|
440
|
+
if (!parents.length) {
|
|
441
|
+
delete queue.end;
|
|
442
|
+
var last = queue.last;
|
|
443
|
+
if (last) {
|
|
444
|
+
while (queue[queue.length - 1] !== last) {
|
|
445
|
+
queue.pop();
|
|
446
|
+
}
|
|
447
|
+
queue.pop();
|
|
448
|
+
index = queue.last.start;
|
|
449
|
+
queue.last = last.prev;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
var m = queue.leave;
|
|
453
|
+
index = queue.end - m.length;
|
|
454
|
+
}
|
|
455
|
+
delete queue.start;
|
|
456
|
+
delete queue.end;
|
|
457
|
+
delete queue.leave;
|
|
458
|
+
delete queue.type;
|
|
459
|
+
delete queue.entry;
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
319
462
|
var scope = queue;
|
|
320
463
|
queue = parents.pop();
|
|
321
464
|
queue_push(scope);
|
|
322
465
|
lasttype = scope.type;
|
|
323
466
|
}
|
|
324
467
|
var push_piece = function (index = match.index) {
|
|
468
|
+
if (cache_stamp) push_stamp();
|
|
325
469
|
if (index > start) {
|
|
326
470
|
var piece = queue[queue.length - 1];
|
|
327
471
|
if (piece && piece.type === PIECE) {
|
|
472
|
+
row -= rowsOf(piece.text);
|
|
328
473
|
piece.text = text.slice(piece.start, index);
|
|
329
|
-
piece.
|
|
474
|
+
setRows(piece.text);
|
|
475
|
+
piece.end = index;
|
|
330
476
|
}
|
|
331
477
|
else {
|
|
332
478
|
m = text.slice(start, index);
|
|
333
|
-
save(PIECE);
|
|
479
|
+
save(space_reg.test(m) ? SPACE : PIECE);
|
|
334
480
|
}
|
|
335
481
|
}
|
|
336
482
|
m = match[0];
|
|
337
483
|
}
|
|
338
484
|
loop: while (index < text.length) {
|
|
339
|
-
|
|
340
|
-
|
|
485
|
+
|
|
486
|
+
if (queue.type & (QUOTED | ELEMENT)) {
|
|
487
|
+
var quote = quote_map[queue.entry];
|
|
341
488
|
var reg = quote.reg;
|
|
342
489
|
start = index;
|
|
343
490
|
while (index < text.length) {
|
|
@@ -359,12 +506,12 @@ class Program {
|
|
|
359
506
|
|
|
360
507
|
continue;
|
|
361
508
|
}
|
|
509
|
+
|
|
362
510
|
if (quote.end.test(m)) {
|
|
363
511
|
end = match.index;
|
|
364
512
|
if (queue.tag) {
|
|
365
513
|
push_piece();
|
|
366
514
|
if (!queue.inTag) continue;
|
|
367
|
-
|
|
368
515
|
if (closeTag() === false) {
|
|
369
516
|
start = index;
|
|
370
517
|
queue.tag_leave = m;
|
|
@@ -391,6 +538,7 @@ class Program {
|
|
|
391
538
|
var scope = [];
|
|
392
539
|
scope.entry = m;
|
|
393
540
|
scope.type = QUOTED;
|
|
541
|
+
if (queue.istype) scope.istype = queue.istype;
|
|
394
542
|
scope.start = index;
|
|
395
543
|
scope.isExpress = queue.inExpress;
|
|
396
544
|
push_parents(scope);
|
|
@@ -411,11 +559,11 @@ class Program {
|
|
|
411
559
|
push_quote();
|
|
412
560
|
continue loop;
|
|
413
561
|
}
|
|
414
|
-
if (m in
|
|
415
|
-
if (
|
|
562
|
+
if (m in quote_map) {
|
|
563
|
+
if (comment_entry.test(m)) {
|
|
416
564
|
push_piece();
|
|
417
565
|
var start = match.index;
|
|
418
|
-
var { reg: comment_reg,end:comment_end } =
|
|
566
|
+
var { reg: comment_reg, end: comment_end } = quote_map[m];
|
|
419
567
|
comment_reg.lastIndex = index;
|
|
420
568
|
do {
|
|
421
569
|
var match = comment_reg.exec(text);
|
|
@@ -439,16 +587,17 @@ class Program {
|
|
|
439
587
|
continue;
|
|
440
588
|
}
|
|
441
589
|
|
|
442
|
-
var
|
|
443
|
-
var
|
|
444
|
-
var match = reg.exec(text);
|
|
590
|
+
var start = entry_reg.lastIndex = index;
|
|
591
|
+
var match = entry_reg.exec(text);
|
|
445
592
|
if (!match) return null;
|
|
446
593
|
var end = match[0].length + match.index;
|
|
447
594
|
index = end;
|
|
448
595
|
var m = match[0];
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
596
|
+
if (cache_stamp && !stamp_reg.test(m)) push_stamp();
|
|
597
|
+
var last = cache_stamp || queue.last;
|
|
598
|
+
|
|
599
|
+
test: if (quote_map.hasOwnProperty(m)) {
|
|
600
|
+
var quote = quote_map[m];
|
|
452
601
|
if (queue.tag && quote.tag) {
|
|
453
602
|
var tagend = end + queue.tag.length
|
|
454
603
|
var leavem = quote.entry[m];
|
|
@@ -460,22 +609,64 @@ class Program {
|
|
|
460
609
|
break test;
|
|
461
610
|
}
|
|
462
611
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
612
|
+
var iscomment = comment_entry.test(m);
|
|
613
|
+
var isTypeTag = false;
|
|
614
|
+
if (iscomment);
|
|
615
|
+
else if (queue.istype) {
|
|
616
|
+
isTypeTag = true;
|
|
617
|
+
}
|
|
618
|
+
else if (!last) {
|
|
619
|
+
if (!queue.brace) {
|
|
620
|
+
isTypeTag = isTypedColon(queue.prev);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
else if (stamp_reg.test(m) && last) {
|
|
624
|
+
if (last.type === STAMP && m === last.text) break test;
|
|
625
|
+
if (last.istype || last.isprop || last.isargl) {
|
|
626
|
+
isTypeTag = true;
|
|
627
|
+
}
|
|
628
|
+
else if ((VALUE | EXPRESS | PROPERTY) & last.type) a: {
|
|
629
|
+
if (queue.classed) {
|
|
630
|
+
isTypeTag = true;
|
|
631
|
+
break a;
|
|
632
|
+
}
|
|
466
633
|
var lp = last.prev;
|
|
467
634
|
if (lp) {
|
|
468
|
-
if (lp.type === STAMP
|
|
469
|
-
|
|
635
|
+
if (lp.type === STAMP) {
|
|
636
|
+
if (lp.text === ':') {
|
|
637
|
+
if (isTypedColon(lp)) {
|
|
638
|
+
last.istype = true;
|
|
639
|
+
isTypeTag = true;
|
|
640
|
+
break a;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
break test;
|
|
644
|
+
}
|
|
645
|
+
if (lp.istype || lp.isargl) {
|
|
646
|
+
isTypeTag = true;
|
|
647
|
+
break a;
|
|
648
|
+
}
|
|
649
|
+
if (lp.type === STRAP) {
|
|
650
|
+
if (lp.transive) break test;
|
|
651
|
+
}
|
|
470
652
|
}
|
|
653
|
+
if (queue.type !== ELEMENT) break test;
|
|
654
|
+
}
|
|
655
|
+
else switch (last.type) {
|
|
656
|
+
case QUOTED:
|
|
657
|
+
if (!last.tag) break test;
|
|
658
|
+
break;
|
|
659
|
+
case SCOPED:
|
|
660
|
+
if (queue.inExpress && !iscomment) break test;
|
|
661
|
+
break;
|
|
662
|
+
case STAMP:
|
|
663
|
+
if (/^(\+\+|\-\-)$/.test(last.text)) break test;
|
|
664
|
+
break;
|
|
471
665
|
}
|
|
472
|
-
if (last.type === QUOTED && !last.tag) break test;
|
|
473
|
-
if (last.type === SCOPED && queue.inExpress) break test;
|
|
474
|
-
if (lasttype === STAMP && m === last.text) break test;
|
|
475
|
-
if (last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) break test;
|
|
476
666
|
}
|
|
477
667
|
var scope = [];
|
|
478
|
-
scope.type =
|
|
668
|
+
scope.type = iscomment ? COMMENT : QUOTED;
|
|
669
|
+
if (isTypeTag && scope.type === QUOTED) scope.istype = isTypeTag;
|
|
479
670
|
scope.isExpress = queue.inExpress;
|
|
480
671
|
scope.start = start;
|
|
481
672
|
push_parents(scope);
|
|
@@ -487,8 +678,8 @@ class Program {
|
|
|
487
678
|
|
|
488
679
|
var m0 = m;
|
|
489
680
|
var reg = quote.reg;
|
|
681
|
+
reg.lastIndex = index;
|
|
490
682
|
while (index < text.length) {
|
|
491
|
-
reg.lastIndex = index;
|
|
492
683
|
var match = reg.exec(text);
|
|
493
684
|
if (!match) {
|
|
494
685
|
index = text.length;
|
|
@@ -519,16 +710,15 @@ class Program {
|
|
|
519
710
|
continue;
|
|
520
711
|
}
|
|
521
712
|
var parent = parents[parents.length - 1];
|
|
522
|
-
if (parent &&
|
|
713
|
+
if (parent && quote_map[parent.entry] && queue.leave_map?.[m] === queue.entry) {
|
|
523
714
|
delete queue.leave_map;
|
|
524
715
|
queue.end = end;
|
|
525
716
|
queue.leave = m;
|
|
526
717
|
pop_parents();
|
|
527
718
|
continue;
|
|
528
719
|
}
|
|
529
|
-
if (
|
|
720
|
+
if (space_reg.test(m)) {
|
|
530
721
|
if (/[\r\n\u2028\u2029]/.test(m)) {
|
|
531
|
-
var last = queue.last;
|
|
532
722
|
if (last && last.isend === false) {
|
|
533
723
|
last.isend = true;
|
|
534
724
|
queue.inExpress = false;
|
|
@@ -541,10 +731,8 @@ class Program {
|
|
|
541
731
|
lasttype = SPACE;
|
|
542
732
|
continue;
|
|
543
733
|
}
|
|
544
|
-
if (
|
|
545
|
-
if (
|
|
546
|
-
else {
|
|
547
|
-
var last = queue.last;
|
|
734
|
+
if (!last?.needle && strap_reg.test(m)) {
|
|
735
|
+
if (funcstrap_reg.test(m)) {
|
|
548
736
|
if (!last);
|
|
549
737
|
else if (last.type === STAMP) {
|
|
550
738
|
queue.inExpress = !/^(;|\+\+|\-\-)$/.test(last.text);
|
|
@@ -554,6 +742,25 @@ class Program {
|
|
|
554
742
|
}
|
|
555
743
|
}
|
|
556
744
|
save(STRAP);
|
|
745
|
+
var last = queue.last;
|
|
746
|
+
if (last.type === STRAP && structstrap_reg.test(last.text) && !queue.classed) {
|
|
747
|
+
queue.classed = [last.text];
|
|
748
|
+
}
|
|
749
|
+
else if (queue.classed) {
|
|
750
|
+
if (last.type === STRAP && funcstrap_reg.test(last.text)) queue.classed.push(last.text);
|
|
751
|
+
}
|
|
752
|
+
if (funcstrap_reg.test(m)) {
|
|
753
|
+
last.isargl = true;
|
|
754
|
+
}
|
|
755
|
+
else if (type_reg.test(m)) {
|
|
756
|
+
last.istype = true;
|
|
757
|
+
}
|
|
758
|
+
if (this.transive_reg.test(m)) {
|
|
759
|
+
last.transive = queue.inExpress = true;
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
queue.inExpress = false;
|
|
763
|
+
}
|
|
557
764
|
continue;
|
|
558
765
|
}
|
|
559
766
|
var isdigit = number_reg.exec(m);
|
|
@@ -564,13 +771,16 @@ class Program {
|
|
|
564
771
|
m = m1;
|
|
565
772
|
index = match.index + m.length;
|
|
566
773
|
}
|
|
774
|
+
else if (/\.$/.test(m1)) {
|
|
775
|
+
m = m1.slice(0, m1.length - 1);
|
|
776
|
+
index = match.index + m.length;
|
|
777
|
+
}
|
|
567
778
|
}
|
|
568
779
|
isdigit = true;
|
|
569
780
|
}
|
|
570
|
-
if (
|
|
781
|
+
if (!last?.needle && value_reg.test(m) || isdigit) {
|
|
571
782
|
queue.inExpress = true;
|
|
572
783
|
if (isdigit && lasttype === STAMP) {
|
|
573
|
-
var last = queue.last;
|
|
574
784
|
var prev = last.prev;
|
|
575
785
|
if ((!prev || prev.type & (STAMP | STRAP) && !/^(\+\+|\-\-)$/.test(prev.text)) && /^[+\-]+$/.test(last.text)) {
|
|
576
786
|
last.type = VALUE;
|
|
@@ -584,49 +794,79 @@ class Program {
|
|
|
584
794
|
save(VALUE);
|
|
585
795
|
continue;
|
|
586
796
|
}
|
|
587
|
-
if (
|
|
588
|
-
|
|
589
|
-
if (last && last.type === STRAP && this.classstrap_reg.test(last.text));
|
|
797
|
+
if (express_reg.test(m)) {
|
|
798
|
+
if (last && last.type === STRAP && funcstrap_reg.test(last.text));
|
|
590
799
|
else queue.inExpress = true;
|
|
591
800
|
save(EXPRESS);
|
|
592
801
|
continue;
|
|
593
802
|
}
|
|
594
803
|
|
|
595
|
-
if (
|
|
804
|
+
if (scope_entry[m]) {
|
|
596
805
|
var scope = [];
|
|
597
806
|
scope.entry = m;
|
|
598
807
|
scope.type = SCOPED;
|
|
599
808
|
scope.start = match.index;
|
|
600
809
|
scope.col = match.index - colstart;
|
|
601
810
|
scope.row = row;
|
|
602
|
-
var last = queue.last;
|
|
603
811
|
if (m === "{") {
|
|
604
812
|
if (!last) {
|
|
605
|
-
scope.
|
|
813
|
+
if (queue.istype) scope.isClass = true;
|
|
814
|
+
else scope.isObject = queue.inExpress;
|
|
606
815
|
}
|
|
607
|
-
else if (queue.classed
|
|
816
|
+
else if (queue.classed) {
|
|
608
817
|
if (last.type !== STAMP || last.text !== "=>") {
|
|
609
|
-
queue.classed
|
|
818
|
+
var classed = queue.classed;
|
|
819
|
+
var clsd = classed.pop();
|
|
610
820
|
scope.isClass = true;
|
|
611
|
-
|
|
821
|
+
if (!classed.length) queue.classed = null;
|
|
822
|
+
scope.istype = clsd !== 'class';
|
|
823
|
+
scope.extend += extends_reg.test(last.text);
|
|
612
824
|
scope.inExpress = false;
|
|
613
825
|
}
|
|
614
826
|
}
|
|
827
|
+
else if (last.type === SCOPED && last.istype) {
|
|
828
|
+
scope.isClass = true;
|
|
829
|
+
}
|
|
615
830
|
else if (last.type === STAMP) {
|
|
616
|
-
if (last.
|
|
831
|
+
if (last.istype) {
|
|
832
|
+
scope.isClass = true;
|
|
833
|
+
}
|
|
834
|
+
else if (last.text === ':') {
|
|
617
835
|
scope.isObject = queue.inExpress;
|
|
618
836
|
}
|
|
619
837
|
else queue.inExpress = scope.isObject = !/^(;|\+\+|\-\-|=>)$/.test(last.text);
|
|
620
838
|
}
|
|
621
|
-
else if (last.type === EXPRESS
|
|
622
|
-
|
|
839
|
+
else if (last.type === EXPRESS) a: {
|
|
840
|
+
var li = queue.length - 1;
|
|
841
|
+
var lp = queue[li];
|
|
842
|
+
while (lp !== last) {
|
|
843
|
+
if (lp.type === SPACE) break a;
|
|
844
|
+
lp = queue[li--];
|
|
845
|
+
}
|
|
846
|
+
var lp = last.prev;
|
|
847
|
+
if (lp?.type === STAMP && powermap[lp.text] === powermap["="]) scope.isObject = true;
|
|
623
848
|
}
|
|
624
849
|
else if (last.type === STRAP) {
|
|
625
850
|
if (last.isend);
|
|
626
|
-
else scope.isObject =
|
|
851
|
+
else scope.isObject = last.transive;
|
|
627
852
|
}
|
|
853
|
+
scope.brace = true;
|
|
854
|
+
scope.isExpress = queue.inExpress;
|
|
628
855
|
}
|
|
629
856
|
else {
|
|
857
|
+
var prev = last;
|
|
858
|
+
if (prev?.type === ELEMENT) prev = prev.prev;
|
|
859
|
+
if (prev?.type === EXPRESS) {
|
|
860
|
+
prev = prev.prev;
|
|
861
|
+
}
|
|
862
|
+
if (prev) {
|
|
863
|
+
if (prev.isargl || prev.isprop || queue.istype) {
|
|
864
|
+
scope.isargl = true;
|
|
865
|
+
}
|
|
866
|
+
else if (prev.istype) {
|
|
867
|
+
scope.istype = true;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
630
870
|
if (!last || (last.type & (SCOPED | STAMP))) queue.inExpress = true;
|
|
631
871
|
scope.isExpress = queue.inExpress;
|
|
632
872
|
scope.inExpress = true;
|
|
@@ -635,11 +875,8 @@ class Program {
|
|
|
635
875
|
continue;
|
|
636
876
|
}
|
|
637
877
|
if (this.scope_leave[m] && queue.entry === this.scope_leave[m]) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
if (lastUncomment.type === PROPERTY) {
|
|
641
|
-
lastUncomment.short = true;
|
|
642
|
-
}
|
|
878
|
+
if (last?.type === PROPERTY) {
|
|
879
|
+
last.short = true;
|
|
643
880
|
}
|
|
644
881
|
|
|
645
882
|
queue.end = end;
|
|
@@ -649,10 +886,7 @@ class Program {
|
|
|
649
886
|
continue;
|
|
650
887
|
}
|
|
651
888
|
if (this.scope_leave[m]) console.warn(i18n`标记不匹配`, queue.entry, m, "queue-start:", queue.start, "position:", `${row}:${index - colstart}\r\n`, index - queue.start < 200 ? text.slice(queue.start, index) : text.slice(queue.start, queue.start + 100) + "..." + text.slice(index - 97, index));
|
|
652
|
-
|
|
653
|
-
save(STAMP);
|
|
654
|
-
}
|
|
655
|
-
|
|
889
|
+
save(STAMP);
|
|
656
890
|
}
|
|
657
891
|
while (queue.tag && parents.length) {
|
|
658
892
|
for (var cx = 0, dx = parents.length; cx < dx; cx++) {
|
|
@@ -667,18 +901,34 @@ class Program {
|
|
|
667
901
|
queue_push(p);
|
|
668
902
|
}
|
|
669
903
|
};
|
|
904
|
+
if (cache_stamp) push_stamp();
|
|
670
905
|
this.lastIndex = index;
|
|
671
906
|
if (queue !== origin) {
|
|
672
|
-
|
|
907
|
+
console.log(
|
|
908
|
+
"代码异常结束",
|
|
909
|
+
createString(origin.slice(0, 30)),
|
|
910
|
+
`\r\n ----- deep: ${parents.length}`,
|
|
911
|
+
`\r\n ---- enrty: ${queue.entry}`,
|
|
912
|
+
`\r\n --- length: ${queue.length}`,
|
|
913
|
+
`\r\n ----- last: ${queue.last ? createString([queue.last]).slice(0, 30) : createString(queue).slice(0, 30)}`,
|
|
914
|
+
`\r\n -- parents: ${parents.map(p => `${p.row}:${p.col}-${p.tag || p.text || p.entry} `).join('-)> ')}`,
|
|
915
|
+
`\r\n ----- snap: ${createString([queue]).slice(-200)}`,
|
|
916
|
+
`\r\n ------ end. `
|
|
917
|
+
);
|
|
918
|
+
while (queue !== origin) {
|
|
919
|
+
queue.error = "代码异常结束";
|
|
920
|
+
queue.leave = '';
|
|
921
|
+
pop_parents();
|
|
922
|
+
}
|
|
673
923
|
}
|
|
674
|
-
return
|
|
924
|
+
return origin;
|
|
675
925
|
}
|
|
676
926
|
commit() {
|
|
677
927
|
this.strap_reg = this.createRegExp(this.straps);
|
|
678
928
|
this.comment_entry = this.createRegExp(this.comments.map(m => m[0]));
|
|
679
929
|
var stamps = this.stamps.join("");
|
|
680
930
|
stamps = this.compile(stamps);
|
|
681
|
-
this.stamp_reg = new RegExp(`^[${stamps}]
|
|
931
|
+
this.stamp_reg = new RegExp(`^[${stamps}]+$`);
|
|
682
932
|
var tokens = {};
|
|
683
933
|
var quote_map = {};
|
|
684
934
|
this.quote_map = quote_map;
|
|
@@ -714,7 +964,8 @@ class Program {
|
|
|
714
964
|
return this.compile(q);
|
|
715
965
|
});
|
|
716
966
|
if (q.tag) r = r.concat(q.tag);
|
|
717
|
-
r = r.concat(ts.map(this.compile))
|
|
967
|
+
r = r.concat(ts.map(this.compile));
|
|
968
|
+
r = sortRegster(r).join("|");
|
|
718
969
|
q.reg = new RegExp(r, 'g');
|
|
719
970
|
q.end = this.createRegExp([q[1]]);
|
|
720
971
|
if (q.length >= 4) {
|
|
@@ -747,8 +998,10 @@ class Program {
|
|
|
747
998
|
this.express_reg = new RegExp(`^${express}$`, flagUnicode);
|
|
748
999
|
this.space_reg = new RegExp(`^[${spaces}]+$`, flagUnicode);
|
|
749
1000
|
this.space_exp = new RegExp(`[${spaces}]+`, flagUnicode);
|
|
750
|
-
var
|
|
751
|
-
|
|
1001
|
+
var quotes_entries = this.createRegExp(this.comments.concat(this.quotes).map(q => q[0]), true).source;
|
|
1002
|
+
var powers = Object.keys(this.powermap).filter(k => this.stamp_reg.test(k));
|
|
1003
|
+
var powers_entries = this.createRegExp(this.tags.map(t => t[0]).concat(powers), true).source;
|
|
1004
|
+
this.entry_reg = new RegExp([`[${spaces}]+|${quotes_entries}|[${scopes}]|${number_reg.source.replace(/^\^|\$$/g, "")}[^${tokens}]*|${express}|${powers_entries}|[${stamps}]`], "gi" + flagUnicode);
|
|
752
1005
|
}
|
|
753
1006
|
}
|
|
754
1007
|
module.exports = Program;
|