|
| 1 | +MAML v0.1 |
| 2 | +========= |
| 3 | + |
| 4 | +Minimal Abstract Markup Language |
| 5 | + |
| 6 | +By Medvedev Anton. |
| 7 | + |
| 8 | + |
| 9 | +Objectives |
| 10 | +---------- |
| 11 | + |
| 12 | +1. MAML aims to be a minimal configuration format. |
| 13 | +2. MAML should be easily readable by humans. |
| 14 | +3. MAML should be easily parsed by machines. |
| 15 | + |
| 16 | + |
| 17 | +Spec |
| 18 | +---- |
| 19 | + |
| 20 | +* MAML is case-sensitive. |
| 21 | +* A MAML file must be a valid UTF-8 encoded Unicode document. |
| 22 | +* Whitespace means a space (0x20) or a tab (0x09). |
| 23 | +* Newline means LF (0x0A) or CRLF (0x0D 0x0A). |
| 24 | + |
| 25 | +Whitespaces and newlines are allowed to separate values and structural |
| 26 | +characters. |
| 27 | + |
| 28 | + |
| 29 | +Comment |
| 30 | +------- |
| 31 | + |
| 32 | +A hash symbol marks the rest of the line as a comment, except when inside a |
| 33 | +string. |
| 34 | + |
| 35 | +```maml |
| 36 | +# Comment before the object |
| 37 | +{ |
| 38 | + foo: "value" # Inline comment |
| 39 | + bar: "# This is not a comment" |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +Control characters other than tab (U+0000 to U+0008, U+000A to U+001F, U+007F) |
| 44 | +are not permitted in comments. |
| 45 | + |
| 46 | + |
| 47 | +Values |
| 48 | +------ |
| 49 | + |
| 50 | +A MAML value is an object, array, string, multiline string, integer, float, |
| 51 | +boolean, or null. |
| 52 | + |
| 53 | + |
| 54 | +Array |
| 55 | +----- |
| 56 | + |
| 57 | +An array structure is represented as `[` `]` square brackets surrounding zero |
| 58 | +or more values. Values are separated by `,` comma or newlines. There is no |
| 59 | +requirement that the values in an array be of the same type. |
| 60 | + |
| 61 | +```maml |
| 62 | +[ |
| 63 | + "red" |
| 64 | + "yellow" |
| 65 | + "green" |
| 66 | +] |
| 67 | +``` |
| 68 | + |
| 69 | +Commas are optional. Trailing comma is allowed. |
| 70 | + |
| 71 | +```maml |
| 72 | +[ "red", "yellow", "green", ] |
| 73 | +``` |
| 74 | + |
| 75 | + |
| 76 | +Objects |
| 77 | +------- |
| 78 | + |
| 79 | +An object is an **ordered** set of key/value pairs. An object begins with `{` |
| 80 | +left brace and ends with `}` right brace. Each key is followed by `:` colon |
| 81 | +and the key/value pairs are separated by `,` comma or newlines. |
| 82 | + |
| 83 | +```maml |
| 84 | +{ |
| 85 | + key: "value" |
| 86 | + "quotted key": "value" |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +Commas are optional. Trailing comma is allowed. |
| 91 | + |
| 92 | +```maml |
| 93 | +{ |
| 94 | + key: "value", |
| 95 | + "quotted key": "value", |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +Duplicate keys are **not allowed** within an object. |
| 100 | + |
| 101 | + |
| 102 | +Keys |
| 103 | +---- |
| 104 | + |
| 105 | +A key may be either an identifier or a quoted string. |
| 106 | + |
| 107 | +**Identifier keys** may only contain `A-Z` `a-z` letters, `0-9` digits, `_` |
| 108 | +underscores, and `-` hyphens. |
| 109 | + |
| 110 | +Identifier keys are allowed to be composed of only digits, (for example, |
| 111 | +`1234`), but are always interpreted as strings. |
| 112 | + |
| 113 | +**Quoted string keys** follow the exact same rules as strings and allow |
| 114 | +you to use a much broader set of key names. |
| 115 | + |
| 116 | +An identifier key must be non-empty, but an empty quoted string key is allowed. |
| 117 | + |
| 118 | + |
| 119 | +String |
| 120 | +------ |
| 121 | + |
| 122 | +**Strings** are surrounded by `"` quotation marks. Any Unicode character |
| 123 | +may be used except those that must be escaped: quotation mark, backslash, and |
| 124 | +the control characters other than tab (U+0000 to U+0008, U+000A to U+001F, |
| 125 | +U+007F). |
| 126 | + |
| 127 | +```maml |
| 128 | +"String with a \"nested\" string, \t tab, 😁 emoji, and \u0022 sequence" |
| 129 | +``` |
| 130 | + |
| 131 | +For convenience, some popular characters have a compact escape sequence. |
| 132 | + |
| 133 | +``` |
| 134 | +\b - backspace (U+0008) |
| 135 | +\t - tab (U+0009) |
| 136 | +\n - linefeed (U+000A) |
| 137 | +\f - form feed (U+000C) |
| 138 | +\r - carriage return (U+000D) |
| 139 | +\" - quote (U+0022) |
| 140 | +\\ - backslash (U+005C) |
| 141 | +``` |
| 142 | + |
| 143 | +A Unicode character may be escaped with the `\uXXXX` form. |
| 144 | +The escape codes must be valid Unicode [scalar |
| 145 | +values](https://unicode.org/glossary/#unicode_scalar_value). |
| 146 | + |
| 147 | +All other escape sequences not listed above are reserved; if they are used, |
| 148 | +MAML should produce an error. All strings must contain only valid UTF-8 |
| 149 | +characters. |
| 150 | + |
| 151 | + |
| 152 | +Multiline String |
| 153 | +---------------- |
| 154 | + |
| 155 | +**Multiline Strings** are surrounded by `"""` three quotes on each |
| 156 | +side and allow newlines. There is no escaping. A newline immediately following |
| 157 | +the opening delimiter is ignored. All other content between the delimiters is |
| 158 | +interpreted as-is without modification. |
| 159 | + |
| 160 | +```maml |
| 161 | +""" |
| 162 | +The quick brown |
| 163 | +fox jumps over |
| 164 | +the lazy dog. |
| 165 | +""" |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +In the previous example, a string ends with a newline at the end. |
| 170 | + |
| 171 | +```maml |
| 172 | +"The quick brown\nfox jumps over\nthe lazy dog.\n" |
| 173 | +``` |
| 174 | + |
| 175 | +To avoid the last newline, place the closing delimiter on the same line. |
| 176 | + |
| 177 | +```maml |
| 178 | +""" |
| 179 | +The quick brown |
| 180 | +fox jumps over |
| 181 | +the lazy dog.""" |
| 182 | +``` |
| 183 | + |
| 184 | +You can write one or two quotes anywhere within a multiline string, |
| 185 | +but sequences of three or more quotes are not permitted. |
| 186 | + |
| 187 | +```maml |
| 188 | +""" |
| 189 | +Maximum of two "" quotes allowed inside. |
| 190 | +""" |
| 191 | +``` |
| 192 | + |
| 193 | +All escape sequences are preserved as is. |
| 194 | + |
| 195 | +```maml |
| 196 | +""" |
| 197 | +There is no escaping, so \n, \u0022, etc., |
| 198 | +are interpreted as-is without modification. |
| 199 | +""" |
| 200 | +``` |
| 201 | + |
| 202 | +Multiline string may also be written in a single line. |
| 203 | + |
| 204 | +```maml |
| 205 | +"""A multiline string and with "quotas".""" |
| 206 | +``` |
| 207 | + |
| 208 | +All multiline strings must contain only valid UTF-8 characters. |
| 209 | + |
| 210 | + |
| 211 | +Integer |
| 212 | +------- |
| 213 | + |
| 214 | +Integers are whole numbers. Negative numbers are prefixed with a minus sign. |
| 215 | +Leading zeros are not allowed. Plus sign is not allowed. |
| 216 | + |
| 217 | +```maml |
| 218 | +{ |
| 219 | + int1: 42 |
| 220 | + int2: -100 |
| 221 | +} |
| 222 | +``` |
| 223 | + |
| 224 | +Arbitrary 64-bit signed integers (from −2^63 to 2^63−1) should be accepted and |
| 225 | +handled losslessly. If an integer cannot be represented losslessly, an error |
| 226 | +must be thrown. |
| 227 | + |
| 228 | + |
| 229 | +Float |
| 230 | +----- |
| 231 | + |
| 232 | +Floats should be implemented as IEEE 754 binary64 values. |
| 233 | + |
| 234 | +A float consists of an integer part (which follows the same rules as integer |
| 235 | +values) followed by a fractional part and/or an exponent part. If both a |
| 236 | +fractional part and an exponent part are present, the fractional part must |
| 237 | +precede the exponent part. |
| 238 | + |
| 239 | +```maml |
| 240 | +[ |
| 241 | + # fractional |
| 242 | + 1.0 |
| 243 | + 3.1415 |
| 244 | + -0.01 |
| 245 | + |
| 246 | + # exponent |
| 247 | + 5e+22 |
| 248 | + 1e06 |
| 249 | + -2E-2 |
| 250 | + |
| 251 | + # both |
| 252 | + 6.626e-34 |
| 253 | +] |
| 254 | +``` |
| 255 | + |
| 256 | +A fractional part is a decimal point followed by one or more digits. |
| 257 | + |
| 258 | +An exponent part is an E (upper or lower case) followed by an integer part |
| 259 | +(which follows the same rules as integer values but may include leading |
| 260 | +zeros). |
| 261 | + |
| 262 | +The decimal point, if used, must be surrounded by at least one digit on each |
| 263 | +side. |
| 264 | + |
| 265 | + |
| 266 | +Boolean |
| 267 | +------- |
| 268 | + |
| 269 | +Booleans are `true` and `false`. Always lowercase. |
| 270 | + |
| 271 | +```maml |
| 272 | +[ true, false ] |
| 273 | +``` |
| 274 | + |
| 275 | + |
| 276 | +Null |
| 277 | +---- |
| 278 | + |
| 279 | +Represents the lack of a value. An object with some key and a null value is |
| 280 | +valid and different from not having that key in the object. Always lowercase. |
| 281 | + |
| 282 | +```maml |
| 283 | +null |
| 284 | +``` |
| 285 | + |
| 286 | + |
| 287 | +Filename Extension |
| 288 | +------------------ |
| 289 | + |
| 290 | +MAML files should use the extension `.maml`. |
| 291 | + |
| 292 | + |
| 293 | +MIME Type |
| 294 | +--------- |
| 295 | + |
| 296 | +When transferring MAML files over the internet, the appropriate MIME type is |
| 297 | +`application/maml`. |
| 298 | + |
| 299 | + |
| 300 | +ABNF Grammar |
| 301 | +------------ |
| 302 | + |
| 303 | +A formal description of MAML's syntax in ABNF format |
| 304 | +([RFC 5234](https://www.ietf.org/rfc/rfc5234.txt)). |
| 305 | + |
| 306 | +<<< @/maml.abnf |
0 commit comments