@@ -117,10 +117,11 @@ Being a node-oriented language means that the real core component of any KDL
117117document is the "node". Every node must have a name, which must be a
118118String ({{string}}).
119119
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`.)
124125
125126Following the name are zero or more Arguments ({{argument}}) or
126127Properties ({{property}}), separated by either whitespace ({{whitespace}}) or a
@@ -247,23 +248,42 @@ Values _MUST_ be either Arguments ({{argument}}) or values of
247248Properties ({{property}}). Only String ({{string}}) values may be used as
248249Node ({{node}}) names or Property ({{property}}) keys.
249250
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}}).
252253
253254# # Type Annotation
254255
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.
263260
264261KDL does not specify any restrictions on what implementations might do with
265262these 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.
267287
268288# ## Suffix Type Annotation
269289
@@ -272,38 +292,38 @@ type annotation as a "suffix", instead of prepending it between `(` and `)`.
272292This makes it possible to, for example, write `10px`, `10.5%`, `512GiB`, etc.,
273293which are equivalent to `(px)10`, `(%)5`, and `(GiB)512`, respectively.
274294
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-
279295Most suffixes can be appended directly to the number (a Bare Suffix Type
280296Annotation ({{bare-suffix-type-annotation}})), as shown in the previous
281297paragraph. To avoid parsing ambiguity, there are some restrictions on this; an
282298Explicit Suffix Type Annotation ({{explicit-suffix-type-annotation}}) avoids all
283299these 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}})
286302for the full list of restrictions.
287303
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.
291308
292309Suffixes MUST BE plain Identifier Strings ({{identifier-string}}). No other
293310String ({{string}}) syntax is acceptable.
294311
295312# ### Bare Suffix Type Annotation
296313
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 :
301318
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`).
307327
308328For example, the following are all illegal :
309329
@@ -312,17 +332,19 @@ For example, the following are all illegal:
312332* `0xyz` (starts with reserved hexadecimal prefix)
313333* `0b` (starts with reserved binary prefix)
314334* `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>`)
315337
316338Whereas the following are all legal :
317339
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.
322344
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.
326348
327349# ### Explicit Suffix Type Annotation
328350
@@ -338,7 +360,9 @@ Note that, unlike Bare Suffix Type Annotations
338360({{number}}) formats (hexadecimal, decimal, octal, and binary). For example,
339361` 0x1234#u32` is valid.
340362
341- # ## Reserved Type Annotations for Numbers Without Decimal Parts
363+ # ## Reserved Type Annotations
364+
365+ # ### For Numbers Without Decimal Parts
342366
343367Additionally, the following type annotations MAY be recognized by KDL parsers
344368and, if used, SHOULD interpret these types as follows.
@@ -364,7 +388,7 @@ Platform-dependent integer types, both signed and unsigned:
364388- ` isize`
365389- ` usize`
366390
367- # ## Reserved Type Annotations for Numbers With Decimal Parts
391+ # ### For Numbers With Decimal Parts
368392
369393IEEE 754 floating point numbers, both single (32) and double (64) precision :
370394
@@ -376,7 +400,7 @@ IEEE 754-2008 decimal floating point numbers
376400- ` decimal64`
377401- ` decimal128`
378402
379- # ## Reserved Type Annotations for Strings
403+ # ### For Strings
380404
381405- `date-time` : ISO8601 date/time format.
382406- `time` : " Time" section of ISO8601.
@@ -404,16 +428,6 @@ IEEE 754-2008 decimal floating point numbers
404428- `base64` : A Base64-encoded string, denoting arbitrary binary data.
405429- `base85` : An [Ascii85](https://en.wikipedia.org/wiki/Ascii85)-encoded string, denoting arbitrary binary data.
406430
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-
417431# # String
418432
419433Strings in KDL represent textual UTF-8 Values ({{value}}). A String is either an
@@ -1105,8 +1119,8 @@ sign := '+' | '-'
11051119
11061120bare-type-suffix := bare-type-suffix-initial identifier-char*
11071121bare-type-suffix-initial := identifier-char
1108- - ' .' - ',' - '_'
1109- - (('e' | 'E') sign? digit)
1122+ - ' .' - ','
1123+ - (('e' | 'E') ( sign | digit) )
11101124explicit-type-suffix := '#' identifier-string
11111125
11121126hex := sign? '0x' hex-digit (hex-digit | '_')*
0 commit comments