@weborigami/language 0.0.51 → 0.0.53

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/language",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
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.51",
15
- "@weborigami/types": "0.0.51",
14
+ "@weborigami/async-tree": "0.0.53",
15
+ "@weborigami/types": "0.0.53",
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 { makeArray, 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.
@@ -39,19 +39,17 @@ args "function arguments"
39
39
  }
40
40
 
41
41
  array "array"
42
- = "[" __ list:list? __ closingBracket {
43
- return annotate([ops.array, ...(list ?? [])], location());
42
+ = "[" __ entries:arrayEntries? __ closingBracket {
43
+ return annotate(makeArray(entries ?? []), location());
44
44
  }
45
45
 
46
- // An assignment statement: `foo = 1`
47
- assignment "tree assignment"
48
- = @identifier __ "=" __ @expr
46
+ // A separated list of array entries
47
+ arrayEntries
48
+ = @arrayEntry|1.., separator| separator?
49
49
 
50
- assignmentOrShorthand
51
- = assignment
52
- / key:identifier {
53
- return annotate([key, [ops.inherited, key]], location());
54
- }
50
+ arrayEntry
51
+ = spread
52
+ / expr
55
53
 
56
54
  // Something that can be called. This is more restrictive than the `expr`
57
55
  // parser; it doesn't accept regular function calls.
@@ -107,6 +105,8 @@ doubleQuoteString "double quote string"
107
105
  doubleQuoteStringChar
108
106
  = !('"' / newLine) @textChar
109
107
 
108
+ ellipsis = "..." / "…" // Unicode ellipsis
109
+
110
110
  escapedChar "backslash-escaped character"
111
111
  = "\\" @.
112
112
 
@@ -199,24 +199,25 @@ number "number"
199
199
  // TODO: Use Object.fromEntries with array of key/value pairs
200
200
  //
201
201
  object "object literal"
202
- = "{" __ properties:objectProperties? __ "}" {
203
- return annotate([ops.object, ...(properties ?? [])], location());
202
+ = "{" __ entries:objectEntries? __ "}" {
203
+ return annotate(makeObject(entries ?? [], ops.object), location());
204
204
  }
205
205
 
206
- // A separated list of object properties or shorthands
207
- objectProperties
208
- = @objectPropertyOrShorthand|1.., separator| separator?
206
+ // A separated list of object entries
207
+ objectEntries
208
+ = @objectEntry|1.., separator| separator?
209
209
 
210
- // A single object property with key and value: `x: 1`
211
- objectProperty "object property"
212
- = @identifier __ ":" __ @expr
213
-
214
- objectPropertyOrShorthand
215
- = objectProperty
210
+ objectEntry
211
+ = spread
212
+ / objectProperty
216
213
  / key:identifier {
217
214
  return annotate([key, [ops.scope, key]], location());
218
215
  }
219
216
 
217
+ // A single object property with key and value: `x: 1`
218
+ objectProperty "object property"
219
+ = @identifier __ ":" __ @expr
220
+
220
221
  parameterizedLambda
221
222
  = "(" __ parameters:identifierList? __ ")" __ doubleArrow __ expr:expr {
222
223
  return annotate([ops.lambda, parameters ?? [], expr], location());
@@ -287,6 +288,9 @@ singleQuoteString "single quote string"
287
288
  singleQuoteStringChar
288
289
  = !("'" / newLine) @textChar
289
290
 
291
+ spread
292
+ = ellipsis expr:expr { return [ops.spread, expr]; }
293
+
290
294
  // A single step in a pipeline, or a top-level expression
291
295
  step
292
296
  // Literals that can't start a function call
@@ -363,13 +367,24 @@ textChar
363
367
 
364
368
  // A tree literal: `{ index.html = "Hello" }`
365
369
  tree "tree literal"
366
- = "{" __ assignments:treeAssignments? __ closingBrace {
367
- return annotate([ops.tree, ...(assignments ?? [])], location());
370
+ = "{" __ entries:treeEntries? __ closingBrace {
371
+ return annotate(makeObject(entries ?? [], ops.tree), location());
368
372
  }
369
373
 
374
+ // A tree assignment statement: `foo = 1`
375
+ treeAssignment "tree assignment"
376
+ = @identifier __ "=" __ @expr
377
+
370
378
  // A separated list of assignments or shorthands
371
- treeAssignments
372
- = @assignmentOrShorthand|1.., separator| separator?
379
+ treeEntries
380
+ = @treeEntry|1.., separator| separator?
381
+
382
+ treeEntry
383
+ = spread
384
+ / treeAssignment
385
+ / key:identifier {
386
+ return annotate([key, [ops.inherited, key]], location());
387
+ }
373
388
 
374
389
  whitespaceWithNewLine
375
390
  = inlineSpace* comment? newLine __