PEGO Tutorial
A series of lessons that builds one project, a parser for a small configuration language, from a first grammar to a shipped, tested and debugged parser. Each lesson ends with a working result and starts from the files of the lessons before it, so read them in order the first time.
Every lesson has the same shape: what you will build, what you need first, the steps with verified output, and where to go next. The guides explain each feature in depth and the cookbook solves single tasks.
| Lesson | You will learn | |
|---|---|---|
| 1 | Getting Started With PEGO | Installing pego, writing a first grammar, parsing from the command line and from Go |
| 2 | Parsing Structured Input | Rules, ordered choice, repetition and lookahead, for a configuration file format |
| 3 | Building Typed Trees | Naming and shaping the tree, struct, join and text types, reading it in Go |
| 4 | Parsing Expressions | Operators and precedence with the Operators Rule, building a calculator |
| 5 | Reporting Errors | Reading syntax errors, writing clear messages, recovering and collecting several errors |
| 6 | Parsing Context-Sensitive Input | Predicates and variables for matching tags and limiting lengths |
| 7 | Testing and Linting a Grammar | Fixture suites, the linter and the formatter |
| 8 | Shipping a Parser | Generating Go code, compiled grammars and backends |
| 9 | Handling Big and Live Input | Streaming input, reparsing after edits |
| 10 | Working With the Tooling | Explaining, tracing and profiling a grammar, sampling inputs, the editor and the playground |
Requirements
Go 1.27.1 or later. The lessons use the pego command, which Getting Started With
PEGO shows how to install.