Skip to content

Commit 26eef3b

Browse files
committed
fix: rename "@" macro to "$array"
1 parent 39e432b commit 26eef3b

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

_docs/json-dsl.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
["parallel",
1818
["lockjson/add",
1919
["repos/get", "github.com/tyru/open-browser.vim"],
20-
["@", "default"]],
20+
["$array", "default"]],
2121
["plugconf/install", "github.com/tyru/open-browser.vim"]]],
2222
["label",
2323
3,
2424
" github.com/tyru/open-browser-github.vim ... {{if .Done}}done!{{end}}",
2525
["parallel",
2626
["lockjson/add",
2727
["repos/get", "github.com/tyru/open-browser-github.vim"],
28-
["@", "default"]],
28+
["$array", "default"]],
2929
["plugconf/install", "github.com/tyru/open-browser-github.vim"]]]]]]
3030
```
3131

@@ -36,7 +36,7 @@
3636
* e.g. "label"
3737
* e.g. "parallel"
3838
* macro: like function, but is expanded before execution
39-
* e.g. "@"
39+
* e.g. "$array"
4040
* expression: the form of operator application
4141
* e.g. `["label", ...]`
4242
* e.g. `["parallel", ...]`
@@ -98,10 +98,10 @@ JSON DSL is a S-expression like DSL represented as JSON format.
9898
```
9999

100100
This is an application form (called "expression" in this note).
101-
An array literal value is written using `@` operator.
101+
An array literal value is written using `$array` operator.
102102

103103
```json
104-
["@", 1, 2, 3]
104+
["$array", 1, 2, 3]
105105
```
106106

107107
This expression is evaluated to `[1, 2, 3]`.
@@ -173,7 +173,7 @@ version for easiness).
173173
["do",
174174
["lockjson/add",
175175
["repos/get", "github.com/tyru/caw.vim"],
176-
["@", "default"]],
176+
["$array", "default"]],
177177
["plugconf/install", "github.com/tyru/caw.vim"]]]
178178
```
179179

@@ -188,7 +188,7 @@ At first, to invert the expression, `$invert` macro is used:
188188
["do",
189189
["lockjson/add",
190190
["repos/get", "github.com/tyru/caw.vim"],
191-
["@", "default"]],
191+
["$array", "default"]],
192192
["plugconf/install", "github.com/tyru/caw.vim"]]]]
193193
```
194194

@@ -203,7 +203,7 @@ API" section.
203203
["do",
204204
["lockjson/add",
205205
["repos/get", "github.com/tyru/caw.vim"],
206-
["@", "default"]],
206+
["$array", "default"]],
207207
["plugconf/install", "github.com/tyru/caw.vim"]]]]
208208
```
209209

@@ -219,7 +219,7 @@ Note that `expr1` and `expr2` becomes reversed order.
219219
["$invert",
220220
["lockjson/add",
221221
["repos/get", "github.com/tyru/caw.vim"],
222-
["@", "default"]]]]]
222+
["$array", "default"]]]]]
223223
```
224224

225225
And
@@ -234,7 +234,7 @@ And
234234
["plugconf/delete", ["$invert", "github.com/tyru/caw.vim"]],
235235
["lockjson/remove",
236236
["$invert", ["repos/get", "github.com/tyru/caw.vim"]],
237-
["$invert", ["@", "default"]]]]]
237+
["$invert", ["$array", "default"]]]]]
238238
```
239239

240240
`["$invert", ["repos/get", path]]` becomes
@@ -246,7 +246,7 @@ And
246246
["plugconf/delete", ["$invert", "github.com/tyru/caw.vim"]],
247247
["lockjson/remove",
248248
["repos/delete", ["$invert", "github.com/tyru/caw.vim"]],
249-
["$invert", ["@", "default"]]]]]
249+
["$invert", ["$array", "default"]]]]]
250250
```
251251

