summaryrefslogtreecommitdiff
path: root/site/spec.html
blob: 0cc88b4fa81c76621f4094e26f4c0ed6006d4af1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta content="width=device-width,initial-scale=1" name="viewport">
	<style>
	td, th {
		border: 2px solid black;
		padding: 0.5em;
	}
	table {
		border-collapse: collapse;
	}
	</style>
	<title>POM Language Specification</title>
	<link rel="icon" href="data:,"><!--TODO-->
</head>

<body>
<p>
	<a href="/index.html">POM homepage</a>
</p>
<h1>POM Language Specification, v. 0.1.0</h1>
<h2>Introduction</h2>
<p>
	POM is a “markup” language, primarily intended for software configuration,
	and designed to be easy to parse without any third-party libraries
	(e.g. for looking up Unicode classes or matching regular expressions),
	while still being terse and legible.
	The POM specification is quite strict, to avoid cases where dubious files can
	be accepted by some parsers while being rejected by others.
</p>
<p>
	Every file describes a <i>configuration</i>, which is a mapping from keys to values.
	A <i>key</i> is a string consisting of <i>components</i> separated by dots (<code>.</code>).
	A <i>value</i> is a string whose interpretation is entirely decided by the application.
	Notably there is no distinction in POM’s syntax between, say,
	the number <code>5</code> and the string <code>5</code>.
	A configuration, such as the one obtained from the POM file
</p>
<pre><code>[ingredients.sugar]
amount = 50&nbsp;g
type = brown

[ingredients.flour]
amount = 100&nbsp;g
type = all-purpose

[baking]
temperature = 150&nbsp;°C
time = 35&nbsp;min
</code></pre>
<p>
	can either be seen as a simple mapping from keys to values:
</p>
<table>
	<thead>
		<tr><th>Key</th><th>Value</th></tr>
	</thead>
	<tbody>
		<tr><td>ingredients.sugar.amount</td><td>50&nbsp;g</td></tr>
		<tr><td>ingredients.sugar.type</td><td>brown</td></tr>
		<tr><td>ingredients.flour.amount</td><td>100&nbsp;g</td></tr>
		<tr><td>ingredients.flour.type</td><td>all-purpose</td></tr>
		<tr><td>baking.temperature</td><td>150&nbsp;°C</td></tr>
		<tr><td>baking.time</td><td>35&nbsp;min</td></tr>
	</tbody>
</table>
<p>
	or a tree of keys, with a value associated to each leaf node:
</p>
<div style="text-align:center;">
	<svg
		viewBox="-281 0 500 200"
		style="width:80%;max-width:600px;"
		xmlns="http://www.w3.org/2000/svg">
		<style>
			text { text-anchor: middle; }
			rect { stroke: black; fill: none; }
			line { stroke: black; stroke-width: 1.5; }
		</style>
		<rect x="-30" y="6" width="60" height="20" />
		<text x="0" y="20" font-size="12">(root)</text>
		<line x1="-20" y1="26" x2="-118" y2="46" />
		<line x1="20" y1="26" x2="118" y2="46" />
		<g transform="translate(-118 46)">
			<rect x="-45" y="0" width="90" height="20" />
			<text x="0" y="14" font-size="12">ingredients</text>
			<line x1="-20" y1="20" x2="-75" y2="54" />
			<line x1="20" y1="20" x2="75" y2="54" />
			<g transform="translate(-75 54)">
				<rect x="-25" y="0" width="50" height="20" />
				<text x="0" y="14" font-size="12">sugar</text>
				<line x1="-10" y1="20" x2="-43" y2="40" />
				<line x1="10" y1="20" x2="43" y2="40" />
				<g transform="translate(-43 40)">
					<rect x="-40" y="0" width="80" height="36" />
					<text x="0" y="14" font-size="12">type</text>
					<text x="0" y="28" font-size="12">brown</text>
				</g>
				<g transform="translate(43 40)">
					<rect x="-40" y="0" width="80" height="36" />
					<text x="0" y="14" font-size="12">amount</text>
					<text x="0" y="28" font-size="12">50&nbsp;g</text>
				</g>
			</g>
			<g transform="translate(75 54)">
				<rect x="-25" y="0" width="50" height="20" />
				<text x="0" y="14" font-size="12">flour</text>
				<line x1="-10" y1="20" x2="-15" y2="40" />
				<line x1="10" y1="20" x2="71" y2="40" />
				<g transform="translate(-15 40)">
					<rect x="-40" y="0" width="80" height="36" />
					<text x="0" y="14" font-size="12">type</text>
					<text x="0" y="28" font-size="12">all-purpose</text>
				</g>
				<g transform="translate(71 40)">
					<rect x="-40" y="0" width="80" height="36" />
					<text x="0" y="14" font-size="12">amount</text>
					<text x="0" y="28" font-size="12">100&nbsp;g</text>
				</g>
			</g>
		</g>
		<g transform="translate(118 46)">
			<rect x="-45" y="0" width="90" height="20" />
			<line x1="-20" y1="20" x2="-50" y2="40" />
			<line x1="20" y1="20" x2="50" y2="40" />
			<text x="0" y="14" font-size="12">baking</text>
			<g transform="translate(-50 40)">
				<rect x="-45" y="0" width="90" height="36" />
				<text x="0" y="14" font-size="12">temperature</text>
				<text x="0" y="30" font-size="12">150&nbsp;°C</text>
			</g>
			<g transform="translate(50 40)">
				<rect x="-45" y="0" width="90" height="36" />
				<text x="0" y="14" font-size="12">time</text>
				<text x="0" y="30" font-size="12">35&nbsp;min</text>
			</g>
		</g>
	</svg>
