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

The Tokora Guide

Tokora writes parsers as plain Rust functions with the reach of a combinator library. It lexes on demand as the parser pulls tokens — there is no separate tokenize pass — and gives you typed, structured errors with rich diagnostics, explicit backtracking and recovery, streaming over partial input, and optional lossless concrete syntax trees that preserve every byte (whitespace and comments included) for formatters, refactoring tools, and language servers.

This guide is the tour. The reference documentation explains each API in isolation; the guide tells the story in order, building Calc — a tiny calculator language with variables — end to end, then reusing it to introduce the harder machinery.

program := stmt+
stmt    := "let" ident "=" expr ";"        bind a variable
         | "print" expr ("," expr)* ";"    print one or more values
         | expr ";"                        evaluate and discard
expr    := integers, variables, + - * / ^, unary -, ( ) grouping

The five parts

Two topics ride a feature flag: Testing (Part II) needs conformance, and both Lossless CSTs (Part IV) and the event-stream CST engine (Part III) need rowan.

How to read this guide

Every non-ignored Rust fence is a doctest — the suite compiles and runs it, so the examples cannot quietly drift from the API. Later chapters may hide reduced token and error definitions to keep the visible code focused (expand an example in the HTML docs to see them). Chapters build on each other, but each states what it teaches up front, so you can jump in anywhere. Pick a path:

  • New to tokora — read Part I, work Part II in order, then open the matching walkthrough in Part IV.
  • Using tokora as a library — Part V is the lookup catalog; its entries point back to the chapter that teaches each API.
  • Contributing, or just curious how it works — Part III is the internals tour; it assumes Part II.

The four examples/ programs in the repository (json, calculator, s_expression, and c_expression) are canonical complete programs; the applied chapters explain how to reproduce their structure without copying their source into the guide.