@weborigami/language 0.0.51 → 0.0.52
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/package.json +3 -3
- package/src/compiler/origami.pegjs +33 -26
- package/src/compiler/parse.js +459 -401
- package/src/compiler/parserHelpers.js +32 -0
- package/src/runtime/mergeTrees.js +73 -0
- package/src/runtime/ops.js +23 -0
- package/test/compiler/parse.test.js +24 -15
- package/test/runtime/mergeTrees.test.js +69 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/language",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.52",
|
|
4
4
|
"description": "Web Origami expression language compiler and runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./main.js",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"typescript": "5.4.5"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/async-tree": "0.0.
|
|
15
|
-
"@weborigami/types": "0.0.
|
|
14
|
+
"@weborigami/async-tree": "0.0.52",
|
|
15
|
+
"@weborigami/types": "0.0.52",
|
|
16
16
|
"watcher": "2.3.1"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
//
|
|
8
8
|
|
|
9
9
|
import * as ops from "../runtime/ops.js";
|
|
10
|
-
import { makeFunctionCall, makePipeline, makeTemplate } from "./parserHelpers.js";
|
|
10
|
+
import { makeFunctionCall, makeObject, makePipeline, makeTemplate } from "./parserHelpers.js";
|
|
11
11
|
|
|
12
12
|
// If a parse result is an object that will be evaluated at runtime, attach the
|
|
13
13
|
// location of the source code that produced it for debugging and error messages.
|
|
@@ -43,16 +43,6 @@ array "array"
|
|
|
43
43
|
return annotate([ops.array, ...(list ?? [])], location());
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
// An assignment statement: `foo = 1`
|
|
47
|
-
assignment "tree assignment"
|
|
48
|
-
= @identifier __ "=" __ @expr
|
|
49
|
-
|
|
50
|
-
assignmentOrShorthand
|
|
51
|
-
= assignment
|
|
52
|
-
/ key:identifier {
|
|
53
|
-
return annotate([key, [ops.inherited, key]], location());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
// Something that can be called. This is more restrictive than the `expr`
|
|
57
47
|
// parser; it doesn't accept regular function calls.
|
|
58
48
|
callTarget "function call"
|
|
@@ -107,6 +97,8 @@ doubleQuoteString "double quote string"
|
|
|
107
97
|
doubleQuoteStringChar
|
|
108
98
|
= !('"' / newLine) @textChar
|
|
109
99
|
|
|
100
|
+
ellipsis = "..." / "…" // Unicode ellipsis
|
|
101
|
+
|
|
110
102
|
escapedChar "backslash-escaped character"
|
|
111
103
|
= "\\" @.
|
|
112
104
|
|
|
@@ -199,24 +191,25 @@ number "number"
|
|
|
199
191
|
// TODO: Use Object.fromEntries with array of key/value pairs
|
|
200
192
|
//
|
|
201
193
|
object "object literal"
|
|
202
|
-
= "{" __
|
|
203
|
-
return annotate(
|
|
194
|
+
= "{" __ entries:objectEntries? __ "}" {
|
|
195
|
+
return annotate(makeObject(entries ?? [], ops.object), location());
|
|
204
196
|
}
|
|
205
197
|
|
|
206
|
-
// A separated list of object
|
|
207
|
-
|
|
208
|
-
= @
|
|
209
|
-
|
|
210
|
-
// A single object property with key and value: `x: 1`
|
|
211
|
-
objectProperty "object property"
|
|
212
|
-
= @identifier __ ":" __ @expr
|
|
198
|
+
// A separated list of object entries
|
|
199
|
+
objectEntries
|
|
200
|
+
= @objectEntry|1.., separator| separator?
|
|
213
201
|
|
|
214
|
-
|
|
215
|
-
=
|
|
202
|
+
objectEntry
|
|
203
|
+
= spread
|
|
204
|
+
/ objectProperty
|
|
216
205
|
/ key:identifier {
|
|
217
206
|
return annotate([key, [ops.scope, key]], location());
|
|
218
207
|
}
|
|
219
208
|
|
|
209
|
+
// A single object property with key and value: `x: 1`
|
|
210
|
+
objectProperty "object property"
|
|
211
|
+
= @identifier __ ":" __ @expr
|
|
212
|
+
|
|
220
213
|
parameterizedLambda
|
|
221
214
|
= "(" __ parameters:identifierList? __ ")" __ doubleArrow __ expr:expr {
|
|
222
215
|
return annotate([ops.lambda, parameters ?? [], expr], location());
|
|
@@ -287,6 +280,9 @@ singleQuoteString "single quote string"
|
|
|
287
280
|
singleQuoteStringChar
|
|
288
281
|
= !("'" / newLine) @textChar
|
|
289
282
|
|
|
283
|
+
spread
|
|
284
|
+
= ellipsis expr:expr { return [ops.spread, expr]; }
|
|
285
|
+
|
|
290
286
|
// A single step in a pipeline, or a top-level expression
|
|
291
287
|
step
|
|
292
288
|
// Literals that can't start a function call
|
|
@@ -363,13 +359,24 @@ textChar
|
|
|
363
359
|
|
|
364
360
|
// A tree literal: `{ index.html = "Hello" }`
|
|
365
361
|
tree "tree literal"
|
|
366
|
-
= "{" __
|
|
367
|
-
return annotate(
|
|
362
|
+
= "{" __ entries:treeEntries? __ closingBrace {
|
|
363
|
+
return annotate(makeObject(entries ?? [], ops.tree), location());
|
|
368
364
|
}
|
|
369
365
|
|
|
366
|
+
// A tree assignment statement: `foo = 1`
|
|
367
|
+
treeAssignment "tree assignment"
|
|
368
|
+
= @identifier __ "=" __ @expr
|
|
369
|
+
|
|
370
370
|
// A separated list of assignments or shorthands
|
|
371
|
-
|
|
372
|
-
= @
|
|
371
|
+
treeEntries
|
|
372
|
+
= @treeEntry|1.., separator| separator?
|
|
373
|
+
|
|
374
|
+
treeEntry
|
|
375
|
+
= spread
|
|
376
|
+
/ treeAssignment
|
|
377
|
+
/ key:identifier {
|
|
378
|
+
return annotate([key, [ops.inherited, key]], location());
|
|
379
|
+
}
|
|
373
380
|
|
|
374
381
|
whitespaceWithNewLine
|
|
375
382
|
= inlineSpace* comment? newLine __
|