@weborigami/language 0.0.65-beta.2 → 0.0.66-beta.1
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 +0 -2
- package/package.json +3 -3
- package/src/compiler/origami.pegjs +45 -23
- package/src/compiler/parse.d.ts +2 -2
- package/src/compiler/parse.js +139 -104
- package/src/compiler/parserHelpers.js +10 -2
- package/src/runtime/codeFragment.js +19 -0
- package/src/runtime/evaluate.js +21 -16
- package/src/runtime/expressionFunction.js +5 -6
- package/src/runtime/formatError.js +6 -6
- package/src/runtime/ops.js +9 -1
- package/test/compiler/parse.test.js +237 -112
- package/test/runtime/evaluate.test.js +20 -7
- package/test/runtime/ops.test.js +28 -10
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/language",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66-beta.1",
|
|
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.5.4"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/async-tree": "0.0.
|
|
15
|
-
"@weborigami/types": "0.0.
|
|
14
|
+
"@weborigami/async-tree": "0.0.66-beta.1",
|
|
15
|
+
"@weborigami/types": "0.0.66-beta.1",
|
|
16
16
|
"watcher": "2.3.1"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
@@ -20,7 +20,9 @@ import {
|
|
|
20
20
|
|
|
21
21
|
// A block of optional whitespace
|
|
22
22
|
__
|
|
23
|
-
= (inlineSpace / newLine / comment)* {
|
|
23
|
+
= (inlineSpace / newLine / comment)* {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
24
26
|
|
|
25
27
|
// A filesystem path that begins with a slash: `/foo/bar`
|
|
26
28
|
// We take care to avoid treating two consecutive leading slashes as a path;
|
|
@@ -98,7 +100,9 @@ digits
|
|
|
98
100
|
doubleArrow = "⇒" / "=>"
|
|
99
101
|
|
|
100
102
|
doubleQuoteString "double quote string"
|
|
101
|
-
= '"' chars:doubleQuoteStringChar* '"' {
|
|
103
|
+
= '"' chars:doubleQuoteStringChar* '"' {
|
|
104
|
+
return annotate([ops.primitive, chars.join("")], location());
|
|
105
|
+
}
|
|
102
106
|
|
|
103
107
|
doubleQuoteStringChar
|
|
104
108
|
= !('"' / newLine) @textChar
|
|
@@ -126,7 +130,7 @@ expression "Origami expression"
|
|
|
126
130
|
|
|
127
131
|
float "floating-point number"
|
|
128
132
|
= sign? digits? "." digits {
|
|
129
|
-
return parseFloat(text());
|
|
133
|
+
return annotate([ops.primitive, parseFloat(text())], location());
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
// Parse a function and its arguments, e.g. `fn(arg)`, possibly part of a chain
|
|
@@ -136,7 +140,7 @@ functionComposition "function composition"
|
|
|
136
140
|
if (end) {
|
|
137
141
|
chain.push(end);
|
|
138
142
|
}
|
|
139
|
-
return annotate(makeFunctionCall(target, chain), location());
|
|
143
|
+
return annotate(makeFunctionCall(target, chain, location()), location());
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
// An expression in parentheses: `(foo)`
|
|
@@ -146,7 +150,9 @@ group "parenthetical group"
|
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
guillemetString "guillemet string"
|
|
149
|
-
= '«' chars:guillemetStringChar* '»' {
|
|
153
|
+
= '«' chars:guillemetStringChar* '»' {
|
|
154
|
+
return annotate([ops.primitive, chars.join("")], location());
|
|
155
|
+
}
|
|
150
156
|
|
|
151
157
|
guillemetStringChar
|
|
152
158
|
= !('»' / newLine) @textChar
|
|
@@ -155,7 +161,9 @@ guillemetStringChar
|
|
|
155
161
|
// This is used as a special case at the head of a path, where we want to
|
|
156
162
|
// interpret a colon as part of a text identifier.
|
|
157
163
|
host "HTTP/HTTPS host"
|
|
158
|
-
= identifier (":" number)? {
|
|
164
|
+
= identifier (":" number)? {
|
|
165
|
+
return annotate([ops.primitive, text()], location());
|
|
166
|
+
}
|
|
159
167
|
|
|
160
168
|
identifier "identifier"
|
|
161
169
|
= chars:identifierChar+ { return chars.join(""); }
|
|
@@ -170,10 +178,6 @@ identifierList
|
|
|
170
178
|
return annotate(list, location());
|
|
171
179
|
}
|
|
172
180
|
|
|
173
|
-
identifierOrString
|
|
174
|
-
= identifier
|
|
175
|
-
/ string
|
|
176
|
-
|
|
177
181
|
implicitParensArgs "arguments with implicit parentheses"
|
|
178
182
|
// Implicit parens args are a separate list of `step`, not `expr`, because
|
|
179
183
|
// they can't contain a pipeline.
|
|
@@ -187,7 +191,7 @@ inlineSpace
|
|
|
187
191
|
|
|
188
192
|
integer "integer"
|
|
189
193
|
= sign? digits {
|
|
190
|
-
return parseInt(text());
|
|
194
|
+
return annotate([ops.primitive, parseInt(text())], location());
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
// A lambda expression: `=foo()`
|
|
@@ -240,7 +244,7 @@ objectEntry
|
|
|
240
244
|
= spread
|
|
241
245
|
/ objectProperty
|
|
242
246
|
/ objectGetter
|
|
243
|
-
/
|
|
247
|
+
/ objectShorthandProperty
|
|
244
248
|
|
|
245
249
|
// A getter definition inside an object literal: `foo = 1`
|
|
246
250
|
objectGetter "object getter"
|
|
@@ -248,15 +252,19 @@ objectGetter "object getter"
|
|
|
248
252
|
return annotate([key, [ops.getter, value]], location());
|
|
249
253
|
}
|
|
250
254
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
= key:identifierOrString {
|
|
254
|
-
return annotate([key, [ops.inherited, key]], location());
|
|
255
|
-
}
|
|
255
|
+
objectHiddenKey
|
|
256
|
+
= hiddenKey:("(" objectPublicKey ")") { return hiddenKey.join(""); }
|
|
256
257
|
|
|
257
258
|
objectKey "object key"
|
|
258
|
-
=
|
|
259
|
-
/
|
|
259
|
+
= objectHiddenKey
|
|
260
|
+
/ objectPublicKey
|
|
261
|
+
|
|
262
|
+
objectPublicKey
|
|
263
|
+
= identifier
|
|
264
|
+
/ string:string {
|
|
265
|
+
// Remove `ops.primitive` from the string code
|
|
266
|
+
return string[1];
|
|
267
|
+
}
|
|
260
268
|
|
|
261
269
|
// A property definition in an object literal: `x: 1`
|
|
262
270
|
objectProperty "object property"
|
|
@@ -264,6 +272,12 @@ objectProperty "object property"
|
|
|
264
272
|
return annotate([key, value], location());
|
|
265
273
|
}
|
|
266
274
|
|
|
275
|
+
// A shorthand reference inside an object literal: `foo`
|
|
276
|
+
objectShorthandProperty "object identifier"
|
|
277
|
+
= key:objectPublicKey {
|
|
278
|
+
return annotate([key, [ops.inherited, key]], location());
|
|
279
|
+
}
|
|
280
|
+
|
|
267
281
|
parameterizedLambda
|
|
268
282
|
= "(" __ parameters:identifierList? __ ")" __ doubleArrow __ expr:expr {
|
|
269
283
|
return annotate([ops.lambda, parameters ?? [], expr], location());
|
|
@@ -288,7 +302,9 @@ path "slash-separated path"
|
|
|
288
302
|
|
|
289
303
|
// A single key in a slash-separated path
|
|
290
304
|
pathKey "path element"
|
|
291
|
-
= chars:pathKeyChar* {
|
|
305
|
+
= chars:pathKeyChar* {
|
|
306
|
+
return annotate([ops.primitive, chars.join("")], location());
|
|
307
|
+
}
|
|
292
308
|
|
|
293
309
|
// A single character in a slash-separated path.
|
|
294
310
|
pathKeyChar
|
|
@@ -338,7 +354,9 @@ singleLineComment
|
|
|
338
354
|
= "//" [^\n\r]* { return null; }
|
|
339
355
|
|
|
340
356
|
singleQuoteString "single quote string"
|
|
341
|
-
= "'" chars:singleQuoteStringChar* "'" {
|
|
357
|
+
= "'" chars:singleQuoteStringChar* "'" {
|
|
358
|
+
return annotate([ops.primitive, chars.join("")], location());
|
|
359
|
+
}
|
|
342
360
|
|
|
343
361
|
singleQuoteStringChar
|
|
344
362
|
= !("'" / newLine) @textChar
|
|
@@ -396,7 +414,9 @@ templateDocumentContents
|
|
|
396
414
|
}
|
|
397
415
|
|
|
398
416
|
templateDocumentText "template text"
|
|
399
|
-
= chars:templateDocumentChar+ {
|
|
417
|
+
= chars:templateDocumentChar+ {
|
|
418
|
+
return annotate([ops.primitive, chars.join("")], location());
|
|
419
|
+
}
|
|
400
420
|
|
|
401
421
|
// A backtick-quoted template literal
|
|
402
422
|
templateLiteral "template literal"
|
|
@@ -415,7 +435,9 @@ templateLiteralContents
|
|
|
415
435
|
|
|
416
436
|
// Plain text in a template literal
|
|
417
437
|
templateLiteralText
|
|
418
|
-
= chars:templateLiteralChar+ {
|
|
438
|
+
= chars:templateLiteralChar+ {
|
|
439
|
+
return annotate([ops.primitive, chars.join("")], location());
|
|
440
|
+
}
|
|
419
441
|
|
|
420
442
|
// A substitution in a template literal: `${x}`
|
|
421
443
|
templateSubstitution "template substitution"
|
package/src/compiler/parse.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Code } from "../../index.ts";
|
|
2
2
|
|
|
3
|
-
export function parse(input: string, options: any):
|
|
3
|
+
export function parse(input: string, options: any): Code;
|