Skip to content

pegtoolA PEG parser generator written in Go

Generate reviewable, deployable parser source for Go, Haxe, TypeScript, C#, C99, and Rust.

What is pegtool?

pegtool is a PEG (Parsing Expression Grammar) parser generator written in Go. A single grammar can generate source code for Go, Haxe, TypeScript, C#, C99, and Rust. The project forked from Pigeon in 2024, from a baseline that included Pigeon's 2023 v1.2.x release line. Its grammar and runtime have evolved independently since then. The main reason for the fork was to improve upstream Pigeon's performance on real grammars. Many optimizations followed, and some required changes to grammar and value semantics. See Pigeon #151 for the early analysis.

powershell
pegtool -t go   -o parser.go grammar.peg
pegtool -t hx   -o Parser.hx grammar.peg
pegtool -t ts   -o parser.ts grammar.peg
pegtool -t cs   -o Parser.cs grammar.peg
pegtool -t c    -o parser.c grammar.peg
pegtool -t rust -o parser.rs grammar.peg

Where to start

Keep the defaults first

Do not enable memoization until benchmarks show that the same named rule is repeatedly evaluated at the same input position. Do not enable rule index optimization unless generated files are excluded from code review.

Released under the BSD 3-Clause License