@weborigami/language 0.0.73 → 0.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.
Files changed (35) hide show
  1. package/index.ts +1 -0
  2. package/main.js +2 -2
  3. package/package.json +6 -4
  4. package/src/compiler/compile.js +42 -17
  5. package/src/compiler/origami.pegjs +248 -182
  6. package/src/compiler/parse.js +1569 -1231
  7. package/src/compiler/parserHelpers.js +180 -48
  8. package/src/runtime/HandleExtensionsTransform.js +1 -1
  9. package/src/runtime/ImportModulesMixin.js +1 -1
  10. package/src/runtime/codeFragment.js +2 -2
  11. package/src/runtime/errors.js +104 -0
  12. package/src/runtime/evaluate.js +3 -3
  13. package/src/runtime/expressionObject.js +8 -5
  14. package/src/runtime/{extensions.js → handlers.js} +6 -24
  15. package/src/runtime/internal.js +1 -0
  16. package/src/runtime/ops.js +156 -185
  17. package/src/runtime/typos.js +71 -0
  18. package/test/cases/ReadMe.md +1 -0
  19. package/test/cases/conditionalExpression.yaml +101 -0
  20. package/test/cases/logicalAndExpression.yaml +146 -0
  21. package/test/cases/logicalOrExpression.yaml +145 -0
  22. package/test/cases/nullishCoalescingExpression.yaml +105 -0
  23. package/test/compiler/compile.test.js +7 -7
  24. package/test/compiler/parse.test.js +506 -294
  25. package/test/generated/conditionalExpression.test.js +58 -0
  26. package/test/generated/logicalAndExpression.test.js +80 -0
  27. package/test/generated/logicalOrExpression.test.js +78 -0
  28. package/test/generated/nullishCoalescingExpression.test.js +64 -0
  29. package/test/generator/generateTests.js +80 -0
  30. package/test/generator/oriEval.js +15 -0
  31. package/test/runtime/fixtures/templates/greet.orit +1 -1
  32. package/test/runtime/{extensions.test.js → handlers.test.js} +2 -2
  33. package/test/runtime/ops.test.js +129 -26
  34. package/test/runtime/typos.test.js +21 -0
  35. package/src/runtime/formatError.js +0 -56
@@ -0,0 +1,21 @@
1
+ import assert from "node:assert";
2
+ import { describe, test } from "node:test";
3
+ import { isTypo, typos } from "../../src/runtime/typos.js";
4
+
5
+ describe("typos", () => {
6
+ test("isTypo", () => {
7
+ assert(isTypo("cat", "bat")); // substitution
8
+ assert(isTypo("cat", "cats")); // insertion
9
+ assert(isTypo("cat", "cast")); // insertion
10
+ assert(isTypo("cat", "at")); // deletion
11
+ assert(isTypo("cat", "ca")); // deletion
12
+ assert(isTypo("cat", "cta")); // transposition
13
+ assert(isTypo("cat", "act")); // transposition
14
+ assert(!isTypo("cat", "dog")); // more than 1 edit
15
+ });
16
+
17
+ test("typos", () => {
18
+ const result = typos("cas", ["ask", "cat", "cast", "cats", "cart"]);
19
+ assert.deepEqual(result, ["cat", "cast", "cats"]);
20
+ });
21
+ });
@@ -1,56 +0,0 @@
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
-
5
- // function in the Origami source code.
6
- const origamiSourceSignals = [
7
- "async-tree/src/",
8
- "language/src/",
9
- "origami/src/",
10
- "at Scope.evaluate",
11
- ];
12
-
13
- /**
14
- * Format an error for display in the console.
15
- *
16
- * @param {Error} error
17
- */
18
- export default function formatError(error) {
19
- let message;
20
- if (error.stack) {
21
- // Display the stack only until we reach the Origami source code.
22
- message = "";
23
- let lines = error.stack.split("\n");
24
- for (let i = 0; i < lines.length; i++) {
25
- const line = lines[i];
26
- if (maybeOrigamiSourceCode(line)) {
27
- break;
28
- }
29
- if (message) {
30
- message += "\n";
31
- }
32
- message += lines[i];
33
- }
34
- } else {
35
- message = error.toString();
36
- }
37
-
38
- // Add location
39
- let location = /** @type {any} */ (error).location;
40
- if (location) {
41
- const fragment = codeFragment(location);
42
- let { source, start } = location;
43
-
44
- message += `\nevaluating: ${fragment}`;
45
- if (typeof source === "object" && source.url) {
46
- message += `\n at ${source.url.href}:${start.line}:${start.column}`;
47
- } else if (source.text.includes("\n")) {
48
- message += `\n at line ${start.line}, column ${start.column}`;
49
- }
50
- }
51
- return message;
52
- }
53
-
54
- export function maybeOrigamiSourceCode(text) {
55
- return origamiSourceSignals.some((signal) => text.includes(signal));
56
- }