百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

PEGTL

> 后端框架
开源

解析表达式语法模板库

2.1K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

解析表达式语法模板库

# Welcome to the PEGTL
The **Parsing Expression Grammar Template Library** (PEGTL) is a zero-dependency [C++](https://en.cppreference.com/w/cpp.html) [header-only](https://en.wikipedia.org/wiki/Header-only) [parser combinator](https://en.wikipedia.org/wiki/Parser_combinator) library for creating [parsers](https://en.wikipedia.org/wiki/Parsing#Parser) according to a [Parsing Expression Grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) (PEG). ## Documentation * [Main Branch Documentation](https://github.com/taocpp/PEGTL/blob/main/doc/README.md)   [C++20](https://en.cppreference.com/w/cpp/20.html) * [Version 4.x Documentation](https://github.com/taocpp/PEGTL/blob/4.x/doc/README.md)   [C++17](https://en.cppreference.com/w/cpp/17.html) * [Version 3.x Documentation](https://github.com/taocpp/PEGTL/blob/3.x/doc/README.md)   [C++17](https://en.cppreference.com/w/cpp/17.html) * [Version 2.x Documnetation](https://github.com/taocpp/PEGTL/blob/2.x/doc/README.md)   [C++11](https://en.cppreference.com/w/cpp/11.html) * [Version 1.x Documentation](https://github.com/taocpp/PEGTL/blob/1.x/doc/README.md)   [C++11](https://en.cppreference.com/w/cpp/11.html) ## 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](doc/Rule-Reference.md) that can be combined and extended by the user is included, as are mechanisms for [debugging grammars](doc/Debug-Facilities.md), and for attaching user-defined [actions](doc/Actions-and-States.md) to grammar rules. Here is an example of a parsing expression [grammar rule](doc/Rules-and-Grammars.md) implemented as a C++ class with the PEGTL. ```c++ // 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](https://en.wikipedia.org/wiki/Context-free_grammar) (CFGs), however the more deterministic nature of PEGs gives rise to some very important differences in semantics. The included [grammar analysis](doc/Debug-Facilities.md#grammar-analysis) finds several typical errors in PEGs, including [left recursion](https://en.wikipedia.org/wiki/Left_recursion). ## Design The PEGTL is designed to be "lean and mean". The core library has around 12K lines of code. Emphasis is on simplicity and efficiency, putting a well-tuned *relatively* simple approach above overly complex 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](doc/Actions-and-States.md) are taken, and whether/which data structures are created during a [parsing run](doc/Inputs-and-Parsing.md), is entirely up to the user. Included are some [examples](doc/Example-Reference.md) for typical situations like parsing integers, unescaping escape sequences in strings, building a generic [JSON](http://www.json.org/) 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 parsing rules of grammars are expressed in C++ as template instantiations, and it is *mostly* the compiler's task to optimize PEGTL grammars. ## Status Each commit is automatically tested with multiple architectures, operating systems, compilers, and versions thereof. Each commit is checked with the GCC and Clang [sanitizers](https://github.com/google/sanitizers), Clang's [Static Analyzer](https://clang-analyzer.llvm.org/), and [`clang-tidy`](http://clang.llvm.org/extra/clang-tidy/). Additionally, we use [CodeQL](https://securitylab.github.com/tools/codeql) to scan for (security) issues. Code coverage is automatically measured, for releases the unit tests cover 100% of the core library (with the caveat that coverage of C++ code, especially with many templates, is not an exact science.) [Releases](https://github.com/taocpp/PEGTL/releases) are done in accordance with [Semantic Versioning](http://semver.org/). Incompatible changes to the public API are *only* allowed to occur with a new major version. For a stable experience please download [the latest release](https://github.com/taocpp/PEGTL/releases). ## 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](https://github.com/taocpp/PEGTL/discussions), an [issue](https://github.com/taocpp/PEGTL/issues) or a [pull request](https://github.com/taocpp/PEGTL/pulls), or contact the authors at `taocpp(at)icemx.net`. ## Thank You In appreciation of all contributions here are the people that have [directly contributed](https://github.com/taocpp/PEGTL/graphs/contributors) to the PEGTL and/or its development. [](https://github.com/amphaal) [](https://github.com/anand-bala) [](https://github.com/andoma) [](https://github.com/barbieri) [](https://github.com/bjoe) [](https://github.com/bwagner) [](https://github.com/cdiggins) [](https://github.com/clausklein) [](https://github.com/delpinux) [](https://github.com/dkopecek) [](https://github.com/gene-hightower) [](https://github.com/irrequietus) [](https://github.com/jedelbo) [](https://github.com/joelfrederico) [](https://github.com/johelegp) [](https://github.com/jovermann) [](https://github.com/jubnzv) [](https://github.com/kelvinhammond) [](https://github.com/kneth) [](https://github.com/kuzmas) [](https://github.com/lambdafu) [](https://github.com/lichray) [](https://github.com/michael-brade) [](https://github.com/mkrupcale) [](https://github.com/newproggie) [](https://github.com/obiwahn) [](https://github.com/ohanar) [](https://github.com/pauloscustodio) [](https://github.com/pleroux0) [](https://github.com/quadfault) [](https://github.com/quarticcat) [](https://github.com/ras0219) [](https://github.com/redmercury) [](https://github.com/robertcampion) [](https://github.com/samhocevar) [](https://github.com/sanssecours) [](https://github.com/sgbeal) [](https://github.com/skyrich62) [](https://github.com/studoot) [](https://github.com/svenjo) [](https://github.com/wickedmic) [](https://github.com/wravery) [](https://github.com/zhihaoy) ## The Art of C++ The PEGTL is part of [The Art of C++](https://taocpp.github.io/). [](https://github.com/ColinH) [](https://github.com/d-frey) [](https://github.com/uilianries) ## License Copyright (c) 2007-2026 Dr. Colin Hirsch and Daniel Frey The PEGTL is certified [Open Source](http://www.opensource.org/docs/definition.html) software. It is [licensed](https://pdimov.github.io/blog/2020/09/06/why-use-the-boost-license/) under the terms of the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt) 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.

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

核心特点

  • •Main Branch Documentation &nbsp; <sup>C++20</sup>
  • •Version 4.x Documentation &nbsp; <sup>C++17</sup>
  • •Version 3.x Documentation &nbsp; <sup>C++17</sup>
  • •Version 2.x Documnetation &nbsp; <sup>C++11</sup>
  • •Version 1.x Documentation &nbsp; <sup>C++11</sup>

> 标签

C++cppcpp11cpp17grammar

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架