@weborigami/language 0.3.0 → 0.3.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/package.json +3 -3
- package/src/compiler/origami.pegjs +37 -10
- package/src/compiler/parse.js +488 -292
- package/src/compiler/parserHelpers.js +9 -0
- package/src/runtime/ops.js +2 -2
- package/test/compiler/parse.test.js +38 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/language",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.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.8.2"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/async-tree": "0.3.
|
|
15
|
-
"@weborigami/types": "0.3.
|
|
14
|
+
"@weborigami/async-tree": "0.3.1",
|
|
15
|
+
"@weborigami/types": "0.3.1",
|
|
16
16
|
"watcher": "2.3.1",
|
|
17
17
|
"yaml": "2.7.0"
|
|
18
18
|
},
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
makeBinaryOperation,
|
|
21
21
|
makeCall,
|
|
22
22
|
makeDeferredArguments,
|
|
23
|
+
makeJsPropertyAccess,
|
|
23
24
|
makeObject,
|
|
24
25
|
makePipeline,
|
|
25
26
|
makeProperty,
|
|
@@ -50,6 +51,8 @@ additiveOperator
|
|
|
50
51
|
arguments "function arguments"
|
|
51
52
|
= parenthesesArguments
|
|
52
53
|
/ pathArguments
|
|
54
|
+
/ jsPropertyAccess
|
|
55
|
+
/ computedPropertyAccess
|
|
53
56
|
/ templateLiteral
|
|
54
57
|
|
|
55
58
|
arrayLiteral "array"
|
|
@@ -126,6 +129,11 @@ comment "comment"
|
|
|
126
129
|
= multiLineComment
|
|
127
130
|
/ singleLineComment
|
|
128
131
|
|
|
132
|
+
computedPropertyAccess
|
|
133
|
+
= __ "[" expression:expression expectClosingBracket {
|
|
134
|
+
return annotate([ops.traverse, expression], location());
|
|
135
|
+
}
|
|
136
|
+
|
|
129
137
|
conditionalExpression
|
|
130
138
|
= condition:logicalOrExpression tail:(__
|
|
131
139
|
"?" __ @shorthandFunction __
|
|
@@ -278,8 +286,8 @@ frontMatterYaml "YAML front matter"
|
|
|
278
286
|
// An expression in parentheses: `(foo)`
|
|
279
287
|
group "parenthetical group"
|
|
280
288
|
= "(" expression:expression expectClosingParenthesis {
|
|
281
|
-
|
|
282
|
-
|
|
289
|
+
return annotate(downgradeReference(expression), location());
|
|
290
|
+
}
|
|
283
291
|
|
|
284
292
|
guillemetString "guillemet string"
|
|
285
293
|
= '«' chars:guillemetStringChar* expectGuillemet {
|
|
@@ -326,6 +334,13 @@ implicitParensthesesArguments
|
|
|
326
334
|
return annotate(values, location());
|
|
327
335
|
}
|
|
328
336
|
|
|
337
|
+
inherited
|
|
338
|
+
= rootDirectory
|
|
339
|
+
/ homeDirectory
|
|
340
|
+
/ qualifiedReference
|
|
341
|
+
/ namespace
|
|
342
|
+
/ scopeReference
|
|
343
|
+
|
|
329
344
|
inlineSpace
|
|
330
345
|
= [ \t]
|
|
331
346
|
|
|
@@ -333,7 +348,26 @@ integerLiteral "integer"
|
|
|
333
348
|
= digits {
|
|
334
349
|
return annotate([ops.literal, parseInt(text())], location());
|
|
335
350
|
}
|
|
336
|
-
|
|
351
|
+
|
|
352
|
+
jsIdentifier
|
|
353
|
+
= $( jsIdentifierStart jsIdentifierPart* )
|
|
354
|
+
|
|
355
|
+
// Continuation of a JavaScript identifier
|
|
356
|
+
// https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#prod-IdentifierPart
|
|
357
|
+
jsIdentifierPart "JavaScript identifier continuation"
|
|
358
|
+
= char:. &{ return char.match(/[$_\p{ID_Continue}]/u) }
|
|
359
|
+
|
|
360
|
+
// Start of a JavaScript identifier
|
|
361
|
+
// https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#prod-IdentifierStart
|
|
362
|
+
jsIdentifierStart "JavaScript identifier start"
|
|
363
|
+
= char:. &{ return char.match(/[$_\p{ID_Start}]/u) }
|
|
364
|
+
|
|
365
|
+
jsPropertyAccess
|
|
366
|
+
= __ "." __ property:jsIdentifier {
|
|
367
|
+
const literal = annotate([ops.literal, property], location());
|
|
368
|
+
return annotate([ops.traverse, literal], location());
|
|
369
|
+
}
|
|
370
|
+
|
|
337
371
|
// A separated list of values
|
|
338
372
|
list "list"
|
|
339
373
|
= values:pipelineExpression|1.., separator| separator? {
|
|
@@ -554,13 +588,6 @@ qualifiedReference
|
|
|
554
588
|
return makeCall(fn, [literal]);
|
|
555
589
|
}
|
|
556
590
|
|
|
557
|
-
inherited
|
|
558
|
-
= rootDirectory
|
|
559
|
-
/ homeDirectory
|
|
560
|
-
/ qualifiedReference
|
|
561
|
-
/ namespace
|
|
562
|
-
/ scopeReference
|
|
563
|
-
|
|
564
591
|
relationalExpression
|
|
565
592
|
= head:shiftExpression tail:(__ @relationalOperator __ @shiftExpression)* {
|
|
566
593
|
return tail.reduce(makeBinaryOperation, head);
|