README.md
1# Rusty Object Notation
2
3[![Build Status](https://travis-ci.org/ron-rs/ron.svg?branch=master)](https://travis-ci.org/ron-rs/ron)
4[![Crates.io](https://img.shields.io/crates/v/ron.svg)](https://crates.io/crates/ron)
5[![Docs](https://docs.rs/ron/badge.svg)](https://docs.rs/ron)
6[![Gitter](https://badges.gitter.im/ron-rs/ron.svg)](https://gitter.im/ron-rs/ron)
7
8RON is a simple readable data serialization format that looks similar to Rust syntax.
9It's designed to support all of [Serde's data model](https://serde.rs/data-model.html), so
10structs, enums, tuples, arrays, generic maps, and primitive values.
11
12## Example
13
14```rust
15GameConfig( // optional struct name
16 window_size: (800, 600),
17 window_title: "PAC-MAN",
18 fullscreen: false,
19
20 mouse_sensitivity: 1.4,
21 key_bindings: {
22 "up": Up,
23 "down": Down,
24 "left": Left,
25 "right": Right,
26
27 // Uncomment to enable WASD controls
28 /*
29 "W": Up,
30 "A": Down,
31 "S": Left,
32 "D": Right,
33 */
34 },
35
36 difficulty_options: (
37 start_difficulty: Easy,
38 adaptive: false,
39 ),
40)
41```
42
43## Why RON?
44
45### Example in JSON
46
47```json
48{
49 "materials": {
50 "metal": {
51 "reflectivity": 1.0
52 },
53 "plastic": {
54 "reflectivity": 0.5
55 }
56 },
57 "entities": [
58 {
59 "name": "hero",
60 "material": "metal"
61 },
62 {
63 "name": "monster",
64 "material": "plastic"
65 }
66 ]
67}
68```
69
70Notice these issues:
71 1. Struct and maps are the same
72 - random order of exported fields
73 - annoying and inconvenient for reading
74 - doesn't work well with version control
75 - quoted field names
76 - too verbose
77 - no support for enums
78 2. No trailing comma allowed
79 3. No comments allowed
80
81### Same example in RON
82
83```rust
84Scene( // class name is optional
85 materials: { // this is a map
86 "metal": (
87 reflectivity: 1.0,
88 ),
89 "plastic": (
90 reflectivity: 0.5,
91 ),
92 },
93 entities: [ // this is an array
94 (
95 name: "hero",
96 material: "metal",
97 ),
98 (
99 name: "monster",
100 material: "plastic",
101 ),
102 ],
103)
104```
105
106The new format uses `(`..`)` brackets for *heterogeneous* structures (classes),
107while preserving the `{`..`}` for maps, and `[`..`]` for *homogeneous* structures (arrays).
108This distinction allows us to solve the biggest problem with JSON.
109
110Here are the general rules to parse the heterogeneous structures:
111
112| class is named? | fields are named? | what is it? | example |
113| --------------- | ------------------| ------------------------- | ------------------- |
114| no | no | tuple | `(a, b)` |
115| yes/no | no | tuple struct | `Name(a, b)` |
116| yes | no | enum value | `Variant(a, b)` |
117| yes/no | yes | struct | `(f1: a, f2: b,)` |
118
119### Specification
120
121There is a very basic, work in progress specification available on
122[the wiki page](https://github.com/ron-rs/ron/wiki/Specification).
123A more formal and complete grammar is available [here](docs/grammar.md).
124
125### Appendix
126
127Why not XML?
128 - too verbose
129 - unclear how to treat attributes vs contents
130
131Why not YAML?
132 - significant white-space
133 - specification is too big
134
135Why not TOML?
136 - alien syntax
137 - absolute paths are not scalable
138
139Why not XXX?
140 - if you know a better format, tell me!
141
142## Tooling
143
144IntelliJ: https://vultix.github.io/intellij-ron-plugin/
145
146VS Code: https://github.com/a5huynh/vscode-ron
147
148Sublime Text: https://packagecontrol.io/packages/RON
149
150Atom: https://atom.io/packages/language-ron
151
152Vim: https://github.com/ron-rs/ron.vim
153
154## License
155
156RON is dual-licensed under Apache-2.0 and MIT.
157
158