</div>
<h2>Error handling</h2>
<p>
	All error conditions are described in this specification.
	A general-purpose POM parser should not reject a file in any other case,
	outside of exceptional circumstances such as running out of memory.
	When an error occurs, it should be reported, ideally with information
	about the file name and line number, and the file must be entirely rejected
	(i.e. parsers must not attempt to preserve only the correct parts of an erroneous file).
	Warnings may also be issued according to the judgment of the parser author.
</p>
<h2>Text encoding</h2>
<p>
	All POM files are encoded using UTF-8. Both LF and CRLF line endings may be used (see below).
	If invalid UTF-8 is encountered, including overlong sequences and UTF-16
	surrogate halves (U+D800-DFFF), an error occurs.
</p>
<h2>Valid keys/values</h2>
<p>
	Keys in a POM file may contain the following characters
</p>
<ul>
	<li>
		The ASCII characters <code>a</code><code>z</code>, <code>A</code><code>Z</code>,
		<code>0</code><code>9</code>, as well as each of
		<code>./-*_</code>.
	</li>
	<li>
		Any non-ASCII Unicode scalar value (U+008010FFFF, but not U+D800–U+DFFF).
	</li>
</ul>
<p>
	A non-empty string containing only these characters is a valid key
	if and only if it does not start or end with a dot
	and does not contain two dots in a row (<code>..</code>).
</p>
<p>
	Any string of non-zero Unicode scalar values (U+000110FFFF, but not U+D800–U+DFFF)
	is a valid value.
</p>
<h2>Parsing</h2>
<p>
	If a “byte order mark” of <code>EF BB BF</code> appears at the start of the file,
	it is ignored.
	Every carriage return character (U+000D) which immediately
	precedes a line feed (U+000A) is deleted.
	Then, if any control characters in the range U+0000 to U+001F
	other than the line feed and horizontal tab (U+0009) are
	present in the file, an error occurs.
</p>
<p>
	The <i>current-section</i> is a string variable which should be maintained during parsing.
	It is initally equal to the empty string.
</p>
<p>
	An <i>accepted-space</i> is either a space (U+0020) or horizontal tab (U+0009) character.
</p>
<p>
	Parsing now proceeds line-by-line, with lines being delimited by line feed characters.
	For each line:
