@weborigami/language 0.0.42 → 0.0.44
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 +4 -9
- package/main.js +1 -0
- package/package.json +3 -3
- package/src/compiler/compile.js +7 -7
- package/src/compiler/origami.pegjs +15 -4
- package/src/compiler/parse.js +573 -331
- package/src/runtime/FileLoadersTransform.js +18 -11
- package/src/runtime/evaluate.js +7 -3
- package/src/runtime/symbols.js +1 -0
- package/test/compiler/compile.test.js +1 -1
- package/test/compiler/parse.test.js +50 -3
- package/test/runtime/FileLoadersTransform.test.js +1 -1
package/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AsyncTree } from "@weborigami/types";
|
|
2
|
-
import { StringLike } from "../async-tree/index.js";
|
|
3
1
|
|
|
4
2
|
export * from "./main.js";
|
|
5
3
|
|
|
@@ -19,15 +17,12 @@ export type Code = ArrayWithSource;
|
|
|
19
17
|
export type Constructor<T> = new (...args: any[]) => T;
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
|
-
* A function that can convert a
|
|
20
|
+
* A function that can convert a value from some persistent form into some kind
|
|
21
|
+
* of live value.
|
|
23
22
|
*/
|
|
24
23
|
export type FileUnpackFunction = (
|
|
25
|
-
input:
|
|
26
|
-
options?:
|
|
27
|
-
compiler?: any,
|
|
28
|
-
key?: any,
|
|
29
|
-
parent?: AsyncTree | null
|
|
30
|
-
}
|
|
24
|
+
input: any,
|
|
25
|
+
options?: any
|
|
31
26
|
) => any;
|
|
32
27
|
|
|
33
28
|
/**
|
package/main.js
CHANGED
|
@@ -19,3 +19,4 @@ export * as expressionFunction from "./src/runtime/expressionFunction.js";
|
|
|
19
19
|
export { default as extname } from "./src/runtime/extname.js";
|
|
20
20
|
export { default as formatError } from "./src/runtime/formatError.js";
|
|
21
21
|
export { default as functionResultsMap } from "./src/runtime/functionResultsMap.js";
|
|
22
|
+
export * as symbols from "./src/runtime/symbols.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/language",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
4
4
|
"description": "Web Origami expression language compiler and runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./main.js",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"typescript": "5.3.3"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@weborigami/async-tree": "
|
|
14
|
-
"@weborigami/types": "0.0.
|
|
13
|
+
"@weborigami/async-tree": "0.0.44",
|
|
14
|
+
"@weborigami/types": "0.0.44",
|
|
15
15
|
"peggy": "3.0.2",
|
|
16
16
|
"watcher": "2.3.0"
|
|
17
17
|
},
|
package/src/compiler/compile.js
CHANGED
|
@@ -30,14 +30,14 @@ export function templateDocument(source) {
|
|
|
30
30
|
//
|
|
31
31
|
// Example:
|
|
32
32
|
//
|
|
33
|
-
// {
|
|
33
|
+
// ${ if `
|
|
34
34
|
// true text
|
|
35
35
|
// `, `
|
|
36
36
|
// false text
|
|
37
|
-
// ` }
|
|
37
|
+
// ` }
|
|
38
38
|
//
|
|
39
39
|
// Case 1: a substitution that starts the text or starts a line (there's only
|
|
40
|
-
// whitespace before the
|
|
40
|
+
// whitespace before the `${`), and has the line end with the start of a
|
|
41
41
|
// template literal (there's only whitespace after the backtick) marks the start
|
|
42
42
|
// of a block.
|
|
43
43
|
//
|
|
@@ -45,17 +45,17 @@ export function templateDocument(source) {
|
|
|
45
45
|
// another is an internal break in the block. Edge case: three backticks in a
|
|
46
46
|
// row, like ```, are common in markdown and are not treated as a break.
|
|
47
47
|
//
|
|
48
|
-
// Case 3: a line that ends a template literal and ends with `}
|
|
48
|
+
// Case 3: a line that ends a template literal and ends with `}` or ends the
|
|
49
49
|
// text marks the end of the block.
|
|
50
50
|
//
|
|
51
51
|
// In all three cases, we trim spaces and tabs from the start and end of the
|
|
52
52
|
// line. In case 1, we also remove the preceding newline.
|
|
53
53
|
function trimTemplateWhitespace(text) {
|
|
54
|
-
const regex1 = /(^|\n)[ \t]*({{.*?`)[ \t]*\n/g;
|
|
54
|
+
const regex1 = /(^|\n)[ \t]*((?:{{|\${).*?`)[ \t]*\n/g;
|
|
55
55
|
const regex2 = /\n[ \t]*(`(?!`).*?`)[ \t]*\n/g;
|
|
56
|
-
const
|
|
56
|
+
const regex3js = /\n[ \t]*(`(?!`).*?(?:}}|[^\\]}))[ \t]*(?:\n|$)/g;
|
|
57
57
|
const trimBlockStarts = text.replace(regex1, "$1$2");
|
|
58
58
|
const trimBlockBreaks = trimBlockStarts.replace(regex2, "\n$1");
|
|
59
|
-
const trimBlockEnds = trimBlockBreaks.replace(
|
|
59
|
+
const trimBlockEnds = trimBlockBreaks.replace(regex3js, "\n$1");
|
|
60
60
|
return trimBlockEnds;
|
|
61
61
|
}
|
|
@@ -25,8 +25,10 @@ __
|
|
|
25
25
|
= (inlineSpace / newLine / comment)* { return ""; }
|
|
26
26
|
|
|
27
27
|
// A filesystem path that begins with a slash: `/foo/bar`
|
|
28
|
+
// We take care to avoid treating two consecutive leading slashes as a path;
|
|
29
|
+
// that starts a comment.
|
|
28
30
|
absoluteFilePath "absolute file path"
|
|
29
|
-
= path:leadingSlashPath {
|
|
31
|
+
= !"//" path:leadingSlashPath {
|
|
30
32
|
return annotate([[ops.filesRoot], ...path], location());
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -91,7 +93,8 @@ closingParen
|
|
|
91
93
|
|
|
92
94
|
// A single line comment
|
|
93
95
|
comment "comment"
|
|
94
|
-
=
|
|
96
|
+
= multiLineComment
|
|
97
|
+
/ singleLineComment
|
|
95
98
|
|
|
96
99
|
digits
|
|
97
100
|
= @[0-9]+
|
|
@@ -177,6 +180,9 @@ leadingSlashPath "path with a leading slash"
|
|
|
177
180
|
list "list"
|
|
178
181
|
= @expr|1.., separator| separator?
|
|
179
182
|
|
|
183
|
+
multiLineComment
|
|
184
|
+
= "/*" (!"*/" .)* "*/" { return null; }
|
|
185
|
+
|
|
180
186
|
newLine
|
|
181
187
|
= "\n"
|
|
182
188
|
/ "\r\n"
|
|
@@ -267,6 +273,10 @@ sign
|
|
|
267
273
|
|
|
268
274
|
singleArrow = "→" / "->"
|
|
269
275
|
|
|
276
|
+
singleLineComment
|
|
277
|
+
= "#" [^\n\r]* { return null; }
|
|
278
|
+
/ "//" [^\n\r]* { return null; }
|
|
279
|
+
|
|
270
280
|
singleQuoteString "single quote string"
|
|
271
281
|
= "'" chars:singleQuoteStringChar* "'" { return chars.join(""); }
|
|
272
282
|
|
|
@@ -312,7 +322,7 @@ templateDocument "template"
|
|
|
312
322
|
|
|
313
323
|
// Template documents can contain backticks at the top level.
|
|
314
324
|
templateDocumentChar
|
|
315
|
-
= !"{{" @textChar
|
|
325
|
+
= !("{{" / "${") @textChar
|
|
316
326
|
|
|
317
327
|
// The contents of a template document containing plain text and substitutions
|
|
318
328
|
templateDocumentContents
|
|
@@ -328,7 +338,7 @@ templateLiteral "template literal"
|
|
|
328
338
|
= "`" @templateLiteralContents "`"
|
|
329
339
|
|
|
330
340
|
templateLiteralChar
|
|
331
|
-
= !("`" / "{{") @textChar
|
|
341
|
+
= !("`" / "{{" / "${") @textChar
|
|
332
342
|
|
|
333
343
|
// The contents of a template literal containing plain text and substitutions
|
|
334
344
|
templateLiteralContents
|
|
@@ -343,6 +353,7 @@ templateLiteralText
|
|
|
343
353
|
// A substitution in a template literal: `{{ fn() }}`
|
|
344
354
|
templateSubstitution "template substitution"
|
|
345
355
|
= "{{" @expression "}}"
|
|
356
|
+
/ "${" @expression "}"
|
|
346
357
|
|
|
347
358
|
textChar
|
|
348
359
|
= escapedChar / .
|