Skip to content

dector/tree-sitter-kdl2

 
 

Repository files navigation

tree-sitter-kdl

Build Status Discord

KDL 2.0 grammar for tree-sitter

Adapted from the official KDL 2.0 spec

KDL 2.0 Support

This grammar implements the KDL 2.0 specification with breaking changes from KDL 1.0.

Breaking Changes from KDL 1.0

1. Tagged Literals (Boolean and Null)

Boolean and null values now require the # prefix:

// KDL 1.0
node true false null

// KDL 2.0
node #true #false #null

2. Raw String Syntax

Raw strings use a new syntax with # delimiters instead of the r prefix:

// KDL 1.0
node r"raw string"
node r#"with hash"#

// KDL 2.0
node #"raw string"#
node ##"with hash"##

3. Multi-line Strings (NEW)

Support for triple-quoted multi-line strings:

node """
    This is a
    multi-line string
    """

Note: Opening delimiter must be followed immediately by a newline. Closing delimiter must be on its own line with optional leading whitespace.

4. String Escape Sequences

  • Removed: \/ (forward slash escape)
  • Added: \s (space character U+0020)
// KDL 2.0 escapes
node "quote: \" backslash: \\ space: \s newline: \n"

5. Optional Version Marker

Documents can optionally start with a version marker:

/- kdl-version 2

node "content"

6. Line Continuations

Line continuations now support EOF:

node \

7. BOM Handling

The Byte Order Mark (U+FEFF) is now only allowed as the first character in a document, not as general whitespace.

Implementation Status

Fully Implemented:

  • Tagged literals (#true, #false, #null)
  • Raw string syntax (#"..."#)
  • String escape changes (\s added, \/ removed)
  • Line continuation with EOF support
  • Optional version marker
  • BOM restrictions

🚧 In Progress:

  • Multi-line string support (parser implemented, needs testing)
  • Character validation for banned code points
  • Test suite updates for KDL 2.0 syntax

Migration from KDL 1.0

To migrate KDL 1.0 documents to KDL 2.0:

  1. Add # prefix to all boolean and null values
  2. Change raw strings from r"..." to #"..."#
  3. Replace \/ escapes with / (no escape needed)
  4. Optionally use \s for explicit space escapes

Installation

See the original repository for installation instructions.

About

KDLv2 grammar for tree-sitter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 32.5%
  • JavaScript 26.5%
  • C++ 25.0%
  • Rust 7.2%
  • Shell 2.9%
  • Tree-sitter Query 2.7%
  • Other 3.2%