</p>
<ol>
	<li>Any accepted-spaces that appear at the start of the line are removed.</li>
	<li>
		If the line begins with <code>#%disable warnings</code> or <code>#%enable warnings</code>,
		warnings should be disabled/enabled if any are implemented.
	</li>
	<li>
		If the line is empty or begins with <code>#</code>,
		parsing proceeds to the next line.
	</li>
	<li>
		If the line begins with <code>[</code>, it is interpreted as a <i>section header</i>.
		In this case:
		<ol>
			<li>
				If the line does not end with <code>]</code> optionally succeeded
				by any number of accepted-spaces, an error occurs.
			</li>
			<li>
				The current-section is set to the text in between
				the initial <code>[</code> and final <code>]</code>
				(white space after the <code>[</code> and before the
				<code>]</code> is <em>not</em> trimmed).
			</li>
			<li>
				If the new current-section is not empty and not a valid key (see above), an error occurs.
			</li>
		</ol>
	</li>
	<li>
		Otherwise, the line is now interpreted as a key-value assignment. In this case:
		<ol>
			<li>If the line does not contain an equal sign (<code>=</code>), an error occurs.</li>
			<li>
				The <i>relative-key</i> is the text preceding the <code>=</code>,
				not including any space or horizontal tab characters
				immediately before the <code>=</code>.
			</li>
			<li>
				If the relative-key is not a valid key (see above), an error occurs.
			</li>
			<li>
				Let <i>c</i> be the first character after the <code>=</code> and any succeeding accepted-spaces.
			</li>
			<li>
				If <i>c</i> is <code>"</code> (U+0022 QUOTATION MARK) or <code>`</code> (U+0060 GRAVE ACCENT),
				the value is <i>quoted</i>, and spans from the first character after <i>c</i>
				to the next unescaped instance of <i>c</i> in the file (which may be on a different line).
				In this case,
				<ol>
					<li>
						Escape sequences are processed as described below.
					</li>
					<li>
						Following the closing instance of <i>c</i>, there must be no characters other
						than accepted-spaces until the next line feed or the end of the file;
						otherwise an error occurs.
					</li>
				</ol>
			</li>
			<li>
				Otherwise, the value is <i>unquoted</i>. In this case,
				<ol>
					<li>accepted-spaces at the end of the line are removed.</li>
					<li>
						The value is the exact text starting from <i>c</i> and going
						to the end of the line (escape sequences are not processed).
					</li>
				</ol>
			</li>
			<li>If the value is not a valid value (i.e. it contains a null character), an error occurs.</li>
			<li>
				The key is equal to the relative-key if the current-section is empty; otherwise, it is equal to
				the concatenation of current-section, a dot, and the relative-key.
			</li>
			<li>
				The key is assigned to the value.
			</li>
		</ol>
	</li>
</ol>

<h2>Escape sequences</h2>

<p>
	POM defines the following escape sequences, which may appear in quoted values.
	If a backslash character occurs in a quoted value but does not form
	a defined escape sequence, an error occurs.
</p>

<table>
	<thead>
		<tr><th>Escape sequence</th><th>Value</th></tr>
	</thead>
	<tbody>
		<tr><td><code>\n</code></td><td>Line feed (U+000A)</td></tr>
		<tr><td><code>\r</code></td><td>Carriage return (U+000D)</td></tr>
		<tr><td><code>\t</code></td><td>Horizontal tab (U+0009)</td></tr>
		<tr><td><code>\\</code></td><td>Literal <code>\</code> (U+005C)</td></tr>
		<tr><td><code>\"</code></td><td>Literal <code>"</code> (U+0022)</td></tr>
		<tr><td><code>\'</code></td><td>Literal <code>'</code> (U+0027)</td></tr>
		<tr><td><code>\`</code></td><td>Literal <code>`</code> (U+0060)</td></tr>
		<tr><td><code>\,</code></td><td>Literal <code>\,</code> (U+005C U+002C)</td></tr>
		<tr><td><code>\x</code><i>NM</i></td>
			<td>ASCII character with code <i>NM</i>,
			<br>interpreted as hexadecimal
			<br>(must be in the range 01–7F).</td>
		</tr>
		<tr><td><code>\u{</code><i>digits</i><code>}</code></td>
			<td>Unicode code point <i>digits</i>,<br>
				interpreted as hexadecimal.<br>
				<i>digits</i> must be 1–6 characters long,<br>
				and may contain leading zeros,<br>
				but must not be zero and<br>
				must not be a UTF-16 surrogate<br>
				half D800–DFFF.</td>
		</tr>
	</tbody>
</table>

<h2>Lists</h2>
<p>
	Although POM does not have a way of specially designating a value as being a list,
	there is a recommended syntax for encoding them. Specifically, a value can be treated as a list
	by first splitting it into comma-delimited parts, treating <code>\,</code> as a literal comma
	in a list entry and <code>\\</code> as a literal backslash,
	then removing any accepted-spaces surrounding list entries.
</p>
<p>
	List entries may be empty, but if the last entry in a list is empty, it is removed
	(if there are two or more empty entries at the end of a list, only one is removed).
	As a consequence, an empty string is considered to be an empty list.
