@weborigami/language 0.6.0 → 0.6.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/main.js +1 -1
- package/package.json +2 -2
- package/src/compiler/optimize.js +3 -1
- package/src/compiler/origami.pegjs +2 -0
- package/src/compiler/parse.js +113 -91
- package/src/compiler/parserHelpers.js +3 -7
- package/src/handlers/getSource.js +36 -0
- package/src/handlers/ori_handler.js +5 -20
- package/src/handlers/oridocument_handler.js +5 -28
- package/src/handlers/yaml_handler.js +159 -3
- package/src/project/jsGlobals.js +2 -62
- package/src/protocols/constructHref.js +3 -0
- package/src/protocols/explorehttp.js +13 -0
- package/src/protocols/protocolGlobals.js +1 -0
- package/src/protocols/protocols.js +1 -0
- package/src/runtime/errors.js +27 -7
- package/src/runtime/evaluate.js +1 -1
- package/src/runtime/handleExtension.js +0 -5
- package/src/runtime/ops.js +10 -0
- package/test/compiler/parse.test.js +13 -19
- package/test/handlers/yaml_handler.test.js +28 -1
- package/test/project/jsGlobals.test.js +14 -8
- package/test/runtime/handleExtension.test.js +0 -7
- package/test/runtime/ops.test.js +34 -10
- package/test/runtime/jsGlobals.test.js +0 -21
package/main.js
CHANGED
|
@@ -8,7 +8,7 @@ export { default as jsGlobals } from "./src/project/jsGlobals.js";
|
|
|
8
8
|
export { default as projectGlobals } from "./src/project/projectGlobals.js";
|
|
9
9
|
export { default as projectRoot } from "./src/project/projectRoot.js";
|
|
10
10
|
export * as Protocols from "./src/protocols/protocols.js";
|
|
11
|
-
export { formatError } from "./src/runtime/errors.js";
|
|
11
|
+
export { formatError, highlightError } from "./src/runtime/errors.js";
|
|
12
12
|
export { default as evaluate } from "./src/runtime/evaluate.js";
|
|
13
13
|
export { default as EventTargetMixin } from "./src/runtime/EventTargetMixin.js";
|
|
14
14
|
export * as expressionFunction from "./src/runtime/expressionFunction.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/language",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Web Origami expression language compiler and runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./main.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"typescript": "5.9.3"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/async-tree": "0.6.
|
|
14
|
+
"@weborigami/async-tree": "0.6.2",
|
|
15
15
|
"exif-parser": "0.1.12",
|
|
16
16
|
"watcher": "2.3.1",
|
|
17
17
|
"yaml": "2.8.1"
|
package/src/compiler/optimize.js
CHANGED
|
@@ -2,7 +2,7 @@ import { pathFromKeys, trailingSlash } from "@weborigami/async-tree";
|
|
|
2
2
|
import jsGlobals from "../project/jsGlobals.js";
|
|
3
3
|
import { entryKey } from "../runtime/expressionObject.js";
|
|
4
4
|
import { ops } from "../runtime/internal.js";
|
|
5
|
-
import { annotate, markers } from "./parserHelpers.js";
|
|
5
|
+
import { annotate, markers, spanLocations } from "./parserHelpers.js";
|
|
6
6
|
|
|
7
7
|
export const REFERENCE_PARAM = 1;
|
|
8
8
|
export const REFERENCE_INHERITED = 2;
|
|
@@ -334,6 +334,8 @@ function resolvePath(code, globals, parent, locals, cache) {
|
|
|
334
334
|
result[0][0] === ops.inherited);
|
|
335
335
|
if (extendResult) {
|
|
336
336
|
result.push(...tail);
|
|
337
|
+
result.location = spanLocations(args);
|
|
338
|
+
result.source = code.source;
|
|
337
339
|
} else {
|
|
338
340
|
result = annotate([result, ...tail], code.location);
|
|
339
341
|
}
|
package/src/compiler/parse.js
CHANGED
|
@@ -396,17 +396,19 @@ function peg$parse(input, options) {
|
|
|
396
396
|
const peg$c55 = "?.";
|
|
397
397
|
const peg$c56 = "<=";
|
|
398
398
|
const peg$c57 = ">=";
|
|
399
|
-
const peg$c58 = "
|
|
400
|
-
const peg$c59 = "
|
|
401
|
-
const peg$c60 = "
|
|
402
|
-
const peg$c61 = "
|
|
403
|
-
const peg$c62 = "
|
|
404
|
-
const peg$c63 = "
|
|
405
|
-
const peg$c64 = "
|
|
406
|
-
const peg$c65 = "
|
|
407
|
-
const peg$c66 = "
|
|
408
|
-
const peg$c67 = "
|
|
409
|
-
const peg$c68 = "
|
|
399
|
+
const peg$c58 = "instanceof";
|
|
400
|
+
const peg$c59 = "in";
|
|
401
|
+
const peg$c60 = "#!";
|
|
402
|
+
const peg$c61 = "<<";
|
|
403
|
+
const peg$c62 = ">>>";
|
|
404
|
+
const peg$c63 = ">>";
|
|
405
|
+
const peg$c64 = "\u2192";
|
|
406
|
+
const peg$c65 = "->";
|
|
407
|
+
const peg$c66 = "${";
|
|
408
|
+
const peg$c67 = "~";
|
|
409
|
+
const peg$c68 = "await";
|
|
410
|
+
const peg$c69 = "typeof";
|
|
411
|
+
const peg$c70 = "void";
|
|
410
412
|
|
|
411
413
|
const peg$r0 = /^[^\/>\t\n\r]/;
|
|
412
414
|
const peg$r1 = /^[0-9]/;
|
|
@@ -515,31 +517,33 @@ function peg$parse(input, options) {
|
|
|
515
517
|
const peg$e88 = peg$classExpectation(["/", "\n", "\r"], true, false, false);
|
|
516
518
|
const peg$e89 = peg$literalExpectation("<=", false);
|
|
517
519
|
const peg$e90 = peg$literalExpectation(">=", false);
|
|
518
|
-
const peg$e91 = peg$literalExpectation("
|
|
519
|
-
const peg$e92 = peg$
|
|
520
|
-
const peg$e93 = peg$literalExpectation("
|
|
521
|
-
const peg$e94 = peg$
|
|
522
|
-
const peg$e95 = peg$literalExpectation("
|
|
523
|
-
const peg$e96 = peg$
|
|
524
|
-
const peg$e97 = peg$literalExpectation("
|
|
525
|
-
const peg$e98 = peg$
|
|
526
|
-
const peg$e99 = peg$
|
|
527
|
-
const peg$e100 = peg$
|
|
528
|
-
const peg$e101 = peg$
|
|
529
|
-
const peg$e102 = peg$otherExpectation("
|
|
530
|
-
const peg$e103 = peg$
|
|
531
|
-
const peg$e104 = peg$otherExpectation("template
|
|
532
|
-
const peg$e105 = peg$
|
|
533
|
-
const peg$e106 = peg$
|
|
534
|
-
const peg$e107 = peg$classExpectation(["
|
|
535
|
-
const peg$e108 = peg$literalExpectation("
|
|
536
|
-
const peg$e109 = peg$
|
|
537
|
-
const peg$e110 = peg$literalExpectation("
|
|
538
|
-
const peg$e111 = peg$
|
|
539
|
-
const peg$e112 = peg$
|
|
540
|
-
const peg$e113 = peg$classExpectation([
|
|
541
|
-
const peg$e114 = peg$
|
|
542
|
-
const peg$e115 = peg$classExpectation(["
|
|
520
|
+
const peg$e91 = peg$literalExpectation("instanceof", false);
|
|
521
|
+
const peg$e92 = peg$literalExpectation("in", false);
|
|
522
|
+
const peg$e93 = peg$literalExpectation("#!", false);
|
|
523
|
+
const peg$e94 = peg$classExpectation(["\n", "\r"], true, false, false);
|
|
524
|
+
const peg$e95 = peg$literalExpectation("<<", false);
|
|
525
|
+
const peg$e96 = peg$literalExpectation(">>>", false);
|
|
526
|
+
const peg$e97 = peg$literalExpectation(">>", false);
|
|
527
|
+
const peg$e98 = peg$otherExpectation("lambda function");
|
|
528
|
+
const peg$e99 = peg$literalExpectation("\u2192", false);
|
|
529
|
+
const peg$e100 = peg$literalExpectation("->", false);
|
|
530
|
+
const peg$e101 = peg$otherExpectation("single quote string");
|
|
531
|
+
const peg$e102 = peg$otherExpectation("string");
|
|
532
|
+
const peg$e103 = peg$literalExpectation("${", false);
|
|
533
|
+
const peg$e104 = peg$otherExpectation("template document");
|
|
534
|
+
const peg$e105 = peg$otherExpectation("template literal");
|
|
535
|
+
const peg$e106 = peg$otherExpectation("template substitution");
|
|
536
|
+
const peg$e107 = peg$classExpectation(["!", "+"], false, false, false);
|
|
537
|
+
const peg$e108 = peg$literalExpectation("~", false);
|
|
538
|
+
const peg$e109 = peg$classExpectation(["/", ")", "]", "}"], false, false, false);
|
|
539
|
+
const peg$e110 = peg$literalExpectation("await", false);
|
|
540
|
+
const peg$e111 = peg$literalExpectation("typeof", false);
|
|
541
|
+
const peg$e112 = peg$literalExpectation("void", false);
|
|
542
|
+
const peg$e113 = peg$classExpectation(["/", ",", ")", "]", "}"], true, false, false);
|
|
543
|
+
const peg$e114 = peg$otherExpectation("slash-separated path");
|
|
544
|
+
const peg$e115 = peg$classExpectation([["a", "z"]], false, false, false);
|
|
545
|
+
const peg$e116 = peg$classExpectation([["a", "z"], ["0", "9"], ["+", "."]], false, false, false);
|
|
546
|
+
const peg$e117 = peg$classExpectation([":"], false, false, false);
|
|
543
547
|
|
|
544
548
|
function peg$f0() {
|
|
545
549
|
return null;
|
|
@@ -5209,6 +5213,24 @@ function peg$parse(input, options) {
|
|
|
5209
5213
|
s0 = peg$FAILED;
|
|
5210
5214
|
if (peg$silentFails === 0) { peg$fail(peg$e3); }
|
|
5211
5215
|
}
|
|
5216
|
+
if (s0 === peg$FAILED) {
|
|
5217
|
+
if (input.substr(peg$currPos, 10) === peg$c58) {
|
|
5218
|
+
s0 = peg$c58;
|
|
5219
|
+
peg$currPos += 10;
|
|
5220
|
+
} else {
|
|
5221
|
+
s0 = peg$FAILED;
|
|
5222
|
+
if (peg$silentFails === 0) { peg$fail(peg$e91); }
|
|
5223
|
+
}
|
|
5224
|
+
if (s0 === peg$FAILED) {
|
|
5225
|
+
if (input.substr(peg$currPos, 2) === peg$c59) {
|
|
5226
|
+
s0 = peg$c59;
|
|
5227
|
+
peg$currPos += 2;
|
|
5228
|
+
} else {
|
|
5229
|
+
s0 = peg$FAILED;
|
|
5230
|
+
if (peg$silentFails === 0) { peg$fail(peg$e92); }
|
|
5231
|
+
}
|
|
5232
|
+
}
|
|
5233
|
+
}
|
|
5212
5234
|
}
|
|
5213
5235
|
}
|
|
5214
5236
|
}
|
|
@@ -5254,12 +5276,12 @@ function peg$parse(input, options) {
|
|
|
5254
5276
|
let s0, s1, s2, s3;
|
|
5255
5277
|
|
|
5256
5278
|
s0 = peg$currPos;
|
|
5257
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
5258
|
-
s1 = peg$
|
|
5279
|
+
if (input.substr(peg$currPos, 2) === peg$c60) {
|
|
5280
|
+
s1 = peg$c60;
|
|
5259
5281
|
peg$currPos += 2;
|
|
5260
5282
|
} else {
|
|
5261
5283
|
s1 = peg$FAILED;
|
|
5262
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5284
|
+
if (peg$silentFails === 0) { peg$fail(peg$e93); }
|
|
5263
5285
|
}
|
|
5264
5286
|
if (s1 !== peg$FAILED) {
|
|
5265
5287
|
s2 = [];
|
|
@@ -5268,7 +5290,7 @@ function peg$parse(input, options) {
|
|
|
5268
5290
|
peg$currPos++;
|
|
5269
5291
|
} else {
|
|
5270
5292
|
s3 = peg$FAILED;
|
|
5271
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5293
|
+
if (peg$silentFails === 0) { peg$fail(peg$e94); }
|
|
5272
5294
|
}
|
|
5273
5295
|
while (s3 !== peg$FAILED) {
|
|
5274
5296
|
s2.push(s3);
|
|
@@ -5277,7 +5299,7 @@ function peg$parse(input, options) {
|
|
|
5277
5299
|
peg$currPos++;
|
|
5278
5300
|
} else {
|
|
5279
5301
|
s3 = peg$FAILED;
|
|
5280
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5302
|
+
if (peg$silentFails === 0) { peg$fail(peg$e94); }
|
|
5281
5303
|
}
|
|
5282
5304
|
}
|
|
5283
5305
|
peg$savedPos = s0;
|
|
@@ -5359,28 +5381,28 @@ function peg$parse(input, options) {
|
|
|
5359
5381
|
function peg$parseshiftOperator() {
|
|
5360
5382
|
let s0;
|
|
5361
5383
|
|
|
5362
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
5363
|
-
s0 = peg$
|
|
5384
|
+
if (input.substr(peg$currPos, 2) === peg$c61) {
|
|
5385
|
+
s0 = peg$c61;
|
|
5364
5386
|
peg$currPos += 2;
|
|
5365
5387
|
} else {
|
|
5366
5388
|
s0 = peg$FAILED;
|
|
5367
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5389
|
+
if (peg$silentFails === 0) { peg$fail(peg$e95); }
|
|
5368
5390
|
}
|
|
5369
5391
|
if (s0 === peg$FAILED) {
|
|
5370
|
-
if (input.substr(peg$currPos, 3) === peg$
|
|
5371
|
-
s0 = peg$
|
|
5392
|
+
if (input.substr(peg$currPos, 3) === peg$c62) {
|
|
5393
|
+
s0 = peg$c62;
|
|
5372
5394
|
peg$currPos += 3;
|
|
5373
5395
|
} else {
|
|
5374
5396
|
s0 = peg$FAILED;
|
|
5375
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5397
|
+
if (peg$silentFails === 0) { peg$fail(peg$e96); }
|
|
5376
5398
|
}
|
|
5377
5399
|
if (s0 === peg$FAILED) {
|
|
5378
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
5379
|
-
s0 = peg$
|
|
5400
|
+
if (input.substr(peg$currPos, 2) === peg$c63) {
|
|
5401
|
+
s0 = peg$c63;
|
|
5380
5402
|
peg$currPos += 2;
|
|
5381
5403
|
} else {
|
|
5382
5404
|
s0 = peg$FAILED;
|
|
5383
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5405
|
+
if (peg$silentFails === 0) { peg$fail(peg$e97); }
|
|
5384
5406
|
}
|
|
5385
5407
|
}
|
|
5386
5408
|
}
|
|
@@ -5450,7 +5472,7 @@ function peg$parse(input, options) {
|
|
|
5450
5472
|
peg$silentFails--;
|
|
5451
5473
|
if (s0 === peg$FAILED) {
|
|
5452
5474
|
s1 = peg$FAILED;
|
|
5453
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5475
|
+
if (peg$silentFails === 0) { peg$fail(peg$e98); }
|
|
5454
5476
|
}
|
|
5455
5477
|
|
|
5456
5478
|
return s0;
|
|
@@ -5460,19 +5482,19 @@ function peg$parse(input, options) {
|
|
|
5460
5482
|
let s0;
|
|
5461
5483
|
|
|
5462
5484
|
if (input.charCodeAt(peg$currPos) === 8594) {
|
|
5463
|
-
s0 = peg$
|
|
5485
|
+
s0 = peg$c64;
|
|
5464
5486
|
peg$currPos++;
|
|
5465
5487
|
} else {
|
|
5466
5488
|
s0 = peg$FAILED;
|
|
5467
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5489
|
+
if (peg$silentFails === 0) { peg$fail(peg$e99); }
|
|
5468
5490
|
}
|
|
5469
5491
|
if (s0 === peg$FAILED) {
|
|
5470
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
5471
|
-
s0 = peg$
|
|
5492
|
+
if (input.substr(peg$currPos, 2) === peg$c65) {
|
|
5493
|
+
s0 = peg$c65;
|
|
5472
5494
|
peg$currPos += 2;
|
|
5473
5495
|
} else {
|
|
5474
5496
|
s0 = peg$FAILED;
|
|
5475
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5497
|
+
if (peg$silentFails === 0) { peg$fail(peg$e100); }
|
|
5476
5498
|
}
|
|
5477
5499
|
}
|
|
5478
5500
|
|
|
@@ -5497,7 +5519,7 @@ function peg$parse(input, options) {
|
|
|
5497
5519
|
peg$currPos++;
|
|
5498
5520
|
} else {
|
|
5499
5521
|
s3 = peg$FAILED;
|
|
5500
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5522
|
+
if (peg$silentFails === 0) { peg$fail(peg$e94); }
|
|
5501
5523
|
}
|
|
5502
5524
|
while (s3 !== peg$FAILED) {
|
|
5503
5525
|
s2.push(s3);
|
|
@@ -5506,7 +5528,7 @@ function peg$parse(input, options) {
|
|
|
5506
5528
|
peg$currPos++;
|
|
5507
5529
|
} else {
|
|
5508
5530
|
s3 = peg$FAILED;
|
|
5509
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5531
|
+
if (peg$silentFails === 0) { peg$fail(peg$e94); }
|
|
5510
5532
|
}
|
|
5511
5533
|
}
|
|
5512
5534
|
peg$savedPos = s0;
|
|
@@ -5553,7 +5575,7 @@ function peg$parse(input, options) {
|
|
|
5553
5575
|
peg$silentFails--;
|
|
5554
5576
|
if (s0 === peg$FAILED) {
|
|
5555
5577
|
s1 = peg$FAILED;
|
|
5556
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5578
|
+
if (peg$silentFails === 0) { peg$fail(peg$e101); }
|
|
5557
5579
|
}
|
|
5558
5580
|
|
|
5559
5581
|
return s0;
|
|
@@ -5726,7 +5748,7 @@ function peg$parse(input, options) {
|
|
|
5726
5748
|
peg$silentFails--;
|
|
5727
5749
|
if (s0 === peg$FAILED) {
|
|
5728
5750
|
s1 = peg$FAILED;
|
|
5729
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5751
|
+
if (peg$silentFails === 0) { peg$fail(peg$e102); }
|
|
5730
5752
|
}
|
|
5731
5753
|
|
|
5732
5754
|
return s0;
|
|
@@ -5775,12 +5797,12 @@ function peg$parse(input, options) {
|
|
|
5775
5797
|
s0 = peg$currPos;
|
|
5776
5798
|
s1 = peg$currPos;
|
|
5777
5799
|
peg$silentFails++;
|
|
5778
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
5779
|
-
s2 = peg$
|
|
5800
|
+
if (input.substr(peg$currPos, 2) === peg$c66) {
|
|
5801
|
+
s2 = peg$c66;
|
|
5780
5802
|
peg$currPos += 2;
|
|
5781
5803
|
} else {
|
|
5782
5804
|
s2 = peg$FAILED;
|
|
5783
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5805
|
+
if (peg$silentFails === 0) { peg$fail(peg$e103); }
|
|
5784
5806
|
}
|
|
5785
5807
|
peg$silentFails--;
|
|
5786
5808
|
if (s2 === peg$FAILED) {
|
|
@@ -5861,7 +5883,7 @@ function peg$parse(input, options) {
|
|
|
5861
5883
|
peg$silentFails--;
|
|
5862
5884
|
if (s0 === peg$FAILED) {
|
|
5863
5885
|
s1 = peg$FAILED;
|
|
5864
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5886
|
+
if (peg$silentFails === 0) { peg$fail(peg$e104); }
|
|
5865
5887
|
}
|
|
5866
5888
|
|
|
5867
5889
|
return s0;
|
|
@@ -5920,7 +5942,7 @@ function peg$parse(input, options) {
|
|
|
5920
5942
|
peg$silentFails--;
|
|
5921
5943
|
if (s0 === peg$FAILED) {
|
|
5922
5944
|
s1 = peg$FAILED;
|
|
5923
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5945
|
+
if (peg$silentFails === 0) { peg$fail(peg$e105); }
|
|
5924
5946
|
}
|
|
5925
5947
|
|
|
5926
5948
|
return s0;
|
|
@@ -5940,12 +5962,12 @@ function peg$parse(input, options) {
|
|
|
5940
5962
|
if (peg$silentFails === 0) { peg$fail(peg$e42); }
|
|
5941
5963
|
}
|
|
5942
5964
|
if (s2 === peg$FAILED) {
|
|
5943
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
5944
|
-
s2 = peg$
|
|
5965
|
+
if (input.substr(peg$currPos, 2) === peg$c66) {
|
|
5966
|
+
s2 = peg$c66;
|
|
5945
5967
|
peg$currPos += 2;
|
|
5946
5968
|
} else {
|
|
5947
5969
|
s2 = peg$FAILED;
|
|
5948
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
5970
|
+
if (peg$silentFails === 0) { peg$fail(peg$e103); }
|
|
5949
5971
|
}
|
|
5950
5972
|
}
|
|
5951
5973
|
peg$silentFails--;
|
|
@@ -5993,12 +6015,12 @@ function peg$parse(input, options) {
|
|
|
5993
6015
|
|
|
5994
6016
|
peg$silentFails++;
|
|
5995
6017
|
s0 = peg$currPos;
|
|
5996
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
5997
|
-
s1 = peg$
|
|
6018
|
+
if (input.substr(peg$currPos, 2) === peg$c66) {
|
|
6019
|
+
s1 = peg$c66;
|
|
5998
6020
|
peg$currPos += 2;
|
|
5999
6021
|
} else {
|
|
6000
6022
|
s1 = peg$FAILED;
|
|
6001
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6023
|
+
if (peg$silentFails === 0) { peg$fail(peg$e103); }
|
|
6002
6024
|
}
|
|
6003
6025
|
if (s1 !== peg$FAILED) {
|
|
6004
6026
|
s2 = peg$parseexpectExpression();
|
|
@@ -6028,7 +6050,7 @@ function peg$parse(input, options) {
|
|
|
6028
6050
|
peg$silentFails--;
|
|
6029
6051
|
if (s0 === peg$FAILED) {
|
|
6030
6052
|
s1 = peg$FAILED;
|
|
6031
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6053
|
+
if (peg$silentFails === 0) { peg$fail(peg$e106); }
|
|
6032
6054
|
}
|
|
6033
6055
|
|
|
6034
6056
|
return s0;
|
|
@@ -6085,16 +6107,16 @@ function peg$parse(input, options) {
|
|
|
6085
6107
|
peg$currPos++;
|
|
6086
6108
|
} else {
|
|
6087
6109
|
s0 = peg$FAILED;
|
|
6088
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6110
|
+
if (peg$silentFails === 0) { peg$fail(peg$e107); }
|
|
6089
6111
|
}
|
|
6090
6112
|
if (s0 === peg$FAILED) {
|
|
6091
6113
|
s0 = peg$currPos;
|
|
6092
6114
|
if (input.charCodeAt(peg$currPos) === 126) {
|
|
6093
|
-
s1 = peg$
|
|
6115
|
+
s1 = peg$c67;
|
|
6094
6116
|
peg$currPos++;
|
|
6095
6117
|
} else {
|
|
6096
6118
|
s1 = peg$FAILED;
|
|
6097
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6119
|
+
if (peg$silentFails === 0) { peg$fail(peg$e108); }
|
|
6098
6120
|
}
|
|
6099
6121
|
if (s1 !== peg$FAILED) {
|
|
6100
6122
|
s2 = peg$currPos;
|
|
@@ -6104,7 +6126,7 @@ function peg$parse(input, options) {
|
|
|
6104
6126
|
peg$currPos++;
|
|
6105
6127
|
} else {
|
|
6106
6128
|
s3 = peg$FAILED;
|
|
6107
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6129
|
+
if (peg$silentFails === 0) { peg$fail(peg$e109); }
|
|
6108
6130
|
}
|
|
6109
6131
|
peg$silentFails--;
|
|
6110
6132
|
if (s3 === peg$FAILED) {
|
|
@@ -6127,12 +6149,12 @@ function peg$parse(input, options) {
|
|
|
6127
6149
|
s0 = peg$parseminus();
|
|
6128
6150
|
if (s0 === peg$FAILED) {
|
|
6129
6151
|
s0 = peg$currPos;
|
|
6130
|
-
if (input.substr(peg$currPos, 5) === peg$
|
|
6131
|
-
s1 = peg$
|
|
6152
|
+
if (input.substr(peg$currPos, 5) === peg$c68) {
|
|
6153
|
+
s1 = peg$c68;
|
|
6132
6154
|
peg$currPos += 5;
|
|
6133
6155
|
} else {
|
|
6134
6156
|
s1 = peg$FAILED;
|
|
6135
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6157
|
+
if (peg$silentFails === 0) { peg$fail(peg$e110); }
|
|
6136
6158
|
}
|
|
6137
6159
|
if (s1 !== peg$FAILED) {
|
|
6138
6160
|
s2 = peg$currPos;
|
|
@@ -6157,12 +6179,12 @@ function peg$parse(input, options) {
|
|
|
6157
6179
|
}
|
|
6158
6180
|
if (s0 === peg$FAILED) {
|
|
6159
6181
|
s0 = peg$currPos;
|
|
6160
|
-
if (input.substr(peg$currPos, 6) === peg$
|
|
6161
|
-
s1 = peg$
|
|
6182
|
+
if (input.substr(peg$currPos, 6) === peg$c69) {
|
|
6183
|
+
s1 = peg$c69;
|
|
6162
6184
|
peg$currPos += 6;
|
|
6163
6185
|
} else {
|
|
6164
6186
|
s1 = peg$FAILED;
|
|
6165
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6187
|
+
if (peg$silentFails === 0) { peg$fail(peg$e111); }
|
|
6166
6188
|
}
|
|
6167
6189
|
if (s1 !== peg$FAILED) {
|
|
6168
6190
|
s2 = peg$currPos;
|
|
@@ -6187,12 +6209,12 @@ function peg$parse(input, options) {
|
|
|
6187
6209
|
}
|
|
6188
6210
|
if (s0 === peg$FAILED) {
|
|
6189
6211
|
s0 = peg$currPos;
|
|
6190
|
-
if (input.substr(peg$currPos, 4) === peg$
|
|
6191
|
-
s1 = peg$
|
|
6212
|
+
if (input.substr(peg$currPos, 4) === peg$c70) {
|
|
6213
|
+
s1 = peg$c70;
|
|
6192
6214
|
peg$currPos += 4;
|
|
6193
6215
|
} else {
|
|
6194
6216
|
s1 = peg$FAILED;
|
|
6195
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6217
|
+
if (peg$silentFails === 0) { peg$fail(peg$e112); }
|
|
6196
6218
|
}
|
|
6197
6219
|
if (s1 !== peg$FAILED) {
|
|
6198
6220
|
s2 = peg$currPos;
|
|
@@ -6372,7 +6394,7 @@ function peg$parse(input, options) {
|
|
|
6372
6394
|
peg$currPos++;
|
|
6373
6395
|
} else {
|
|
6374
6396
|
s1 = peg$FAILED;
|
|
6375
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6397
|
+
if (peg$silentFails === 0) { peg$fail(peg$e113); }
|
|
6376
6398
|
}
|
|
6377
6399
|
if (s1 !== peg$FAILED) {
|
|
6378
6400
|
s2 = peg$currPos;
|
|
@@ -6435,7 +6457,7 @@ function peg$parse(input, options) {
|
|
|
6435
6457
|
peg$silentFails--;
|
|
6436
6458
|
if (s0 === peg$FAILED) {
|
|
6437
6459
|
s1 = peg$FAILED;
|
|
6438
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6460
|
+
if (peg$silentFails === 0) { peg$fail(peg$e114); }
|
|
6439
6461
|
}
|
|
6440
6462
|
|
|
6441
6463
|
return s0;
|
|
@@ -6450,7 +6472,7 @@ function peg$parse(input, options) {
|
|
|
6450
6472
|
peg$currPos++;
|
|
6451
6473
|
} else {
|
|
6452
6474
|
s1 = peg$FAILED;
|
|
6453
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6475
|
+
if (peg$silentFails === 0) { peg$fail(peg$e115); }
|
|
6454
6476
|
}
|
|
6455
6477
|
if (s1 !== peg$FAILED) {
|
|
6456
6478
|
s2 = [];
|
|
@@ -6459,7 +6481,7 @@ function peg$parse(input, options) {
|
|
|
6459
6481
|
peg$currPos++;
|
|
6460
6482
|
} else {
|
|
6461
6483
|
s3 = peg$FAILED;
|
|
6462
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6484
|
+
if (peg$silentFails === 0) { peg$fail(peg$e116); }
|
|
6463
6485
|
}
|
|
6464
6486
|
while (s3 !== peg$FAILED) {
|
|
6465
6487
|
s2.push(s3);
|
|
@@ -6468,7 +6490,7 @@ function peg$parse(input, options) {
|
|
|
6468
6490
|
peg$currPos++;
|
|
6469
6491
|
} else {
|
|
6470
6492
|
s3 = peg$FAILED;
|
|
6471
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6493
|
+
if (peg$silentFails === 0) { peg$fail(peg$e116); }
|
|
6472
6494
|
}
|
|
6473
6495
|
}
|
|
6474
6496
|
s3 = input.charAt(peg$currPos);
|
|
@@ -6476,7 +6498,7 @@ function peg$parse(input, options) {
|
|
|
6476
6498
|
peg$currPos++;
|
|
6477
6499
|
} else {
|
|
6478
6500
|
s3 = peg$FAILED;
|
|
6479
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
6501
|
+
if (peg$silentFails === 0) { peg$fail(peg$e117); }
|
|
6480
6502
|
}
|
|
6481
6503
|
if (s3 !== peg$FAILED) {
|
|
6482
6504
|
peg$savedPos = s0;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { trailingSlash } from "@weborigami/async-tree";
|
|
2
1
|
import * as YAMLModule from "yaml";
|
|
3
2
|
import codeFragment from "../runtime/codeFragment.js";
|
|
4
3
|
import * as ops from "../runtime/ops.js";
|
|
@@ -143,6 +142,8 @@ export function makeBinaryOperation(left, [operatorToken, right]) {
|
|
|
143
142
|
">>>": ops.shiftRightUnsigned,
|
|
144
143
|
"^": ops.bitwiseXor,
|
|
145
144
|
"|": ops.bitwiseOr,
|
|
145
|
+
instanceof: ops.instanceOf,
|
|
146
|
+
in: ops.inOperator,
|
|
146
147
|
};
|
|
147
148
|
const op = operators[operatorToken];
|
|
148
149
|
|
|
@@ -380,11 +381,6 @@ export function makePath(keys) {
|
|
|
380
381
|
const location = spanLocations(code);
|
|
381
382
|
code = annotate(code, location);
|
|
382
383
|
|
|
383
|
-
// Last key has trailing slash implies unpack operation
|
|
384
|
-
if (trailingSlash.has(args.at(-1)[1])) {
|
|
385
|
-
code = annotate([ops.unpack, code], location);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
384
|
return code;
|
|
389
385
|
}
|
|
390
386
|
|
|
@@ -518,7 +514,7 @@ export function makeYamlObject(text, location) {
|
|
|
518
514
|
|
|
519
515
|
// Create a locations that spans those in the array. This assumes the locations
|
|
520
516
|
// are in order and non-overlapping.
|
|
521
|
-
function spanLocations(code) {
|
|
517
|
+
export function spanLocations(code) {
|
|
522
518
|
const first = code.find((item) => item.location).location;
|
|
523
519
|
const last = code[code.findLastIndex((item) => item.location)].location;
|
|
524
520
|
return {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getParent, toString } from "@weborigami/async-tree";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Given packed source text and a handler's options, return a source
|
|
5
|
+
* object that can be passed to the compiler.
|
|
6
|
+
*/
|
|
7
|
+
export default function getSource(packed, options = {}) {
|
|
8
|
+
const parent = getParent(packed, options);
|
|
9
|
+
|
|
10
|
+
// Try to determine a URL for error messages
|
|
11
|
+
const sourceName = options.key;
|
|
12
|
+
let url;
|
|
13
|
+
if (sourceName) {
|
|
14
|
+
if (/** @type {any} */ (parent)?.url) {
|
|
15
|
+
let parentHref = /** @type {any} */ (parent).url.href;
|
|
16
|
+
if (!parentHref.endsWith("/")) {
|
|
17
|
+
parentHref += "/";
|
|
18
|
+
}
|
|
19
|
+
url = new URL(sourceName, parentHref);
|
|
20
|
+
} else if (/** @type {any} */ (parent)?.path) {
|
|
21
|
+
let parentHref = new URL(/** @type {any} */ (parent).path, "file:///")
|
|
22
|
+
.href;
|
|
23
|
+
if (!parentHref.endsWith("/")) {
|
|
24
|
+
parentHref += "/";
|
|
25
|
+
}
|
|
26
|
+
url = new URL(sourceName, parentHref);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const source = {
|
|
31
|
+
text: toString(packed),
|
|
32
|
+
name: options.key,
|
|
33
|
+
url,
|
|
34
|
+
};
|
|
35
|
+
return source;
|
|
36
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getParent, setParent
|
|
1
|
+
import { getParent, setParent } from "@weborigami/async-tree";
|
|
2
2
|
import * as compile from "../compiler/compile.js";
|
|
3
3
|
import projectGlobals from "../project/projectGlobals.js";
|
|
4
|
+
import getSource from "./getSource.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* An Origami expression file
|
|
@@ -13,34 +14,18 @@ export default {
|
|
|
13
14
|
/** @type {import("@weborigami/async-tree").UnpackFunction} */
|
|
14
15
|
async unpack(packed, options = {}) {
|
|
15
16
|
const parent = getParent(packed, options);
|
|
17
|
+
const source = getSource(packed, options);
|
|
16
18
|
|
|
17
|
-
//
|
|
18
|
-
const sourceName = options.key;
|
|
19
|
-
let url;
|
|
20
|
-
if (sourceName && /** @type {any} */ (parent)?.url) {
|
|
21
|
-
let parentHref = /** @type {any} */ (parent).url.href;
|
|
22
|
-
if (!parentHref.endsWith("/")) {
|
|
23
|
-
parentHref += "/";
|
|
24
|
-
}
|
|
25
|
-
url = new URL(sourceName, parentHref);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const source = {
|
|
29
|
-
text: toString(packed),
|
|
30
|
-
name: options.key,
|
|
31
|
-
url,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// Compile the source code as an Origami program and evaluate it.
|
|
19
|
+
// Compile the source code as an Origami program
|
|
35
20
|
const compiler = options.compiler ?? compile.program;
|
|
36
21
|
const globals = options.globals ?? (await projectGlobals());
|
|
37
|
-
|
|
38
22
|
const fn = compiler(source, {
|
|
39
23
|
globals,
|
|
40
24
|
mode: "program",
|
|
41
25
|
parent,
|
|
42
26
|
});
|
|
43
27
|
|
|
28
|
+
// Evaluate the program
|
|
44
29
|
const result = await fn();
|
|
45
30
|
|
|
46
31
|
if (parent) {
|