A parser and stringifier for the KDL Document Language bram.tngl.io/kdl
v0.4.0 6afe7797 Bram Gotink

v0.4.0 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAz/vE3F9CogluW0 vgibgT5WVNl+dKPw4t6vat6aSepR0xtzVbqpmnna5qzRcvhkEoQUKIa8Rs0JaF6YwL9a7H DAEAACjd -----END SSH SIGNATURE-----

v0.4.0-next.2 0a63f1d2 Bram Gotink

v0.4.0-next.2 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABA00ja/5EFLvp8zV 9oD1z7MnGAmxerVr25gh7e1QlBHLQuaQuk2OeLWKm5Dp7vfFYeni5zkRYIL/oTu9ugE8xR AwEAABMV -----END SSH SIGNATURE-----

v0.4.0-next.1 ed1da3a0 Bram Gotink

v0.4.0-next.1 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABA6RLMlTH10IX19z OV/mNRGarMeS+1UzosAnoHh+vFKnXLX3Z9tSjR6CZCUx1Qs5IMIlaJICdtD2RcbRsv8ZGw BgEAABFW -----END SSH SIGNATURE-----

v0.4.0-next.0 059806ed Bram Gotink

v0.4.0-next.0 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAKpMcejXreWUp6n f5xw2SF+S+SWxRteaoJrT/yzvxbYh5T1vppaFt9E2Zy2Rg67cVoyRJFD7ZIWBd1sI+0rhC BgEAABE9 -----END SSH SIGNATURE-----

v0.3.1 f3fa1250 Bram Gotink

v0.3.1

Fixes for two issues detected right after publishing v0.3.0: - An off-by-one error in the position of some errors in invalid numbers - An unescaped backslash in a regular expression makes multiline strings that end on `x` invalid -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAFRXeSFTHSt5jlE ygDv7KUbvq2uqcrLlONBMU9pIid7L8CnAphsU9vYkv0IAaMDDupUqhqJDMbxCx4tDTVo2f BQEAAA6g -----END SSH SIGNATURE-----

v0.3.0 add45486 Bram Gotink

v0.3.0

This release of `@bgotink/kdl` contains some major improvements and a few smaller breaking changes. **Breaking Changes** - The `Location` export is now called `StoredLocation`, `TokenLocation` is now called `Location`. - The shape of `StoredLocation` has changed from `location.startOffset` to `location.start.offset` etc. - The `tag` property has moved from the `Entry` to the `Value`. The `getTag`/`setTag` methods still exist on `Entry`. - The `Identifier` and `Value` classes are now mutable, i.e. their value can be changed. Use the `setName` / `setValue` method instead of modifying the `name` / `value` property directly to prevent issues in parsed documents. **Error improvements** Parts of the tokenizer and parser have been rewritten to improve the errors thrown by the `parse` function. More errors are now considered "recoverable", which means the parser can continue to see if there are more errors so it can give the caller more information than only the first mistake in the source text. Some of the error messages have been extended with more useful information. The `InvalidKdlError` class introduces two new properties `start` and `end` to point towards a specific location in the source text where the error occurs. These new properties allow for more precision and flexibility than the `token` property, which still exists. Many of the errors thrown by the parser are updated to point directly towards the character or characters that cause the error. **(De)Serialization Tools** This release introduces a new export: `@bgotink/kdl/dessert` which contains a bunch of utilities to deserialize KDL text into a JavaScript structure and serialize it back again. The API doesn't enforce any programming paradigm, working with regular functions and with classes. Here's an example with functions: ```ts import { type DeserializationContext, type SerializationContext, deserialize, serialize, } from "@bgotink/kdl/dessert"; type Tree = {value: number; left?: Tree; right?: Tree}; function treeDeserializer(ctx: DeserializationContext): Tree { return { value: ctx.argument.required("number"), left: ctx.child.single("left", treeDeserializer), right: ctx.child.single("right", treeDeserializer), }; } export function readTree(node: Node): Tree { return deserialize(node, treeDeserializer); } function treeSerializer(ctx: SerializationContext, tree: Tree) { ctx.argument(tree.value); if (tree.left) { ctx.child("left", treeSerializer, tree.left); } if (tree.right) { ctx.child("right", treeSerializer, tree.right); } } export function writeTree(tree: Tree): Node { return serialize("root", treeDeserializer, tree); } ``` and here's that same example using classes: ```ts import { type DeserializationContext, type SerializationContext, deserialize, serialize, } from "@bgotink/kdl/dessert"; class Tree { static deserialize(ctx: DeserializationContext): Tree { return new Tree( ctx.argument.required("number"), ctx.child.single("left", Tree), ctx.child.single("right", Tree), ); } constructor( readonly value: number, readonly left?: Tree, readonly right?: Tree, ) {} serialize(ctx: SerializationContext) { ctx.argument(this.value); if (this.left) { ctx.child("left", this.left); } if (this.right) { ctx.child("right", this.right); } } } export function readTree(node: Node): Tree { return deserialize(node, Tree); } export function writeTree(tree: Tree): Node { return serialize("root", tree); } ``` Both of these examples turn the following KDL node into a `Tree` structure and back. ```kdl root 10 { left 5 right 5 { left 2 { left 1; right 1 } right 3 { left 2; right 1 } } } ``` The dessert API supports preserving comments and formatting when making modifications to a KDL file. This preservation can be enabled by linking the `DeserializationContext` used to deserialize the value from KDL to the `SerializationContext` used when serializing the value back to KDL. This is done via the `SerializationContext`'s new `source` function. This takes two steps: 1. Store the `DeserializationContext` while deserializing, e.g. by adding it to a hidden/private property on the returned object 2. Pass the stored `DeserializationContext` to the `SerializationContext` inside the serializer It is important that step 2 is done at the start of the serializer. Doing so after making changes to the `SerializationContext` will throw an error. Here we've taken the `Tree` class from above and added in the necessary code to enable preserving formatting and comments: ```ts class Tree { static deserialize(ctx: DeserializationContext): Tree { const tree = new Tree( ctx.argument.required("number"), ctx.child.single("left", Tree), ctx.child.single("right", Tree), ); tree.#deserializationCtx = ctx; return tree; } // We store the deserialization context #deserializationCtx?: DeserializationContext; constructor( readonly value: number, readonly left?: Tree, readonly right?: Tree, ) {} serialize(ctx: SerializationContext) { // we pass the deserialization context used to create // this Tree instance to the serialization context, linking // them together ctx.source(this.#deserializationContext); ctx.argument(this.value); if (this.left) { ctx.child("left", this.left); } if (this.right) { ctx.child("right", this.right); } } } ``` -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAb981sVv8VJe3PB XMUE98E/d9g9Y2dieMxM59O8SW/uEhdftLJheHW7Xwv24ewcwsWLOVenyNgSUL5he2bWd/ DwEAAA6G -----END SSH SIGNATURE-----