252252
And if `$invert` is applied to literals like string, JSON array, it just remains
@@ -258,7 +258,7 @@ as-is.
258258
["plugconf/delete", "github.com/tyru/caw.vim"],
259259
["lockjson/remove",
260260
["repos/delete", "github.com/tyru/caw.vim"],
261-
["@", "default"]]]]
261+
["$array", "default"]]]]
262262
```
263263

264264
We can successfully evaluate the inverse expression of the first expression :)
@@ -322,7 +322,7 @@ TODO: Move to Godoc.
322322
All macros has `$` prefixed name for readability.
323323
Macros are not saved in transaction log (expanded before saving).
324324

325-
* `["@", v1 Value, ...] Array`
325+
* `["$array", v1 Value, ...] Array`
326326
* Returns inverse expression of given expression.
327327
* Internally, this macro calls `InvertExpr()` method of each operator struct.
328328
* What value is returned depends on each operator's `InvertExpr()`
@@ -334,7 +334,7 @@ Macros are not saved in transaction log (expanded before saving).
334334
* What value is returned depends on each operator's `InvertExpr()`
335335
implementation.
336336

337-
* `["$eval", expr Expr[* => *]] Expr[* => *]`
337+
* `["$expand-macro", expr Value] Value`
338338
* Evaluate `expr` at parsing time.
339339
This is useful to save evaluated value to transaction log,
340340
instead of its expression.
@@ -416,9 +416,9 @@ Macros are not saved in transaction log (expanded before saving).
416416
{target_hash}`
417417
* It does nothing for bare git repository.
418418
* e.g.
419-
* `["repos/git/update", "github.com/tyru/caw.vim", ["$eval", ["repos/git/rev-parse", "HEAD", "github.com/tyru/caw.vim"]], ["$eval", ["repos/git/fetch", "github.com/tyru/caw.vim"]]]`
419+
* `["repos/git/update", "github.com/tyru/caw.vim", ["$expand-macro", ["repos/git/rev-parse", "HEAD", "github.com/tyru/caw.vim"]], ["$expand-macro", ["repos/git/fetch", "github.com/tyru/caw.vim"]]]`
420420
* To save evaluated hash string in transaction log instead of its
421-
expression, apply `$eval` to `repos/git/fetch` expression.
421+
expression, apply `$expand-macro` to `repos/git/fetch` expression.
422422
* `["$invert", ["repos/git/update", path, target_hash, prev_hash]]` = `["repos/git/update", ["$invert", path], ["$invert", prev_hash], ["$invert", target_hash]]`
423423
424424
* `["repos/git/rev-parse", str string, path ReposPath] hash string`
@@ -437,7 +437,7 @@ Macros are not saved in transaction log (expanded before saving).
437437
* It fails if specified profile name does not exist.
438438
* Need to create profile before using `lockjson/profile/add`.
439439
* e.g.
440-
* `["lockjson/add", ["repos/get", "github.com/tyru/caw.vim"], ["@", "default"]]`
440+
* `["lockjson/add", ["repos/get", "github.com/tyru/caw.vim"], ["$array", "default"]]`
441441
* `["$invert", ["lockjson/add", repos, profiles]]` = `["lockjson/remove", ["$invert", repos], ["$invert", profiles]]`
442442
443443
* `["lockjson/profile/add", name string] Profile`
@@ -500,7 +500,7 @@ directory:
500500
"path": "github.com/tyru/caw.vim",
501501
"version": "deadbeefcafebabe"
502502
},
503-
["@", "default"]
503+
["$array", "default"]
504504
],
505505
["repos/delete", "github.com/tyru/caw.vim"],
506506
["plugconf/delete", "github.com/tyru/caw.vim"],
@@ -522,7 +522,7 @@ And below is the inverse expression of above.
522522
"path": "github.com/tyru/caw.vim",
523523
"version": "deadbeefcafebabe"
524524
},
525-
["@", "default"]
525+
["$array", "default"]
526526
]
527527
]
528528
```
@@ -550,7 +550,7 @@ This is what we expected.
550550
"path": "github.com/tyru/caw.vim",
551551
"version": "deadbeefcafebabe"
552552
},
553-
["@", "default"]
553+
["$array", "default"]
554554
],
555555
["repos/delete", "github.com/tyru/caw.vim"],
556556
["plugconf/delete", "github.com/tyru/caw.vim"]]]
@@ -570,7 +570,7 @@ The inverse expression of the above is:
570570
"path": "github.com/tyru/caw.vim",
571571
"version": "deadbeefcafebabe"
572572
},
573-
["@", "default"]]]]
573+
["$array", "default"]]]]
574574
```
575575

