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";
}
}
This library is header-only, and has no Boost dependencies by default.
Features:
This library first appeared in Boost 1.87.0
Master status:
Develop status:
<h1>parser</h1> <p>This is a parser combinator library for C++. As a quick example of use, here is a complete program that parses one or more <code>double</code>s separated by commas, ignoring whitespace:</p> <pre class="highlightjs highlight"><code class="language-c++ hljs">#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"; } } </code></pre> <p>This library is header-only, and has no Boost dependencies by default.</p> <p>Features:</p> <ul> <li>Parsers that parse a variety of things.</li> <li>Combining operations that make complex parsers out of simpler ones.</li> <li>Multiple ways of getting data out of the parse, including via callbacks.</li> <li>Sentinel- and range-friendly.</li> <li>Very Unicode friendliness.</li> <li>Excellent error reporting, via diagnostics like those produced by GCC and Clang.</li> <li>Trace support for debugging your parsers.</li> <li>Clever hacks to make compile time errors easier to deal with. (These are totally optional.)</li> </ul> <p>This library first appeared in Boost 1.87.0</p> <p>Master status:</p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml/badge.svg?branch=master" alt="Ubuntu" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/fedora.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/fedora.yml/badge.svg?branch=master" alt="Fedora" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/windows.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/windows.yml/badge.svg?branch=master" alt="Windows MSVC" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/macos-13.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/macos-13.yml/badge.svg?branch=master" alt="macos-13 - Clang 14" /></a></p> <p>Develop status:</p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml/badge.svg?branch=develop" alt="Ubuntu" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/fedora.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/fedora.yml/badge.svg?branch=develop" alt="Fedora" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/windows.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/windows.yml/badge.svg?branch=develop" alt="Windows MSVC" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/macos-15.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/macos-15.yml/badge.svg?branch=develop" alt="macos-15 - Clang" /></a></p> <p><a href="LICENSE_1_0.txt"><img src="https://img.shields.io/badge/license-boost-brightgreen.svg" alt="License" /></a></p>
<h1>parser</h1> <p>This is a parser combinator library for C++. As a quick example of use, here is a complete program that parses one or more <code>double</code>s separated by commas, ignoring whitespace:</p> <pre class="highlightjs highlight"><code class="language-c++ hljs">#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"; } } </code></pre> <p>This library is header-only, and has no Boost dependencies by default.</p> <p>Features:</p> <ul> <li>Parsers that parse a variety of things.</li> <li>Combining operations that make complex parsers out of simpler ones.</li> <li>Multiple ways of getting data out of the parse, including via callbacks.</li> <li>Sentinel- and range-friendly.</li> <li>Very Unicode friendliness.</li> <li>Excellent error reporting, via diagnostics like those produced by GCC and Clang.</li> <li>Trace support for debugging your parsers.</li> <li>Clever hacks to make compile time errors easier to deal with. (These are totally optional.)</li> </ul> <p>This library first appeared in Boost 1.87.0</p> <p>Master status:</p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml/badge.svg?branch=master" alt="Ubuntu" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/fedora.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/fedora.yml/badge.svg?branch=master" alt="Fedora" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/windows.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/windows.yml/badge.svg?branch=master" alt="Windows MSVC" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/macos-13.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/macos-13.yml/badge.svg?branch=master" alt="macos-13 - Clang 14" /></a></p> <p>Develop status:</p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/ubuntu.yml/badge.svg?branch=develop" alt="Ubuntu" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/fedora.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/fedora.yml/badge.svg?branch=develop" alt="Fedora" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/windows.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/windows.yml/badge.svg?branch=develop" alt="Windows MSVC" /></a></p> <p><a href="https://github.com/tzlaine/parser/actions/workflows/macos-15.yml"><img src="https://github.com/tzlaine/parser/actions/workflows/macos-15.yml/badge.svg?branch=develop" alt="macos-15 - Clang" /></a></p> <p><a href="LICENSE_1_0.txt"><img src="https://img.shields.io/badge/license-boost-brightgreen.svg" alt="License" /></a></p>