Skip to content

Commit 0b6b030

Browse files
committed
doc: More ReadMe improvements
1 parent b1f14c4 commit 0b6b030

15 files changed

Lines changed: 160 additions & 222 deletions

File tree

ReadMe.md

Lines changed: 86 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Program in YAML — Code is Data
66

77
## About YS / YAMLScript
88

9-
[YS](https://yamlscript.org) is a new YAML loader for 15 (and counting)
10-
programming languages:
9+
**[YS](https://yamlscript.org) (aka YAMLScript) is a new YAML loader** for 15
10+
(and counting) programming languages:
1111
[C#](https://www.nuget.org/packages/YAMLScript/),
1212
[Clojure](https://clojars.org/org.yamlscript/clj-yamlscript),
13-
[Crystal](https://github.com/yaml/yamlscript/crystal)
13+
[Crystal](https://shardbox.org/shards/yamlscript),
1414
[Go](https://github.com/yaml/yamlscript-go),
1515
[Haskell](https://hackage.haskell.org/package/yamlscript),
1616
[Java](https://clojars.org/org.yamlscript/yamlscript),
@@ -24,67 +24,68 @@ programming languages:
2424
[Ruby](https://rubygems.org/gems/yamlscript) and
2525
[Rust](https://crates.io/crates/yamlscript).
2626

27-
You should consider trying out YS to replace your current YAML loader, because:
27+
Try using YS in place of your current YAML loader!
2828

29-
* It's easy to use
29+
* It's as easy to use as your current YAML loader
30+
* Loads your existing YAML files properly
3031
* It works the same way in every programming language
31-
* Same features, same bugs, same bug fixes
32+
* Same API, same features, same bugs, same bug fixes
3233
* YS has optional functional programming features
3334
* File imports, string interpolation, standard library, etc
3435
* Everything a compiled programming language has
3536

3637
How can YS offer all this?
3738

38-
YS is also a functional programming language!
39+
**YS is also a functional programming language!**
3940

4041
Like [PyYAML](https://pyyaml.org/) and many other YAML loaders, YS is
4142
implemented to the [YAML 1.2 specification](https://yaml.org/spec/1.2.2/).
42-
But instead of loading YAML into its intended data structure, a YS loader loads
43-
YAML into a Lisp AST (abstract syntax tree) data structure.
44-
The AST is then rendered into Lisp code and evaluated, resulting in
45-
the intended data structure.
43+
But instead of loading YAML into directly into its intended data structure, a YS
44+
loader loads YAML into a Lisp AST (abstract syntax tree) data structure.
45+
The AST is then rendered into Lisp code and evaluated by a full-featured
46+
runtime, resulting in the intended data structure.
4647

4748
The specific Lisp is [Clojure](https://clojure.org/), which is very capable,
4849
mature and well-documented programming language with a large ecosystem of
4950
libraries and tools.
5051

51-
You may be aware that Clojure is a JVM hosted language (and also a JavaScript
52-
hosted one via ClojureScript), but YS doesn't need either of those.
53-
YS is compiled to a native binary executable and also a native shared library.
54-
The shared library can be used by nearly any programming language, including the
55-
ones listed above.
52+
> Note: You may be aware that Clojure is a JVM hosted language (and also a
53+
> JavaScript hosted one via ClojureScript), but YS doesn't need either of those.
54+
> YS is compiled to a native binary executable and also a native shared library.
55+
> The shared library can be used by nearly any programming language, including
56+
> the ones listed above.
5657
57-
Not only can you use YS as a loader libraryfrom a programming language, but you
58+
Not only can you use YS as a loader library from a programming language, but you
5859
can also use it from the command line with the `ys` command.
5960

6061
YS is awesome for:
6162

6263
* Querying, manipulating and transforming YAML (and JSON) files
6364
* Outputs include YAML, JSON, CSV, TSV and EDN
64-
* Refactoring large monolythic YAML files into smaller, more manageable files
65-
* Using data in your YAML files from external sources
65+
* Refactoring large monolithic YAML files into smaller, more manageable files
66+
* Using data from external sources in your YAML files
6667
* Files, web, databases, APIs, shell commands, etc
6768
* Applying over 1000 built-in functions to your YAML data
6869
* Using YS libraries for even more functionality
6970
* Writing complete programs, applications, automation scripts
7071

71-
> Note: YS is an official language on the
72-
> [Exercism](https://exercism.org/tracks) (free) language learning site!
73-
> It's a great way to learn how to program in YS.
72+
**YS is an official language on the
73+
[Exercism](https://exercism.org/tracks) (free) language learning site!**
74+
It's a great way to learn how to program in YS.
7475

7576

76-
### Using YS
77-
78-
First you need to install `ys` and `libys`.
79-
You can install both to `~/.local/bin/ys` and `~/.local/lib/libys.so`
80-
respectively, with:
77+
## A Quick Example
8178

79+
First you'll need to install `ys` and/or `libys`.
80+
You can install them both to `~/.local/bin/ys` and `~/.local/lib/libys.so`
81+
respectively, with this single command:
8282
```bash
8383
curl https://yamlscript.org/install | bash
8484
```
85-
See the [Installing YS](#installing-ys) section below for more details.
8685

87-
Now say you have a file called `file.ys` that looks like this:
86+
> See [Installing YS](https://yamlscript.org/doc/install/) for full details.
87+
88+
Now say you have a file called `file.yaml` that looks like this:
8889
```yaml
8990
name: Fido
9091
age: 6
@@ -94,24 +95,23 @@ likes: [running, fetching, playing, treats]
9495
9596
You can load it with:
9697
```bash
97-
ys --json file.ys
98+
ys --json file.yaml
9899
```
99100

100101
And get this output:
101102
```json
102-
{
103-
"name": "Fido",
104-
"age": 6,
105-
"dog years": 42,
106-
"likes": ["running", "fetching", "playing", "treats"]
107-
}
103+
{"name":"Fido",
104+
"age":6,
105+
"dog years":42,
106+
"likes":["fetching", "playing", "running", "treats"]}
108107
```
109108

110-
Wait, that's just regular YAML! Exactly! YS is 100% compatible with existing
111-
YAML files.
112-
But here's where it gets interesting...
109+
Nothing special here.
110+
YS is 100% compatible with existing YAML files, so this is just what you'd
111+
expect.
113112

114-
Let's say you want to calculate the dog years dynamically:
113+
But here's where it gets interesting...
114+
Let's say you want to add some dynamic logic:
115115

116116
```yaml
117117
!YS-v0:
@@ -120,29 +120,29 @@ age =: 6
120120
name: Fido
121121
age:: age
122122
dog years:: age * 7
123-
likes: [running, fetching, playing, treats]
123+
likes::
124+
sort:: [running, fetching, playing, treats]
124125
```
125126
126-
Now when you load it, the dog years are calculated automatically!
127+
The first line is a special tag that tells YS that this file may contain code.
127128
The `age =: 6` sets a variable, and the `::` tells YS that the value is a code
128129
expression, not a data value.
130+
We've also used the standard `sort` function to sort the `likes` list.
129131

132+
Let's load it via a Python using the `yamlscript.py` module this time:
133+
```bash
134+
python3 -c '
135+
import json, yamlscript;
136+
print(json.dumps(yamlscript.YAMLScript()
137+
.load(open("file.yaml").read())))'
138+
{"name": "Fido", "age": 6, "dog years": 42,
139+
"likes": ["fetching", "playing", "running", "treats"]}
140+
```
130141

131-
### Why YS is Different
132-
133-
With YS, YAML files can either be "loaded" or "run".
134-
When a YS program is loaded, it evaluates to a JSON-model data structure.
135-
When a YS program is run, it is executed as a normal program.
136-
137-
If you have a valid YAML ([1.2 Core Schema](
138-
https://yaml.org/spec/1.2.2/#103-core-schema)) file that doesn't use custom
139-
tags, and loads to a value expressible in JSON, then it will load properly with
140-
YS.
141-
The YS `load` operation will evaluate that file exactly the same in any
142-
programming language / environment.
142+
The good stuff is all sorted and the dog years are calculated automatically!
143143

144144

145-
### Real-World Examples
145+
## Real-World Examples
146146

147147
Want to merge multiple YAML files with environment variable overrides?
148148

@@ -212,12 +212,12 @@ deployments::
212212
-->
213213

214214

215-
### Getting Started with YS
215+
## Getting Started with YS
216216

217217
There are two primary ways to use YS:
218218

219219
* Using the `ys` command line runner / loader / compiler / installer
220-
* Using a YS library in your own programming language
220+
* Using a YAMLScript library in your own programming language
221221

222222
The `ys` command line tool is the easiest way to get started with YS.
223223
You can use it to load / evaluate / transform YAML files and print the result as
@@ -228,8 +228,8 @@ You can also use YS as a library in your own programming language.
228228
For example, in Python you can use the `yamlscript` module like this:
229229

230230
```python
231-
import yamlscript
232-
ys = yamlscript.YAMLScript()
231+
from yamlscript import YAMLScript
232+
ys = YAMLScript()
233233
text = open("foo.yaml").read()
234234
data = ys.load(text)
235235
```
@@ -241,7 +241,7 @@ YS is supported on these operating systems:
241241

242242
* Linux
243243
* macOS
244-
* Windows (work in progress)
244+
* Windows (coming soon)
245245

246246
YS is supported on these architectures:
247247

@@ -250,9 +250,14 @@ YS is supported on these architectures:
250250

251251
For now other systems cannot be supported because `ys` and `libys` are compiled
252252
by GraalVM's `native-image` tool, which only supports the above systems.
253+
However, work is underway to have YS use alternate runtimes such as JVM, Go,
254+
JavaScript and WebAssembly.
255+
253256

257+
## Usage Examples in Your Language
254258

255-
### Quick Examples in Your Language
259+
Here's some examples of how to use YS in a few different programming languages.
260+
Usage in other languages is similar.
256261

257262
**Python:**
258263
```python
@@ -263,16 +268,15 @@ config = ys.load(open('config.yaml').read())
263268

264269
**JavaScript/Node:**
265270
```javascript
266-
const YS = require('@yaml/yamlscript');
267-
const ys = new YS();
268-
const config = ys.load(fs.readFileSync('config.yaml', 'utf8'));
271+
YS = require('@yaml/yamlscript');
272+
ys = new YS();
273+
config = ys.load(fs.readFileSync('config.yaml', 'utf8'));
269274
```
270275

271276
**Go:**
272277
```go
273278
import "github.com/yaml/yamlscript-go"
274-
ys := yamlscript.New()
275-
data, _ := ys.Load(yamlContent)
279+
data, err := ys.Load(yamlContent)
276280
```
277281

278282
**Ruby:**
@@ -283,98 +287,20 @@ config = ys.load(File.read('config.yaml'))
283287
```
284288

285289

286-
### Why Choose YS?
287-
288-
* **🔧 Reliability** - Same implementation across all languages means consistent behavior
289-
* **📦 Zero Dependencies** - Single shared library with no runtime dependencies
290-
* **🎯 100% YAML Compatible** - Works with all your existing YAML files today
291-
* **🚀 Performance** - Native compiled code runs as fast or faster than Python/Perl
292-
* **💪 Powerful When Needed** - Access to 1000+ built-in functions and full Clojure ecosystem
293-
* **🌐 Universal** - One syntax to learn, use everywhere
294-
295-
296-
## Installing YS
297-
298-
You can install the YS `ys` interpreter and/or its `libys.so` shared
299-
library from pre-built binaries or building from source.
300-
Both are very easy to do.
301-
302-
303-
### Installing YS Pre-built Binary Releases
304-
305-
YS ships pre-built binaries for each release version [here](
306-
https://github.com/yaml/yamlscript/releases).
307-
308-
To install a latest release for your machine platform, try:
309-
310-
```bash
311-
curl https://yamlscript.org/install | bash
312-
```
313-
314-
Make sure `~/.local/bin` is in your `PATH` environment variable.
315-
316-
You can use the following environment variables to control the installation:
290+
## Why Choose YS?
317291

318-
* `PREFIX=...` - The directory to install to. Default: `~/.local`
319-
* `VERSION=...` - The YS version to install. Default: `0.2.3`
320-
* `BIN=1` - Only install the `PREFIX/bin/ys` command line tool.
321-
* `LIB=1` - Only install the `PREFIX/lib/libys` shared library.
322-
* `DEBUG=1` - Print the Bash commands that are being run.
323-
324-
Once you have installed the `ys` command you can upgrade to a bin binary
325-
version with `ys --upgrade`.
326-
327-
328-
### Installing YS from Source
329-
330-
This is very easy to build and install YS from its source code because the YS
331-
build process has very few dependencies:
332-
333-
* `bash` (your interactive shell can be any shell)
334-
* `curl`
335-
* `git`
336-
* `make`
337-
338-
To install the `ys` command line tool, and `libys` shared library, run these
339-
commands:
340-
341-
```bash
342-
git clone https://github.com/yaml/yamlscript
343-
cd yamlscript
344-
make build
345-
make install
346-
```
347-
348-
That's it!
349-
350-
See [Installing YS](https://yamlscript.org/doc/install/) for full details.
351-
352-
353-
### Installing a YS Binding for a Programming Language
354-
355-
YS ships its language binding libraries and the `libys.so` shared library
356-
separately.
357-
358-
Currently, each binding release version requires an exact version of the shared
359-
library, or it will not work.
360-
361-
The best way to install a binding library is to use your programming language's
362-
package manager to install the latest binding version, and the YS installer to
363-
install the latest shared library version.
364-
365-
So for Python you would:
366-
367-
```bash
368-
pip install yamlscript
369-
curl https://yamlscript.org/install | bash
370-
```
371-
372-
The Perl installation process can automatically install the shared library, so
373-
you can just do:
374-
375-
```bash
376-
cpanm YAMLScript
377-
```
292+
* **🔧 Reliability** -
293+
Same implementation across all languages means consistent behavior
294+
* **📦 Zero Dependencies** -
295+
Single shared library with no runtime dependencies
296+
* **🎯 100% YAML Compatible** -
297+
Works with all your existing YAML files today
298+
* **🚀 Performance** -
299+
Native compiled code runs as fast or faster than Python/Perl
300+
* **💪 Powerful When Needed** -
301+
Access to 1000+ built-in functions and full Clojure ecosystem
302+
* **🌐 Universal** -
303+
One syntax to learn, use everywhere
378304

379305

380306
## The YS Repository
@@ -394,7 +320,7 @@ is a mono-repo containing:
394320

395321
The YS repository uses a `Makefile` system to build, test and install its
396322
various offerings.
397-
It installs (locally within this directory)all the dependencies you need to
323+
It installs (locally within this directory) all the dependencies you need to
398324
build and test YS, including every programming language needed by the bindings.
399325

400326
There is a top level `Makefile` and each repo subdirectory has its own
@@ -408,8 +334,8 @@ it and run `make` targets (try `make test`) without any problems.
408334

409335
### Contributing to YS
410336

411-
To ensure that YS libraries work the same across all languages, this project
412-
aims to have a binding implementation for each programming language.
337+
This project aims to have a binding implementation for each every programming
338+
language where YAML is used.
413339

414340
If you would like to contribute a new YS binding for a programming language,
415341
you are encouraged to

0 commit comments

Comments
 (0)