@@ -252,18 +252,37 @@ Type Annotation ({{type-annotation}}).
252
252
253
253
# # Type Annotation
254
254
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.
255
+ A type annotation is a String ({{string}}) value attached to any Node Name
256
+ ({{node}}) or Value ({{value}}) that includes a _suggestion_ of what type the
257
+ value is _intended_ to be treated as, or as a _context-specific elaboration_ of
258
+ the more generic type the node name indicates.
263
259
264
260
KDL does not specify any restrictions on what implementations might do with
265
261
these annotations. They are free to ignore them, or use them to make decisions
266
- about how to interpret a value.
262
+ about how to interpret a value. That said, KDL does reserve certain well-known
263
+ strings for what would be their intended purpose, for the sake of
264
+ interoperability ({{reserved-type-annotations}}).
265
+
266
+ There are two kinds of Type Annotation syntaxes in KDL : Prefix Type Annotations
267
+ ({{prefix-type-annotation}}) and Suffix Type Annotations
268
+ ({{suffix-type-annotation}}).
269
+
270
+ # ## Examples
271
+
272
+ ~~~kdl
273
+ node 123u8
274
+ node 0#b 20b 50GiB
275
+ node prop=(regex).*
276
+ (published)date "1970-01-01"
277
+ (contributor)person name="Foo McBar"
278
+ ~~~
279
+
280
+ # ## Prefix Type Annotation
281
+
282
+ Prefix Type Annotations are written as a set of `(` and `)` with a single String
283
+ ({{string}}) in it. It may contain Whitespace after the `(` and before the `)`,
284
+ and may be separated from its target by Whitespace. Unlike the other annotation
285
+ types, any String type may be used.
267
286
268
287
# ## Suffix Type Annotation
269
288
@@ -294,16 +313,18 @@ String ({{string}}) syntax is acceptable.
294
313
295
314
# ### Bare Suffix Type Annotation
296
315
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
316
+ When a Value ({{value}}) is a decimal Number ({{number}}) WITHOUT an exponential
317
+ part--that is, numbers which do NOT have a `0b`/`0o`/`0x` prefix with an
318
+ optional sign, or which look like `5.2e+3`-- it's possible to append the type
300
319
annotation as a suffix directly to the number, without any additional syntax.
301
320
302
321
To remove further ambiguity, on top of not being available for non-decimal
303
322
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.
323
+ ({{identifier-string}}) itself MUST NOT start with either `.` or `,`, as well as
324
+ ` [eE][-+]?[0-9]?` (as part of the exponential restriction above). Note the
325
+ optional digit, which is added to prevent typo ambiguity. Additionally, a
326
+ standalone non-decimal Number ({{number}}) prefix MUST yield a syntax error
327
+ (e.g. `0b` is an incorrect binary number, not `(b)0`).
307
328
308
329
For example, the following are all illegal :
309
330
@@ -338,7 +359,9 @@ Note that, unlike Bare Suffix Type Annotations
338
359
({{number}}) formats (hexadecimal, decimal, octal, and binary). For example,
339
360
` 0x1234#u32` is valid.
340
361
341
- # ## Reserved Type Annotations for Numbers Without Decimal Parts
362
+ # ## Reserved Type Annotations
363
+
364
+ # ### For Numbers Without Decimal Parts
342
365
343
366
Additionally, the following type annotations MAY be recognized by KDL parsers
344
367
and, if used, SHOULD interpret these types as follows.
@@ -364,7 +387,7 @@ Platform-dependent integer types, both signed and unsigned:
364
387
- ` isize`
365
388
- ` usize`
366
389
367
- # ## Reserved Type Annotations for Numbers With Decimal Parts
390
+ # ### For Numbers With Decimal Parts
368
391
369
392
IEEE 754 floating point numbers, both single (32) and double (64) precision :
370
393
@@ -376,7 +399,7 @@ IEEE 754-2008 decimal floating point numbers
376
399
- ` decimal64`
377
400
- ` decimal128`
378
401
379
- # ## Reserved Type Annotations for Strings
402
+ # ### For Strings
380
403
381
404
- `date-time` : ISO8601 date/time format.
382
405
- `time` : " Time" section of ISO8601.
@@ -404,16 +427,6 @@ IEEE 754-2008 decimal floating point numbers
404
427
- `base64` : A Base64-encoded string, denoting arbitrary binary data.
405
428
- `base85` : An [Ascii85](https://en.wikipedia.org/wiki/Ascii85)-encoded string, denoting arbitrary binary data.
406
429
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
430
# # String
418
431
419
432
Strings in KDL represent textual UTF-8 Values ({{value}}). A String is either an
@@ -1105,8 +1118,8 @@ sign := '+' | '-'
1105
1118
1106
1119
bare-type-suffix := bare-type-suffix-initial identifier-char*
1107
1120
bare-type-suffix-initial := identifier-char
1108
- - ' .' - ',' - '_'
1109
- - (('e' | 'E') sign? digit)
1121
+ - ' .' - ','
1122
+ - (('e' | 'E') ( sign | digit) )
1110
1123
explicit-type-suffix := '#' identifier-string
1111
1124
1112
1125
hex := sign? '0x' hex-digit (hex-digit | '_')*
0 commit comments