@weborigami/language 0.0.40 → 0.0.41
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 +21 -8
- package/src/compiler/parse.js +322 -189
- package/src/compiler/parserHelpers.js +5 -1
- package/src/runtime/evaluate.js +20 -14
- package/src/runtime/expressionFunction.js +1 -0
- package/src/runtime/format.js +2 -1
- package/src/runtime/ops.js +42 -9
- package/test/compiler/parse.test.js +53 -20
- package/test/runtime/evaluate.test.js +8 -0
- package/test/runtime/format.test.js +1 -1
- package/test/runtime/ops.test.js +17 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/language",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
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": "0.0.
|
|
14
|
-
"@weborigami/types": "0.0.
|
|
13
|
+
"@weborigami/async-tree": "0.0.41",
|
|
14
|
+
"@weborigami/types": "0.0.41",
|
|
15
15
|
"peggy": "3.0.2",
|
|
16
16
|
"watcher": "2.3.0"
|
|
17
17
|
},
|
|
@@ -18,9 +18,9 @@ __
|
|
|
18
18
|
absoluteFilePath "absolute file path"
|
|
19
19
|
= path:leadingSlashPath { return [[ops.filesRoot], ...path]; }
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
args "function arguments"
|
|
22
|
+
= parensArgs
|
|
23
|
+
/ path:leadingSlashPath { return [ops.traverse, ...path]; }
|
|
24
24
|
|
|
25
25
|
// An assignment statement: `foo = 1`
|
|
26
26
|
assignment "tree assignment"
|
|
@@ -41,6 +41,7 @@ callTarget "function call"
|
|
|
41
41
|
/ object
|
|
42
42
|
/ tree
|
|
43
43
|
/ lambda
|
|
44
|
+
/ parameterizedLambda
|
|
44
45
|
/ protocolCall
|
|
45
46
|
/ group
|
|
46
47
|
/ scopeReference
|
|
@@ -73,8 +74,9 @@ expr "expression"
|
|
|
73
74
|
/ array
|
|
74
75
|
/ object
|
|
75
76
|
/ tree
|
|
76
|
-
/ lambda
|
|
77
77
|
/ templateLiteral
|
|
78
|
+
/ lambda
|
|
79
|
+
/ parameterizedLambda
|
|
78
80
|
/ group
|
|
79
81
|
/ string
|
|
80
82
|
/ number
|
|
@@ -95,7 +97,8 @@ float "floating-point number"
|
|
|
95
97
|
// Parse a function and its arguments, e.g. `fn(arg)`, possibly part of a chain
|
|
96
98
|
// of function calls, like `fn(arg1)(arg2)(arg3)`.
|
|
97
99
|
functionComposition "function composition"
|
|
98
|
-
= target:callTarget chain:argsChain { return makeFunctionCall(target, chain); }
|
|
100
|
+
// = target:callTarget chain:argsChain { return makeFunctionCall(target, chain); }
|
|
101
|
+
= target:callTarget chain:args+ { return makeFunctionCall(target, chain); }
|
|
99
102
|
|
|
100
103
|
// An expression in parentheses: `(foo)`
|
|
101
104
|
group "parenthetical group"
|
|
@@ -105,9 +108,14 @@ identifier "identifier"
|
|
|
105
108
|
= chars:identifierChar+ { return chars.join(""); }
|
|
106
109
|
|
|
107
110
|
identifierChar
|
|
108
|
-
= [^(){}\[\]
|
|
111
|
+
= [^(){}\[\]<>,/:=\`"'\\# \t\n\r] // No unescaped whitespace or special chars
|
|
109
112
|
/ escapedChar
|
|
110
113
|
|
|
114
|
+
identifierList
|
|
115
|
+
= head:identifier tail:(separator @identifier)* separator? {
|
|
116
|
+
return [head].concat(tail);
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
// A function call with implicit parentheses: `fn 1, 2, 3`
|
|
112
120
|
implicitParensCall "function call with implicit parentheses"
|
|
113
121
|
= target:(functionComposition / callTarget) inlineSpace+ args:list {
|
|
@@ -130,7 +138,7 @@ integer "integer"
|
|
|
130
138
|
|
|
131
139
|
// A lambda expression: `=foo()`
|
|
132
140
|
lambda "lambda function"
|
|
133
|
-
= "=" __ expr:expr { return [ops.lambda, expr]; }
|
|
141
|
+
= "=" __ expr:expr { return [ops.lambda, null, expr]; }
|
|
134
142
|
|
|
135
143
|
// A path that begins with a slash: `/foo/bar`
|
|
136
144
|
leadingSlashPath "path with a leading slash"
|
|
@@ -172,6 +180,11 @@ objectPropertyOrShorthand
|
|
|
172
180
|
= objectProperty
|
|
173
181
|
/ key:identifier { return [key, [ops.scope, key]]; }
|
|
174
182
|
|
|
183
|
+
parameterizedLambda
|
|
184
|
+
= "(" __ parameters:identifierList? ")" __ ("=>"/"⇒") __ expr:expr {
|
|
185
|
+
return [ops.lambda, parameters ?? [], expr];
|
|
186
|
+
}
|
|
187
|
+
|
|
175
188
|
// Function arguments in parentheses
|
|
176
189
|
parensArgs "function arguments in parentheses"
|
|
177
190
|
= "(" __ list:list? ")" { return list ?? [undefined]; }
|
|
@@ -230,7 +243,7 @@ string "string"
|
|
|
230
243
|
// A top-level document defining a template. This is the same as a template
|
|
231
244
|
// literal, but can contain backticks at the top level.
|
|
232
245
|
templateDocument "template"
|
|
233
|
-
= contents:templateDocumentContents { return [ops.lambda, contents]; }
|
|
246
|
+
= contents:templateDocumentContents { return [ops.lambda, null, contents]; }
|
|
234
247
|
|
|
235
248
|
// Template documents can contain backticks at the top level.
|
|
236
249
|
templateDocumentChar
|