@weborigami/language 0.0.65-beta.2 → 0.0.66-beta.1
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/index.ts +0 -2
- package/package.json +3 -3
- package/src/compiler/origami.pegjs +45 -23
- package/src/compiler/parse.d.ts +2 -2
- package/src/compiler/parse.js +139 -104
- package/src/compiler/parserHelpers.js +10 -2
- package/src/runtime/codeFragment.js +19 -0
- package/src/runtime/evaluate.js +21 -16
- package/src/runtime/expressionFunction.js +5 -6
- package/src/runtime/formatError.js +6 -6
- package/src/runtime/ops.js +9 -1
- package/test/compiler/parse.test.js +237 -112
- package/test/runtime/evaluate.test.js +20 -7
- package/test/runtime/ops.test.js +28 -10
|
@@ -5,20 +5,19 @@ import { evaluate } from "./internal.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Given parsed Origami code, return a function that executes that code.
|
|
7
7
|
*
|
|
8
|
-
* @param {import("../../index.js").
|
|
8
|
+
* @param {import("../../index.js").Code} code - parsed Origami expression
|
|
9
9
|
* @param {string} [name] - optional name of the function
|
|
10
10
|
*/
|
|
11
|
-
export function createExpressionFunction(
|
|
11
|
+
export function createExpressionFunction(code, name) {
|
|
12
12
|
/** @this {AsyncTree|null} */
|
|
13
13
|
async function fn() {
|
|
14
|
-
return evaluate.call(this,
|
|
14
|
+
return evaluate.call(this, code);
|
|
15
15
|
}
|
|
16
16
|
if (name) {
|
|
17
17
|
Object.defineProperty(fn, "name", { value: name });
|
|
18
18
|
}
|
|
19
|
-
fn.code =
|
|
20
|
-
fn.toString = () =>
|
|
21
|
-
parsed instanceof Array ? parsed.location.source.text : parsed;
|
|
19
|
+
fn.code = code;
|
|
20
|
+
fn.toString = () => code.location.source.text;
|
|
22
21
|
return fn;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// Text we look for in an error stack to guess whether a given line represents a
|
|
2
|
+
|
|
3
|
+
import codeFragment from "./codeFragment.js";
|
|
4
|
+
|
|
2
5
|
// function in the Origami source code.
|
|
3
6
|
const origamiSourceSignals = [
|
|
4
7
|
"async-tree/src/",
|
|
@@ -35,12 +38,9 @@ export default function formatError(error) {
|
|
|
35
38
|
// Add location
|
|
36
39
|
let location = /** @type {any} */ (error).location;
|
|
37
40
|
if (location) {
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
// Use entire source.
|
|
42
|
-
fragment = source.text;
|
|
43
|
-
}
|
|
41
|
+
const fragment = codeFragment(location);
|
|
42
|
+
let { source, start } = location;
|
|
43
|
+
|
|
44
44
|
message += `\nevaluating: ${fragment}`;
|
|
45
45
|
if (typeof source === "object" && source.url) {
|
|
46
46
|
message += `\n at ${source.url.href}:${start.line}:${start.column}`;
|
package/src/runtime/ops.js
CHANGED
|
@@ -222,7 +222,7 @@ export function lambda(parameters, code) {
|
|
|
222
222
|
// We set the `length` property on the function so that Tree.traverseOrThrow()
|
|
223
223
|
// will correctly identify how many parameters it wants. This is unorthodox
|
|
224
224
|
// but doesn't appear to affect other behavior.
|
|
225
|
-
const fnLength =
|
|
225
|
+
const fnLength = parameters.length;
|
|
226
226
|
Object.defineProperty(invoke, "length", {
|
|
227
227
|
value: fnLength,
|
|
228
228
|
});
|
|
@@ -282,6 +282,14 @@ export function spread(...args) {
|
|
|
282
282
|
}
|
|
283
283
|
spread.toString = () => "«ops.spread»";
|
|
284
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Return a primitive value
|
|
287
|
+
*/
|
|
288
|
+
export async function primitive(value) {
|
|
289
|
+
return value;
|
|
290
|
+
}
|
|
291
|
+
primitive.toString = () => "«ops.primitive»";
|
|
292
|
+
|
|
285
293
|
/**
|
|
286
294
|
* Traverse a path of keys through a tree.
|
|
287
295
|
*/
|