GithubHelp home page GithubHelp logo

tempbottle / pegtl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taocpp/pegtl

0.0 1.0 0.0 2.39 MB

Parsing Expression Grammar Template Library

License: MIT License

Python 0.47% CMake 0.98% C++ 98.23% Makefile 0.32%

pegtl's Introduction

Welcome to the PEGTL

Release Download TravisCI AppVeyor Coverage

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

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 how a PEG grammar rule is implemented as C++ class with the PEGTL.

// PEG rule for integers consisting of a non-empty
// sequence of digits with an optional sign:

// integer ::= ( '+' / '-' )? digit+

// The same parsing rule implemented with the PEGTL:

using namespace tao::pegtl;

struct integer : seq< opt< one< '+', '-' > >, 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. The included grammar analysis finds several typical errors in PEGs, including left recursion.

Design

The PEGTL is designed to be "lean and mean", the core library consists of approximately 6000 lines of code. Emphasis is on simplicity and efficiency, preferring a well-tuned simple approach over complicated optimisations.

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 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.

With the PEG formalism, the separation into lexer and parser stages is usually dropped -- everything is done in a single grammar. The rules are expressed in C++ as template instantiations, and it is the compiler's task to optimise PEGTL grammars.

Status

Each commit is automatically tested with multiple architectures, operating systems, compilers, and versions thereof.

  • Windows

    • Visual Studio 2017 (x86, x64)
  • macOS (using libc++)

    • macOS 10.13, Xcode 9.4
    • macOS 10.13, Xcode 10.0
  • Ubuntu 14.04 LTS (using libstdc++)

    • GCC 7.x, 8.x
    • Clang 5.x, 6.x, 7.x

Additionally, each commit is checked with GCC's and Clang's sanitizers, as well as valgrind and clang-tidy. Code coverage is automatically measured and the unit tests cover 100% of the core library code (for releases).

Releases are done in accordance with Semantic Versioning. Incompatible API changes are only allowed to occur between major versions. For details see the changelog.

Thank You

  • Christopher Diggins and the YARD parser for the general idea.
  • George Makrydakis for the inspiration to TAO_PEGTL_STRING.
  • Johannes Overmann for his invaluable streplace command-line tool.
  • Jörg-Christian Böhme for improving the Android CI build.
  • Kai Wolf for help with CMake.
  • Kenneth Geisshirt for Android compatibility and Android CI.
  • Kuzma Shapran for EOL testing and fixes.
  • Michael Becker for help with CMake.
  • Paul Le Roux for CMake improvements and Conan support.
  • Paulo Custodio for Windows-related fixes.
  • Sam Hocevar for contributing Visual Studio 2015 compatibility.
  • Stephan Beal for the bug reports, suggestions and discussions.
  • Stuart Dootson for mmap_input<> support on Windows.
  • Sven Johannsen for help with CMake.
  • Zhihao Yuan for fixing several warnings when compiling with Visual Studio 2015.

Contact

The PEGTL is part of The Art of C++.

For questions and suggestions regarding the PEGTL, success or failure stories, and any other kind of feedback, please feel free to contact the authors at taocpp(at)icemx.net.

License

The PEGTL is certified Open Source software. It may be used for any purpose, including commercial purposes, at absolutely no cost. It is distributed under the terms of the MIT license reproduced here.

Copyright (c) 2007-2018 Dr. Colin Hirsch and Daniel Frey

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pegtl's People

Contributors

andoma avatar bjoe avatar bwagner avatar colinh avatar d-frey avatar delpinux avatar joelfrederico avatar kuzmas avatar lambdafu avatar lichray avatar michael-brade avatar mkrupcale avatar pauloscustodio avatar pleroux0 avatar quadfault avatar samhocevar avatar sanssecours avatar studoot avatar uilianries avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.