Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tutorial: TOML Parser

Build a complete TOML parser with round-trip printing using synkit.

Source Code

📦 Complete source: examples/toml-parser

What You’ll Build

A parser for a TOML subset supporting:

# Comment
key = "value"
number = 42
flag = true

[section]
nested = "data"

[section.subsection]
array = [1, 2, 3]
inline = { a = 1, b = 2 }

Source Code

The complete example lives in examples/toml-parser/. Each chapter references the actual code.

Chapters

  1. Project Setup - Dependencies, error type, parser_kit! invocation
  2. Defining Tokens - Token patterns and attributes
  3. AST Design - Node types with Spanned<T>
  4. Parse Implementations - Converting tokens to AST
  5. Round-trip Printing - ToTokens for output
  6. Visitors - Traversing the AST
  7. Testing - Parse and round-trip tests