</p>
<p>
	If a list’s order is irrelevant and it might be large or benefit from labelling its entries,
	a key prefix should be used instead
	(see the <code>ingredients</code> “list” in the opening example).
</p>
<h3>Examples</h3>
<p>
	The following lines describe 3-entry lists.
</p>
<table>
	<thead>
		<tr><th>POM line</th><th>Entry 1</th><th>Entry 2</th><th>Entry 3</th></tr>
	</thead>
	<tbody>
		<tr>
			<td><code>fonts = monospace, sans-serif, serif</code></td>
			<td><code>monospace</code></td>
			<td><code>sans-serif</code></td>
			<td><code>serif</code></td>
		</tr>
		<tr>
			<td><code>files = " foo.txt, weird\,name,z "</code></td>
			<td><code>foo.txt</code></td>
			<td><code>weird,name</code></td>
			<td><code>z</code></td>
		</tr>
		<tr>
			<td><code>things = \,,,76</code></td>
			<td><code>,</code></td>
			<td><code></code></td>
			<td><code>76</code></td>
		</tr>
		<tr>
			<td><code>empties = ,,,,</code></td>
			<td><code></code></td>
			<td><code></code></td>
			<td><code></code></td>
		</tr>
		<tr>
			<td><code>escapees = \\,\a,\,</code></td>
			<td><code>\</code></td>
			<td><code>\a</code></td>
			<td><code>,</code></td>
		</tr>
	</tbody>
</table>


<h2>Merging configurations</h2>
<p>
	A configuration <i>B</i> can be <i>merged into</i> another configuration <i>A</i>
	by parsing both of them and setting the value associated with a key <i>k</i> to be
</p>
<ol>
	<li>The value associated with <i>k</i> in <i>B</i>, if any.</li>
	<li>Otherwise, the value associated with <i>k</i> in <i>A</i>, if any.</li>
</ol>
<p>
	(Likewise, an ordered series of configurations <i>A<sub>1</sub></i>, …, <i>A<sub>n</sub></i>
	can be merged by merging <i>A<sub>2</sub></i> into <i>A<sub>1</sub></i>,
	then <i>A<sub>3</sub></i> into the resulting configuration, etc.)
</p>
<p>
	This is useful, for example, when you want to have a global configuration for
	a piece of software installed on a multi-user machine where individual settings
	can be overriden by each user (in this case, the user configuration would
	be merged into the global configuration).
</p>

<h2>Schemas</h2>
<p>
	A <i>schema</i> is a POM file that describes how other POM files should be formatted
	(i.e. what keys they should include, and what values they can be associated with).
	A configuration can be said to <i>follow</i> a schema
	when it obeys all of the schema’s rules.
</p>
<p>
	POM’s schema format is not powerful to enforce all possible restrictions;
	some will have to be enforced by the application.
</p>
<p>
	Every schema key must be of the form <i>k</i><code>.</code><i>rule</i>, where
	<i>k</i> is a valid key, and <i>rule</i> is one of the rule names listed below.
</p>
<p>
	For any valid key <i>k</i> the value of the rule <i>rule</i> for <i>k</i> is determined as follows:
</p>
<ul>
	<li>Break <i>k</i> down into its <i>n</i> components.</li>
	<li>For each schema key <i>s</i>.<i>rule</i> where <i>s</i> has <i>n</i> components:
		<ul>
			<li>Match up the components of <i>s</i> with the components of <i>k</i>.</li>
			<li>
				If every component of <i>s</i> is equal to <code>*</code> or the corresponding component
				of <i>k</i>, add <i>s</i>.<i>rule</i> to the <i>candidate-list</i>.
			</li>
	</ul></li>
	<li>If the candidate-list is empty, use the default value for the rule.</li>
	<li>If the candidate-list has exactly one schema key, use the value of that schema key.</li>
	<li>
		Otherwise select the schema key in the candidate-list with the
		latest first <code>*</code>-component (in terms of component index),
		preferring keys with no <code>*</code>,
		breaking ties by the latest second <code>*</code>-component,
		preferring keys with only one <code>*</code>, etc. Use its value.
	</li>
</ul>

