libyay 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
libyay-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,897 @@
1
+ Metadata-Version: 2.4
2
+ Name: libyay
3
+ Version: 1.0.0
4
+ Summary: A parser and serializer for the YAY data format
5
+ Author: Kris Kowal
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://kriskowal.com/yay
8
+ Project-URL: Repository, https://github.com/kriskowal/yay
9
+ Project-URL: Documentation, https://github.com/kriskowal/yay/tree/main/python
10
+ Keywords: yay,parser,serialization,config,data-format
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Text Processing :: Markup
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+
23
+ # YAY Parser for Python
24
+
25
+ [![PyPI](https://img.shields.io/pypi/v/libyay.svg)](https://pypi.org/project/libyay/)
26
+
27
+ A parser for the [YAY](https://kriskowal.com/yay) data format, implemented in Python.
28
+
29
+ ## Requirements
30
+
31
+ - Python 3.10+
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install libyay
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ import libyay as yay
43
+
44
+ # Parse a YAY string
45
+ data = yay.loads("""
46
+ name: Alice
47
+ age: 30
48
+ tags:
49
+ - python
50
+ - data
51
+ """)
52
+ # {'name': 'Alice', 'age': 30, 'tags': ['python', 'data']}
53
+
54
+ # Parse from file
55
+ with open('config.yay') as f:
56
+ data = yay.load(f)
57
+ ```
58
+
59
+ ## API
60
+
61
+ ### `loads(source)`
62
+
63
+ Parses a YAY document string and returns the corresponding Python value.
64
+
65
+ ### `load(file)`
66
+
67
+ Parses a YAY document from a file object.
68
+
69
+ ### `dumps(value, indent=True)`
70
+
71
+ Serializes a Python value to a YAY string.
72
+
73
+ ### `dump(value, file, indent=True)`
74
+
75
+ Serializes a Python value to a file in YAY format.
76
+
77
+ ## Type Mapping
78
+
79
+ | YAY Type | Python Type | Notes |
80
+ |----------|-------------|-------|
81
+ | `null` | `None` | |
82
+ | big integer | `int` | Arbitrary precision |
83
+ | float64 | `float` | Including `float('inf')`, `float('-inf')`, `float('nan')` |
84
+ | boolean | `bool` | |
85
+ | string | `str` | |
86
+ | array | `list` | |
87
+ | object | `dict` | |
88
+ | bytes | `bytes` | |
89
+
90
+ # YAY Format
91
+
92
+ [at-a-glance.yay](https://github.com/kriskowal/yay/blob/main/test/yay/at-a-glance.yay)
93
+ ```yay
94
+ roses-are-red: true # There is no "yes" or "on".
95
+ violets-are-blue: false # Violets are violet.
96
+ arrays:
97
+ - "may"
98
+ - "have"
99
+ - "many"
100
+ - "values"
101
+ and-objects-too:
102
+ integers-are-distinct: 42
103
+ from-their-floating-friends: 6.283 185 307 179 586 # digit grouping
104
+ inline:
105
+ string: "is concise"
106
+ array: [infinity, -infinity, nan]
107
+ object: {bigint: 1, float64: 2.0}
108
+ bytes: <f33d face>
109
+ block:
110
+ string: `
111
+ This is a string.
112
+ There are many like it.
113
+ array:
114
+ - "But"
115
+ - "this"
116
+ - "one's"
117
+ object:
118
+ mine: null
119
+ bytes: >
120
+ b0 b5 c0 ff # Bob's Coffee
121
+ fe fa ca de # Facade.
122
+ concatenated:
123
+ "I'm not dead yet. "
124
+ "I feel happy!"
125
+ unicode-code-point: "\u{1F600}" # UTF-16 surrogates are inexpressible
126
+ "name with spaces": 'works too'
127
+ ```
128
+
129
+ ## Null
130
+
131
+ The keyword `null` denotes a null value.
132
+
133
+ [null-literal.yay](https://github.com/kriskowal/yay/blob/main/test/yay/null-literal.yay)
134
+ ```yay
135
+ null
136
+ ```
137
+
138
+ [null-literal.py](https://github.com/kriskowal/yay/blob/main/test/py/null-literal.py)
139
+ ```python
140
+ None
141
+ ```
142
+
143
+ ## Booleans
144
+
145
+ The literals `true` and `false` denote booleans.
146
+
147
+ A true boolean value.
148
+
149
+ [boolean-true.yay](https://github.com/kriskowal/yay/blob/main/test/yay/boolean-true.yay)
150
+ ```yay
151
+ true
152
+ ```
153
+
154
+ [boolean-true.py](https://github.com/kriskowal/yay/blob/main/test/py/boolean-true.py)
155
+ ```python
156
+ True
157
+ ```
158
+
159
+ A false boolean value.
160
+
161
+ [boolean-false.yay](https://github.com/kriskowal/yay/blob/main/test/yay/boolean-false.yay)
162
+ ```yay
163
+ false
164
+ ```
165
+
166
+ [boolean-false.py](https://github.com/kriskowal/yay/blob/main/test/py/boolean-false.py)
167
+ ```python
168
+ False
169
+ ```
170
+
171
+ ## Big Integers
172
+
173
+ Unquoted decimal digit sequences are big integers (arbitrary precision).
174
+ A leading minus sign denotes a negative big integer; the minus must not be followed by a space.
175
+ Spaces may be used to group digits for readability; they do not change the value.
176
+
177
+ Python's `int` type is arbitrary precision, so YAY big integers map directly.
178
+
179
+ A basic positive integer.
180
+
181
+ [integer-big-basic.yay](https://github.com/kriskowal/yay/blob/main/test/yay/integer-big-basic.yay)
182
+ ```yay
183
+ 42
184
+ ```
185
+
186
+ [integer-big-basic.py](https://github.com/kriskowal/yay/blob/main/test/py/integer-big-basic.py)
187
+ ```python
188
+ 42
189
+ ```
190
+
191
+ A negative integer.
192
+
193
+ [integer-big-negative.yay](https://github.com/kriskowal/yay/blob/main/test/yay/integer-big-negative.yay)
194
+ ```yay
195
+ -42
196
+ ```
197
+
198
+ [integer-big-negative.py](https://github.com/kriskowal/yay/blob/main/test/py/integer-big-negative.py)
199
+ ```python
200
+ -42
201
+ ```
202
+
203
+ Spaces group digits for readability without changing the value.
204
+
205
+ [integer-big.yay](https://github.com/kriskowal/yay/blob/main/test/yay/integer-big.yay)
206
+ ```yay
207
+ 867 5309
208
+ ```
209
+
210
+ [integer-big.py](https://github.com/kriskowal/yay/blob/main/test/py/integer-big.py)
211
+ ```python
212
+ 8675309
213
+ ```
214
+
215
+ ## Floating-Point (Float64)
216
+
217
+ A decimal point must be present to distinguish a float from a big integer.
218
+ Decimal literals with a decimal point, or the keywords `infinity`, `-infinity`, and `nan`, denote 64-bit floats.
219
+ A leading minus must not be followed by a space.
220
+ Spaces may group digits.
221
+
222
+ A basic floating-point number.
223
+
224
+ [number-float.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float.yay)
225
+ ```yay
226
+ 6.283185307179586
227
+ ```
228
+
229
+ [number-float.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float.py)
230
+ ```python
231
+ 6.283185307179586
232
+ ```
233
+
234
+ A float with a leading decimal point (no integer part).
235
+
236
+ [number-float-leading-dot.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-leading-dot.yay)
237
+ ```yay
238
+ .5
239
+ ```
240
+
241
+ [number-float-leading-dot.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-leading-dot.py)
242
+ ```python
243
+ 0.5
244
+ ```
245
+
246
+ A float with a trailing decimal point (no fractional part).
247
+
248
+ [number-float-trailing-dot.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-trailing-dot.yay)
249
+ ```yay
250
+ 1.
251
+ ```
252
+
253
+ [number-float-trailing-dot.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-trailing-dot.py)
254
+ ```python
255
+ 1.0
256
+ ```
257
+
258
+ Negative zero is distinct from positive zero.
259
+
260
+ [number-float-negative-zero.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-negative-zero.yay)
261
+ ```yay
262
+ -0.0
263
+ ```
264
+
265
+ [number-float-negative-zero.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-negative-zero.py)
266
+ ```python
267
+ -0.0
268
+ ```
269
+
270
+ Positive infinity.
271
+
272
+ [number-float-infinity.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-infinity.yay)
273
+ ```yay
274
+ infinity
275
+ ```
276
+
277
+ [number-float-infinity.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-infinity.py)
278
+ ```python
279
+ float("inf")
280
+ ```
281
+
282
+ Negative infinity.
283
+
284
+ [number-float-negative-infinity.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-negative-infinity.yay)
285
+ ```yay
286
+ -infinity
287
+ ```
288
+
289
+ [number-float-negative-infinity.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-negative-infinity.py)
290
+ ```python
291
+ float("-inf")
292
+ ```
293
+
294
+ Not-a-number (canonical NaN).
295
+
296
+ [number-float-nan.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-nan.yay)
297
+ ```yay
298
+ nan
299
+ ```
300
+
301
+ [number-float-nan.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-nan.py)
302
+ ```python
303
+ float("nan")
304
+ ```
305
+
306
+ Spaces group digits for readability in floats.
307
+
308
+ [number-float-grouped.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-grouped.yay)
309
+ ```yay
310
+ 6.283 185 307 179 586
311
+ ```
312
+
313
+ [number-float-grouped.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-grouped.py)
314
+ ```python
315
+ 6.283185307179586
316
+ ```
317
+
318
+ Scientific notation using `e` or `E` for the exponent (Avogadro's number).
319
+
320
+ [number-float-avogadro.yay](https://github.com/kriskowal/yay/blob/main/test/yay/number-float-avogadro.yay)
321
+ ```yay
322
+ 6.022e23
323
+ ```
324
+
325
+ [number-float-avogadro.py](https://github.com/kriskowal/yay/blob/main/test/py/number-float-avogadro.py)
326
+ ```python
327
+ 602200000000000000000000.0
328
+ ```
329
+
330
+ ## Block Strings
331
+
332
+ Block strings use the backtick (`` ` ``) introducer.
333
+ The body continues until the next line that is indented the same or less.
334
+ The first two spaces of each content line are stripped; any further indentation is preserved.
335
+ Empty lines are interpreted as newlines.
336
+ Trailing empty lines collapse to a single trailing newline.
337
+ Block strings do not support escape sequences—a backslash is just a backslash.
338
+ Comments are also not recognized inside block strings; `#` is literal content.
339
+
340
+ ### At Root Level
341
+
342
+ At root level or as an array item, content may appear on the same line after `` ` `` (backtick + space + content).
343
+ When the backtick is alone on a line, the result has an implicit leading newline.
344
+
345
+ Content on the same line as the backtick starts the string without a leading newline.
346
+
347
+ [string-block-root-same-line.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-root-same-line.yay)
348
+ ```yay
349
+ ` I think you ought to know I'm feeling very depressed.
350
+ This will all end in tears.
351
+ ```
352
+
353
+ [string-block-root-same-line.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-root-same-line.py)
354
+ ```python
355
+ "I think you ought to know I'm feeling very depressed.\nThis will all end in tears.\n"
356
+ ```
357
+
358
+ Backtick alone on its line produces a leading newline because content starts on the following line.
359
+
360
+ [string-block-root-next-line.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-root-next-line.yay)
361
+ ```yay
362
+ `
363
+ I've calculated your chance of survival,
364
+ but I don't think you'll like it.
365
+ ```
366
+
367
+ [string-block-root-next-line.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-root-next-line.py)
368
+ ```python
369
+ "\nI've calculated your chance of survival,\nbut I don't think you'll like it.\n"
370
+ ```
371
+
372
+ An empty line in the middle of a block string is preserved as a newline.
373
+
374
+ [string-block-empty-middle.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-empty-middle.yay)
375
+ ```yay
376
+ `
377
+ I'm getting better!
378
+
379
+ No you're not.
380
+ ```
381
+
382
+ [string-block-empty-middle.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-empty-middle.py)
383
+ ```python
384
+ "\nI'm getting better!\n\nNo you're not.\n"
385
+ ```
386
+
387
+ The `#` character inside a block string is literal content, not a comment.
388
+
389
+ [string-block-root-hash.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-root-hash.yay)
390
+ ```yay
391
+ ` # this is not a comment
392
+ it is content
393
+ ```
394
+
395
+ [string-block-root-hash.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-root-hash.py)
396
+ ```python
397
+ "# this is not a comment\nit is content\n"
398
+ ```
399
+
400
+ A block string may be deeply nested and the indentation prefix will be absent
401
+ in the value.
402
+ The string will end with a single newline regardless of any subsequent newlines
403
+ in the YAY text.
404
+
405
+ [string-block-nested-in-object-and-array.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-nested-in-object-and-array.yay)
406
+ ```yay
407
+ parrot:
408
+ condition: `
409
+ No, no, it's just resting!
410
+
411
+ remarks:
412
+ - ` Remarkable bird, the Norwegian Blue.
413
+ Beautiful plumage, innit?
414
+
415
+ - ` It's probably pining for the fjords.
416
+ Lovely plumage.
417
+ ```
418
+
419
+ [string-block-nested-in-object-and-array.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-nested-in-object-and-array.py)
420
+ ```python
421
+ {"parrot": {"condition": "No, no, it's just resting!\n", "remarks": ["Remarkable bird, the Norwegian Blue.\nBeautiful plumage, innit?\n", "It's probably pining for the fjords.\nLovely plumage.\n"]}}
422
+ ```
423
+
424
+ ### As Object Property
425
+
426
+ In property context, the backtick must be alone on the line (no content after it).
427
+ There is no implicit leading newline.
428
+ The first content line becomes the start of the string.
429
+
430
+ [string-block-property.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-property.yay)
431
+ ```yay
432
+ message: `
433
+ By Grabthar's hammer, we live to tell the tale.
434
+ ```
435
+
436
+ [string-block-property.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-property.py)
437
+ ```python
438
+ {"message": "By Grabthar's hammer, we live to tell the tale.\n"}
439
+ ```
440
+
441
+ An empty line in the middle of a block string property is preserved.
442
+
443
+ [string-block-property-empty-middle.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-property-empty-middle.yay)
444
+ ```yay
445
+ message: `
446
+ It's not pining!
447
+
448
+ It's passed on! This parrot is no more!
449
+ ```
450
+
451
+ [string-block-property-empty-middle.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-property-empty-middle.py)
452
+ ```python
453
+ {"message": "It's not pining!\n\nIt's passed on! This parrot is no more!\n"}
454
+ ```
455
+
456
+ A block string property followed by another property: the block ends when a line at the same or lesser indent appears.
457
+ Trailing empty lines collapse to a single trailing newline.
458
+
459
+ [string-block-property-trailing-empty.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-block-property-trailing-empty.yay)
460
+ ```yay
461
+ message: `
462
+ By Grabthar's hammer... what a savings.
463
+
464
+
465
+ next: 1
466
+ ```
467
+
468
+ [string-block-property-trailing-empty.py](https://github.com/kriskowal/yay/blob/main/test/py/string-block-property-trailing-empty.py)
469
+ ```python
470
+ {"message": "By Grabthar's hammer... what a savings.\n", "next": 1}
471
+ ```
472
+
473
+ ## Inline Strings
474
+
475
+ Strings may be quoted with double or single quotes.
476
+ Double-quoted strings support escape sequences: `\"`, `\\`, `\/`, `\b`, `\f`, `\n`, `\r`, `\t`, and `\u{XXXXXX}` for Unicode code points.
477
+ Single-quoted strings are literal (no escape sequences).
478
+
479
+ A double-quoted string.
480
+
481
+ [string-inline-doublequote-basic.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-inline-doublequote-basic.yay)
482
+ ```yay
483
+ "This will all end in tears."
484
+ ```
485
+
486
+ [string-inline-doublequote-basic.py](https://github.com/kriskowal/yay/blob/main/test/py/string-inline-doublequote-basic.py)
487
+ ```python
488
+ "This will all end in tears."
489
+ ```
490
+
491
+ A single-quoted string (literal, no escapes).
492
+
493
+ [string-inline-singlequote-basic.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-inline-singlequote-basic.yay)
494
+ ```yay
495
+ 'Are you suggesting coconuts migrate?'
496
+ ```
497
+
498
+ [string-inline-singlequote-basic.py](https://github.com/kriskowal/yay/blob/main/test/py/string-inline-singlequote-basic.py)
499
+ ```python
500
+ "Are you suggesting coconuts migrate?"
501
+ ```
502
+
503
+ A double-quoted string with escape sequences.
504
+
505
+ [string-inline-doublequote-escapes.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-inline-doublequote-escapes.yay)
506
+ ```yay
507
+ "\"\\\/\b\f\n\r\t\u{263A}"
508
+ ```
509
+
510
+ [string-inline-doublequote-escapes.py](https://github.com/kriskowal/yay/blob/main/test/py/string-inline-doublequote-escapes.py)
511
+ ```python
512
+ "\"\\/\b\f\n\r\t☺"
513
+ ```
514
+
515
+ A double-quoted string with a Unicode emoji (literal UTF-8).
516
+
517
+ [string-inline-doublequote-unicode-emoji.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-inline-doublequote-unicode-emoji.yay)
518
+ ```yay
519
+ "😀"
520
+ ```
521
+
522
+ [string-inline-doublequote-unicode-emoji.py](https://github.com/kriskowal/yay/blob/main/test/py/string-inline-doublequote-unicode-emoji.py)
523
+ ```python
524
+ "😀"
525
+ ```
526
+
527
+ A Unicode code point escape for a character outside the BMP (U+1F600), which requires a surrogate pair in UTF-16.
528
+ The `\u{...}` escape accepts 1 to 6 hexadecimal digits representing a Unicode code point (e.g. `\u{41}` for "A", `\u{1F600}` for "😀").
529
+ Surrogate code points (U+D800 through U+DFFF) are forbidden in `\u{...}` escapes.
530
+ Unlike JSON, the four-digit `\uXXXX` form is not supported; use `\u{XXXX}` instead.
531
+
532
+ [string-inline-doublequote-unicode-surrogate-pair.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-inline-doublequote-unicode-surrogate-pair.yay)
533
+ ```yay
534
+ "\u{1F600}"
535
+ ```
536
+
537
+ [string-inline-doublequote-unicode-surrogate-pair.py](https://github.com/kriskowal/yay/blob/main/test/py/string-inline-doublequote-unicode-surrogate-pair.py)
538
+ ```python
539
+ "😀"
540
+ ```
541
+
542
+ ## Concatenated Strings (Quoted Lines)
543
+
544
+ Multiple quoted strings on consecutive lines are concatenated into a single
545
+ string.
546
+ This is useful for breaking long strings across lines without introducing
547
+ newlines in the result, or including visibly escaped characters like tab
548
+ that are otherwise forbidden in string blocks.
549
+
550
+ [string-multiline-concat.yay](https://github.com/kriskowal/yay/blob/main/test/yay/string-multiline-concat.yay)
551
+ ```yay
552
+ confession:
553
+ "I'm not dead yet. "
554
+ "I feel happy!"
555
+ ```
556
+
557
+ [string-multiline-concat.py](https://github.com/kriskowal/yay/blob/main/test/py/string-multiline-concat.py)
558
+ ```python
559
+ {"confession": "I'm not dead yet. I feel happy!"}
560
+ ```
561
+
562
+ ## Block Arrays
563
+
564
+ Arrays are written as a sequence of items, each introduced by `- ` (dash and space).
565
+ The two-character `- ` prefix is the list marker; the value follows immediately.
566
+ Items may be nested: a bullet line whose content starts with `- ` begins an inner list.
567
+ An array may be given a name as a key followed by `:`.
568
+
569
+ A basic block array with three integer items.
570
+
571
+ [array-multiline.yay](https://github.com/kriskowal/yay/blob/main/test/yay/array-multiline.yay)
572
+ ```yay
573
+ - 5
574
+ - 3
575
+ ```
576
+
577
+ [array-multiline.py](https://github.com/kriskowal/yay/blob/main/test/py/array-multiline.py)
578
+ ```python
579
+ [5, 3]
580
+ ```
581
+
582
+ Nested arrays where each top-level item contains an inner array.
583
+
584
+ [array-multiline-nested.yay](https://github.com/kriskowal/yay/blob/main/test/yay/array-multiline-nested.yay)
585
+ ```yay
586
+ - - "a"
587
+ - "b"
588
+ - - 1
589
+ - 2
590
+ ```
591
+
592
+ [array-multiline-nested.py](https://github.com/kriskowal/yay/blob/main/test/py/array-multiline-nested.py)
593
+ ```python
594
+ [["a", "b"], [1, 2]]
595
+ ```
596
+
597
+ An array as the value of an object property.
598
+
599
+ [array-multiline-named.yay](https://github.com/kriskowal/yay/blob/main/test/yay/array-multiline-named.yay)
600
+ ```yay
601
+ complaints:
602
+ - "I didn't vote for you."
603
+ - "Help, help, I'm being repressed!"
604
+ ```
605
+
606
+ [array-multiline-named.py](https://github.com/kriskowal/yay/blob/main/test/py/array-multiline-named.py)
607
+ ```python
608
+ {"complaints": ["I didn't vote for you.", "Help, help, I'm being repressed!"]}
609
+ ```
610
+
611
+ ## Inline Arrays
612
+
613
+ Inline arrays use JSON-style bracket syntax with strict spacing rules: no space after `[`, no space before `]`, exactly one space after each `,`.
614
+
615
+ [array-inline-doublequote.yay](https://github.com/kriskowal/yay/blob/main/test/yay/array-inline-doublequote.yay)
616
+ ```yay
617
+ ["And there was much rejoicing.", "yay."]
618
+ ```
619
+
620
+ [array-inline-doublequote.py](https://github.com/kriskowal/yay/blob/main/test/py/array-inline-doublequote.py)
621
+ ```python
622
+ ["And there was much rejoicing.", "yay."]
623
+ ```
624
+
625
+ [array-inline-integers.yay](https://github.com/kriskowal/yay/blob/main/test/yay/array-inline-integers.yay)
626
+ ```yay
627
+ [42, 404, 418]
628
+ ```
629
+
630
+ [array-inline-integers.py](https://github.com/kriskowal/yay/blob/main/test/py/array-inline-integers.py)
631
+ ```python
632
+ [42, 404, 418]
633
+ ```
634
+
635
+ [array-inline-bytearray.yay](https://github.com/kriskowal/yay/blob/main/test/yay/array-inline-bytearray.yay)
636
+ ```yay
637
+ [<b0b5>, <cafe>]
638
+ ```
639
+
640
+ [array-inline-bytearray.py](https://github.com/kriskowal/yay/blob/main/test/py/array-inline-bytearray.py)
641
+ ```python
642
+ [bytes.fromhex("b0b5"), bytes.fromhex("cafe")]
643
+ ```
644
+
645
+ [array-inline-nested.yay](https://github.com/kriskowal/yay/blob/main/test/yay/array-inline-nested.yay)
646
+ ```yay
647
+ [["I feel happy!", "yay."], ["And there was much rejoicing.", "yay."]]
648
+ ```
649
+
650
+ [array-inline-nested.py](https://github.com/kriskowal/yay/blob/main/test/py/array-inline-nested.py)
651
+ ```python
652
+ [["I feel happy!", "yay."], ["And there was much rejoicing.", "yay."]]
653
+ ```
654
+
655
+ ## Block Objects
656
+
657
+ Objects are key–value pairs.
658
+ A key is followed by `:` and then the value.
659
+ Object keys must be either alphanumeric or quoted.
660
+ Nested objects are indented by two spaces.
661
+
662
+ [object-multiline.yay](https://github.com/kriskowal/yay/blob/main/test/yay/object-multiline.yay)
663
+ ```yay
664
+ answer: 42
665
+ error: 404
666
+ ```
667
+
668
+ [object-multiline.py](https://github.com/kriskowal/yay/blob/main/test/py/object-multiline.py)
669
+ ```python
670
+ {"answer": 42, "error": 404}
671
+ ```
672
+
673
+ Nested object.
674
+
675
+ [object-multiline-nested.yay](https://github.com/kriskowal/yay/blob/main/test/yay/object-multiline-nested.yay)
676
+ ```yay
677
+ parrot:
678
+ status: "pining for the fjords"
679
+ plumage: "beautiful"
680
+ ```
681
+
682
+ [object-multiline-nested.py](https://github.com/kriskowal/yay/blob/main/test/py/object-multiline-nested.py)
683
+ ```python
684
+ {"parrot": {"plumage": "beautiful", "status": "pining for the fjords"}}
685
+ ```
686
+
687
+ Object keys containing spaces or special characters must be quoted.
688
+
689
+ [object-multiline-doublequote-key.yay](https://github.com/kriskowal/yay/blob/main/test/yay/object-multiline-doublequote-key.yay)
690
+ ```yay
691
+ "key name": 1
692
+ ```
693
+
694
+ [object-multiline-doublequote-key.py](https://github.com/kriskowal/yay/blob/main/test/py/object-multiline-doublequote-key.py)
695
+ ```python
696
+ {"key name": 1}
697
+ ```
698
+
699
+ [object-inline-empty.yay](https://github.com/kriskowal/yay/blob/main/test/yay/object-inline-empty.yay)
700
+ ```yay
701
+ empty: {}
702
+ ```
703
+
704
+ [object-inline-empty.py](https://github.com/kriskowal/yay/blob/main/test/py/object-inline-empty.py)
705
+ ```python
706
+ {"empty": {}}
707
+ ```
708
+
709
+ ## Inline Objects
710
+
711
+ Inline objects use JSON-style brace syntax with strict spacing rules.
712
+
713
+ [object-inline-integers.yay](https://github.com/kriskowal/yay/blob/main/test/yay/object-inline-integers.yay)
714
+ ```yay
715
+ {answer: 42, error: 404}
716
+ ```
717
+
718
+ [object-inline-integers.py](https://github.com/kriskowal/yay/blob/main/test/py/object-inline-integers.py)
719
+ ```python
720
+ {"answer": 42, "error": 404}
721
+ ```
722
+
723
+ [object-inline-mixed.yay](https://github.com/kriskowal/yay/blob/main/test/yay/object-inline-mixed.yay)
724
+ ```yay
725
+ {name: 'Marvin', mood: 'depressed'}
726
+ ```
727
+
728
+ [object-inline-mixed.py](https://github.com/kriskowal/yay/blob/main/test/py/object-inline-mixed.py)
729
+ ```python
730
+ {"mood": "depressed", "name": "Marvin"}
731
+ ```
732
+
733
+ [object-inline-nested.yay](https://github.com/kriskowal/yay/blob/main/test/yay/object-inline-nested.yay)
734
+ ```yay
735
+ {luggage: {combination: 12345}, air: ["canned", "Perri-Air"]}
736
+ ```
737
+
738
+ [object-inline-nested.py](https://github.com/kriskowal/yay/blob/main/test/py/object-inline-nested.py)
739
+ ```python
740
+ {"air": ["canned", "Perri-Air"], "luggage": {"combination": 12345}}
741
+ ```
742
+
743
+ ## Block Byte Arrays
744
+
745
+ Block byte arrays use the `>` introducer.
746
+ Each line may hold hex chunks and comments.
747
+
748
+ At root level, hex may appear on the same line after `> `.
749
+
750
+ [bytearray-block-basic.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-block-basic.yay)
751
+ ```yay
752
+ > b0b5
753
+ c0ff
754
+ ```
755
+
756
+ [bytearray-block-basic.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-block-basic.py)
757
+ ```python
758
+ bytes.fromhex("b0b5c0ff")
759
+ ```
760
+
761
+ [bytearray-block-comment-only.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-block-comment-only.yay)
762
+ ```yay
763
+ > # header comment
764
+ b0b5 c0ff
765
+ ```
766
+
767
+ [bytearray-block-comment-only.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-block-comment-only.py)
768
+ ```python
769
+ bytes.fromhex("b0b5c0ff")
770
+ ```
771
+
772
+ [bytearray-block-hex-and-comment.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-block-hex-and-comment.yay)
773
+ ```yay
774
+ > b0b5 # first chunk
775
+ c0ff # second chunk
776
+ ```
777
+
778
+ [bytearray-block-hex-and-comment.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-block-hex-and-comment.py)
779
+ ```python
780
+ bytes.fromhex("b0b5c0ff")
781
+ ```
782
+
783
+ In property context, `>` must be followed only by a comment or newline.
784
+
785
+ [bytearray-block-property.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-block-property.yay)
786
+ ```yay
787
+ data: >
788
+ b0b5 c0ff
789
+ eefa cade
790
+ ```
791
+
792
+ [bytearray-block-property.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-block-property.py)
793
+ ```python
794
+ {"data": bytes.fromhex("b0b5c0ffeefacade")}
795
+ ```
796
+
797
+ [bytearray-block-property-comment.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-block-property-comment.yay)
798
+ ```yay
799
+ data: > # raw bytes
800
+ b0b5 c0ff
801
+ ```
802
+
803
+ [bytearray-block-property-comment.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-block-property-comment.py)
804
+ ```python
805
+ {"data": bytes.fromhex("b0b5c0ff")}
806
+ ```
807
+
808
+ ## Inline Byte Arrays
809
+
810
+ Binary data is written as hexadecimal inside angle brackets.
811
+ Hexadecimal must be lowercase.
812
+
813
+ [bytearray-inline-empty.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-inline-empty.yay)
814
+ ```yay
815
+ <>
816
+ ```
817
+
818
+ [bytearray-inline-empty.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-inline-empty.py)
819
+ ```python
820
+ b''
821
+ ```
822
+
823
+ [bytearray-inline-even.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-inline-even.yay)
824
+ ```yay
825
+ <b0b5c0ffeefacade>
826
+ ```
827
+
828
+ [bytearray-inline-even.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-inline-even.py)
829
+ ```python
830
+ bytes.fromhex("b0b5c0ffeefacade")
831
+ ```
832
+
833
+ [bytearray-inline-named.yay](https://github.com/kriskowal/yay/blob/main/test/yay/bytearray-inline-named.yay)
834
+ ```yay
835
+ data: <b0b5c0ffeefacade>
836
+ ```
837
+
838
+ [bytearray-inline-named.py](https://github.com/kriskowal/yay/blob/main/test/py/bytearray-inline-named.py)
839
+ ```python
840
+ {"data": bytes.fromhex("b0b5c0ffeefacade")}
841
+ ```
842
+
843
+ ## Error Handling
844
+
845
+ Errors include line and column numbers for debugging:
846
+
847
+ ```python
848
+ import libyay as yay
849
+ from libyay import YayError, YaySyntaxError
850
+
851
+ try:
852
+ data = yay.loads('invalid: [')
853
+ except YaySyntaxError as e:
854
+ print(f"Syntax error at line {e.line}, column {e.col}: {e}")
855
+ except YayError as e:
856
+ print(f"YAY error: {e}")
857
+ ```
858
+
859
+ ## Whitespace Rules
860
+
861
+ YAY has strict whitespace rules that the parser enforces:
862
+
863
+ - Two spaces for indentation (tabs are illegal)
864
+ - No trailing spaces on lines
865
+ - Exactly one space after `:` in key-value pairs
866
+ - Exactly one space after `,` in inline arrays/objects
867
+ - No spaces after `[` or `{`, or before `]` or `}`
868
+ - No space before `:` in keys
869
+
870
+ ## Running Tests
871
+
872
+ ```bash
873
+ cd python
874
+ python -m pytest test_yay.py
875
+ ```
876
+
877
+ The test runner uses fixture files from `../test/`.
878
+ Files with `.yay` extension contain YAY input.
879
+ Files with `.py` extension contain expected Python output.
880
+
881
+ ## References
882
+
883
+ Examples in this document pay homage to:
884
+
885
+ - The Hitchhiker's Guide to the Galaxy (Douglas Adams)
886
+ - Monty Python and the Holy Grail
887
+ - Monty Python's Flying Circus ("Dead Parrot" sketch)
888
+ - Galaxy Quest
889
+ - Spaceballs
890
+ - Tommy Tutone ("867-5309/Jenny")
891
+ - The Tau Manifesto
892
+
893
+ ## License
894
+
895
+ Apache 2.0
896
+
897
+ Copyright (C) 2026 Kris Kowal