6
6
## Example of JSON DSL
7
7
8
8
``` json
9
- [" label" ,
9
+ [" $ label" ,
10
10
1 ,
11
11
" installing plugins:" ,
12
- [" vimdir/with-install" ,
13
- [" parallel" ,
14
- [" label" ,
12
+ [" $ vimdir/with-install" ,
13
+ [" $ parallel" ,
14
+ [" $ label" ,
15
15
2 ,
16
16
" github.com/tyru/open-browser.vim ... {{if .Done}}done!{{end}}" ,
17
- [" parallel" ,
17
+ [" $ parallel" ,
18
18
[" lockjson/add" ,
19
19
[" repos/get" , " github.com/tyru/open-browser.vim" ],
20
20
[" $array" , " default" ]],
21
21
[" plugconf/install" , " github.com/tyru/open-browser.vim" ]]],
22
- [" label" ,
22
+ [" $ label" ,
23
23
3 ,
24
24
" github.com/tyru/open-browser-github.vim ... {{if .Done}}done!{{end}}" ,
25
- [" parallel" ,
25
+ [" $ parallel" ,
26
26
[" lockjson/add" ,
27
27
[" repos/get" , " github.com/tyru/open-browser-github.vim" ],
28
28
[" $array" , " default" ]],
29
- [" plugconf/install" , " github.com/tyru/open-browser-github.vim" ]]]]]]
29
+ [" plugconf/install" ,
30
+ " github.com/tyru/open-browser-github.vim" ]]]]]]
30
31
```
31
32
32
33
## Wordings
@@ -107,7 +108,7 @@ An array literal value is written using `$array` operator.
107
108
This expression is evaluated to ` [1, 2, 3] ` .
108
109
109
110
Each expression has 0 or more parameters. And evaluation
110
- strategy is a non-strict evaluation.
111
+ strategy is an eager evaluation.
111
112
112
113
Parameter types are
113
114
@@ -117,7 +118,8 @@ Parameter types are
117
118
* number
118
119
* array
119
120
* object
120
- * expression
121
+ * lambda
122
+ * expression (only macro can treat this)
121
123
122
124
But all values must be able to be serialized to JSON. Because AST of whole
123
125
process is serialized and saved as a "transaction log file". The process can be
@@ -169,14 +171,29 @@ different with latest volt's JSON DSL when installing. this is a simplified
169
171
version for easiness).
170
172
171
173
``` json
172
- [" vimdir/with-install" ,
173
- [" do" ,
174
+ [" $ vimdir/with-install" ,
175
+ [" $ do" ,
174
176
[" lockjson/add" ,
175
177
[" repos/get" , " github.com/tyru/caw.vim" ],
176
178
[" $array" , " default" ]],
177
179
[" plugconf/install" , " github.com/tyru/caw.vim" ]]]
178
180
```
179
181
182
+ At first, expands all macros (` ["$array", "default"] ` cannot be written in JSON
183
+ notation, it is expanded to array but array literal is ` ["$array", "default"] ` ).
184
+
185
+ ``` json
186
+ [" vimdir/with-install" ,
187
+ [" fn" , [],
188
+ [" do" ,
189
+ [" fn" , [],
190
+ [" lockjson/add" ,
191
+ [" repos/get" , " github.com/tyru/caw.vim" ],
192
+ [" $array" , " default" ]]],
193
+ [" fn" , [],
194
+ [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]]
195
+ ```
196
+
180
197
I show you what happens in several steps when you "invert" the expression like
181
198
` volt history undo ` .
182
199
@@ -185,41 +202,65 @@ At first, to invert the expression, `$invert` macro is used:
185
202
``` json
186
203
[" $invert" ,
187
204
[" vimdir/with-install" ,
188
- [" do" ,
189
- [" lockjson/add" ,
190
- [" repos/get" , " github.com/tyru/caw.vim" ],
191
- [" $array" , " default" ]],
192
- [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]
205
+ [" fn" , [],
206
+ [" do" ,
207
+ [" fn" , [],
208
+ [" lockjson/add" ,
209
+ [" repos/get" , " github.com/tyru/caw.vim" ],
210
+ [" $array" , " default" ]]],
211
+ [" fn" , [],
212
+ [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]]]
193
213
```
194
214
195
- ` ["$invert", ["vimdir/with-install", expr]] ` is expanded to
196
- ` ["vimdir/with-install", ["$invert", expr]] ` . Internally, it is implemented as
197
- calling ` Invert() ` method of ` vimdir/with-install ` operator struct. See "Go
198
- API" section.
215
+ ` ["$invert", ["vimdir/with-install", thunk]] ` is expanded to
216
+ ` ["vimdir/with-install", ["$invert", thunk]] ` . Internally, it is implemented as
217
+ calling ` InvertExpr() ` method of ` vimdir/with-install ` operator struct.
199
218
200
219
``` json
201
220
[" vimdir/with-install" ,
202
221
[" $invert" ,
203
- [" do" ,
204
- [" lockjson/add" ,
205
- [" repos/get" , " github.com/tyru/caw.vim" ],
206
- [" $array" , " default" ]],
207
- [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]
222
+ [" fn" , [],
223
+ [" do" ,
224
+ [" fn" , [],
225
+ [" lockjson/add" ,
226
+ [" repos/get" , " github.com/tyru/caw.vim" ],
227
+ [" $array" , " default" ]]],
228
+ [" fn" , [],
229
+ [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]]]
208
230
```
209
231
210
- And ` ["$invert", ["do", expr1, expr2]] ` becomes
211
- ` ["do", ["$invert", expr2], ["$invert", expr1]] ` .
212
- Note that ` expr1 ` and ` expr2 ` becomes reversed order.
232
+ And ` ["$invert", ["fn", args, body]] ` becomes
233
+ ` ["fn", args, ["$invert", body]] ` .
213
234
214
235
``` json
215
236
[" vimdir/with-install" ,
216
- [" do" ,
217
- [" $invert" ,
218
- [" plugconf/install" , " github.com/tyru/caw.vim" ]],
237
+ [" fn" , [],
219
238
[" $invert" ,
220
- [" lockjson/add" ,
221
- [" repos/get" , " github.com/tyru/caw.vim" ],
222
- [" $array" , " default" ]]]]]
239
+ [" do" ,
240
+ [" fn" , [],
241
+ [" lockjson/add" ,
242
+ [" repos/get" , " github.com/tyru/caw.vim" ],
243
+ [" $array" , " default" ]]],
244
+ [" fn" , [],
245
+ [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]]]
246
+ ```
247
+
248
+ And ` ["$invert", ["do", thunk1, thunk2]] ` becomes
249
+ ` ["do", ["$invert", thunk2], ["$invert", thunk1]] ` .
250
+ Note that ` thunk1 ` and ` thunk2 ` become reversed order.
251
+
252
+ ``` json
253
+ [" vimdir/with-install" ,
254
+ [" fn" , [],
255
+ [" do" ,
256
+ [" fn" , [],
257
+ [" $invert" ,
258
+ [" lockjson/add" ,
259
+ [" repos/get" , " github.com/tyru/caw.vim" ],
260
+ [" $array" , " default" ]]]],
261
+ [" fn" , [],
262
+ [" $invert" ,
263
+ [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]]]
223
264
```
224
265
225
266
And
@@ -230,38 +271,47 @@ And
230
271
231
272
``` json
232
273
[" vimdir/with-install" ,
233
- [" do" ,
234
- [" plugconf/delete" , [" $invert" , " github.com/tyru/caw.vim" ]],
235
- [" lockjson/remove" ,
236
- [" $invert" , [" repos/get" , " github.com/tyru/caw.vim" ]],
237
- [" $invert" , [" $array" , " default" ]]]]]
274
+ [" fn" , [],
275
+ [" do" ,
276
+ [" fn" , [],
277
+ [" lockjson/add" ,
278
+ [" $invert" , [" repos/get" , " github.com/tyru/caw.vim" ]],
279
+ [" $invert" , [" $array" , " default" ]]]],
280
+ [" fn" , [],
281
+ [" plugconf/install" , [" $invert" , " github.com/tyru/caw.vim" ]]]]]]
238
282
```
239
283
240
284
` ["$invert", ["repos/get", path]] ` becomes
241
285
` ["repos/delete", ["$invert", path]] ` .
242
286
243
287
``` json
244
288
[" vimdir/with-install" ,
245
- [" do" ,
246
- [" plugconf/delete" , [" $invert" , " github.com/tyru/caw.vim" ]],
247
- [" lockjson/remove" ,
248
- [" repos/delete" , [" $invert" , " github.com/tyru/caw.vim" ]],
249
- [" $invert" , [" $array" , " default" ]]]]]
289
+ [" fn" , [],
290
+ [" do" ,
291
+ [" fn" , [],
292
+ [" lockjson/add" ,
293
+ [" repos/delete" , [" $invert" , " github.com/tyru/caw.vim" ]],
294
+ [" $invert" , [" $array" , " default" ]]]],
295
+ [" fn" , [],
296
+ [" plugconf/install" , [" $invert" , " github.com/tyru/caw.vim" ]]]]]]
250
297
```
251
298
252
299
And if ` $invert ` is applied to literals like string, JSON array, it just remains
253
300
as-is.
254
301
255
302
``` json
256
303
[" vimdir/with-install" ,
257
- [" do" ,
258
- [" plugconf/delete" , " github.com/tyru/caw.vim" ],
259
- [" lockjson/remove" ,
260
- [" repos/delete" , " github.com/tyru/caw.vim" ],
261
- [" $array" , " default" ]]]]
304
+ [" fn" , [],
305
+ [" do" ,
306
+ [" fn" , [],
307
+ [" lockjson/add" ,
308
+ [" repos/delete" , " github.com/tyru/caw.vim" ],
309
+ [" $array" , " default" ]]],
310
+ [" fn" , [],
311
+ [" plugconf/install" , " github.com/tyru/caw.vim" ]]]]]
262
312
```
263
313
264
- We can successfully evaluate the inverse expression of the first expression :)
314
+ We can successfully evaluate the inverse expression of the first expression! :)
265
315
266
316
### Uninstall operation should be "Recovable"?
267
317
@@ -317,7 +367,7 @@ As the above signature shows, operators must take care the following points:
317
367
318
368
TODO: Move to Godoc.
319
369
320
- ### Macro
370
+ ### Basic macros
321
371
322
372
All macros has `$` prefixed name for readability.
323
373
Macros are not saved in transaction log (expanded before saving).
@@ -342,27 +392,39 @@ Macros are not saved in transaction log (expanded before saving).
342
392
343
393
### Basic operators
344
394
345
- * `["label", linenum: number, tmpl string, expr Expr[* => R]] R`
395
+ * `["$label", linenum: number, tmpl string, expr Expr[* => R]] R`
396
+ * `["$label", linenum, tmpl, expr]` expands to
397
+ `["label", linenum, tmpl, ["fn", [] expr]]`
398
+
399
+ * `["label", linenum: number, tmpl string, thunk Func[* => R]] R`
346
400
* Render `tmpl` by text/template to `linenum` line (1-origin).
347
- Returns the evaluated value of `expr `.
401
+ Returns the evaluated value of `thunk `.
348
402
* e.g.
349
- * `["$invert", ["label", linenum, "msg", expr ]]` = `["label", ["$invert", linenum], "revert: \"msg\"", ["$invert", expr ]]`
403
+ * `["$invert", ["label", linenum, "msg", thunk ]]` = `["label", ["$invert", linenum], "revert: \"msg\"", ["$invert", thunk ]]`
350
404
* See `Label examples` section for more details
351
405
352
- * `["do", expr1 R1, ..., expr_last R2] R2`
353
- * Executes multiple expressions in series.
354
- * Returns the evaluated value of the last expression.
406
+ * `["$do", expr1 Expr[* => R1], ..., expr_last Expr[* => R2]] R2`
407
+ * `["$do", expr1, expr2]` expands to
408
+ `["do", ["fn", [], expr1], ["fn", [], expr2]]`
409
+
410
+ * `["do", thunk1 R1, ..., thunk_last R2] R2`
411
+ * Executes multiple lambdas in series.
412
+ * Returns the evaluated value of the last lambda.
355
413
* e.g.
356
- * `["$invert", ["do", expr1, expr2 ]]` = `["do", ["$invert", expr1 ], ["$invert", expr2 ]]`
414
+ * `["$invert", ["do", thunk1, thunk2 ]]` = `["do", ["$invert", thunk1 ], ["$invert", thunk2 ]]`
357
415
* Note that the arguments are reversed.
358
416
359
- * `["parallel", msg string, expr1 R1, ..., expr_last R2] R2`
360
- * Executes multiple expressions in parallel.
361
- * Returns the evaluated value of the last expression.
417
+ * `["$parallel", expr1 Expr[* => R1], ..., expr_last Expr[* => R2]] R2`
418
+ * `["$parallel", expr1, expr2]` expands to
419
+ `["parallel", ["fn", [], expr1], ["fn", [], expr2]]`
420
+
421
+ * `["parallel", thunk1 Func[* => R1], ..., thunk_last Func[* => R2]] R2`
422
+ * Executes multiple lambdas in parallel.
423
+ * Returns the evaluated value of the last lambda.
362
424
* e.g.
363
- * `["$invert", ["parallel", expr1, expr2 ]]` = `["parallel", ["$invert", expr2 ], ["$invert", expr1 ]]`
425
+ * `["$invert", ["parallel", thunk1, thunk2 ]]` = `["parallel", ["$invert", thunk2 ], ["$invert", thunk1 ]]`
364
426
* The arguments are **not** reversed because parallel does not care of
365
- execution order of given expressions .
427
+ execution order of given value .
366
428
367
429
### Repository operators
368
430
0 commit comments