<h3>Example</h3>
<p>
Given the following schema:
</p>
<pre><code>
*.*.id.type = Int
vehicle.*.id.type = UInt
*.truck.id.type = Float
vehicle.car.id.type = String
</code></pre>
<p>
The value of the <code>type</code> rule for vehicle.car.id is String,
for vehicle.truck.id is UInt,
for my.truck.id is Float,
for my.car.id is Int,
and for my.nephews.car.id is String (no schema key matches, so the default of String is used).
</p>

<h3><code>type</code> rule</h3>
<p>
	Default: <code>String</code>.
</p>
<p>
	This describes what values a key is allowed to be associated with.
	The following types are defined:
</p>
<ul>
	<li><code>String</code> — accepts any value</li>
	<li><code>None</code> — accepts an unset value (special—see below)</li>
	<li><code>Empty</code> — accepts an empty value</li>
	<li><code>Bool</code> — accepts <code>true</code>, <code>on</code>, <code>yes</code>,
		<code>false</code>, <code>off</code>, <code>no</code> (case-sensitive).</li>
	<li><code>UInt</code> — accepts any unsigned integer that fits in 63 [sic] bits,
	written in decimal or <code>0x</code> or <code>0X</code>-prefixed hexadecimal.
		A leading <code>+</code> is permitted, but <code>-0</code> is not.
		Only 63 bits are allowed to support languages (Java) with no 64-bit unsigned integers.</li>
	<li><code>Int</code> — accepts any (two’s complement) signed integer that fits in 64 bits,
		written in decimal or <code>0x</code> or <code>0X</code>-prefixed hexadecimal.
		A leading <code>+</code> (or, of course, <code>-</code>) is permitted.</li>
	<li><code>Float</code> —
		A floating-point number, written in ordinary decimal
		(e.g. <code>-1.234</code>, <code>7.</code>, <code>265</code>) or in scientific notation
		(e.g. <code>3e5</code>, <code>3.E-5</code>, <code>-3.7e+5</code>).
		A leading <code>+</code> (or, of course, <code>-</code>) is permitted.
	<li>
		<code>'</code><i>value</i><code>'</code> —
		accepts the literal value <i>value</i>.
		<i>value</i> cannot contain a literal apostrophe <code>'</code>.
	</li>
	<li>
		<i>T</i><code> | </code><i>U</i>, where <i>T</i>, <i>U</i> are types
		— accepts a value of type <i>T</i> or <i>U</i>.
	</li>
	<li>
		<code>Optional[</code><i>T</i><code>]</code>, where <i>T</i> is a type
		— equivalent to <i>T</i><code> | None</code>.
	</li>
	<li>
		<code>List[</code><i>T</i><code>]</code>, where <i>T</i> is a type
		— accepts a list of entries of type <i>T</i> (see description
		of lists above). Nested lists are not permitted.
	</li>
</ul>
<p>
	A type may optionally have accepted-spaces on either side; this does not change its meaning.
</p>

<h3><code>allow_unknown</code> rule</h3>
<p>
		Default: inherited from parent (i.e. if <i>k</i> = <i>j</i><code>.</code><i>component</i>,
		look up the <code>allow_unknown</code> rule for <i>j</i>),
		or <code>yes</code> if <i>k</i> has no parent (does not contain a dot).
</p>
<p>
	This describes whether or the key <i>k</i> is allowed if it is not described in the schema.
	It must be set to either <code>yes</code> or <code>no</code>.
</p>
<p>
	If a key is encountered in a configuration
	and the value of its <code>allow_unknown</code> rule is <code>no</code>,
	and it has no matching <code>type</code>, <code>maxlength</code>, or <code>default</code> rule,
	the configuration does not follow the schema.
</p>
<h3><code>min</code>, <code>max</code> rules</h3>
<p>
	This schema key’s value sets the minimum/maximum value for the key’s value.
	This may only be set if <code>type</code> explicitly allows numeric values
	(i.e. it contains a type <code>Int</code>/<code>UInt</code>/<code>Float</code>).
</p>
<h3><code>maxlength</code> rule</h3>
<p>
	This schema key’s value must be a non-negative integer no greater than 2<sup>31</sup>−1,
	written in decimal with no leading sign.
	It specifies that the value of a key can be no longer than  that number of UTF-8 bytes.
</p>
<h3><code>default</code> rule</h3>
<p>
	Sets the default value for a key.
