Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Example for SO question
/**
* \author Sergey Miryanov (sergey.miryanov@gmail.com)
* */
#define BOOST_SPIRIT_QI_DEBUG
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/bind.hpp>
#include <iostream>
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;
namespace spirit = boost::spirit;
template <typename Iterator>
struct Grammar : qi::grammar <Iterator>
{
Grammar ()
: Grammar::base_type (expression)
{
using qi::char_;
using qi::string;
using qi::symbols;
using qi::no_case;
using qi::alnum;
using qi::lexeme;
using qi::_val;
using ascii::space;
symbols <char, char const*> control, limit;
control.add
("prod", "PROD")
;
limit.add
("oil", "OIL")
;
qi::rule <Iterator, std::string ()> str = +alnum;
param = "WELL" >> space >> str >> ((space >> no_case[control]) || (space >> no_case[limit])) >> space >> qi::eol
;
BOOST_SPIRIT_DEBUG_NODE (param);
expression = qi::no_skip[param];
}
qi::rule <Iterator> param, expression;
qi::rule <Iterator> well;
};
void
parse (char *text, size_t len)
{
std::cout << text << std::endl;
char *begin = text;
char *end = &text[len];
Grammar <char *> g;
bool r = phrase_parse (begin, end, g, ascii::space);
if (begin != end)
{
std::cout << r << ": " << end - begin << std::endl;
std::cout << r << ": " << end << std::endl;
}
}
int
main ()
{
char test[] = "WELL name3 PROD OIL \n";
parse (test, sizeof (test) - 1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.