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).
Selama pengembangan versi utama baru, cabang utama dapat mengalami perubahan yang tidak kompatibel. Untuk pengalaman yang stabil, silakan unduh rilis terbaru daripada menggunakan cabang utama.
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 .
Grammars are written as regular C++ code, created with template programming (not template meta programming), ie 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. Berikut adalah contoh bagaimana aturan tata bahasa ekspresi parsing diimplementasikan sebagai kelas C ++ dengan 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. Analisis tata bahasa yang disertakan menemukan beberapa kesalahan khas dalam pasak, termasuk rekursi kiri.
PEGTL dirancang untuk "ramping dan rata -rata", perpustakaan inti terdiri dari sekitar 6000 baris kode. Penekanannya adalah pada kesederhanaan dan efisiensi, lebih memilih pendekatan sederhana yang disetel dengan baik daripada optimisasi yang rumit.
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. Apakah/tindakan mana yang diambil, dan apakah/struktur data mana yang dibuat selama penguraian, sepenuhnya tergantung pada pengguna.
Included are some examples for typical situation like 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.
Dengan formalisme PEG, pemisahan ke tahap lexer dan parser biasanya dijatuhkan - semuanya dilakukan dalam satu tata bahasa. Aturan dinyatakan dalam C ++ sebagai instantiasi template, dan itu adalah tugas kompiler untuk mengoptimalkan tata bahasa PEGTL.
Setiap komit diuji secara otomatis dengan beberapa arsitektur, sistem operasi, kompiler, dan versi daripadanya.
Setiap komit diperiksa dengan sanitizer GCC dan Clang, penganalisa statis Clang, dan clang-tidy . Selain itu, kami menggunakan CodeQL untuk memindai masalah (keamanan).
Cakupan kode diukur secara otomatis dan tes unit mencakup 100% kode perpustakaan inti (untuk rilis).
Rilis dilakukan sesuai dengan versi semantik. Perubahan API yang tidak kompatibel hanya diizinkan terjadi antara versi utama.
Sebagai penghargaan atas semua kontribusi di sini adalah orang -orang yang secara langsung berkontribusi pada PEGTL dan/atau pengembangannya.
PEGTL adalah bagian dari seni C ++.
Hak Cipta (C) 2007-2023 Daniel Frey dan Dr. Colin Hirsch
PEGTL adalah perangkat lunak open source bersertifikat. Ini dilisensikan berdasarkan ketentuan lisensi perangkat lunak Boost, versi 1.0 direproduksi di sini.
Boost Software License - Versi 1.0 - 17 Agustus 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.