@@ -117,10 +117,11 @@ Being a node-oriented language means that the real core component of any KDL
117
117
document is the "node". Every node must have a name, which must be a
118
118
String ({{string}}).
119
119
120
- The name may be preceded by a Type Annotation ({{type-annotation}}) to further
121
- clarify its type, particularly in relation to its parent node. (For example,
122
- clarifying that a particular `date` child node is for the _publication_ date,
123
- rather than the last-modified date, with `(published)date`.)
120
+ The name may be preceded by a Prefix Type Annotation
121
+ ({{prefix-type-annotation}}) to further clarify its type, particularly in
122
+ relation to its parent node. (For example, clarifying that a particular `date`
123
+ child node is for the _publication_ date, rather than the last-modified date,
124
+ with `(published)date`.)
124
125
125
126
Following the name are zero or more Arguments ({{argument}}) or
126
127
Properties ({{property}}), separated by either whitespace ({{whitespace}}) or a
@@ -247,23 +248,42 @@ Values _MUST_ be either Arguments ({{argument}}) or values of
247
248
Properties ({{property}}). Only String ({{string}}) values may be used as
248
249
Node ({{node}}) names or Property ({{property}}) keys.
249
250
250
- Values (both as arguments and in properties) _MAY_ be prefixed by a single
251
- Type Annotation ({{type-annotation}}).
251
+ Values (both as arguments and in properties) _MAY_ include a single Type
252
+ Annotation ({{type-annotation}}).
252
253
253
254
# # Type Annotation
254
255
255
- A type annotation is a prefix to any Node Name ({{node}}) or Value ({{value}}) that
256
- includes a _suggestion_ of what type the value is _intended_ to be treated as,
257
- or as a _context-specific elaboration_ of the more generic type the node name
258
- indicates.
259
-
260
- Type annotations are written as a set of `(` and `)` with a single
261
- String ({{string}}) in it. It may contain Whitespace after the `(` and before
262
- the `)`, and may be separated from its target by Whitespace.
256
+ A type annotation is a String ({{string}}) value attached to any Node Name
257
+ ({{node}}) or Value ({{value}}) that includes a _suggestion_ of what type the
258
+ value is _intended_ to be treated as, or as a _context-specific elaboration_ of
259
+ the more generic type the node name indicates.
263
260
264
261
KDL does not specify any restrictions on what implementations might do with
265
262
these annotations. They are free to ignore them, or use them to make decisions
266
- about how to interpret a value.
263
+ about how to interpret a value. That said, KDL does reserve certain well-known
264
+ strings for what would be their intended purpose, for the sake of
265
+ interoperability ({{reserved-type-annotations}}).
266
+
267
+ There are two kinds of Type Annotation syntaxes in KDL : Prefix Type Annotations
268
+ ({{prefix-type-annotation}}) and Suffix Type Annotations
269
+ ({{suffix-type-annotation}}).
270
+
271
+ # ## Examples
272
+
273
+ ~~~kdl
274
+ node 123u8
275
+ node 0#b 20b 50GiB
276
+ node prop=(regex).*
277
+ (published)date "1970-01-01"
278
+ (contributor)person name="Foo McBar"
279
+ ~~~
280
+
281
+ # ## Prefix Type Annotation
282
+
283
+ Prefix Type Annotations are written as a set of `(` and `)` with a single String
284
+ ({{string}}) in it. It may contain Whitespace after the `(` and before the `)`,
285
+ and may be separated from its target by Whitespace. Unlike the other annotation
286
+ types, any String type may be used.
267
287
268
288
# ## Suffix Type Annotation
269
289
@@ -272,38 +292,38 @@ type annotation as a "suffix", instead of prepending it between `(` and `)`.
272
292
This makes it possible to, for example, write `10px`, `10.5%`, `512GiB`, etc.,
273
293
which are equivalent to `(px)10`, `(%)5`, and `(GiB)512`, respectively.
274
294
275
- There are two kinds of Suffix Type Annotations ({{suffix-type-annotation}})
276
- available : Bare Suffix Type Annotations ({{bare-suffix-type-annotation}})s and
277
- Explicit Suffix Type Annotations ({{explicit-suffix-type-annotation}}).
278
-
279
295
Most suffixes can be appended directly to the number (a Bare Suffix Type
280
296
Annotation ({{bare-suffix-type-annotation}})), as shown in the previous
281
297
paragraph. To avoid parsing ambiguity, there are some restrictions on this; an
282
298
Explicit Suffix Type Annotation ({{explicit-suffix-type-annotation}}) avoids all
283
299
these restrictions by using an additional `#` to explicitly indicate it. For
284
- example, `10.0u8 ` is invalid, but `10.0#u8 ` is valid and equivalent to
285
- ` (u8)10. 0` . See Bare Suffix Type Annotation ({{bare-suffix-type-annotation}})
300
+ example, `0bytes ` is invalid, but `0#bytes ` is valid and equivalent to
301
+ ` (bytes) 0` . See Bare Suffix Type Annotation ({{bare-suffix-type-annotation}})
286
302
for the full list of restrictions.
287
303
288
- An implementation that finds BOTH a parenthesized ({{type-annotation}}) and a
289
- Suffix Type Annotation ({{suffix-type-annotation}}) on the same Number
290
- ({{number}}) MUST yield a syntax error.
304
+ An implementation that finds BOTH a parenthesized Prefix Type Annotation
305
+ ({{prefix-type-annotation}}) and a Suffix Type Annotation
306
+ ({{suffix-type-annotation}}) on the same Number ({{number}}) MUST yield a syntax
307
+ error.
291
308
292
309
Suffixes MUST BE plain Identifier Strings ({{identifier-string}}). No other
293
310
String ({{string}}) syntax is acceptable.
294
311
295
312
# ### Bare Suffix Type Annotation
296
313
297
- When a Value ({{value}}) is a decimal Number ({{number}}) WITHOUT exponential
298
- syntax (`1e+5` etc) (and ONLY a decimal. That is, numbers which do NOT have a
299
- ` 0b ` /`0o`/`0x` prefix with an optional sign), it's possible to append the type
300
- annotation as a suffix directly to the number, without any additional syntax.
314
+ When a Value ({{value}}) is a Number ({{number}}) that meets certain criteria,
315
+ it's possible to append an Identifier String ({{identifier-string}}), and ONLY
316
+ an Identifier String, as a suffix directly to the Number, as its Type Annotation
317
+ ({{type- annotation}}). The criteria are as follows :
301
318
302
- To remove further ambiguity, on top of not being available for non-decimal
303
- prefixes, and for decimals with exponent parts, the suffix Identifier String
304
- ({{identifier-string}}) itself MUST NOT start with any of `.`, `,`, or `_`, as
305
- well as `[eE][-+]?[0-9]?` as part of the exponential restriction above. Note the
306
- optional digit, which is added to prevent typo ambiguity.
319
+ * The Number MUST be a Decimal (that is, it MUST NOT start with `0b`, `0o`, or
320
+ ` 0x` ). Additionally, the tokens `0b`, `0o`, and `0x` MUST be treated as syntax
321
+ errors (incomplete non-decimal numbers).
322
+ * It MUST NOT have an exponent part (e.g. `5.2e+3`).
323
+ * The Identifier String used for the type itself MUST NOT start with either `.` or `,`.
324
+ * As part of the exponential restriction, the suffix MUST NOT match
325
+ ` [eE]([-+]|[0-9])` (e.g. `5.2e+` SHOULD be considered a "bad exponential", and
326
+ MUST NOT parse as `(e+)5.2`).
307
327
308
328
For example, the following are all illegal :
309
329
@@ -312,17 +332,19 @@ For example, the following are all illegal:
312
332
* `0xyz` (starts with reserved hexadecimal prefix)
313
333
* `0b` (starts with reserved binary prefix)
314
334
* `5e+oops` (looks too close to an exponential)
335
+ * `1.2.3-abc` (suffix would start with `.` AND Identifier Strings can't start
336
+ with `.<digit>`)
315
337
316
338
Whereas the following are all legal :
317
339
318
- * `0u8` (aka `(u8)0`)
319
- * `5em` (aka `(em)5`. The `e` is not followed by a digit.)
320
- * `1xyz` (aka `(xyz)1`. No longer starts with `0` as above.)
321
- * `20b` (aka `(b)20`, "20 bytes". No longer starts with just `0` as above.)
340
+ * `0u8` = `(u8)0`
341
+ * `5em` = `(em)5`, the `e` is not followed by a digit.
342
+ * `1xyz` = `(xyz)1`, no longer starts with `0` as above.
343
+ * `20b` = `(b)20`, "20 bytes", no longer starts with just `0` as above.
322
344
323
- If the desired suffix would violate any of the above rules, either regular
324
- parenthetical Type Annotations ({{type-annotation}}) or Explicit Suffix Type
325
- Annotations ({{explicit-suffix-type-annotation}}) may be used.
345
+ If the desired suffix would violate any of the above rules, either Prefix Type
346
+ Annotations ({{prefix- type-annotation}}) or Explicit Suffix Type Annotations
347
+ ({{explicit-suffix-type-annotation}}) may be used.
326
348
327
349
# ### Explicit Suffix Type Annotation
328
350
@@ -338,7 +360,9 @@ Note that, unlike Bare Suffix Type Annotations
338
360
({{number}}) formats (hexadecimal, decimal, octal, and binary). For example,
339
361
` 0x1234#u32` is valid.
340
362
341
- # ## Reserved Type Annotations for Numbers Without Decimal Parts
363
+ # ## Reserved Type Annotations
364
+
365
+ # ### For Numbers Without Decimal Parts
342
366
343
367
Additionally, the following type annotations MAY be recognized by KDL parsers
344
368
and, if used, SHOULD interpret these types as follows.
@@ -364,7 +388,7 @@ Platform-dependent integer types, both signed and unsigned:
364
388
- ` isize`
365
389
- ` usize`
366
390
367
- # ## Reserved Type Annotations for Numbers With Decimal Parts
391
+ # ### For Numbers With Decimal Parts
368
392
369
393
IEEE 754 floating point numbers, both single (32) and double (64) precision :
370
394
@@ -376,7 +400,7 @@ IEEE 754-2008 decimal floating point numbers
376
400
- ` decimal64`
377
401
- ` decimal128`
378
402
379
- # ## Reserved Type Annotations for Strings
403
+ # ### For Strings
380
404
381
405
- `date-time` : ISO8601 date/time format.
382
406
- `time` : " Time" section of ISO8601.
@@ -404,16 +428,6 @@ IEEE 754-2008 decimal floating point numbers
404
428
- `base64` : A Base64-encoded string, denoting arbitrary binary data.
405
429
- `base85` : An [Ascii85](https://en.wikipedia.org/wiki/Ascii85)-encoded string, denoting arbitrary binary data.
406
430
407
- # ## Examples
408
-
409
- ~~~kdl
410
- node 123u8
411
- node 0#b 20b 50GiB
412
- node prop=(regex).*
413
- (published)date "1970-01-01"
414
- (contributor)person name="Foo McBar"
415
- ~~~
416
-
417
431
# # String
418
432
419
433
Strings in KDL represent textual UTF-8 Values ({{value}}). A String is either an
@@ -1105,8 +1119,8 @@ sign := '+' | '-'
1105
1119
1106
1120
bare-type-suffix := bare-type-suffix-initial identifier-char*
1107
1121
bare-type-suffix-initial := identifier-char
1108
- - ' .' - ',' - '_'
1109
- - (('e' | 'E') sign? digit)
1122
+ - ' .' - ','
1123
+ - (('e' | 'E') ( sign | digit) )
1110
1124
explicit-type-suffix := '#' identifier-string
1111
1125
1112
1126
hex := sign? '0x' hex-digit (hex-digit | '_')*
0 commit comments