GithubHelp home page GithubHelp logo

tzlaine / parser Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 4.0 7.56 MB

A C++ parser combinator library.

License: Boost Software License 1.0

CMake 0.23% Shell 0.14% Python 2.00% C++ 97.41% C 0.14% Starlark 0.09%

parser's Introduction

parser

This is a parser combinator library for C++. As a quick example of use, here is a complete program that parses one or more doubles separated by commas, ignoring whitespace:

#include <boost/parser/parser.hpp>

#include <iostream>
#include <string>


namespace bp = boost::parser;

int main()
{
    std::cout << "Enter a list of doubles, separated by commas.  No pressure. ";
    std::string input;
    std::getline(std::cin, input);

    auto const result = bp::parse(
        input, bp::double_ >> *(',' >> bp::double_), bp::ws);

    if (result) {
        std::cout << "Great! It looks like you entered:\n";
        for (double x : *result) {
            std::cout << x << "\n";
        }
    } else {
        std::cout
            << "Good job!  Please proceed to the recovery annex for cake.\n";
    }
}

Features:

  • Parsers that parse a variety of things.
  • Combining operations that make complex parsers out of simpler ones.
  • Multiple ways of getting data out of the parse, including via callbacks.
  • Sentinel- and range-friendly.
  • Very Unicode friendliness.
  • Excellent error reporting, via diagnostics like those produced by GCC and Clang.
  • Trace support for debugging your parsers.
  • Clever hacks to make compile time errors easier to deal with. (These are totally optional.)

This library targets submission to Boost.

Online docs: https://tzlaine.github.io/parser

Master status:

example workflow

example workflow

example workflow

example workflow

example workflow

Develop status:

example workflow

example workflow

example workflow

example workflow

example workflow

License

parser's People

Contributors

djowel avatar hkaiser avatar mjcaisse avatar tobias-loew avatar tzlaine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

parser's Issues

Generation of variants is probably broken if multiple alternatives have the same type

Unverified. If this is the case, this is a fix:

    template<typename... Ts>
    auto to_variant(hana::set<Ts...> const &)
    {
        return std::variant<typename Ts::type...>{};
    }

            auto const types = hana::transform(tuple_of_possible_dupes, [](auto const & x) {
                return hana::type_c<std::remove_cvref_t<decltype(x)>>;
            });
            auto const unique_types = hana::to_set(types);
            return detail::to_variant(unique_types);

Consider making eps | int_ il-formed

It should be ill-formed because we know that eps matches anything, and so later alternatives will never be executed. It is almost certainly a mistake for the user to write that, and catching it at compile time which a helpful static_assert() will catch bugs. There may be more cases than just eps to consider as well.

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.