Skip to content

Add KDL format support (v1 + v2)#546

Merged
TomWright merged 5 commits into
masterfrom
feat/kdl-format
May 13, 2026
Merged

Add KDL format support (v1 + v2)#546
TomWright merged 5 commits into
masterfrom
feat/kdl-format

Conversation

@TomWright
Copy link
Copy Markdown
Owner

@TomWright TomWright commented May 13, 2026

Summary

  • Add KDL (KDL Document Language) as a new input/output format (-i kdl / -o kdl), supporting both v1 and v2 syntax with automatic version detection
  • Hand-written tokenizer, parser, and generator with zero external dependencies
  • Maps KDL's node-oriented model to dasel's ordered maps: scalar nodes become direct values, duplicate names promote to slices, mixed nodes use $args for arguments and properties as map keys
  • Configurable output version via --write-flag kdl-version=1 (bare true/false/null) or --write-flag kdl-version=2 (#true/#false/#null). Defaults to v2

Closes #504

Test plan

  • Internal tokenizer tests (v1 + v2 syntax, escapes, raw strings, multi-line strings, comments, numbers)
  • Internal parser tests (all node forms, slashdash, type annotations, version markers)
  • Internal generator tests (round-trip, compact mode, escaping, v1 vs v2 output)
  • Official KDL v2 spec test suite (73 tests from kdl-org/kdl test cases)
  • Official KDL v1 spec test suite (28 tests)
  • v1↔v2 conversion tests (20 tests verifying identical ASTs and round-trips)
  • Reader/writer integration tests (22 tests including version flag)
  • Cross-format tests: KDL↔JSON, KDL↔YAML, JSON→KDL, YAML→KDL (28 tests)
  • CLI-level cross-format tests in generic_test.go (33 subtests)
  • Full test suite passes with zero regressions

TomWright added 3 commits May 13, 2026 19:54
Implement KDL (KDL Document Language) as a new input/output format,
supporting both v1 and v2 syntax with automatic version detection.

Includes a from-scratch tokenizer, parser, and generator with no external
dependencies. The data model maps KDL nodes to ordered maps, with duplicate
node names promoted to slices and a $args key for multi-argument nodes.

Closes #504
- Check error returns from NextToken calls in parser
- Convert if/else chains to switch statements (staticcheck QF1003)
- Remove unused variable in test
Supports --write-flag kdl-version=1 for v1 output (bare true/false/null)
and --write-flag kdl-version=2 for v2 output (#true/#false/#null).
Defaults to v2.
@TomWright TomWright mentioned this pull request May 13, 2026
@TomWright TomWright merged commit 242bdc9 into master May 13, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add KDL support

1 participant