From a15818bd452fc832c1f4a3076237c47168aa9236 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 22 Dec 2024 03:32:56 +0700 Subject: [PATCH] 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 * add a mandatory newline after the version marker * add mandatory space between version number --------- Co-authored-by: eilvelia --- CHANGELOG.md | 3 +-- SPEC.md | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce96591..6ec134c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/SPEC.md b/SPEC.md index d21ae81..8ada158 100644 --- a/SPEC.md +++ b/SPEC.md @@ -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