### KDL Document Example Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md This is an example KDL document used to demonstrate query syntax. ```kdl package { name foo version "1.0.0" dependencies platform=windows { winapi "1.0.0" path="./crates/my-winapi-fork" } dependencies { miette "2.0.0" dev=#true integrity=(sri)sha512-deadbeef } } ``` -------------------------------- ### KDL Package Manifest Example (Cargo.kdl style) Source: https://context7.com/kdl-org/kdl/llms.txt Example of a KDL-formatted package manifest, similar to Cargo.toml. Demonstrates defining package metadata, dependencies with features, and script commands. ```kdl package { name my-app version "1.2.3" description "An example KDL package manifest" authors "Alice " license-file LICENSE.md edition "2021" } dependencies { serde "1.0" features=derive tokio "1.0" features=full optional=#false /-unused-crate "0.1" // slashdash-commented out } scripts { build #""" cargo build --release strip target/release/my-app """# test "cargo test --all-features" } ``` -------------------------------- ### KDL Argument Example Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md A simple KDL node demonstrating multiple arguments and properties. ```kdl my-node 1 2 3 a b c ``` -------------------------------- ### KDL CI Pipeline Configuration Example Source: https://context7.com/kdl-org/kdl/llms.txt Example of a KDL configuration for a CI/CD pipeline. Defines pipeline triggers, jobs, and steps using a structure similar to GitHub Actions. ```kdl pipeline { name my-ci on push pull_request jobs { build { runs-on ubuntu-latest steps { - uses=actions/checkout@v4 - name="Set up Rust" uses=dtolnay/rust-toolchain@stable - name=Build run="cargo build --release" - name=Test run="cargo test --all" } } lint { runs-on ubuntu-latest steps { - uses=actions/checkout@v4 - name=Clippy run="cargo clippy -- -D warnings" - name=Format run="cargo fmt --check" } } } } ``` -------------------------------- ### Fetch Node Example Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md Fetches the 'name' node directly. ```kdl package >> name ``` -------------------------------- ### KDL Multi-line String Syntax Error: Single Line Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md This example demonstrates an illegal multi-line string syntax where the content does not start with a newline after the opening triple quotes. ```kdl multi-line """can't be single line""" ``` -------------------------------- ### KDL Line Continuation Example Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Shows how to use a backslash `\` for line continuation in KDL. Comments are permitted after the backslash and before the newline. ```kdl my-node 1 2 \ // comments are ok after \ 3 4 // This is the actual end of the Node. ``` -------------------------------- ### KDL Node Examples Source: https://context7.com/kdl-org/kdl/llms.txt Demonstrates the structure of KDL nodes, including names, positional arguments, key-value properties, and child nodes. Supports mixing arguments and properties, and line continuation. ```kdl // Node name only empty-node ``` ```kdl // Positional arguments (order is preserved) bookmarks 12 15 188 1234 ``` ```kdl // Key/value properties (order is NOT guaranteed) author "Alex Monad" email=alex@example.com active=#true ``` ```kdl // Arguments and properties freely mixed, just like CLI flags server "prod-1" host=10.0.0.1 port=8080 tls=#true weight=100 ``` ```kdl // Children block package { name my-app version "2.1.0" dependencies { serde "1.0" features=derive tokio "1.0" features=full } } ``` ```kdl // Multiple nodes on one line with semicolons node1; node2; node3 ``` ```kdl // Line continuation with backslash matrix 1 2 3 \ 4 5 6 \ 7 8 9 ``` -------------------------------- ### KDL Children Block Examples Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Two examples of KDL children blocks. The first uses standard block syntax, while the second demonstrates nodes terminated by semicolons within a single line. ```kdl parent { child1 child2 } ``` ```kdl parent { child1; child2 } ``` -------------------------------- ### KDL Node Example Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Demonstrates a KDL node with an argument list, properties, and a children block. Note the argument list `[1, 3]` for `foo` and the nested node `baz` with a type annotation. ```kdl // `foo` will have an Argument value list like `[1, 3]`. foo 1 key=val 3 { bar (role)baz 1 2 } ``` -------------------------------- ### KDL Document Structure Example Source: https://github.com/kdl-org/kdl/blob/main/README.md Demonstrates the basic structure of a KDL document, including nodes, values, key/value pairs, nested structures, and different types of comments. Use this to understand the syntax and organization of KDL files. ```kdl package { name my-pkg version "1.2.3" dependencies { // Nodes can have standalone values as well as // key/value pairs. lodash "^3.2.1" optional=#true alias=underscore } scripts { // "Raw" and dedented multi-line strings are supported. message """ hello world """ build #""" echo "foo" node -c "console.log('hello, world!');" echo "foo" > some-file.txt """# } // `\` breaks up a single node across multiple lines. the-matrix 1 2 3 \ 4 5 6 \ 7 8 9 // "Slashdash" comments operate at the node level, // with just `/-`. /-this-is-commented { this entire node { is gone } } } ``` -------------------------------- ### KDL Property Overriding Example Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Illustrates how properties with the same name are resolved, with the rightmost property taking precedence. ```kdl node a=1 a=2 ``` -------------------------------- ### KDL Document Example Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md A simple KDL document consisting of two top-level nodes, 'foo' and 'baz'. 'foo' contains a nested node 'bar'. ```kdl foo { bar } baz ``` -------------------------------- ### KDL Raw String Example Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Raw strings do not support \-escapes. The number of preceding '#' characters must match the number of trailing '#' characters. ```kdl just-escapes #"\n will be literal" ``` -------------------------------- ### KDL C-Style Comments Source: https://github.com/kdl-org/kdl/blob/main/README.md Examples of single-line and multiline C-style comments in KDL. Multiline comments can be nested. ```kdl // C style /* C style multiline */ tag /*foo=#true*/ bar=#false /*/* hello */*/ ``` -------------------------------- ### KDL Node Separation and Encoding Source: https://github.com/kdl-org/kdl/blob/main/README.md Illustrates separating KDL nodes across multiple lines and mentions the UTF-8 encoding requirement. Also shows examples of using quoted and raw strings for node names and property keys. ```kdl // Nodes can be separated into multiple lines title \ "Some title" // Files must be utf8 encoded! smile 😁 // Node names and property keys are just strings, so you can write them like // quoted or raw strings, too! "illegal(){}[]/\=#;identifier" #"1.2.3"# #"false"=#true // Identifiers are very flexible. The following is a legal bare identifier: -<123~!$@%^&*,.:'`|?+> // And you can also use non-ASCII unicode! γƒŽγƒΌγƒ‰γ€€γŠεε‰=ΰΈ…^β€’ο»Œβ€’^ΰΈ… ``` -------------------------------- ### XML-in-KDL (XiK) Microsyntax Examples Source: https://context7.com/kdl-org/kdl/llms.txt Encode XML elements, text, comments, and processing instructions directly in KDL using the XiK microsyntax. XML attributes map to KDL properties, and text content becomes string arguments or child nodes. ```kdl // XML: element foo=bar { child baz=quux } ``` ```kdl // XML with text-only content: click here a href="http://example.com" "click here" ``` ```kdl // Mixed content: some bold text span { - "some " b bold - " text" } ``` ```kdl // XML namespace (colon is valid in KDL identifiers) svg:svg width=100 height=100 { svg:circle cx=50 cy=50 r=40 fill=red } ``` ```kdl // XML comment: /* This is a comment */ // Or as a preservable node: ! " This is a comment " ``` ```kdl // Processing instruction: ?xml version="1.0" ``` ```kdl // Doctype: !doctype html ``` ```kdl // Full HTML5 document fragment !doctype html html lang=en { head { meta charset=UTF-8 title "My Page" } body { h1 "Hello, World!" p class=intro "Welcome to XiK." ul { li "Item one" li "Item two" } } } ``` -------------------------------- ### KDL Binary Number Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Binary numbers start with '0b' and use digits 0-1, with underscores as separators. ```kdl binary 0b1101_0101 ``` -------------------------------- ### KDL Node with Nested Child Nodes Source: https://github.com/kdl-org/kdl/blob/main/README.md Example of a KDL node containing nested child nodes, demonstrating hierarchical structure. ```kdl contents { section "First section" { paragraph "This is the first paragraph" paragraph "This is the second paragraph" } } ``` -------------------------------- ### KDL Decimal Number Format Source: https://github.com/kdl-org/kdl/blob/main/README.md Example of a KDL decimal number with an optional decimal part and exponent. ```kdl num 1.234e-42 ``` -------------------------------- ### JSON-in-KDL (JiK) Microsyntax Examples Source: https://context7.com/kdl-org/kdl/llms.txt Encode JSON values, arrays, and objects losslessly within KDL using the JiK microsyntax. Use '-' for anonymous containers and explicit annotations for empty or single-element arrays. ```kdl // JSON literal: 42 - 42 ``` ```kdl // JSON literal: "hello" - "hello" ``` ```kdl // JSON literal: true - #true ``` ```kdl // JSON array: [1, 2, 3] - 1 2 3 ``` ```kdl // Single-element array needs explicit annotation: [1] (array)- 1 ``` ```kdl // Empty array: [] (array)- ``` ```kdl // Nested array: [1, [true, false], 3] - { - 1 - #true #false - 3 } ``` ```kdl // JSON object: {"foo": 1, "bar": true} - foo=1 bar=#true ``` ```kdl // Empty object: {} (object)- ``` ```kdl // Nested object: {"foo": 1, "bar": [2, {"baz": 3}], "qux": 4} - foo=1 qux=4 { bar 2 { - baz=3 } } ``` ```kdl // Real-world: HTTP request with a JSON body embedded in KDL request "/api/cart" method=PUT { body { items { - id=1234 amount=1 - id=2341 amount=2 { options { color red size XXL } } } } } // The `body` node above encodes: // {"items": [{"id":1234,"amount":1}, {"id":2341,"amount":2,"options":{"color":"red","size":"XXL"}}]} ``` -------------------------------- ### KDL Multi-line String Syntax Error: Content After Closing Quote Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md This example demonstrates an illegal multi-line string where there is content after the closing triple quotes on the same line. ```kdl multi-line """stuff """ ``` -------------------------------- ### KDL Multi-line String Syntax Error: Closing Quote Prefix Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md This example shows an illegal multi-line string where the closing triple quotes are preceded by non-whitespace characters on the same line. ```kdl multi-line """ closing quote with non-whitespace prefix""" ``` -------------------------------- ### KDL Validation Node Examples Source: https://context7.com/kdl-org/kdl/llms.txt Define constraints for values and properties using KDL validation nodes. Supports type, enum, format, range, multiple-of, length, and pattern constraints. ```kdl // Type constraint node my-count { value { type number } } ``` ```kdl // Enum constraint node log-level { value { type string enum debug info warn error } } ``` ```kdl // String format constraints node contact { prop email { type string format email } prop website { type string format url } } ``` ```kdl // Numeric range constraints node percentage { value { type number >= 0 <= 100 } } ``` ```kdl // Multiple-of constraint node chunk-size { value { type number % 512 } } ``` ```kdl // String length constraints node username { value { type string min-length 3 max-length 32 pattern #"^[a-z0-9_-]+$" # } } ``` ```kdl // Reusable definitions with `ref` document { definitions { prop email-prop id=email-validation { type string format email } } node user { prop primary-email ref=#"[id="email-validation"]"# prop backup-email ref=#"[id="email-validation"]"# } } ``` -------------------------------- ### KDL Multi-line String Syntax Error: Inconsistent Indentation Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md This example shows an illegal multi-line string where intermediate lines do not share the exact same whitespace prefix as the closing line. ```kdl // Every line must share the exact same prefix as the closing line. multi-line """[\n] [tab]a[\n] [space][space]b[\n] [space][tab][\n] [tab]""" ``` -------------------------------- ### JSON Object Representation Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md This JSON object represents the data structure embedded within the KDL 'body' node in the previous example. It shows the equivalent JSON format for the nested KDL data. ```json { "items": [ {"id": 1234, "amount": 1}, {"id": 2341, "amount": 2, "options": {"color": "red", "size": "XXL"}} ] } ``` -------------------------------- ### KDL Octal Number Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Octal numbers start with '0o' and use digits 0-7, with underscores as separators. ```kdl octal 0o777 ``` -------------------------------- ### Basic KDL Node Source: https://github.com/kdl-org/kdl/blob/main/README.md Demonstrates a simple KDL node with a title string argument. ```kdl title "Hello, World" ``` -------------------------------- ### KDL Node with Properties Source: https://github.com/kdl-org/kdl/blob/main/README.md Illustrates a KDL node with string arguments and properties like email and active status. ```kdl author "Alex Monad" email=alex@example.com active=#true ``` -------------------------------- ### Fetch Dependencies with Property Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md Fetches 'dependencies' nodes that have a 'platform' property. ```kdl dependencies[platform] ``` -------------------------------- ### Fetch Dependencies with Prop Function Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md Identical to `dependencies[platform]`, this fetches 'dependencies' nodes with a 'platform' property using the explicit `prop()` function. ```kdl dependencies[prop(platform)] ``` -------------------------------- ### KDL Hexadecimal Number Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Hexadecimal numbers start with '0x' and use digits 0-9 and A-F, with underscores as separators. ```kdl hex 0x_DEAD_BEEF ``` -------------------------------- ### KDL Query Language (KQL) Selectors Source: https://context7.com/kdl-org/kdl/llms.txt Illustrates KQL syntax for selecting nodes using direct child, descendant, sibling, and union operators. ```kql // Direct child: a > b // Descendant: a >> b // Adjacent sibling: a + b // General sibling: a ++ b // Any node: [] // Union: selector1 || selector2 // Document root: top() ``` ```kdl // Sample document being queried: package { name foo version "1.0.0" dependencies platform=windows { winapi "1.0.0" path="./crates/winapi" } dependencies { miette "2.0.0" dev=#true integrity=(sri)sha512-deadbeef } } ``` ```kql // Fetch the `name` node anywhere under `package` package >> name // Guarantee `package` is at document root, then fetch `name` top() > package >> name // Fetch all `dependencies` nodes anywhere in the document dependencies // Fetch `dependencies` nodes that have a `platform` property dependencies[platform] // Equivalent: plain identifier = prop() accessor dependencies[prop(platform)] // Fetch all direct children of any `dependencies` node dependencies > [] // Union: fetch both `winapi` and `miette` nodes package >> dependencies > winapi || package >> dependencies > miette ``` -------------------------------- ### Fetch Node with Root Guarantee Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md Fetches the 'name' node, ensuring 'package' is at the document root. ```kdl top() > package >> name ``` -------------------------------- ### Configure KDL Web Server Source: https://context7.com/kdl-org/kdl/llms.txt This snippet shows a KDL configuration for a web server, defining host, port, TLS settings, worker count, routes with middleware, and logging options. Ensure KDL is integrated into your project to use this configuration. ```kdl server { host 0.0.0.0 port 8443 tls=#true workers 4 routes { route "/" handler=index_handler methods=GET route "/api/v1" handler=api_v1 methods=GET POST PUT DELETE { middleware auth rate-limit timeout 30 } } logging { level info format json output "/var/log/myapp.log" } } ``` -------------------------------- ### KDL Booleans and Null Source: https://context7.com/kdl-org/kdl/llms.txt Demonstrates the syntax for boolean and null values in KDL, which are prefixed with '#' to distinguish them from identifier strings. ```kdl // Booleans feature-flag enabled=#true maintenance-mode=#false ``` ```kdl // Null optional-field #null config timeout=#null ``` ```kdl // Mixed in a node with other types service name=api port=8080 debug=#false timeout=#null weight=1.5 ``` -------------------------------- ### KDL Comment Syntax Source: https://context7.com/kdl-org/kdl/llms.txt Demonstrates KDL's support for single-line, multi-line (nestable), and slashdash comments for various use cases. ```kdl // Single-line comment /* Multi-line comment. /* Can be nested! */ */ // Slashdash a whole node and its children /-deprecated-option "value" key=1 { sub-node } // Slashdash individual arguments or properties server "prod" /-"staging" port=8080 /-debug=#true // Slashdash an entire children block package /-{ this-block will-be-ignored } ``` -------------------------------- ### KDL Number Radix Literals Source: https://github.com/kdl-org/kdl/blob/main/README.md Demonstrates hexadecimal, octal, and binary number representations in KDL using standard prefixes. ```kdl my-hex 0xdeadbeef my-octal 0o755 my-binary 0b10101101 ``` -------------------------------- ### KDL Type Annotations Source: https://context7.com/kdl-org/kdl/llms.txt Explains KDL's type annotations, which can be applied to node names or values as hints. Includes standard numeric and string-format types, as well as custom annotations. ```kdl // Standard numeric type annotations node (u8)255 node (i32)-2147483648 node (f64)3.14159 ``` ```kdl // Standard string-format type annotations user-id (uuid)"550e8400-e29b-41d4-a716-446655440000" created-at (date-time)"2024-12-21T09:00:00Z" homepage (url)"https://kdl.dev" contact (email)"hello@example.com" ``` ```kdl // Custom application-defined annotations (published)date "2024-12-21" (contributor)person name="Kat MarchΓ‘n" numbers (u8)10 (i32)20 myfloat=(f32)1.5 { strings (uuid)"123e4567-e89b-12d3-a456-426614174000" (date)"2021-02-03" } ``` -------------------------------- ### KDL Interspersed Properties and Values Source: https://github.com/kdl-org/kdl/blob/main/README.md Demonstrates KDL's flexibility in interspersing properties and values, similar to command-line arguments. ```kdl foo bar=#true baz quux=#false 1 2 3 ``` -------------------------------- ### KDL Query Language (KQL) Matchers Source: https://context7.com/kdl-org/kdl/llms.txt Explains KQL matchers for filtering nodes based on values, properties, names, and type annotations using comparison operators. ```kql // Accessors: // val() β€” first positional argument // val(N) β€” Nth positional argument (0-indexed) // prop(key) β€” property named "key" (same as just [key]) // name() β€” the node's name as a string // tag() β€” the node's type annotation ``` ```kql // Nodes whose first value equals "2.0.0" dependencies > [val() = "2.0.0"] // Nodes with a `dev` property set to #true dependencies > [dev = #true] // Nodes whose name starts with "win" [name() ^= win] // Nodes whose first value contains "dead" [val() *= dead] // Nodes with an (sri) type annotation on their first value [val() = (sri)] // Nodes with any type annotation [()] // Numeric comparisons scores > [val() >= 90] prices > [val() < 100] // Inequality [version != "1.0.0"] ``` -------------------------------- ### KDL Multi-line String with Empty Lines Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Shows how empty lines within a multi-line string, including those with only whitespace, are preserved as empty lines in the string's value. ```kdl multi-line """ Indented a bit A second indented paragraph. """ ``` -------------------------------- ### KDL String Formats Source: https://github.com/kdl-org/kdl/blob/main/README.md Demonstrates KDL's three string input formats: unquoted, quoted with escapes, and raw strings. Unquoted strings are used for simple values, while quoted strings handle whitespace and special characters. Raw strings are useful for literal content like paths or commands. ```kdl node1 this-is-a-string node2 "this\nhas\tescapes" node3 #"C:\\Users\\zkat\\raw\\string"# ``` -------------------------------- ### KDL Node with Type Annotations Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Demonstrates using type annotations for nodes and properties in KDL. The `(u8)` annotation specifies an unsigned 8-bit integer, and `(regex)` indicates a regular expression pattern. ```kdl node (u8)123 node prop=(regex).* ``` ```kdl (published)date "1970-01-01" ``` ```kdl (contributor)person name="Foo McBar" ``` -------------------------------- ### KDL Node with Multiple Arguments Source: https://github.com/kdl-org/kdl/blob/main/README.md Shows a KDL node accepting multiple numerical arguments. ```kdl bookmarks 12 15 188 1234 ``` -------------------------------- ### KDL Node Termination Source: https://github.com/kdl-org/kdl/blob/main/README.md Demonstrates how KDL nodes can be terminated by a newline, semicolon, or end of file. ```kdl node1; node2; node3 ``` -------------------------------- ### Fetch Direct Children of Dependencies Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md Fetches all direct child nodes of any 'dependencies' nodes in the document. ```kdl dependencies > [] ``` -------------------------------- ### KDL Multiline Quoted Strings Source: https://github.com/kdl-org/kdl/blob/main/README.md Shows how to define multiline strings in KDL using triple quotes. Indentation shared with the closing quotes is automatically stripped. ```kdl string """ my multiline value """ ``` -------------------------------- ### KDL Raw Strings with Escapes Source: https://github.com/kdl-org/kdl/blob/main/README.md Illustrates KDL's raw string format for content that should not be interpreted with backslash escapes, such as shell commands or regular expressions. It also shows how to disambiguate raw strings containing literal hash characters. ```kdl exec #""" echo "foo" echo "bar" cd C:\path\to\dir """# regex #"\d{3} "[^/\"]+""# ``` ```kdl other-raw ##"hello#"world"## ``` -------------------------------- ### KDL Query Grammar Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md The full grammar for KDL queries, defining the structure of selectors, filters, and matchers. ```kdl query-str := $bom? query query := selector q-ws+ "||" q-ws+ query | selector selector := filter q-ws+ selector-operator q-ws+ selector-subsequent | filter selector-subsequent := matchers q-ws+ selector-operator q-ws+ selector-subsequent | matchers selector-operator := ">"" | ">" | "++" | "+" filter := "top(" q-ws* ")" | matchers matchers := type-matcher $string? accessor-matcher* | $string accessor-matcher* | accessor-matcher+ type-matcher := "(" q-ws* ")" | $type accessor-matcher := "[" q-ws* (comparison | accessor)? q-ws* "]" comparison := accessor q-ws+ matcher-operator q-ws+ ($type | $string | $number | $keyword) accessor := "val(" q-ws* $integer q-ws* ")" | "prop(" q-ws* $string q-ws* ")" | "name(" q-ws* ")" | "tag(" q-ws* ")" | "values(" q-ws* ")" | "props(" q-ws* ")" | $string matcher-operator := "=" | "!=" | ">" | "<" | ">=" | "<=" | "^=" | "$=" | "*=" q-ws := $node-space ``` -------------------------------- ### KDL Version Marker Source: https://context7.com/kdl-org/kdl/llms.txt Shows how to declare the KDL version using a special slashdash comment at the beginning of a document. ```kdl /- kdl-version 2 package { name my-app version "1.0.0" } ``` -------------------------------- ### Deep Fetch Dependencies Source: https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md Deep-fetches all 'dependencies' nodes within the document. ```kdl dependencies ``` -------------------------------- ### KDL Multi-line String with Indentation Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Demonstrates a multi-line string with standard indentation. The string value omits the first and last newlines, and the common whitespace prefix from intermediate lines. ```kdl multi-line """ foo This is the base indentation bar """ ``` -------------------------------- ### KDL Special Float Keywords Source: https://github.com/kdl-org/kdl/blob/main/README.md Shows the use of special keywords for representing IEEE 754 floating-point values in KDL. ```kdl special-floats #inf #-inf #nan ``` -------------------------------- ### KDL String Types Source: https://context7.com/kdl-org/kdl/llms.txt Illustrates KDL's four string syntaxes: unquoted identifiers, quoted strings with escapes, raw strings disabling escapes, and multi-line strings that auto-dedent. ```kdl // Unquoted identifier string β€” no quotes needed unless it would be ambiguous node simple-value node path.to.thing node --flag ``` ```kdl // Quoted string with escape sequences node1 "line one\nline two\ttabbed" node2 "unicode \u{1F600} and backslash \\" ``` ```kdl // Raw string β€” backslashes are LITERAL, no escaping regex #"\d{3}-\d{4}" # windows-path #"C:\\Users\\Alice\\Documents"# ``` ```kdl // Multi-line raw string β€” useful for scripts and embedded code build-script #""" #!/usr/bin/env bash echo "building..." cargo build --release """# ``` ```kdl // Multi-line quoted string β€” dedented by the closing-quote indentation description """ This is the first line. This is the second line. """ // Value is: "This is the first line.\nThis is the second line." ``` ```kdl // Extra # symbols handle embedded delimiters tricky ##"the string ends with # not here"## ``` -------------------------------- ### Representing JSON True and Numbers in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md JSON literals can be written as nodes with any nodename and a single argument. Use '#' prefix for boolean literals. ```kdl - #true ``` ```kdl foo 5 ``` -------------------------------- ### KDL Slashdash Comments Source: https://github.com/kdl-org/kdl/blob/main/README.md Demonstrates KDL's 'slashdash' comments (`/-`) for commenting out nodes, entries, or child blocks. ```kdl // This entire node and its children are all commented out. /-mynode foo key=1 { a b c } mynode /-commented "not commented" /-key=value /-{ a b } // The above is equivalent to: mynode "not commented" ``` -------------------------------- ### Encode Unstructured PI Content to KDL String Source: https://github.com/kdl-org/kdl/blob/main/XML-IN-KDL.md If a PI's content is not attribute-like, it is encoded as a single string argument to the '?' prefixed KDL node. ```kdl ?xml #"version=\"1.0\""# ``` -------------------------------- ### Mixing Arguments and Child Nodes for JSON Arrays in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md Arguments and child nodes can be mixed to represent JSON array items. Arguments are placed before child nodes. ```kdl - 1 { - #true #false - 3 } ``` -------------------------------- ### Representing JSON Arrays with Arguments in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md JSON arrays can be represented using a KDL node with any nodename and zero or more arguments, where each argument is an array item. ```kdl - 1 2 3 ``` -------------------------------- ### Representing JSON Objects with Properties in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md JSON objects can be represented using a KDL node with properties, where property names are keys and arguments are values. ```kdl - foo=1 bar=#true ``` -------------------------------- ### KDL Multi-line String Newline Normalization Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Illustrates KDL's newline normalization for multi-line strings. Literal newline sequences like CRLF are converted to a single LF, while escaped newlines are preserved. ```kdl multi-line """ \r\n[CRLF] foo[CRLF] """ ``` -------------------------------- ### Semantically Identical Quoted Strings with Literal Whitespace Escapes Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Illustrates that literal whitespace characters preceded by a backslash are discarded, resulting in semantically identical strings. ```kdl "Hello World" ``` ```kdl "Hello \ World" ``` -------------------------------- ### KDL Number Literals Source: https://context7.com/kdl-org/kdl/llms.txt Shows KDL's number literal formats, including decimal, hexadecimal, octal, binary, and IEEE 754 special keywords. Underscores can be used for readability. ```kdl // Decimal integers and floats count 42 pi 3.141_592_653 scientific 1.234e-10 negative -0.5 with-plus +100 ``` ```kdl // Hexadecimal, octal, binary color 0xFF_AA_BB permissions 0o755 flags 0b1010_1111 ``` ```kdl // IEEE 754 special float keywords special-floats #inf #-inf #nan ``` ```kdl // Underscores for readability population 8_000_000_000 ``` -------------------------------- ### KDL Multi-line String with Shorter Last-line Indent Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Illustrates how a less-indented final line affects the dedentation of a multi-line string. The string value reflects the reduced common whitespace prefix. ```kdl multi-line """ foo This is no longer on the left edge bar """ ``` -------------------------------- ### Semantically Identical Quoted Strings with Escaped Whitespace Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Demonstrates how escaped whitespace is discarded, making strings with different whitespace representations semantically identical. Note that newline escapes (`\n`) are retained. ```kdl "Hello\nWorld" ``` ```kdl "Hello\n\ World" ``` ```kdl "Hello\nWorld" ``` ```kdl """ Hello World """ ``` -------------------------------- ### Encode XML Processing Instruction to KDL Node Source: https://github.com/kdl-org/kdl/blob/main/XML-IN-KDL.md Processing instructions are encoded as KDL nodes with a '?' prefix. Attributes within the PI are mapped to KDL properties. ```kdl ?xml version="1.0" ``` -------------------------------- ### KDL Raw String with Quotes Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Raw strings can contain quotes. The closing delimiter must match the number of '#' characters preceding the opening quote. ```kdl quotes-and-escapes ##"hello\n\r\asd"#world"## ``` -------------------------------- ### KDL Multi-line String Allowed Whitespace Escape Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Shows a valid use of whitespace escapes within a multi-line string. The escape sequence `\` at the end of a line is processed, and the string is dedented correctly. ```kdl """ foo \ bar baz \ """ ``` -------------------------------- ### KDL Number Readability Underscores Source: https://github.com/kdl-org/kdl/blob/main/README.md Illustrates the use of underscores within KDL numbers to improve readability. ```kdl bignum 1_000_000 ``` -------------------------------- ### Optimizing JSON Objects with Literal Properties in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md Literal-valued keys in a JSON object can be moved to properties, leaving child nodes for nested structures, for a more compact representation. ```kdl - foo=1 qux=4 { bar 2 { - baz=3 } } ``` -------------------------------- ### KDL Decimal Number Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Decimal numbers can include digits, underscores as separators, a decimal point, and an exponent. ```kdl decimal 1_000_000.5e-2 ``` -------------------------------- ### KDL Keyword Numbers Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md KDL supports special keyword numbers for infinity and NaN, which are often represented using IEEE 754 floats. ```kdl my-node #inf value=#-inf nan=#nan ``` -------------------------------- ### KDL Raw Multi-line String Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Multi-line raw strings do not interpret escape sequences. They are useful for embedding text with special characters. ```kdl raw-multi-line #""" Here's a """ multiline string """ without escapes. """# ``` -------------------------------- ### Encode XML Comment as KDL Node Source: https://github.com/kdl-org/kdl/blob/main/XML-IN-KDL.md Alternatively, comments can be encoded as a KDL node named '!' with a string argument. Use this if your KDL toolchain discards comments but you need to preserve them. ```kdl ! " comment! " ``` -------------------------------- ### KDL Boolean Values Source: https://github.com/kdl-org/kdl/blob/main/draft-marchan-kdl2.md Boolean values are represented by the symbols #true and #false. Implementations should map these to logical boolean values. ```kdl my-node #true value=#false ``` -------------------------------- ### KDL Object Node with Embedded JSON Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md This KDL snippet demonstrates embedding a JSON object within a KDL document, representing an HTTP request with a JSON body. The 'body' node contains the embedded JiK object. ```kdl request "/api/cart" method="PUT" { body { items { - id=1234 amount=1 - id=2341 amount=2 { options { color "red" size "XXL" } } } } } ``` -------------------------------- ### Annotating Single-Element JSON Arrays in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md A single-element array written with arguments, like '- 1', is ambiguous with a literal node. Use the '(array)' type annotation to clarify. ```kdl (array)- 1 ``` -------------------------------- ### Representing JSON Objects with Child Nodes in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md JSON objects can also be represented using child nodes, where the child nodename serves as the key and the child content represents the value. ```kdl - { foo 1 bar 2 { - baz=3 } qux 4 } ``` -------------------------------- ### Annotating Empty JSON Arrays in JiK Source: https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md An empty JSON array must use the '(array)' type annotation when represented as a node with no arguments or children. ```kdl (array)- ```