@lokascript/core 1.1.4 → 1.2.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/dist/bundle-generator/index.d.ts +2 -1
- package/dist/bundle-generator/index.d.ts.map +1 -1
- package/dist/bundle-generator/index.js +1335 -9
- package/dist/bundle-generator/index.js.map +1 -1
- package/dist/bundle-generator/index.mjs +1330 -10
- package/dist/bundle-generator/index.mjs.map +1 -1
- package/dist/bundle-generator/parser-templates.d.ts +6 -0
- package/dist/bundle-generator/parser-templates.d.ts.map +1 -0
- package/dist/bundle-generator/template-capabilities.d.ts +2 -2
- package/dist/bundle-generator/template-capabilities.d.ts.map +1 -1
- package/dist/bundle-generator/templates.d.ts +1 -0
- package/dist/bundle-generator/templates.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/bundle-generator/index.ts +10 -0
- package/src/bundle-generator/parser-templates.ts +1158 -0
- package/src/bundle-generator/template-capabilities.ts +17 -14
- package/src/bundle-generator/templates.ts +228 -0
- package/src/bundle-generator/validation.test.ts +25 -3
|
@@ -215,6 +215,33 @@ const COMMAND_IMPLEMENTATIONS_TS = {
|
|
|
215
215
|
ctx.it = content;
|
|
216
216
|
return content;
|
|
217
217
|
}`,
|
|
218
|
+
morph: `
|
|
219
|
+
case 'morph': {
|
|
220
|
+
const targets = await getTarget();
|
|
221
|
+
const content = await evaluate(cmd.args[0], ctx);
|
|
222
|
+
const contentStr = String(content);
|
|
223
|
+
const isOuter = cmd.modifier === 'over';
|
|
224
|
+
|
|
225
|
+
for (const target of targets) {
|
|
226
|
+
try {
|
|
227
|
+
if (isOuter) {
|
|
228
|
+
morphlexMorph(target, contentStr);
|
|
229
|
+
} else {
|
|
230
|
+
morphlexMorphInner(target, contentStr);
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
// Fallback to innerHTML/outerHTML if morph fails
|
|
234
|
+
console.warn('[LokaScript] Morph failed, falling back:', error);
|
|
235
|
+
if (isOuter) {
|
|
236
|
+
target.outerHTML = contentStr;
|
|
237
|
+
} else {
|
|
238
|
+
target.innerHTML = contentStr;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
ctx.it = targets.length === 1 ? targets[0] : targets;
|
|
243
|
+
return ctx.it;
|
|
244
|
+
}`,
|
|
218
245
|
take: `
|
|
219
246
|
case 'take': {
|
|
220
247
|
const className = getClassName(await evaluate(cmd.args[0], ctx));
|
|
@@ -299,6 +326,188 @@ const COMMAND_IMPLEMENTATIONS_TS = {
|
|
|
299
326
|
case 'continue': {
|
|
300
327
|
throw { type: 'continue' };
|
|
301
328
|
}`,
|
|
329
|
+
halt: `
|
|
330
|
+
case 'halt': {
|
|
331
|
+
// Check for "halt the event" pattern
|
|
332
|
+
const firstArg = cmd.args[0];
|
|
333
|
+
let targetEvent = ctx.event;
|
|
334
|
+
if (firstArg?.type === 'identifier' && firstArg.name === 'the' && cmd.args[1]?.name === 'event') {
|
|
335
|
+
targetEvent = ctx.event;
|
|
336
|
+
} else if (firstArg) {
|
|
337
|
+
const evaluated = await evaluate(firstArg, ctx);
|
|
338
|
+
if (evaluated?.preventDefault) targetEvent = evaluated;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (targetEvent && typeof targetEvent.preventDefault === 'function') {
|
|
342
|
+
targetEvent.preventDefault();
|
|
343
|
+
targetEvent.stopPropagation();
|
|
344
|
+
return { halted: true, eventHalted: true };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Regular halt - stop execution
|
|
348
|
+
const haltError = new Error('HALT_EXECUTION');
|
|
349
|
+
(haltError as any).isHalt = true;
|
|
350
|
+
throw haltError;
|
|
351
|
+
}`,
|
|
352
|
+
exit: `
|
|
353
|
+
case 'exit': {
|
|
354
|
+
const exitError = new Error('EXIT_COMMAND');
|
|
355
|
+
(exitError as any).isExit = true;
|
|
356
|
+
throw exitError;
|
|
357
|
+
}`,
|
|
358
|
+
throw: `
|
|
359
|
+
case 'throw': {
|
|
360
|
+
const message = cmd.args[0] ? await evaluate(cmd.args[0], ctx) : 'Error';
|
|
361
|
+
const errorToThrow = message instanceof Error ? message : new Error(String(message));
|
|
362
|
+
throw errorToThrow;
|
|
363
|
+
}`,
|
|
364
|
+
beep: `
|
|
365
|
+
case 'beep': {
|
|
366
|
+
const values = await Promise.all(cmd.args.map((a: any) => evaluate(a, ctx)));
|
|
367
|
+
const displayValues = values.length > 0 ? values : [ctx.it];
|
|
368
|
+
|
|
369
|
+
for (const val of displayValues) {
|
|
370
|
+
const typeInfo = val === null ? 'null' :
|
|
371
|
+
val === undefined ? 'undefined' :
|
|
372
|
+
Array.isArray(val) ? \`Array[\${val.length}]\` :
|
|
373
|
+
val instanceof Element ? \`Element<\${val.tagName.toLowerCase()}>\` :
|
|
374
|
+
typeof val;
|
|
375
|
+
console.log('[beep]', typeInfo + ':', val);
|
|
376
|
+
}
|
|
377
|
+
return displayValues[0];
|
|
378
|
+
}`,
|
|
379
|
+
js: `
|
|
380
|
+
case 'js': {
|
|
381
|
+
const codeArg = cmd.args[0];
|
|
382
|
+
let jsCode = '';
|
|
383
|
+
|
|
384
|
+
if (codeArg.type === 'string') {
|
|
385
|
+
jsCode = codeArg.value;
|
|
386
|
+
} else if (codeArg.type === 'template') {
|
|
387
|
+
jsCode = await evaluate(codeArg, ctx);
|
|
388
|
+
} else {
|
|
389
|
+
jsCode = String(await evaluate(codeArg, ctx));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Build context object for the Function
|
|
393
|
+
const jsContext = {
|
|
394
|
+
me: ctx.me,
|
|
395
|
+
it: ctx.it,
|
|
396
|
+
event: ctx.event,
|
|
397
|
+
target: ctx.target || ctx.me,
|
|
398
|
+
locals: Object.fromEntries(ctx.locals),
|
|
399
|
+
globals: Object.fromEntries(globalVars),
|
|
400
|
+
document: typeof document !== 'undefined' ? document : undefined,
|
|
401
|
+
window: typeof window !== 'undefined' ? window : undefined,
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
const fn = new Function('ctx', \`with(ctx) { return (async () => { \${jsCode} })(); }\`);
|
|
406
|
+
const result = await fn(jsContext);
|
|
407
|
+
ctx.it = result;
|
|
408
|
+
return result;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
console.error('[js] Execution error:', error);
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
}`,
|
|
414
|
+
copy: `
|
|
415
|
+
case 'copy': {
|
|
416
|
+
const source = await evaluate(cmd.args[0], ctx);
|
|
417
|
+
let textToCopy = '';
|
|
418
|
+
|
|
419
|
+
if (typeof source === 'string') {
|
|
420
|
+
textToCopy = source;
|
|
421
|
+
} else if (source instanceof Element) {
|
|
422
|
+
textToCopy = source.textContent || '';
|
|
423
|
+
} else {
|
|
424
|
+
textToCopy = String(source);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
try {
|
|
428
|
+
if (navigator.clipboard) {
|
|
429
|
+
await navigator.clipboard.writeText(textToCopy);
|
|
430
|
+
} else {
|
|
431
|
+
// Fallback for older browsers
|
|
432
|
+
const textarea = document.createElement('textarea');
|
|
433
|
+
textarea.value = textToCopy;
|
|
434
|
+
textarea.style.cssText = 'position:fixed;top:0;left:-9999px';
|
|
435
|
+
document.body.appendChild(textarea);
|
|
436
|
+
textarea.select();
|
|
437
|
+
document.execCommand('copy');
|
|
438
|
+
document.body.removeChild(textarea);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (ctx.me instanceof Element) {
|
|
442
|
+
ctx.me.dispatchEvent(new CustomEvent('copy:success', {
|
|
443
|
+
bubbles: true,
|
|
444
|
+
detail: { text: textToCopy }
|
|
445
|
+
}));
|
|
446
|
+
}
|
|
447
|
+
ctx.it = textToCopy;
|
|
448
|
+
return textToCopy;
|
|
449
|
+
} catch (error) {
|
|
450
|
+
if (ctx.me instanceof Element) {
|
|
451
|
+
ctx.me.dispatchEvent(new CustomEvent('copy:error', {
|
|
452
|
+
bubbles: true,
|
|
453
|
+
detail: { error }
|
|
454
|
+
}));
|
|
455
|
+
}
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
}`,
|
|
459
|
+
push: `
|
|
460
|
+
case 'push':
|
|
461
|
+
case 'push-url': {
|
|
462
|
+
// Handle "push url '/path'" pattern
|
|
463
|
+
let urlArg = cmd.args[0];
|
|
464
|
+
if (urlArg?.type === 'identifier' && urlArg.name === 'url') {
|
|
465
|
+
urlArg = cmd.args[1];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const url = String(await evaluate(urlArg, ctx));
|
|
469
|
+
let title = '';
|
|
470
|
+
|
|
471
|
+
// Check for "with title" modifier
|
|
472
|
+
if (cmd.modifiers?.title) {
|
|
473
|
+
title = String(await evaluate(cmd.modifiers.title, ctx));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
window.history.pushState(null, '', url);
|
|
477
|
+
if (title) document.title = title;
|
|
478
|
+
|
|
479
|
+
window.dispatchEvent(new CustomEvent('lokascript:pushurl', {
|
|
480
|
+
detail: { url, title }
|
|
481
|
+
}));
|
|
482
|
+
|
|
483
|
+
return { url, title, mode: 'push' };
|
|
484
|
+
}`,
|
|
485
|
+
replace: `
|
|
486
|
+
case 'replace':
|
|
487
|
+
case 'replace-url': {
|
|
488
|
+
// Handle "replace url '/path'" pattern
|
|
489
|
+
let urlArg = cmd.args[0];
|
|
490
|
+
if (urlArg?.type === 'identifier' && urlArg.name === 'url') {
|
|
491
|
+
urlArg = cmd.args[1];
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const url = String(await evaluate(urlArg, ctx));
|
|
495
|
+
let title = '';
|
|
496
|
+
|
|
497
|
+
// Check for "with title" modifier
|
|
498
|
+
if (cmd.modifiers?.title) {
|
|
499
|
+
title = String(await evaluate(cmd.modifiers.title, ctx));
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
window.history.replaceState(null, '', url);
|
|
503
|
+
if (title) document.title = title;
|
|
504
|
+
|
|
505
|
+
window.dispatchEvent(new CustomEvent('lokascript:replaceurl', {
|
|
506
|
+
detail: { url, title }
|
|
507
|
+
}));
|
|
508
|
+
|
|
509
|
+
return { url, title, mode: 'replace' };
|
|
510
|
+
}`,
|
|
302
511
|
};
|
|
303
512
|
const BLOCK_IMPLEMENTATIONS_TS = {
|
|
304
513
|
if: `
|
|
@@ -397,6 +606,7 @@ const BLOCK_IMPLEMENTATIONS_TS = {
|
|
|
397
606
|
};
|
|
398
607
|
const STYLE_COMMANDS = ['set', 'put', 'increment', 'decrement'];
|
|
399
608
|
const ELEMENT_ARRAY_COMMANDS = ['put', 'increment', 'decrement'];
|
|
609
|
+
const MORPH_COMMANDS = ['morph'];
|
|
400
610
|
function getCommandImplementations(format = 'ts') {
|
|
401
611
|
const result = {};
|
|
402
612
|
for (const [name, code] of Object.entries(COMMAND_IMPLEMENTATIONS_TS)) {
|
|
@@ -885,6 +1095,1114 @@ function generateBundle(config) {
|
|
|
885
1095
|
};
|
|
886
1096
|
}
|
|
887
1097
|
|
|
1098
|
+
const LITE_PARSER_TEMPLATE = `
|
|
1099
|
+
// Lite Parser - Regex-based for minimal bundle size
|
|
1100
|
+
|
|
1101
|
+
function parseLite(code) {
|
|
1102
|
+
const trimmed = code.trim();
|
|
1103
|
+
|
|
1104
|
+
// Handle event handlers: "on click toggle .active"
|
|
1105
|
+
const onMatch = trimmed.match(/^on\\s+(\\w+)(?:\\s+from\\s+([^\\s]+))?\\s+(.+)$/i);
|
|
1106
|
+
if (onMatch) {
|
|
1107
|
+
return {
|
|
1108
|
+
type: 'event',
|
|
1109
|
+
event: onMatch[1],
|
|
1110
|
+
filter: onMatch[2] ? { type: 'selector', value: onMatch[2] } : undefined,
|
|
1111
|
+
modifiers: {},
|
|
1112
|
+
body: parseCommands(onMatch[3]),
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// Handle "every Nms" event pattern
|
|
1117
|
+
const everyMatch = trimmed.match(/^every\\s+(\\d+)(ms|s)?\\s+(.+)$/i);
|
|
1118
|
+
if (everyMatch) {
|
|
1119
|
+
const ms = everyMatch[2] === 's' ? parseInt(everyMatch[1]) * 1000 : parseInt(everyMatch[1]);
|
|
1120
|
+
return {
|
|
1121
|
+
type: 'event',
|
|
1122
|
+
event: 'interval:' + ms,
|
|
1123
|
+
modifiers: {},
|
|
1124
|
+
body: parseCommands(everyMatch[3]),
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// Handle "init" pattern
|
|
1129
|
+
const initMatch = trimmed.match(/^init\\s+(.+)$/i);
|
|
1130
|
+
if (initMatch) {
|
|
1131
|
+
return {
|
|
1132
|
+
type: 'event',
|
|
1133
|
+
event: 'init',
|
|
1134
|
+
modifiers: {},
|
|
1135
|
+
body: parseCommands(initMatch[1]),
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
return { type: 'sequence', commands: parseCommands(trimmed) };
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
function parseCommands(code) {
|
|
1143
|
+
const parts = code.split(/\\s+(?:then|and)\\s+/i);
|
|
1144
|
+
return parts.map(parseCommand).filter(Boolean);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
function parseCommand(code) {
|
|
1148
|
+
const trimmed = code.trim();
|
|
1149
|
+
if (!trimmed) return null;
|
|
1150
|
+
|
|
1151
|
+
let match;
|
|
1152
|
+
|
|
1153
|
+
// toggle .class [on target]
|
|
1154
|
+
match = trimmed.match(/^toggle\\s+(\\.\\w+|\\w+)(?:\\s+on\\s+(.+))?$/i);
|
|
1155
|
+
if (match) {
|
|
1156
|
+
return {
|
|
1157
|
+
type: 'command',
|
|
1158
|
+
name: 'toggle',
|
|
1159
|
+
args: [{ type: 'selector', value: match[1] }],
|
|
1160
|
+
target: match[2] ? parseTarget(match[2]) : undefined,
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
// add .class [to target]
|
|
1165
|
+
match = trimmed.match(/^add\\s+(\\.\\w+|\\w+)(?:\\s+to\\s+(.+))?$/i);
|
|
1166
|
+
if (match) {
|
|
1167
|
+
return {
|
|
1168
|
+
type: 'command',
|
|
1169
|
+
name: 'add',
|
|
1170
|
+
args: [{ type: 'selector', value: match[1] }],
|
|
1171
|
+
target: match[2] ? parseTarget(match[2]) : undefined,
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// remove .class [from target] | remove [target]
|
|
1176
|
+
match = trimmed.match(/^remove\\s+(\\.\\w+)(?:\\s+from\\s+(.+))?$/i);
|
|
1177
|
+
if (match) {
|
|
1178
|
+
return {
|
|
1179
|
+
type: 'command',
|
|
1180
|
+
name: 'removeClass',
|
|
1181
|
+
args: [{ type: 'selector', value: match[1] }],
|
|
1182
|
+
target: match[2] ? parseTarget(match[2]) : undefined,
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
match = trimmed.match(/^remove\\s+(.+)$/i);
|
|
1186
|
+
if (match) {
|
|
1187
|
+
return {
|
|
1188
|
+
type: 'command',
|
|
1189
|
+
name: 'remove',
|
|
1190
|
+
args: [],
|
|
1191
|
+
target: parseTarget(match[1]),
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// put "content" into target
|
|
1196
|
+
match = trimmed.match(/^put\\s+(?:"([^"]+)"|'([^']+)'|(\\S+))\\s+(into|before|after)\\s+(.+)$/i);
|
|
1197
|
+
if (match) {
|
|
1198
|
+
const content = match[1] || match[2] || match[3];
|
|
1199
|
+
return {
|
|
1200
|
+
type: 'command',
|
|
1201
|
+
name: 'put',
|
|
1202
|
+
args: [{ type: 'literal', value: content }],
|
|
1203
|
+
modifier: match[4],
|
|
1204
|
+
target: parseTarget(match[5]),
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// set target to value | set :var to value
|
|
1209
|
+
match = trimmed.match(/^set\\s+(.+?)\\s+to\\s+(.+)$/i);
|
|
1210
|
+
if (match) {
|
|
1211
|
+
return {
|
|
1212
|
+
type: 'command',
|
|
1213
|
+
name: 'set',
|
|
1214
|
+
args: [parseTarget(match[1]), parseLiteValue(match[2])],
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
// log message
|
|
1219
|
+
match = trimmed.match(/^log\\s+(.+)$/i);
|
|
1220
|
+
if (match) {
|
|
1221
|
+
return {
|
|
1222
|
+
type: 'command',
|
|
1223
|
+
name: 'log',
|
|
1224
|
+
args: [parseLiteValue(match[1])],
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
// send event [to target]
|
|
1229
|
+
match = trimmed.match(/^send\\s+(\\w+)(?:\\s+to\\s+(.+))?$/i);
|
|
1230
|
+
if (match) {
|
|
1231
|
+
return {
|
|
1232
|
+
type: 'command',
|
|
1233
|
+
name: 'send',
|
|
1234
|
+
args: [{ type: 'literal', value: match[1] }],
|
|
1235
|
+
target: match[2] ? parseTarget(match[2]) : undefined,
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// wait Nms | wait Ns
|
|
1240
|
+
match = trimmed.match(/^wait\\s+(\\d+)(ms|s)?$/i);
|
|
1241
|
+
if (match) {
|
|
1242
|
+
const ms = match[2] === 's' ? parseInt(match[1]) * 1000 : parseInt(match[1]);
|
|
1243
|
+
return {
|
|
1244
|
+
type: 'command',
|
|
1245
|
+
name: 'wait',
|
|
1246
|
+
args: [{ type: 'literal', value: ms }],
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// show/hide shortcuts
|
|
1251
|
+
match = trimmed.match(/^(show|hide)(?:\\s+(.+))?$/i);
|
|
1252
|
+
if (match) {
|
|
1253
|
+
return {
|
|
1254
|
+
type: 'command',
|
|
1255
|
+
name: match[1].toLowerCase(),
|
|
1256
|
+
args: [],
|
|
1257
|
+
target: match[2] ? parseTarget(match[2]) : undefined,
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
// Unknown command - try generic parsing
|
|
1262
|
+
const parts = trimmed.split(/\\s+/);
|
|
1263
|
+
if (parts.length > 0) {
|
|
1264
|
+
return {
|
|
1265
|
+
type: 'command',
|
|
1266
|
+
name: parts[0],
|
|
1267
|
+
args: parts.slice(1).map(p => ({ type: 'literal', value: p })),
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
return null;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
function parseTarget(str) {
|
|
1275
|
+
const s = str.trim();
|
|
1276
|
+
if (s === 'me') return { type: 'identifier', value: 'me' };
|
|
1277
|
+
if (s === 'body') return { type: 'identifier', value: 'body' };
|
|
1278
|
+
if (s.startsWith('#') || s.startsWith('.') || s.startsWith('[')) {
|
|
1279
|
+
return { type: 'selector', value: s };
|
|
1280
|
+
}
|
|
1281
|
+
if (s.startsWith(':')) {
|
|
1282
|
+
return { type: 'variable', name: s, scope: 'local' };
|
|
1283
|
+
}
|
|
1284
|
+
return { type: 'identifier', value: s };
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
function parseLiteValue(str) {
|
|
1288
|
+
const s = str.trim();
|
|
1289
|
+
if ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'"))) {
|
|
1290
|
+
return { type: 'literal', value: s.slice(1, -1) };
|
|
1291
|
+
}
|
|
1292
|
+
if (/^-?\\d+(\\.\\d+)?$/.test(s)) {
|
|
1293
|
+
return { type: 'literal', value: parseFloat(s) };
|
|
1294
|
+
}
|
|
1295
|
+
if (s === 'true') return { type: 'literal', value: true };
|
|
1296
|
+
if (s === 'false') return { type: 'literal', value: false };
|
|
1297
|
+
if (s === 'null') return { type: 'literal', value: null };
|
|
1298
|
+
if (s.startsWith(':')) return { type: 'variable', name: s, scope: 'local' };
|
|
1299
|
+
if (s === 'me') return { type: 'identifier', value: 'me' };
|
|
1300
|
+
return { type: 'identifier', value: s };
|
|
1301
|
+
}
|
|
1302
|
+
`;
|
|
1303
|
+
const HYBRID_PARSER_TEMPLATE = `
|
|
1304
|
+
// Hybrid Parser - Full AST with operator precedence
|
|
1305
|
+
|
|
1306
|
+
// Tokenizer
|
|
1307
|
+
const KEYWORDS = new Set([
|
|
1308
|
+
'on', 'from', 'to', 'into', 'before', 'after', 'in', 'of', 'at', 'with',
|
|
1309
|
+
'if', 'else', 'unless', 'end', 'then', 'and', 'or', 'not',
|
|
1310
|
+
'repeat', 'times', 'for', 'each', 'while', 'until',
|
|
1311
|
+
'toggle', 'add', 'remove', 'put', 'set', 'get', 'call', 'return', 'append',
|
|
1312
|
+
'log', 'send', 'trigger', 'wait', 'settle', 'fetch', 'as',
|
|
1313
|
+
'show', 'hide', 'take', 'increment', 'decrement', 'focus', 'blur', 'go', 'transition', 'over',
|
|
1314
|
+
'the', 'a', 'an', 'my', 'its', 'me', 'it', 'you',
|
|
1315
|
+
'first', 'last', 'next', 'previous', 'closest', 'parent',
|
|
1316
|
+
'true', 'false', 'null', 'undefined',
|
|
1317
|
+
'is', 'matches', 'contains', 'includes', 'exists', 'has', 'init', 'every', 'by',
|
|
1318
|
+
]);
|
|
1319
|
+
|
|
1320
|
+
const COMMAND_ALIASES = {
|
|
1321
|
+
flip: 'toggle', switch: 'toggle', display: 'show', reveal: 'show',
|
|
1322
|
+
conceal: 'hide', increase: 'increment', decrease: 'decrement',
|
|
1323
|
+
fire: 'trigger', dispatch: 'send', navigate: 'go', goto: 'go',
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
const EVENT_ALIASES = {
|
|
1327
|
+
clicked: 'click', pressed: 'keydown', changed: 'change',
|
|
1328
|
+
submitted: 'submit', loaded: 'load',
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
function normalizeCommand(name) {
|
|
1332
|
+
const lower = name.toLowerCase();
|
|
1333
|
+
return COMMAND_ALIASES[lower] || lower;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
function normalizeEvent(name) {
|
|
1337
|
+
const lower = name.toLowerCase();
|
|
1338
|
+
return EVENT_ALIASES[lower] || lower;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
function tokenize(code) {
|
|
1342
|
+
const tokens = [];
|
|
1343
|
+
let pos = 0;
|
|
1344
|
+
|
|
1345
|
+
while (pos < code.length) {
|
|
1346
|
+
if (/\\s/.test(code[pos])) { pos++; continue; }
|
|
1347
|
+
if (code.slice(pos, pos + 2) === '--') {
|
|
1348
|
+
while (pos < code.length && code[pos] !== '\\n') pos++;
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
const start = pos;
|
|
1353
|
+
|
|
1354
|
+
// HTML selector <tag/>
|
|
1355
|
+
if (code[pos] === '<' && /[a-zA-Z]/.test(code[pos + 1] || '')) {
|
|
1356
|
+
pos++;
|
|
1357
|
+
while (pos < code.length && code[pos] !== '>') pos++;
|
|
1358
|
+
if (code[pos] === '>') pos++;
|
|
1359
|
+
const val = code.slice(start, pos);
|
|
1360
|
+
if (val.endsWith('/>') || val.endsWith('>')) {
|
|
1361
|
+
const normalized = val.slice(1).replace(/\\/?>$/, '');
|
|
1362
|
+
tokens.push({ type: 'selector', value: normalized, pos: start });
|
|
1363
|
+
continue;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
// Possessive 's
|
|
1368
|
+
if (code.slice(pos, pos + 2) === "'s" && !/[a-zA-Z]/.test(code[pos + 2] || '')) {
|
|
1369
|
+
tokens.push({ type: 'operator', value: "'s", pos: start });
|
|
1370
|
+
pos += 2;
|
|
1371
|
+
continue;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// String literals
|
|
1375
|
+
if (code[pos] === '"' || code[pos] === "'") {
|
|
1376
|
+
const quote = code[pos++];
|
|
1377
|
+
while (pos < code.length && code[pos] !== quote) {
|
|
1378
|
+
if (code[pos] === '\\\\') pos++;
|
|
1379
|
+
pos++;
|
|
1380
|
+
}
|
|
1381
|
+
pos++;
|
|
1382
|
+
tokens.push({ type: 'string', value: code.slice(start, pos), pos: start });
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
// Numbers with units
|
|
1387
|
+
if (/\\d/.test(code[pos]) || (code[pos] === '-' && /\\d/.test(code[pos + 1] || ''))) {
|
|
1388
|
+
if (code[pos] === '-') pos++;
|
|
1389
|
+
while (pos < code.length && /[\\d.]/.test(code[pos])) pos++;
|
|
1390
|
+
if (code.slice(pos, pos + 2) === 'ms') pos += 2;
|
|
1391
|
+
else if (code[pos] === 's' && !/[a-zA-Z]/.test(code[pos + 1] || '')) pos++;
|
|
1392
|
+
else if (code.slice(pos, pos + 2) === 'px') pos += 2;
|
|
1393
|
+
tokens.push({ type: 'number', value: code.slice(start, pos), pos: start });
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// Local variable :name
|
|
1398
|
+
if (code[pos] === ':') {
|
|
1399
|
+
pos++;
|
|
1400
|
+
while (pos < code.length && /[\\w]/.test(code[pos])) pos++;
|
|
1401
|
+
tokens.push({ type: 'localVar', value: code.slice(start, pos), pos: start });
|
|
1402
|
+
continue;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// Global variable $name
|
|
1406
|
+
if (code[pos] === '$') {
|
|
1407
|
+
pos++;
|
|
1408
|
+
while (pos < code.length && /[\\w]/.test(code[pos])) pos++;
|
|
1409
|
+
tokens.push({ type: 'globalVar', value: code.slice(start, pos), pos: start });
|
|
1410
|
+
continue;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
// CSS selectors: #id, .class
|
|
1414
|
+
if (code[pos] === '#' || code[pos] === '.') {
|
|
1415
|
+
if (code[pos] === '.') {
|
|
1416
|
+
const afterDot = code.slice(pos + 1).match(/^(once|prevent|stop|debounce|throttle)\\b/i);
|
|
1417
|
+
if (afterDot) {
|
|
1418
|
+
tokens.push({ type: 'symbol', value: '.', pos: start });
|
|
1419
|
+
pos++;
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
pos++;
|
|
1424
|
+
while (pos < code.length && /[\\w-]/.test(code[pos])) pos++;
|
|
1425
|
+
tokens.push({ type: 'selector', value: code.slice(start, pos), pos: start });
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// Array literal vs Attribute selector
|
|
1430
|
+
if (code[pos] === '[') {
|
|
1431
|
+
let lookahead = pos + 1;
|
|
1432
|
+
while (lookahead < code.length && /\\s/.test(code[lookahead])) lookahead++;
|
|
1433
|
+
const nextChar = code[lookahead] || '';
|
|
1434
|
+
const isArrayLiteral = /['"\\d\\[\\]:\\$\\-]/.test(nextChar) || nextChar === '';
|
|
1435
|
+
if (isArrayLiteral) {
|
|
1436
|
+
tokens.push({ type: 'symbol', value: '[', pos: start });
|
|
1437
|
+
pos++;
|
|
1438
|
+
continue;
|
|
1439
|
+
} else {
|
|
1440
|
+
pos++;
|
|
1441
|
+
let depth = 1;
|
|
1442
|
+
while (pos < code.length && depth > 0) {
|
|
1443
|
+
if (code[pos] === '[') depth++;
|
|
1444
|
+
if (code[pos] === ']') depth--;
|
|
1445
|
+
pos++;
|
|
1446
|
+
}
|
|
1447
|
+
tokens.push({ type: 'selector', value: code.slice(start, pos), pos: start });
|
|
1448
|
+
continue;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
if (code[pos] === ']') {
|
|
1453
|
+
tokens.push({ type: 'symbol', value: ']', pos: start });
|
|
1454
|
+
pos++;
|
|
1455
|
+
continue;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// Multi-char operators
|
|
1459
|
+
const twoChar = code.slice(pos, pos + 2);
|
|
1460
|
+
if (['==', '!=', '<=', '>=', '&&', '||'].includes(twoChar)) {
|
|
1461
|
+
tokens.push({ type: 'operator', value: twoChar, pos: start });
|
|
1462
|
+
pos += 2;
|
|
1463
|
+
continue;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// Style property *opacity
|
|
1467
|
+
if (code[pos] === '*' && /[a-zA-Z]/.test(code[pos + 1] || '')) {
|
|
1468
|
+
pos++;
|
|
1469
|
+
while (pos < code.length && /[\\w-]/.test(code[pos])) pos++;
|
|
1470
|
+
tokens.push({ type: 'styleProperty', value: code.slice(start, pos), pos: start });
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
if ('+-*/%<>!'.includes(code[pos])) {
|
|
1475
|
+
tokens.push({ type: 'operator', value: code[pos], pos: start });
|
|
1476
|
+
pos++;
|
|
1477
|
+
continue;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
if ('()[]{},.'.includes(code[pos])) {
|
|
1481
|
+
tokens.push({ type: 'symbol', value: code[pos], pos: start });
|
|
1482
|
+
pos++;
|
|
1483
|
+
continue;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if (/[a-zA-Z_]/.test(code[pos])) {
|
|
1487
|
+
while (pos < code.length && /[\\w-]/.test(code[pos])) pos++;
|
|
1488
|
+
const value = code.slice(start, pos);
|
|
1489
|
+
const type = KEYWORDS.has(value.toLowerCase()) ? 'keyword' : 'identifier';
|
|
1490
|
+
tokens.push({ type, value, pos: start });
|
|
1491
|
+
continue;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
pos++;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
tokens.push({ type: 'eof', value: '', pos: code.length });
|
|
1498
|
+
return tokens;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// Parser
|
|
1502
|
+
class HybridParser {
|
|
1503
|
+
constructor(code) {
|
|
1504
|
+
this.tokens = tokenize(code);
|
|
1505
|
+
this.pos = 0;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
peek(offset = 0) {
|
|
1509
|
+
return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)];
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
advance() {
|
|
1513
|
+
return this.tokens[this.pos++];
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
match(...values) {
|
|
1517
|
+
const token = this.peek();
|
|
1518
|
+
return values.some(v => token.value.toLowerCase() === v.toLowerCase());
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
matchType(...types) {
|
|
1522
|
+
return types.includes(this.peek().type);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
expect(value) {
|
|
1526
|
+
if (!this.match(value) && normalizeCommand(this.peek().value) !== value) {
|
|
1527
|
+
throw new Error("Expected '" + value + "', got '" + this.peek().value + "'");
|
|
1528
|
+
}
|
|
1529
|
+
return this.advance();
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
isAtEnd() {
|
|
1533
|
+
return this.peek().type === 'eof';
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
parse() {
|
|
1537
|
+
if (this.match('on')) return this.parseEventHandler();
|
|
1538
|
+
if (this.match('init')) {
|
|
1539
|
+
this.advance();
|
|
1540
|
+
return { type: 'event', event: 'init', modifiers: {}, body: this.parseCommandSequence() };
|
|
1541
|
+
}
|
|
1542
|
+
if (this.match('every')) return this.parseEveryHandler();
|
|
1543
|
+
return { type: 'sequence', commands: this.parseCommandSequence() };
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
parseEventHandler() {
|
|
1547
|
+
this.expect('on');
|
|
1548
|
+
const eventName = this.advance().value;
|
|
1549
|
+
const modifiers = {};
|
|
1550
|
+
let filter;
|
|
1551
|
+
|
|
1552
|
+
while (this.peek().value === '.') {
|
|
1553
|
+
this.advance();
|
|
1554
|
+
const mod = this.advance().value.toLowerCase();
|
|
1555
|
+
if (mod === 'once') modifiers.once = true;
|
|
1556
|
+
else if (mod === 'prevent') modifiers.prevent = true;
|
|
1557
|
+
else if (mod === 'stop') modifiers.stop = true;
|
|
1558
|
+
else if (mod === 'debounce' || mod === 'throttle') {
|
|
1559
|
+
if (this.peek().value === '(') {
|
|
1560
|
+
this.advance();
|
|
1561
|
+
const num = this.advance().value;
|
|
1562
|
+
this.expect(')');
|
|
1563
|
+
if (mod === 'debounce') modifiers.debounce = parseInt(num) || 100;
|
|
1564
|
+
else modifiers.throttle = parseInt(num) || 100;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
if (this.match('from')) {
|
|
1570
|
+
this.advance();
|
|
1571
|
+
filter = this.parseExpression();
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
return { type: 'event', event: normalizeEvent(eventName), filter, modifiers, body: this.parseCommandSequence() };
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
parseEveryHandler() {
|
|
1578
|
+
this.expect('every');
|
|
1579
|
+
const interval = this.advance().value;
|
|
1580
|
+
return { type: 'event', event: 'interval:' + interval, modifiers: {}, body: this.parseCommandSequence() };
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
parseCommandSequence() {
|
|
1584
|
+
const commands = [];
|
|
1585
|
+
while (!this.isAtEnd() && !this.match('end', 'else')) {
|
|
1586
|
+
const cmd = this.parseCommand();
|
|
1587
|
+
if (cmd) commands.push(cmd);
|
|
1588
|
+
if (this.match('then', 'and')) this.advance();
|
|
1589
|
+
}
|
|
1590
|
+
return commands;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
parseCommand() {
|
|
1594
|
+
if (this.match('if', 'unless')) return this.parseIf();
|
|
1595
|
+
if (this.match('repeat')) return this.parseRepeat();
|
|
1596
|
+
if (this.match('for')) return this.parseFor();
|
|
1597
|
+
if (this.match('while')) return this.parseWhile();
|
|
1598
|
+
if (this.match('fetch')) return this.parseFetchBlock();
|
|
1599
|
+
|
|
1600
|
+
const cmdMap = {
|
|
1601
|
+
toggle: () => this.parseToggle(),
|
|
1602
|
+
add: () => this.parseAdd(),
|
|
1603
|
+
remove: () => this.parseRemove(),
|
|
1604
|
+
put: () => this.parsePut(),
|
|
1605
|
+
append: () => this.parseAppend(),
|
|
1606
|
+
set: () => this.parseSet(),
|
|
1607
|
+
get: () => this.parseGet(),
|
|
1608
|
+
call: () => this.parseCall(),
|
|
1609
|
+
log: () => this.parseLog(),
|
|
1610
|
+
send: () => this.parseSend(),
|
|
1611
|
+
trigger: () => this.parseSend(),
|
|
1612
|
+
wait: () => this.parseWait(),
|
|
1613
|
+
show: () => this.parseShow(),
|
|
1614
|
+
hide: () => this.parseHide(),
|
|
1615
|
+
take: () => this.parseTake(),
|
|
1616
|
+
increment: () => this.parseIncDec('increment'),
|
|
1617
|
+
decrement: () => this.parseIncDec('decrement'),
|
|
1618
|
+
focus: () => this.parseFocusBlur('focus'),
|
|
1619
|
+
blur: () => this.parseFocusBlur('blur'),
|
|
1620
|
+
go: () => this.parseGo(),
|
|
1621
|
+
return: () => this.parseReturn(),
|
|
1622
|
+
transition: () => this.parseTransition(),
|
|
1623
|
+
};
|
|
1624
|
+
|
|
1625
|
+
const normalized = normalizeCommand(this.peek().value);
|
|
1626
|
+
if (cmdMap[normalized]) return cmdMap[normalized]();
|
|
1627
|
+
|
|
1628
|
+
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) this.advance();
|
|
1629
|
+
return null;
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
parseIf() {
|
|
1633
|
+
const isUnless = this.match('unless');
|
|
1634
|
+
this.advance();
|
|
1635
|
+
const condition = this.parseExpression();
|
|
1636
|
+
const body = this.parseCommandSequence();
|
|
1637
|
+
let elseBody;
|
|
1638
|
+
|
|
1639
|
+
if (this.match('else')) {
|
|
1640
|
+
this.advance();
|
|
1641
|
+
elseBody = this.parseCommandSequence();
|
|
1642
|
+
}
|
|
1643
|
+
if (this.match('end')) this.advance();
|
|
1644
|
+
|
|
1645
|
+
return {
|
|
1646
|
+
type: 'if',
|
|
1647
|
+
condition: isUnless ? { type: 'unary', operator: 'not', operand: condition } : condition,
|
|
1648
|
+
body,
|
|
1649
|
+
elseBody,
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
parseRepeat() {
|
|
1654
|
+
this.expect('repeat');
|
|
1655
|
+
let count;
|
|
1656
|
+
if (!this.match('until', 'while', 'forever')) {
|
|
1657
|
+
count = this.parseExpression();
|
|
1658
|
+
if (this.match('times')) this.advance();
|
|
1659
|
+
}
|
|
1660
|
+
const body = this.parseCommandSequence();
|
|
1661
|
+
if (this.match('end')) this.advance();
|
|
1662
|
+
return { type: 'repeat', condition: count, body };
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
parseFor() {
|
|
1666
|
+
this.expect('for');
|
|
1667
|
+
if (this.match('each')) this.advance();
|
|
1668
|
+
const variable = this.advance().value;
|
|
1669
|
+
this.expect('in');
|
|
1670
|
+
const iterable = this.parseExpression();
|
|
1671
|
+
const body = this.parseCommandSequence();
|
|
1672
|
+
if (this.match('end')) this.advance();
|
|
1673
|
+
return { type: 'for', condition: { type: 'forCondition', variable, iterable }, body };
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
parseWhile() {
|
|
1677
|
+
this.expect('while');
|
|
1678
|
+
const condition = this.parseExpression();
|
|
1679
|
+
const body = this.parseCommandSequence();
|
|
1680
|
+
if (this.match('end')) this.advance();
|
|
1681
|
+
return { type: 'while', condition, body };
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
parseFetchBlock() {
|
|
1685
|
+
this.expect('fetch');
|
|
1686
|
+
const url = this.parseExpression();
|
|
1687
|
+
let responseType = { type: 'literal', value: 'text' };
|
|
1688
|
+
if (this.match('as')) {
|
|
1689
|
+
this.advance();
|
|
1690
|
+
responseType = this.parseExpression();
|
|
1691
|
+
}
|
|
1692
|
+
if (this.match('then')) this.advance();
|
|
1693
|
+
const body = this.parseCommandSequence();
|
|
1694
|
+
return { type: 'fetch', condition: { type: 'fetchConfig', url, responseType }, body };
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
parseToggle() {
|
|
1698
|
+
this.expect('toggle');
|
|
1699
|
+
const what = this.parseExpression();
|
|
1700
|
+
let target;
|
|
1701
|
+
if (this.match('on')) {
|
|
1702
|
+
this.advance();
|
|
1703
|
+
target = this.parseExpression();
|
|
1704
|
+
}
|
|
1705
|
+
return { type: 'command', name: 'toggle', args: [what], target };
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
parseAdd() {
|
|
1709
|
+
this.expect('add');
|
|
1710
|
+
const what = this.parseExpression();
|
|
1711
|
+
let target;
|
|
1712
|
+
if (this.match('to')) {
|
|
1713
|
+
this.advance();
|
|
1714
|
+
target = this.parseExpression();
|
|
1715
|
+
}
|
|
1716
|
+
return { type: 'command', name: 'add', args: [what], target };
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
parseRemove() {
|
|
1720
|
+
this.expect('remove');
|
|
1721
|
+
if (this.matchType('selector')) {
|
|
1722
|
+
const what = this.parseExpression();
|
|
1723
|
+
let target;
|
|
1724
|
+
if (this.match('from')) {
|
|
1725
|
+
this.advance();
|
|
1726
|
+
target = this.parseExpression();
|
|
1727
|
+
}
|
|
1728
|
+
return { type: 'command', name: 'removeClass', args: [what], target };
|
|
1729
|
+
}
|
|
1730
|
+
const target = this.parseExpression();
|
|
1731
|
+
return { type: 'command', name: 'remove', args: [], target };
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
parsePut() {
|
|
1735
|
+
this.expect('put');
|
|
1736
|
+
const content = this.parseExpression();
|
|
1737
|
+
let modifier = 'into';
|
|
1738
|
+
if (this.match('into', 'before', 'after', 'at')) {
|
|
1739
|
+
modifier = this.advance().value;
|
|
1740
|
+
if (modifier === 'at') {
|
|
1741
|
+
const pos = this.advance().value;
|
|
1742
|
+
this.expect('of');
|
|
1743
|
+
modifier = 'at ' + pos + ' of';
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
const target = this.parseExpression();
|
|
1747
|
+
return { type: 'command', name: 'put', args: [content], target, modifier };
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
parseAppend() {
|
|
1751
|
+
this.expect('append');
|
|
1752
|
+
const content = this.parseExpression();
|
|
1753
|
+
let target;
|
|
1754
|
+
if (this.match('to')) {
|
|
1755
|
+
this.advance();
|
|
1756
|
+
target = this.parseExpression();
|
|
1757
|
+
}
|
|
1758
|
+
return { type: 'command', name: 'append', args: [content], target };
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
parseSet() {
|
|
1762
|
+
this.expect('set');
|
|
1763
|
+
const target = this.parseExpression();
|
|
1764
|
+
if (this.match('to')) {
|
|
1765
|
+
this.advance();
|
|
1766
|
+
const value = this.parseExpression();
|
|
1767
|
+
return { type: 'command', name: 'set', args: [target, value] };
|
|
1768
|
+
}
|
|
1769
|
+
return { type: 'command', name: 'set', args: [target] };
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
parseGet() {
|
|
1773
|
+
this.expect('get');
|
|
1774
|
+
return { type: 'command', name: 'get', args: [this.parseExpression()] };
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
parseCall() {
|
|
1778
|
+
this.expect('call');
|
|
1779
|
+
return { type: 'command', name: 'call', args: [this.parseExpression()] };
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
parseLog() {
|
|
1783
|
+
this.expect('log');
|
|
1784
|
+
const args = [];
|
|
1785
|
+
while (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
1786
|
+
args.push(this.parseExpression());
|
|
1787
|
+
if (this.match(',')) this.advance();
|
|
1788
|
+
else break;
|
|
1789
|
+
}
|
|
1790
|
+
return { type: 'command', name: 'log', args };
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
parseSend() {
|
|
1794
|
+
this.advance();
|
|
1795
|
+
const event = this.advance().value;
|
|
1796
|
+
let target;
|
|
1797
|
+
if (this.match('to')) {
|
|
1798
|
+
this.advance();
|
|
1799
|
+
target = this.parseExpression();
|
|
1800
|
+
}
|
|
1801
|
+
return { type: 'command', name: 'send', args: [{ type: 'literal', value: event }], target };
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
parseWait() {
|
|
1805
|
+
this.expect('wait');
|
|
1806
|
+
if (this.match('for')) {
|
|
1807
|
+
this.advance();
|
|
1808
|
+
const event = this.advance().value;
|
|
1809
|
+
let target;
|
|
1810
|
+
if (this.match('from')) {
|
|
1811
|
+
this.advance();
|
|
1812
|
+
target = this.parseExpression();
|
|
1813
|
+
}
|
|
1814
|
+
return { type: 'command', name: 'waitFor', args: [{ type: 'literal', value: event }], target };
|
|
1815
|
+
}
|
|
1816
|
+
return { type: 'command', name: 'wait', args: [this.parseExpression()] };
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
parseShow() {
|
|
1820
|
+
this.expect('show');
|
|
1821
|
+
let target;
|
|
1822
|
+
const modifiers = {};
|
|
1823
|
+
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else', 'when', 'where')) {
|
|
1824
|
+
target = this.parseExpression();
|
|
1825
|
+
}
|
|
1826
|
+
if (!this.isAtEnd() && this.match('when', 'where')) {
|
|
1827
|
+
const keyword = this.advance().value;
|
|
1828
|
+
modifiers[keyword] = this.parseExpression();
|
|
1829
|
+
}
|
|
1830
|
+
return { type: 'command', name: 'show', args: [], target, modifiers };
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
parseHide() {
|
|
1834
|
+
this.expect('hide');
|
|
1835
|
+
let target;
|
|
1836
|
+
const modifiers = {};
|
|
1837
|
+
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else', 'when', 'where')) {
|
|
1838
|
+
target = this.parseExpression();
|
|
1839
|
+
}
|
|
1840
|
+
if (!this.isAtEnd() && this.match('when', 'where')) {
|
|
1841
|
+
const keyword = this.advance().value;
|
|
1842
|
+
modifiers[keyword] = this.parseExpression();
|
|
1843
|
+
}
|
|
1844
|
+
return { type: 'command', name: 'hide', args: [], target, modifiers };
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
parseTake() {
|
|
1848
|
+
this.expect('take');
|
|
1849
|
+
const what = this.parseExpression();
|
|
1850
|
+
let from;
|
|
1851
|
+
if (this.match('from')) {
|
|
1852
|
+
this.advance();
|
|
1853
|
+
from = this.parseExpression();
|
|
1854
|
+
}
|
|
1855
|
+
return { type: 'command', name: 'take', args: [what], target: from };
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
parseIncDec(name) {
|
|
1859
|
+
this.advance();
|
|
1860
|
+
const target = this.parseExpression();
|
|
1861
|
+
let amount = { type: 'literal', value: 1 };
|
|
1862
|
+
if (this.match('by')) {
|
|
1863
|
+
this.advance();
|
|
1864
|
+
amount = this.parseExpression();
|
|
1865
|
+
}
|
|
1866
|
+
return { type: 'command', name, args: [target, amount] };
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
parseFocusBlur(name) {
|
|
1870
|
+
this.advance();
|
|
1871
|
+
let target;
|
|
1872
|
+
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
1873
|
+
target = this.parseExpression();
|
|
1874
|
+
}
|
|
1875
|
+
return { type: 'command', name, args: [], target };
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
parseGo() {
|
|
1879
|
+
this.expect('go');
|
|
1880
|
+
if (this.match('to')) this.advance();
|
|
1881
|
+
if (this.match('url')) this.advance();
|
|
1882
|
+
const dest = this.parseExpression();
|
|
1883
|
+
return { type: 'command', name: 'go', args: [dest] };
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
parseReturn() {
|
|
1887
|
+
this.expect('return');
|
|
1888
|
+
let value;
|
|
1889
|
+
if (!this.isAtEnd() && !this.match('then', 'and', 'end', 'else')) {
|
|
1890
|
+
value = this.parseExpression();
|
|
1891
|
+
}
|
|
1892
|
+
return { type: 'command', name: 'return', args: value ? [value] : [] };
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
parseTransition() {
|
|
1896
|
+
this.expect('transition');
|
|
1897
|
+
let target;
|
|
1898
|
+
if (this.match('my', 'its')) {
|
|
1899
|
+
const ref = this.advance().value;
|
|
1900
|
+
target = { type: 'identifier', value: ref === 'my' ? 'me' : 'it' };
|
|
1901
|
+
} else if (this.matchType('selector')) {
|
|
1902
|
+
const expr = this.parseExpression();
|
|
1903
|
+
if (expr.type === 'possessive') {
|
|
1904
|
+
return this.parseTransitionRest(expr.object, expr.property);
|
|
1905
|
+
}
|
|
1906
|
+
target = expr;
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
const propToken = this.peek();
|
|
1910
|
+
let property;
|
|
1911
|
+
if (propToken.type === 'styleProperty') {
|
|
1912
|
+
property = this.advance().value;
|
|
1913
|
+
} else if (propToken.type === 'identifier' || propToken.type === 'keyword') {
|
|
1914
|
+
property = this.advance().value;
|
|
1915
|
+
} else {
|
|
1916
|
+
property = 'opacity';
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
return this.parseTransitionRest(target, property);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
parseTransitionRest(target, property) {
|
|
1923
|
+
let toValue = { type: 'literal', value: 1 };
|
|
1924
|
+
if (this.match('to')) {
|
|
1925
|
+
this.advance();
|
|
1926
|
+
toValue = this.parseExpression();
|
|
1927
|
+
}
|
|
1928
|
+
let duration = { type: 'literal', value: 300 };
|
|
1929
|
+
if (this.match('over')) {
|
|
1930
|
+
this.advance();
|
|
1931
|
+
duration = this.parseExpression();
|
|
1932
|
+
}
|
|
1933
|
+
return { type: 'command', name: 'transition', args: [{ type: 'literal', value: property }, toValue, duration], target };
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
parseExpression() { return this.parseOr(); }
|
|
1937
|
+
|
|
1938
|
+
parseOr() {
|
|
1939
|
+
let left = this.parseAnd();
|
|
1940
|
+
while (this.match('or', '||')) {
|
|
1941
|
+
this.advance();
|
|
1942
|
+
left = { type: 'binary', operator: 'or', left, right: this.parseAnd() };
|
|
1943
|
+
}
|
|
1944
|
+
return left;
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
parseAnd() {
|
|
1948
|
+
let left = this.parseEquality();
|
|
1949
|
+
while (this.match('and', '&&') && !this.isCommandKeyword(this.peek(1))) {
|
|
1950
|
+
this.advance();
|
|
1951
|
+
left = { type: 'binary', operator: 'and', left, right: this.parseEquality() };
|
|
1952
|
+
}
|
|
1953
|
+
return left;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
isCommandKeyword(token) {
|
|
1957
|
+
const cmds = ['toggle', 'add', 'remove', 'set', 'put', 'log', 'send', 'wait', 'show', 'hide', 'increment', 'decrement', 'focus', 'blur', 'go'];
|
|
1958
|
+
return cmds.includes(normalizeCommand(token.value));
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
parseEquality() {
|
|
1962
|
+
let left = this.parseComparison();
|
|
1963
|
+
while (this.match('==', '!=', 'is', 'matches', 'contains', 'includes', 'has')) {
|
|
1964
|
+
const op = this.advance().value;
|
|
1965
|
+
if (op.toLowerCase() === 'is' && this.match('not')) {
|
|
1966
|
+
this.advance();
|
|
1967
|
+
left = { type: 'binary', operator: 'is not', left, right: this.parseComparison() };
|
|
1968
|
+
} else {
|
|
1969
|
+
left = { type: 'binary', operator: op, left, right: this.parseComparison() };
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
return left;
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
parseComparison() {
|
|
1976
|
+
let left = this.parseAdditive();
|
|
1977
|
+
while (this.match('<', '>', '<=', '>=')) {
|
|
1978
|
+
const op = this.advance().value;
|
|
1979
|
+
left = { type: 'binary', operator: op, left, right: this.parseAdditive() };
|
|
1980
|
+
}
|
|
1981
|
+
return left;
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
parseAdditive() {
|
|
1985
|
+
let left = this.parseMultiplicative();
|
|
1986
|
+
while (this.match('+', '-')) {
|
|
1987
|
+
const op = this.advance().value;
|
|
1988
|
+
left = { type: 'binary', operator: op, left, right: this.parseMultiplicative() };
|
|
1989
|
+
}
|
|
1990
|
+
return left;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
parseMultiplicative() {
|
|
1994
|
+
let left = this.parseUnary();
|
|
1995
|
+
while (this.match('*', '/', '%')) {
|
|
1996
|
+
const op = this.advance().value;
|
|
1997
|
+
left = { type: 'binary', operator: op, left, right: this.parseUnary() };
|
|
1998
|
+
}
|
|
1999
|
+
return left;
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
parseUnary() {
|
|
2003
|
+
if (this.match('not', '!')) {
|
|
2004
|
+
this.advance();
|
|
2005
|
+
return { type: 'unary', operator: 'not', operand: this.parseUnary() };
|
|
2006
|
+
}
|
|
2007
|
+
if (this.match('-') && this.peek(1).type === 'number') {
|
|
2008
|
+
this.advance();
|
|
2009
|
+
const num = this.advance();
|
|
2010
|
+
return { type: 'literal', value: -parseFloat(num.value) };
|
|
2011
|
+
}
|
|
2012
|
+
return this.parsePostfix();
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
parsePostfix() {
|
|
2016
|
+
let left = this.parsePrimary();
|
|
2017
|
+
while (true) {
|
|
2018
|
+
if (this.match("'s")) {
|
|
2019
|
+
this.advance();
|
|
2020
|
+
const next = this.peek();
|
|
2021
|
+
const prop = next.type === 'styleProperty' ? this.advance().value : this.advance().value;
|
|
2022
|
+
left = { type: 'possessive', object: left, property: prop };
|
|
2023
|
+
} else if (this.peek().type === 'styleProperty') {
|
|
2024
|
+
const prop = this.advance().value;
|
|
2025
|
+
left = { type: 'possessive', object: left, property: prop };
|
|
2026
|
+
} else if (this.peek().value === '.') {
|
|
2027
|
+
this.advance();
|
|
2028
|
+
const prop = this.advance().value;
|
|
2029
|
+
left = { type: 'member', object: left, property: prop };
|
|
2030
|
+
} else if (this.peek().type === 'selector' && this.peek().value.startsWith('.')) {
|
|
2031
|
+
const prop = this.advance().value.slice(1);
|
|
2032
|
+
left = { type: 'member', object: left, property: prop };
|
|
2033
|
+
} else if (this.peek().value === '(') {
|
|
2034
|
+
this.advance();
|
|
2035
|
+
const args = [];
|
|
2036
|
+
while (!this.match(')')) {
|
|
2037
|
+
args.push(this.parseExpression());
|
|
2038
|
+
if (this.match(',')) this.advance();
|
|
2039
|
+
}
|
|
2040
|
+
this.expect(')');
|
|
2041
|
+
left = { type: 'call', callee: left, args };
|
|
2042
|
+
} else if (this.peek().value === '[' && left.type !== 'selector') {
|
|
2043
|
+
this.advance();
|
|
2044
|
+
const index = this.parseExpression();
|
|
2045
|
+
this.expect(']');
|
|
2046
|
+
left = { type: 'member', object: left, property: index, computed: true };
|
|
2047
|
+
} else {
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
return left;
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
parsePrimary() {
|
|
2055
|
+
const token = this.peek();
|
|
2056
|
+
|
|
2057
|
+
if (token.value === '(') {
|
|
2058
|
+
this.advance();
|
|
2059
|
+
const expr = this.parseExpression();
|
|
2060
|
+
this.expect(')');
|
|
2061
|
+
return expr;
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
if (token.value === '{') return this.parseObjectLiteral();
|
|
2065
|
+
if (token.value === '[') return this.parseArrayLiteral();
|
|
2066
|
+
|
|
2067
|
+
if (token.type === 'number') {
|
|
2068
|
+
this.advance();
|
|
2069
|
+
const val = token.value;
|
|
2070
|
+
if (val.endsWith('ms')) return { type: 'literal', value: parseInt(val), unit: 'ms' };
|
|
2071
|
+
if (val.endsWith('s')) return { type: 'literal', value: parseFloat(val) * 1000, unit: 'ms' };
|
|
2072
|
+
return { type: 'literal', value: parseFloat(val) };
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
if (token.type === 'string') {
|
|
2076
|
+
this.advance();
|
|
2077
|
+
return { type: 'literal', value: token.value.slice(1, -1) };
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
if (this.match('true')) { this.advance(); return { type: 'literal', value: true }; }
|
|
2081
|
+
if (this.match('false')) { this.advance(); return { type: 'literal', value: false }; }
|
|
2082
|
+
if (this.match('null')) { this.advance(); return { type: 'literal', value: null }; }
|
|
2083
|
+
if (this.match('undefined')) { this.advance(); return { type: 'literal', value: undefined }; }
|
|
2084
|
+
|
|
2085
|
+
if (token.type === 'localVar') {
|
|
2086
|
+
this.advance();
|
|
2087
|
+
return { type: 'variable', name: token.value, scope: 'local' };
|
|
2088
|
+
}
|
|
2089
|
+
if (token.type === 'globalVar') {
|
|
2090
|
+
this.advance();
|
|
2091
|
+
return { type: 'variable', name: token.value, scope: 'global' };
|
|
2092
|
+
}
|
|
2093
|
+
if (token.type === 'selector') {
|
|
2094
|
+
this.advance();
|
|
2095
|
+
return { type: 'selector', value: token.value };
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
if (this.match('my')) {
|
|
2099
|
+
this.advance();
|
|
2100
|
+
const next = this.peek();
|
|
2101
|
+
if ((next.type === 'identifier' || next.type === 'keyword') && !this.isCommandKeyword(next)) {
|
|
2102
|
+
const prop = this.advance().value;
|
|
2103
|
+
return { type: 'possessive', object: { type: 'identifier', value: 'me' }, property: prop };
|
|
2104
|
+
}
|
|
2105
|
+
return { type: 'identifier', value: 'me' };
|
|
2106
|
+
}
|
|
2107
|
+
if (this.match('its')) {
|
|
2108
|
+
this.advance();
|
|
2109
|
+
const next = this.peek();
|
|
2110
|
+
if ((next.type === 'identifier' || next.type === 'keyword') && !this.isCommandKeyword(next)) {
|
|
2111
|
+
const prop = this.advance().value;
|
|
2112
|
+
return { type: 'possessive', object: { type: 'identifier', value: 'it' }, property: prop };
|
|
2113
|
+
}
|
|
2114
|
+
return { type: 'identifier', value: 'it' };
|
|
2115
|
+
}
|
|
2116
|
+
if (this.match('me')) { this.advance(); return { type: 'identifier', value: 'me' }; }
|
|
2117
|
+
if (this.match('it')) { this.advance(); return { type: 'identifier', value: 'it' }; }
|
|
2118
|
+
if (this.match('you')) { this.advance(); return { type: 'identifier', value: 'you' }; }
|
|
2119
|
+
|
|
2120
|
+
if (this.match('the', 'a', 'an')) {
|
|
2121
|
+
this.advance();
|
|
2122
|
+
if (this.match('first', 'last', 'next', 'previous', 'closest', 'parent')) {
|
|
2123
|
+
const position = this.advance().value;
|
|
2124
|
+
const target = this.parsePositionalTarget();
|
|
2125
|
+
return { type: 'positional', position, target };
|
|
2126
|
+
}
|
|
2127
|
+
return this.parsePrimary();
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
if (this.match('first', 'last', 'next', 'previous', 'closest', 'parent')) {
|
|
2131
|
+
const position = this.advance().value;
|
|
2132
|
+
const target = this.parsePositionalTarget();
|
|
2133
|
+
return { type: 'positional', position, target };
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
if (token.type === 'identifier' || token.type === 'keyword') {
|
|
2137
|
+
this.advance();
|
|
2138
|
+
return { type: 'identifier', value: token.value };
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
this.advance();
|
|
2142
|
+
return { type: 'identifier', value: token.value };
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
parseObjectLiteral() {
|
|
2146
|
+
this.expect('{');
|
|
2147
|
+
const properties = [];
|
|
2148
|
+
while (!this.match('}')) {
|
|
2149
|
+
const key = this.advance().value;
|
|
2150
|
+
this.expect(':');
|
|
2151
|
+
const value = this.parseExpression();
|
|
2152
|
+
properties.push({ key, value });
|
|
2153
|
+
if (this.match(',')) this.advance();
|
|
2154
|
+
}
|
|
2155
|
+
this.expect('}');
|
|
2156
|
+
return { type: 'object', properties };
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
parseArrayLiteral() {
|
|
2160
|
+
this.expect('[');
|
|
2161
|
+
const elements = [];
|
|
2162
|
+
while (!this.match(']')) {
|
|
2163
|
+
elements.push(this.parseExpression());
|
|
2164
|
+
if (this.match(',')) this.advance();
|
|
2165
|
+
}
|
|
2166
|
+
this.expect(']');
|
|
2167
|
+
return { type: 'array', elements };
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
parsePositionalTarget() {
|
|
2171
|
+
const token = this.peek();
|
|
2172
|
+
if (token.type === 'selector') {
|
|
2173
|
+
return { type: 'selector', value: this.advance().value };
|
|
2174
|
+
}
|
|
2175
|
+
if (token.type === 'identifier' || token.type === 'keyword') {
|
|
2176
|
+
return { type: 'identifier', value: this.advance().value };
|
|
2177
|
+
}
|
|
2178
|
+
return this.parseExpression();
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
`;
|
|
2182
|
+
function getParserTemplate(type) {
|
|
2183
|
+
return type === 'lite' ? LITE_PARSER_TEMPLATE : HYBRID_PARSER_TEMPLATE;
|
|
2184
|
+
}
|
|
2185
|
+
const LITE_PARSER_COMMANDS = [
|
|
2186
|
+
'toggle',
|
|
2187
|
+
'add',
|
|
2188
|
+
'remove',
|
|
2189
|
+
'put',
|
|
2190
|
+
'set',
|
|
2191
|
+
'log',
|
|
2192
|
+
'send',
|
|
2193
|
+
'wait',
|
|
2194
|
+
'show',
|
|
2195
|
+
'hide',
|
|
2196
|
+
];
|
|
2197
|
+
function canUseLiteParser(commands, blocks, positional) {
|
|
2198
|
+
if (blocks.length > 0)
|
|
2199
|
+
return false;
|
|
2200
|
+
if (positional)
|
|
2201
|
+
return false;
|
|
2202
|
+
const liteCommands = new Set(LITE_PARSER_COMMANDS);
|
|
2203
|
+
return commands.every(cmd => liteCommands.has(cmd));
|
|
2204
|
+
}
|
|
2205
|
+
|
|
888
2206
|
const AVAILABLE_COMMANDS = [
|
|
889
2207
|
'toggle',
|
|
890
2208
|
'add',
|
|
@@ -905,33 +2223,35 @@ const AVAILABLE_COMMANDS = [
|
|
|
905
2223
|
'trigger',
|
|
906
2224
|
'log',
|
|
907
2225
|
'call',
|
|
2226
|
+
'copy',
|
|
2227
|
+
'beep',
|
|
908
2228
|
'go',
|
|
2229
|
+
'push',
|
|
2230
|
+
'push-url',
|
|
2231
|
+
'replace',
|
|
2232
|
+
'replace-url',
|
|
909
2233
|
'focus',
|
|
910
2234
|
'blur',
|
|
911
2235
|
'return',
|
|
912
2236
|
'break',
|
|
913
2237
|
'continue',
|
|
2238
|
+
'halt',
|
|
2239
|
+
'exit',
|
|
2240
|
+
'throw',
|
|
2241
|
+
'js',
|
|
2242
|
+
'morph',
|
|
914
2243
|
];
|
|
915
2244
|
const AVAILABLE_BLOCKS = ['if', 'repeat', 'for', 'while', 'fetch'];
|
|
916
2245
|
const FULL_RUNTIME_ONLY_COMMANDS = [
|
|
917
2246
|
'async',
|
|
918
|
-
'js',
|
|
919
2247
|
'make',
|
|
920
2248
|
'swap',
|
|
921
|
-
'morph',
|
|
922
2249
|
'process-partials',
|
|
923
2250
|
'bind',
|
|
924
2251
|
'persist',
|
|
925
2252
|
'default',
|
|
926
|
-
'beep',
|
|
927
2253
|
'tell',
|
|
928
|
-
'copy',
|
|
929
2254
|
'pick',
|
|
930
|
-
'push-url',
|
|
931
|
-
'replace-url',
|
|
932
|
-
'halt',
|
|
933
|
-
'exit',
|
|
934
|
-
'throw',
|
|
935
2255
|
'unless',
|
|
936
2256
|
'settle',
|
|
937
2257
|
'measure',
|
|
@@ -947,5 +2267,5 @@ function requiresFullRuntime(command) {
|
|
|
947
2267
|
return FULL_RUNTIME_ONLY_COMMANDS.includes(command);
|
|
948
2268
|
}
|
|
949
2269
|
|
|
950
|
-
export { AVAILABLE_BLOCKS, AVAILABLE_COMMANDS, BLOCK_IMPLEMENTATIONS, COMMAND_IMPLEMENTATIONS, ELEMENT_ARRAY_COMMANDS, FULL_RUNTIME_ONLY_COMMANDS, STYLE_COMMANDS, generateBundle, generateBundleCode, getAvailableBlocks, getAvailableCommands, getBlockImplementations, getCommandImplementations, isAvailableBlock, isAvailableCommand, requiresFullRuntime };
|
|
2270
|
+
export { AVAILABLE_BLOCKS, AVAILABLE_COMMANDS, BLOCK_IMPLEMENTATIONS, COMMAND_IMPLEMENTATIONS, ELEMENT_ARRAY_COMMANDS, FULL_RUNTIME_ONLY_COMMANDS, HYBRID_PARSER_TEMPLATE, LITE_PARSER_COMMANDS, LITE_PARSER_TEMPLATE, MORPH_COMMANDS, STYLE_COMMANDS, canUseLiteParser, generateBundle, generateBundleCode, getAvailableBlocks, getAvailableCommands, getBlockImplementations, getCommandImplementations, getParserTemplate, isAvailableBlock, isAvailableCommand, requiresFullRuntime };
|
|
951
2271
|
//# sourceMappingURL=index.mjs.map
|