576576
1. Installs plugconf
@@ -595,7 +595,7 @@ But, of course if we placed `vimdir/with-install` at before `repos/delete` or
595595
"path": "github.com/tyru/caw.vim",
596596
"version": "deadbeefcafebabe"
597597
},
598-
["@", "default"]
598+
["$array", "default"]
599599
],
600600
["repos/delete", "github.com/tyru/caw.vim"],
601601
["plugconf/delete", "github.com/tyru/caw.vim"]]
@@ -611,7 +611,7 @@ But, of course if we placed `vimdir/with-install` at before `repos/delete` or
611611
"path": "github.com/tyru/caw.vim",
612612
"version": "deadbeefcafebabe"
613613
},
614-
["@", "default"]],
614+
["$array", "default"]],
615615
["vimdir/with-install",
616616
["github.com/tyru/caw.vim"],
617617
"dummy"]]
@@ -630,7 +630,7 @@ Here is the simple JSON to install
630630
["do",
631631
["lockjson/add",
632632
["repos/get", "github.com/tyru/caw.vim"],
633-
["@", "default"]],
633+
["$array", "default"]],
634634
["plugconf/install", "github.com/tyru/caw.vim"]]]
635635
```
636636

@@ -642,7 +642,7 @@ Here is the inverse expression of above.
642642
["plugconf/delete", "github.com/tyru/caw.vim"],
643643
["lockjson/remove",
644644
["repos/delete", "github.com/tyru/caw.vim"],
645-
["@", "default"]]]]
645+
["$array", "default"]]]]
646646
```
647647

648648
Here is the JSON to install plugins from local directory (static repository).
@@ -651,7 +651,7 @@ Here is the JSON to install plugins from local directory (static repository).
651651
["vimdir/with-install",
652652
["lockjson/add",
653653
{ ... (repository information of local directory) ... },
654-
["@", "default"]],
654+
["$array", "default"]],
655655
["plugconf/install", "localhost/local/myplugin"]]
656656
```
657657

@@ -662,7 +662,7 @@ Here is the inverse expression of above.
662662
["plugconf/delete", "localhost/local/myplugin"],
663663
["lockjson/remove",
664664
{ ... (repository information of local directory) ... },
665-
["@", "default"]]]
665+
["$array", "default"]]]
666666
```
667667

668668
### Label examples
@@ -678,7 +678,7 @@ Here is the simple example of installing
678678
["do",
679679
["lockjson/add",
680680
["repos/get", "github.com/tyru/caw.vim"],
681-
["@", "default"]],
681+
["$array", "default"]],
682682
["plugconf/install", "github.com/tyru/caw.vim"]]]]
683683
```
684684

@@ -698,7 +698,7 @@ Note that:
698698
["plugconf/install", "github.com/tyru/caw.vim"],
699699
["lockjson/add",
700700
["repos/get", "github.com/tyru/caw.vim"],
701-
["@", "default"]]]]]
701+
["$array", "default"]]]]]
702702
```
703703

704704
Here is more complex example to install two plugins "tyru/open-browser.vim",
@@ -716,15 +716,15 @@ Here is more complex example to install two plugins "tyru/open-browser.vim",
716716
["parallel",
717717
["lockjson/add",
718718
["repos/get", "github.com/tyru/open-browser.vim"],
719-
["@", "default"]],
719+
["$array", "default"]],
720720
["plugconf/install", "github.com/tyru/open-browser.vim"]]],
721721
["label",
722722
3,
723723
" github.com/tyru/open-browser-github.vim ... {{if .Done}}done!{{end}}",
724724
["parallel",
725725
["lockjson/add",
726726
["repos/get", "github.com/tyru/open-browser-github.vim"],
727-
["@", "default"]],
727+
["$array", "default"]],
728728
["plugconf/install", "github.com/tyru/open-browser-github.vim"]]]]]]
729729
```
730730

dsl/op/array.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ import (
55
)
66

77
func init() {
8-
macroMap[string(ArrayOp)] = &ArrayOp
8+
s := arrayOp("$array")
9+
ArrayOp = &s
10+
macroMap[string(*ArrayOp)] = ArrayOp
911
}
1012

1113
type arrayOp string
1214

13-
// ArrayOp is "@" operation
14-
var ArrayOp arrayOp = "@"
15+
// ArrayOp is "$array" operation
16+
var ArrayOp *arrayOp
1517

16-
// String returns "@"
18+
// String returns "$array"
1719
func (*arrayOp) String() string {
18-
return string(ArrayOp)
20+
return string(*ArrayOp)
1921
}
2022

21-
// Execute executes "@" operation
23+
// Execute executes "$array" operation
2224
func (*arrayOp) Expand(args []types.Value) (types.Value, error) {
2325
return types.NewArray(args, types.AnyValue), nil
2426
}

0 commit comments

Comments
 (0)