kdl-org.github.io/index.html

161 lines
14 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="kdl is a document language, mostly based on SDLang, with xml-like semantics that looks like you're invoking a bunch of CLI commands!"
/>
<title>KDL - KDL Document Language</title>
<link rel="stylesheet" href="/styles/global.css" />
</head>
<body>
<main><header class="py-10 bg-gray-300">
<h1 class="text-4xl text-center">KDL - KDL Document Language</h1>
</header>
<section class="kdl-section" id="description">
<p>KDL is a document language with xml-like semantics that looks like you're
invoking a bunch of CLI commands!</p>
<p>It's meant to be used both as a serialization format and a configuration
language, and is relatively light on syntax compared to XML.</p>
<p>There's a living <a href="https://github.com/kdl-org/kdl/blob/main/SPEC.md">specification</a>, as well as
<a href="#implementations">implementations</a>. The language is based on
<a href="https://sdlang.org">SDLang</a>, with a number of modifications and
clarifications on its syntax and behavior.</p>
</section>
<section class="kdl-section" id="design-and-discussion">
<h2>Design and Discussion</h2>
<p>KDL is still extremely new, and discussion about the format should happen over
on the <a href="https://github.com/kdl-org/kdl/discussions">discussions</a> page in the
Github repo. Feel free to jump in and give us your 2 cents!</p>
</section>
<section class="kdl-section" id="design-principles">
<h2>Design Principles</h2>
<ol>
<li>Maintainability</li>
<li>Flexibility</li>
<li>Cognitive simplicity and Learnability</li>
<li>Ease of de/serialization</li>
<li>Ease of implementation</li>
</ol>
</section>
<section class="kdl-section" id="implementations">
<h2>Implementations</h2>
<ul>
<li>Rust: <a href="https://github.com/kdl-org/kdl-rs">kdl-rs</a></li>
<li>JavaScript: <a href="https://github.com/kdl-org/kdljs">kdljs</a></li>
</ul>
<h2>Editor Support</h2>
<ul>
<li><a href="https://marketplace.visualstudio.com/items?itemName=kdl-org.kdl&amp;ssr=false#review-details">VS Code</a></li>
</ul>
</section>
<section class="kdl-section" id="overview">
<h2>Overview</h2>
<h3>Basics</h3>
<p>A KDL node is a node name, followed by zero or more &quot;arguments&quot;, and
children.</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">title</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;Hello, World&quot;</span></span></code></pre>
<p>You can also have multiple values in a single node!</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">bookmarks</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">12</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">15</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">188</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1234</span></span></code></pre>
<p>Nodes can have properties.</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">author</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;Alex Monad&quot;</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">email</span><span style="color: #ECEFF4">=</span><span style="color: #A3BE8C">&quot;alex@example.com&quot;</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">active</span><span style="color: #ECEFF4">=</span><span style="color: #81A1C1">true</span></span></code></pre>
<p>And they can have nested child nodes, too!</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">contents</span><span style="color: #D8DEE9FF"> {</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">section</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;First section&quot;</span><span style="color: #D8DEE9FF"> {</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">paragraph</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;This is the first paragraph&quot;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">paragraph</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;This is the second paragraph&quot;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> }</span></span>
<span class="line"><span style="color: #D8DEE9FF">}</span></span></code></pre>
<p>Nodes without children are terminated by a newline, a semicolon, or the end of
a file stream:</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">node1</span><span style="color: #D8DEE9FF">; </span><span style="color: #81A1C1">node2</span><span style="color: #D8DEE9FF">; </span><span style="color: #81A1C1">node3</span><span style="color: #D8DEE9FF">;</span></span></code></pre>
<h3>Values</h3>
<p>KDL supports 4 data types:</p>
<ul>
<li>Strings: <code>&quot;hello world&quot;</code></li>
<li>Numbers: <code>123.45</code></li>
<li>Booleans: <code>true</code> and <code>false</code></li>
<li>Null: <code>null</code></li>
</ul>
<h4>Strings</h4>
<p>It supports two different formats for string input: escaped and raw.</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">node</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;this</span><span style="color: #EBCB8B">\n</span><span style="color: #A3BE8C">has</span><span style="color: #EBCB8B">\t</span><span style="color: #A3BE8C">escapes&quot;</span></span>
<span class="line"><span style="color: #81A1C1">other</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">r&quot;C:\Users\zkat\&quot;</span></span></code></pre>
<p>Both types of string can be multiline as-is, without a different syntax:</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">string</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;my</span></span>
<span class="line"><span style="color: #A3BE8C">multiline</span></span>
<span class="line"><span style="color: #A3BE8C">value&quot;</span></span></code></pre>
<p>And for raw strings, you can add any number of # after the r and the last &quot; to
disambiguate literal &quot; characters:</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">other-raw</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">r#&quot;hello&quot;world&quot;#</span></span></code></pre>
<h4>Numbers</h4>
<p>There's 4 ways to represent numbers in KDL. KDL does not prescribe any
representation for these numbers, and it's entirely up to individual
implementations whether to represent all numbers with a single type, or to
have different representations for different forms.</p>
<p>KDL has regular decimal-radix numbers, with optional decimal part, as well as
an optional exponent.</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">num</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1.234e-42</span></span></code></pre>
<p>And using the appropriate prefix, you can also enter hexadecimal, octal, and
binary literals:</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">my-hex</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0xdeadbeef</span></span>
<span class="line"><span style="color: #81A1C1">my-octal</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0o755</span></span>
<span class="line"><span style="color: #81A1C1">my-binary</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0b10101101</span></span></code></pre>
<p>Finally, all numbers can have underscores to help readability:</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #81A1C1">bignum</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1_000_000</span></span></code></pre>
<h3>Comments</h3>
<p>KDL supports C-style comments, both line-based and multiline. Multiline
comments can be nested.</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #616E88">// C style</span></span>
<span class="line"><span style="color: #616E88">/*</span></span>
<span class="line"><span style="color: #616E88">C style multiline</span></span>
<span class="line"><span style="color: #616E88">*/</span></span>
<span class="line"><span style="color: #81A1C1">tag</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/*foo=true*/</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">bar</span><span style="color: #ECEFF4">=</span><span style="color: #81A1C1">false</span></span>
<span class="line"><span style="color: #616E88">/*/*</span></span>
<span class="line"><span style="color: #616E88">hello</span></span>
<span class="line"><span style="color: #616E88">*/*/</span></span></code></pre>
<p>On top of that, KDL supports <code>/-</code> &quot;slashdash&quot; comments, which can be used to
comment out individual nodes, arguments, or children:</p>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #616E88">// This entire node and its children are all commented out.</span></span>
<span class="line"><span style="color: #616E88">/-mynode &quot;foo&quot; key=1 {</span></span>
<span class="line"><span style="color: #616E88"> a</span></span>
<span class="line"><span style="color: #616E88"> b</span></span>
<span class="line"><span style="color: #616E88"> c</span></span>
<span class="line"><span style="color: #616E88">}</span></span>
<span class="line"><span style="color: #81A1C1">mynode</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/-&quot;commented&quot; </span><span style="color: #A3BE8C">&quot;not commented&quot;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/-key=&quot;value&quot; /-{</span></span>
<span class="line"><span style="color: #616E88"> a</span></span>
<span class="line"><span style="color: #616E88"> b</span></span>
<span class="line"><span style="color: #616E88">}</span></span></code></pre>
<h3>More Details</h3>
<pre class="shiki" style="background-color: #2e3440ff"><code><span class="line"><span style="color: #616E88">// Nodes can be separated into multiple lines</span></span>
<span class="line"><span style="color: #81A1C1">title</span><span style="color: #D8DEE9FF"> \</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;Some title&quot;</span></span>
<span class="line"><span style="color: #616E88">// Files must be utf8 encoded!</span></span>
<span class="line"><span style="color: #81A1C1">smile</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;😁&quot;</span></span>
<span class="line"><span style="color: #616E88">// Instead of anonymous nodes, nodes and properties can be wrapped</span></span>
<span class="line"><span style="color: #616E88">// in &quot;&quot; for arbitrary node names.</span></span>
<span class="line"><span style="color: #A3BE8C">&quot;!@#$@$%Q#$%~@!40&quot;</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;1.2.3&quot;</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;!!!!!&quot;</span><span style="color: #D8DEE9FF">=</span><span style="color: #81A1C1">true</span></span>
<span class="line"><span style="color: #616E88">// The following is a legal bare identifier:</span></span>
<span class="line"><span style="color: #81A1C1">foo123~!@#$%^&amp;*.</span><span style="color: #D8DEE9FF">:&#39;</span><span style="color: #81A1C1">|/</span><span style="color: #D8DEE9FF">?</span><span style="color: #81A1C1">+</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;weeee&quot;</span></span>
<span class="line"><span style="color: #616E88">// And you can also use unicode!</span></span>
<span class="line"><span style="color: #81A1C1">ノード</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">お名前</span><span style="color: #D8DEE9FF"></span><span style="color: #A3BE8C">&quot;☜(゚ヮ゚☜)&quot;</span></span>
<span class="line"><span style="color: #616E88">// kdl specifically allows properties and values to be</span></span>
<span class="line"><span style="color: #616E88">// interspersed with each other, much like CLI commands.</span></span>
<span class="line"><span style="color: #81A1C1">foo</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">bar</span><span style="color: #ECEFF4">=</span><span style="color: #81A1C1">true</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">&quot;baz&quot;</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">quux</span><span style="color: #ECEFF4">=</span><span style="color: #81A1C1">false</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">2</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">3</span></span></code></pre>
</section>
</main>
</body>
</html>