</p>
<h3>Missing values</h3>
<p>
	If there is a schema key <i>k</i><code>.type</code>, where <i>k</i>
	does not contain any <code>*</code>-components,
	and the type does not allow unset values (<code>None</code>),
	and there is no schema key <i>k</i><code>.default</code>,
	then a configuration must contain the key <i>k</i> to follow the schema.
</p>
<p>
	Additionally, if there is a schema key <i>j</i><code>.*.</code><i>k</i><code>.type</code>
	that does not allow unset values and no correspoding <code>default</code> schema key,
	where <i>k</i> does not contain any <code>*</code>-components, then a configuration
	containing a key <i>x</i> matching <i>j</i><code>.*</code> must also contain
	the key <i>x</i><code>.</code><i>k</i>.
</p>

<h2>Extensions</h2>
<p>
	If needed for a particular domain, an parser may accept an extended form of the POM syntax.
	Ideally, extensions should use lines containing invalid key characters (e.g. <code>!&amp;%</code>)
	before the <code>=</code> (if any)
	so that there is no ambiguity, and the file cannot be parsed without the extension.
</p>

<h2>API recommendations</h2>
<p>
	The following functions are (lightly) recommended
	in any general-purpose library for parsing POM files
	(their exact names/signatures can be changed to fit the style of the language).
</p>
<ul>
	<li>
		<code>load(file: File) -&gt; Configuration</code><br>
		Load a configuration from a file.
	</li>
	<li>
		<code>load_string(string: String) -&gt; Configuration</code><br>
		Load a configuration from a string
		(may be overloaded with <code>load</code> if language supports it).
	</li>
	<li>
		<code>load_path(path: String) -&gt; Configuration</code><br>
		Convenience function for loading by path.
	</li>
	<li>
		<code>print(conf: Configuration)</code><br>
		Print <code>key = value</code> on a separate line for each key in <code>conf</code>,
		sorted alphabetically by key. The value format doesn’t need to match POM’s format exactly,
		since this function should only be used for debugging anyways.
	</li>
	<li>
		<code>has(conf: Configuration, key: String) -&gt; Bool</code><br>
		Returns whether <code>key</code> is associated with any value.
	</li>
	<li>
		<code>keys(conf: Configuration) -&gt; List&lt;String&gt;</code><br>
		Returns a list of all unique first components of keys in the configuration,
		in an arbitrary order.
	</li>
	<li>
		<code>subkeys(conf: Configuration, key: String) -&gt; List&lt;String&gt;</code><br>
		Equivalent to <code>keys(section(conf, key))</code> but may be implemented more efficiently.
	</li>
	<li>
		<code>location(conf: Configuration, key: String) -&gt; Optional&lt;Location&gt;</code><br>
		Location of the definition of <code>key</code> in the configuration (file and line number).
		Useful for reporting invalid values when
		the format of valid values can’t be described by a schema type.
		If a key <i>k</i> isn’t given a value in the configuration, but a key of the form
		<i>k</i><code>.</code><i>j</i> is, then the
		location of the definition of an arbitrary such key
		should be considered the location of <i>k</i>.
	</li>
	<li>
		<code>get(conf: Configuration, key: String) -&gt; Optional&lt;String&gt;</code><br>
		Get value associated with <code>key</code>, if any exists.
	</li>
	<li>
		<code>get_or_default(conf: Configuration, key: String, default: String) -&gt; String</code><br>
		Get value associated with <code>key</code>, if any exists, returning <code>default</code> if not.
	</li>
	<li>
		<code>get_int(conf: Configuration, key: String) -&gt; Optional&lt;Int&gt;</code><br>
		<code>get_int_or_default(conf: Configuration, key: String, default: Int) -&gt; Int</code><br>
		Get value associated with <code>key</code>,
		if any exists, and parse it as a signed 64-bit integer,
		following the <code>Int</code> schema type described above
		(returning <code>default</code> if the key doesn’t exist).
		Returns an error if the key exists but its value is not a valid signed 64-bit integer.
	</li>
	<li>
		<code>get_uint(conf: Configuration, key: String) -&gt; Optional&lt;UInt&gt;</code><br>
		<code>get_uint_or_default(conf: Configuration, key: String, default: UInt) -&gt; UInt</code><br>
		Get value associated with <code>key</code>, if any exists,
		and parse it as an unsigned 63-bit [sic] integer,
		following the <code>UInt</code> schema type described above
		(returning <code>default</code> if the key doesn’t exist).
		Returns an error if the key exists but its value is not a valid unsigned 63-bit integer.
	</li>
	<li>
		<code>get_float(conf: Configuration, key: String) -&gt; Optional&lt;Float&gt;</code><br>
		<code>get_float_or_default(conf: Configuration, key: String, default: Float) -&gt; Float</code><br>
		Get value associated with <code>key</code>, if any exists,
		and parse it as a 64-bit IEEE-754 double precision
		floating-point number, following the <code>Float</code> schema type described above
		(returning <code>default</code> if the key doesn’t exist).
		Returns an error if the key exists but its value is not a valid floating-point number.
	</li>
	<li>
		<code>get_bool(conf: Configuration, key: String) -&gt; Optional&lt;Bool&gt;</code><br>
		<code>get_bool_or_default(conf: Configuration, key: String, default: Bool) -&gt; Bool</code><br>
		Get value associated with <code>key</code>, if any exists, and parse it as a boolean,
		taking  <code>true</code>, <code>on</code>, <code>yes</code> to be <code>true</code>, and
		<code>false</code>, <code>off</code>, <code>no</code> to be <code>false</code> (case-sensitive).
		Returns an error if the key exists but is not one of those values.
	</li>
	<li>
		<code>get_list(conf: Configuration, key: String) -&gt; Optional&lt;List&lt;String&gt;&gt;</code><br>
		<code>get_list_or_default(conf: Configuration, key: String, default: List&lt;String&gt;) -&gt; List&lt;String&gt;</code><br>
		Get value associated with <code>key</code>, if any exists, and parse it as a list
		(returning <code>default</code> if the key isn’t present).
	</li>
	<li>
		<code>section(conf: Configuration, key: String) -&gt; Configuration</code><br>
		Get the sub-configuration consisting of the descendants of <code>key</code>
		(i.e. keys starting with <code>key.</code>),
		with the initial <code>key.</code> removed, and their corresponding values.
		Returns an empty configuration if there are no descendants of <code>key</code> defined.
	</li>
	<li>
		<code>check_against_schema(conf: Configuration, schema: Configuration) -&gt; Configuration</code> (<i>optional</i>)<br>
		Check that <code>schema</code>
		is a valid schema and that <code>conf</code> follows it,
		returning an error with detailed information
		if not. If successful, returns a configuration with default values filled out.
	</li>
	<li>
		<code>merge(conf_a: Configuration, conf_b: Configuration) -&gt; Configuration</code><br>
		Returns the result of merging <code>conf_b</code> into <code>conf_a</code>.
	</li>
