taocpp/PEGTL
taocpp/PEGTL has 2,170 GitHub stars and 248 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-07 22:49 UTC. Last push 2026-11-02.
Parsing Expression Grammar Template Library
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalWelcome to the PEGTL
The Parsing Expression Grammar Template Library (PEGTL) is a zero-dependency C++ header-only parser combinator library for creating parsers according to a Parsing Expression Grammar (PEG).
Documentation
- Main Branch Documentation C++23
- Version 4.x Documentation C++17
- Version 3.x Documentation C++17
- Version 2.x Documnetation C++11
- Version 1.x Documentation C++11
Introduction
Grammars are written as regular C++ code, created with template programming (not template meta programming), i.e. nested template instantiations that naturally correspond to the inductive definition of PEGs (and other parser-combinator approaches).
A comprehensive set of parser rules that can be combined and extended by the user is included, as are mechanisms for debugging grammars, and for attaching user-defined actions to grammar rules. Here is an example of a parsing expression grammar rule implemented as a C++ class with the PEGTL.
// PEG rule for integers consisting of a non-empty
// sequence of digits with an optional sign:
// sign ::= '+' / '-'
// integer ::= sign? digit+
// The same parsing rule implemented with the PEGTL:
using namespace tao::pegtl;
struct sign : one< '+', '-' > {};
struct integer : seq< opt< sign >, plus< digit > > {};
PEGs are superficially similar to Context-Free Grammars (CFGs), however the more deterministic nature of PEGs gives rise to some very important differences in semantics. The included grammar analysis finds several typical errors in PEGs, including left recursion.
Design
The PEGTL is designed to be "lean and mean", putting a well-tuned relatively simple approach above overly complex optimizations. Grammars and parsing rules are expressed in C++ as template instantiations, burdening the compiler with a lot of the optimizations.
The PEGTL is mostly concerned with parsing combinators and grammar rules, and with giving the user of the library (the possibility of) full control over all other aspects of a parsing run. Whether/which actions are taken, and whether/which data structures are created during a parsing run, is entirely up to the user.
Included are some examples for typical situations like parsing integers, unescaping escape sequences in strings, building a generic JSON data structure, and on-the-fly evaluation of arithmetic expressions.
Through the use of template programming and template specialisations it is possible to write a grammar once, and use it in multiple ways with different (semantic) actions in different (or the same) parsing runs.
With the PEG formalism, the separation into lexer and parser stages is usually dropped -- everything is done in a single grammar. The PEGTL can however also be used to implement a tokenizer as well as for parsing sequences of arbitrary custom token objects.
Quality
An extensive test suite is run automatically on each push, running on multiple architectures, operating system, compilers, and versions thereof.
The test suite is also run with the GCC and Clang sanitizers, Clang's Static Analyzer, and clang-tidy.
Additionally, CodeQL is used to scan for (security) issues.
Releases are done in accordance with Semantic Versioning; incompatible changes to the public API are only allowed to occur with a new major version.
For releases the test suite covers 100% of the core library. To make up for the imprecision of code coverage measurements on C++ code with this many templates, AI is also used to verify full test coverage.
For a stable experience please download the latest release instead of using the current state of development on the main branch.
Contact
For questions and suggestions regarding the PEGTL, success or failure stories, and any other kind of feedback, please feel free to open a discussion, an issue or a pull request, or contact the authors at taocpp(at)icemx.net.
Thank You
In appreciation of all contributions here are the people that have directly contributed to the PEGTL and/or its development.
The Art of C++
The PEGTL is part of The Art of C++.
License
Copyright (c) 2007-2026 Dr. Colin Hirsch and Daniel Frey
The PEGTL is certified Open Source software. It is licensed under the terms of the Boost Software License, Version 1.0 reproduced here.
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following:
The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Explore related projects
codecrafters-io/build-your-own-x
Master programming by recreating your favorite technologies from scratch.
560,836 starspublic-apis/public-apis
A collective list of free APIs
497,076 starsmorluto/rea
Reverse engineer anything with agents, from app behavior down to native binaries.
441,480 starsopenclaw/openclaw
The AI that really does things. Any OS. Any Platform. The lobster way. 🦞
394,157 stars