v0.3.0-next.1 41da4a77 Bram Gotink

v0.3.0-next.1 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABA/Dy8ZEzY3f2J3p A0n1BB+Cn2Pawbd12R1RSEqeGoCClrQSqOY1o5pEVMOrrgPG2F415gx2OytFaDEUlRfLjG DgEAAA2S -----END SSH SIGNATURE-----

v0.3.0-next.0 ad64859b Bram Gotink

v0.3.0-next.0 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAIBSuZWOyXEV7a/ 3PG7eMm0ZfgEHWK3GlxcoGh7+HXT3y8S6Y0kQOJTPeWMppQXvw7wiiGBrmXfbGckRTH5Y/ AQEAAA0H -----END SSH SIGNATURE-----

v0.2.1 922f4549 Bram Gotink

v0.2.1 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAhg3G3NbBIHUF8F kWoMm9HuIoealq/6LPIqY5G3lPv0w9cX7UlZOFg+0jLC2015Pxj18eXp9GyekbSt8XG7H8 AgEAAAxy -----END SSH SIGNATURE-----

v0.2.0 367b2402 Bram Gotink

v0.2.0 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAZhkq8nkdJXUc0x JzV5Xb5jx3XZSQBqb2LIxDZ6ftMwjzIIqsXN7w3Q7bSwGM9aPzEcFAFq1TcB/wSvELw8+r CAEAAAu0 -----END SSH SIGNATURE-----

v0.2.0-next.6 740d46ab Bram Gotink

v0.2.0-next.6 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABArkj1FiAawEXXr2 n/AL5X8j1jrh8sT6YzVPfCWvbn0Y+/4i/dutCAMb4aHkf+/XadkxW8lqU4jpe6Af4R5H9k DwEAAAsX -----END SSH SIGNATURE-----

v0.2.0-next.5 0a149cbb Bram Gotink

v0.2.0-next.5 -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgj7Z2wD uvwAIMm+fgx6NBisnruMqqnd3phbvf1Seqv2kAAAAEc3NoOgAAAANnaXQAAAAAAAAABnNo YTUxMgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABA3y8fhqhAq2Uszh usS0aMxGNJ0KMqB3p2USIdZ7XQ1iOWbA4N6bqLTpCq0zEXik9iQ98J1NMFXpfBNsFSPEGV CAEAAAP6 -----END SSH SIGNATURE-----

v0.2.0-next.4 c2769195 Bram Gotink

v0.2.0-next.4

v0.2.0-next.3 d6007073 Bram Gotink

v0.2.0-next.3

v0.2.0-next.2 482643b3 Bram Gotink

v0.2.0-next.2

v0.2.0-next.1 f73e76d1 Bram Gotink

v0.2.0-next.1

v0.2.0-next.0 6130bb4d Bram Gotink

v0.2.0-next.0

v0.1.6 d7eddece Bram Gotink

v0.1.6

v0.1.5 cd8c8e17 Bram Gotink

v0.1.5

v0.1.4 79973ce6 Bram Gotink

v0.1.4

v0.1.3 66c6ca7e Bram Gotink

v0.1.3