</ul>

<h2>Examples</h2>
<p>
	This section lists some examples of POM files. For more examples, see the <code>tests/</code>
	directory in the main POM repository.
</p>

<h3>All syntax</h3>
This is a configuration which demonstrates almost all of the syntactic forms of POM.

<pre><code>
title = 'Crème brûlée'
0-*/_description_/*-0 =`A 'beautiful' crème br\u{FB}l\u{0000e9}e recipe
that\'s sure to delight your friends!`
author == `Jean\0\\"P." D'Martingale
[ingredients.flour]
	quantity= "100 g"
	type="all-purpose"
[ingredients.sugar]
	quantity		=	   50 g
	type = "br\x6f\u{77}n"
[ingrédients]
	œufs.quantité=3
	œufs.type = "extra large\,farm fresh\\,free-range"
[]
DIRECTIONS.en_CA.version.5 = "
1. Separate the egg yolks from the \"whites\".
2. Mix the yolks in a bowl with the sugar.
…
59. Enjoy!
"
</code></pre>
<p>
This configuration has the following mapping of keys to values:
</p>
<table>
	<thead>
		<tr><th>Key</th><th>Value</th></tr>
	</thead>
	<tbody>
		<tr><td>title</td><td>'Crème brûlée'</td></tr>
		<tr><td>0-*/_description_/*-0</td><td>A 'beautiful' crème brûlée recipe<br>
that's sure to delight your friends!</td></tr>
		<tr><td>author</td><td>= `Jean\0\\"P." D'Martingale</td></tr>
		<tr><td>ingredients.flour.quantity</td><td>100 g</td></tr>
		<tr><td>ingredients.flour.type</td><td>all-purpose</td></tr>
		<tr><td>ingredients.sugar.quantity</td><td>50 g</td></tr>
		<tr><td>ingredients.sugar.type</td><td>brown</td></tr>
		<tr><td>ingrédients.œufs.quantité</td><td>3</td></tr>
		<tr><td>ingrédients.œufs.type</td><td>extra large\,farm fresh\,free-range</td></tr>
		<tr><td>DIRECTIONS.en_CA.version.5</td><td><br>1. Separate the egg yolks from the "whites".<br>
2. Mix the yolks in a bowl with the sugar.<br>
…<br>
59. Enjoy!<br><br></td></tr>
	</tbody>
</table>

<h3>Configuration for a text editor</h3>
<pre><code>
indentation-type = tabs
show-line-numbers = yes
tab-size = 4
font-size = "18"

[file-extensions]
C = .c
Cpp = .cpp, .h, .hpp

[plug-in.edit-over-ssh]
path = ~/misc/edit-over-ssh.so
enabled = yes

[plug-in.edit-over-ssh.settings]
favourite-host = my-web-server

[plug-in.edit-over-ssh.settings.hosts.my-web-server]
address = example.org
port = 22
ssh-key = ~/.ssh/id_ed25519

</code></pre>
<p>
This configuration has the following mapping of keys to values:
</p>
<table>
	<thead>
		<tr><th>Key</th><th>Value</th></tr>
	</thead>
	<tbody>
		<tr><td>indentation-type</td><td>tabs</td></tr>
		<tr><td>show-line-numbers</td><td>yes</td></tr>
		<tr><td>tab-size</td><td>4</td></tr>
		<tr><td>font-size</td><td>18</td></tr>
		<tr><td>file-extensions.C</td><td>.c</td></tr>
		<tr><td>file-extensions.Cpp</td><td>.cpp, .h, .hpp</td></tr>
		<tr><td>plug-in.edit-over-ssh.path</td><td>~/misc/edit-over-ssh.so</td></tr>
		<tr><td>plug-in.edit-over-ssh.enabled</td><td>yes</td></tr>
		<tr><td>plug-in.edit-over-ssh.settings.favourite-host</td><td>my-web-server</td></tr>
		<tr><td>plug-in.edit-over-ssh.settings.hosts.my-web-server.address</td><td>example.org</td></tr>
		<tr><td>plug-in.edit-over-ssh.settings.hosts.my-web-server.port</td><td>22</td></tr>
		<tr><td>plug-in.edit-over-ssh.settings.hosts.my-web-server.ssh-key</td><td>~/.ssh/id_ed25519</td></tr>
	</tbody>
</table>

<h3>Schema for text editor’s configuration</h3>
<p>
	Here is a schema which a text editor might use.
	The example text editor configuration above follows it.
</p>
<pre><code>
# don't allow unknown keys by default
*.allow_unknown = no

# must put this in your config! I can't make the decision for you!
indentation-type.type = 'spaces' | 'tabs'

show-line-numbers.type = Bool
show-line-numbers.default = on

[tab-size]
type = UInt
min = 1
default = 4

[font-size]
# allow fractional font sizes; why not!
type = Float
min = 0.5
max = 100
default = 14

[plug-in.*]
enabled.type = Bool
enabled.default = yes
path.type = String
# everyone be nice to the Microsoft Windows®
path.maxlength = 260
# allow arbitrary keys in plug-ins' settings
settings.allow_unknown = yes

[file-extensions]
*.type = List[String]
C.default = .c, .h
Cpp.default = .cpp, .hpp, .cc, .hh
C-sharp.default = .cs
</code></pre>

<h3>Errors</h3>
<p>
This section lists some erroneous lines that might appear in a POM file:
</p>
<pre><code>
# Invalid key character '!'
cool-key! = 23
# Invalid key character ' '
fun times = yes
# Missing equals
music is on
# No closing ]
[my.section
# Invalid key character ' '
[ my.section ]
# Invalid escape sequence "\?"
no_trigraph = "a?\?=b"
# Invalid escape sequence "\xCE" — even though "\xCE\x92" is valid UTF-8.
#     ("\u{392}" should be used instead)
capital_beta = "\xCE\x92"
# Invalid escape sequence "\x00" / Invalid character in value (null character)
C_string = "Hello, world!\x00"
# Stray characters after closing "
name = "Andy" B
# Duplicate key 'tab-size'
tab-size = 4
tab-size = 8
</code></pre>

</body>

</html>