@weborigami/language 0.0.42 → 0.0.43

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.42",
3
+ "version": "0.0.43",
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": "https://gitpkg.now.sh/WebOrigami/origami/async-tree?e08c2451",
14
- "@weborigami/types": "0.0.42",
13
+ "@weborigami/async-tree": "0.0.43",
14
+ "@weborigami/types": "0.0.43",
15
15
  "peggy": "3.0.2",
16
16
  "watcher": "2.3.0"
17
17
  },
@@ -30,14 +30,14 @@ export function templateDocument(source) {
30
30
  //
31
31
  // Example:
32
32
  //
33
- // {{ if `
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 `{{`), and has the line end with the start of a
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 `}}` or ends the
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 regex3 = /\n[ \t]*(`(?!`).*?}})[ \t]*(?:\n|$)/g;
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(regex3, "\n$1");
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
- = "#" [^\n\r]*
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 / .