Add an optional version marker (#444)

* Add version marker to the grammer

* Add version marker to the Changelog

* Update SPEC.md

Co-authored-by: eilvelia <hi@eilvelia.cat>

* add a mandatory newline after the version marker

* add mandatory space between version number

---------

Co-authored-by: eilvelia <hi@eilvelia.cat>
This commit is contained in:
Evgeny 2024-12-22 03:32:56 +07:00 committed by GitHub
parent da5cbf5984
commit a15818bd45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -73,8 +73,7 @@
intuitive. They can now be used in exactly three different places: before nodes,
before entire entries, or before entire child blocks.
* Furthermore, The ordering of slashdashed elements has been restricted such
that a slashdashed child block cannot go before an entry (including slashdashed
entries).
* Optional version marker `/- kdl-version 2` (or `1`) as the first line in a document, optionally preceded by the BOM.
### KQL

View File

@ -828,6 +828,10 @@ They may be represented in Strings (but not Raw Strings) using [Unicode Escapes]
* `U+FEFF`, aka Zero-width Non-breaking Space (ZWNBSP)/Byte Order Mark (BOM),
except as the first code point in a document.
### Version marker
A version marker `/- kdl-version 2` (or `1`) _MAY_ be added to the beginning of a KDL document, optionally preceded by the BOM, and parsers _MAY_ use that as a hint as to which version to parse the document as.
## Full Grammar
This is the full official grammar for KDL and should be considered
@ -835,7 +839,7 @@ authoritative if something seems to disagree with the text above. The [grammar
language syntax](#grammar-language) is defined below.
```
document := bom? nodes
document := bom? version? nodes
// Nodes
nodes := (line-space* node)* line-space*
@ -920,6 +924,9 @@ newline := See Table (All Newline White_Space)
line-space := node-space | newline | single-line-comment
// Whitespace within nodes, where newline-ish things must be esclined.
node-space := ws* escline ws* | ws+
// Version marker
version := '/-' unicode-space* 'kdl-version' unicode-space+ ('1' | '2') unicode-space* newline
```
### Grammar language