yaml / yamlscript

Programming in YAML
MIT License
362 stars 31 forks source link

Support multi doc with addressing #89

Closed ingydotnet closed 4 months ago

ingydotnet commented 5 months ago

Currently YS only supports YAML streams with a single document.

We can support multiple documents. Each evaluated sequentially. A load operation would produce the value of the final document.

From any document evaluation you can access data from a previously evaluated document in the stream with a special symbol. Maybe ^ or $ or * or %. Let's use ^ for now.

In the third document, ^1 points to the second (previous document) and ^2 points to the first and ^3 or higher returns nil. ^ is an alias for ^1.

The ys CLI will be changed to evaluate -e expressions after any file evaluation. Then one can use ys like jq applying YS path syntax like so:

ys --load file.ys -e '^.foo.bar'

Another symbol ^^ points to a vector of all currently evaluated documents. Thus ^^.0 is the first document and ^^.last() would be the current last one.