@@ -252,18 +252,37 @@ Type Annotation ({{type-annotation}}).
252252
253253# # Type Annotation
254254
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.
263259
264260KDL does not specify any restrictions on what implementations might do with
265261these 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.
267286
268287# ## Suffix Type Annotation
269288
@@ -294,16 +313,18 @@ String ({{string}}) syntax is acceptable.
294313
295314# ### Bare Suffix Type Annotation
296315
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
300319annotation as a suffix directly to the number, without any additional syntax.
301320
302321To remove further ambiguity, on top of not being available for non-decimal
303322prefixes, 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`).
307328
308329For example, the following are all illegal :
309330
@@ -338,7 +359,9 @@ Note that, unlike Bare Suffix Type Annotations
338359({{number}}) formats (hexadecimal, decimal, octal, and binary). For example,
339360` 0x1234#u32` is valid.
340361
341- # ## Reserved Type Annotations for Numbers Without Decimal Parts
362+ # ## Reserved Type Annotations
363+
364+ # ### For Numbers Without Decimal Parts
342365
343366Additionally, the following type annotations MAY be recognized by KDL parsers
344367and, if used, SHOULD interpret these types as follows.
@@ -364,7 +387,7 @@ Platform-dependent integer types, both signed and unsigned:
364387- ` isize`
365388- ` usize`
366389
367- # ## Reserved Type Annotations for Numbers With Decimal Parts
390+ # ### For Numbers With Decimal Parts
368391
369392IEEE 754 floating point numbers, both single (32) and double (64) precision :
370393
@@ -376,7 +399,7 @@ IEEE 754-2008 decimal floating point numbers
376399- ` decimal64`
377400- ` decimal128`
378401
379- # ## Reserved Type Annotations for Strings
402+ # ### For Strings
380403
381404- `date-time` : ISO8601 date/time format.
382405- `time` : " Time" section of ISO8601.
@@ -404,16 +427,6 @@ IEEE 754-2008 decimal floating point numbers
404427- `base64` : A Base64-encoded string, denoting arbitrary binary data.
405428- `base85` : An [Ascii85](https://en.wikipedia.org/wiki/Ascii85)-encoded string, denoting arbitrary binary data.
406429
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-
417430# # String
418431
419432Strings in KDL represent textual UTF-8 Values ({{value}}). A String is either an
@@ -1105,8 +1118,8 @@ sign := '+' | '-'
11051118
11061119bare-type-suffix := bare-type-suffix-initial identifier-char*
11071120bare-type-suffix-initial := identifier-char
1108- - ' .' - ',' - '_'
1109- - (('e' | 'E') sign? digit)
1121+ - ' .' - ','
1122+ - (('e' | 'E') ( sign | digit) )
11101123explicit-type-suffix := '#' identifier-string
11111124
11121125hex := sign? '0x' hex-digit (hex-digit | '_')*
0 commit comments