Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/spirit/home/x3.hpp>
- #include <string>
- #include <iostream>
- #include <ios>
- namespace x3 = boost::spirit::x3;
- namespace ascii = boost::spirit::x3::ascii;
- using ascii::char_;
- using x3::lexeme;
- using x3::_val;
- using x3::_attr;
- auto const append = [](auto& ctx) {
- _val(ctx) += _attr(ctx);
- };
- auto const backtick_code_point_foo = lexeme[
- '`' >> *char_("\x60\x6f")[append] >> '`'
- ];
- auto const backtick_ascii_foo = lexeme[
- '`' >> *char_("fo")[append] >> '`'
- ];
- class name_ascii_class;
- typedef x3::rule<name_ascii_class, std::string> name_ascii_type;
- name_ascii_type const name_ascii = "name_ascii";
- auto const name_ascii_def =
- backtick_ascii_foo
- ;
- class name_code_point_class;
- typedef x3::rule<name_code_point_class, std::string> name_code_point_type;
- name_code_point_type const name_code_point = "name_code_point";
- auto const name_code_point_def =
- backtick_code_point_foo
- ;
- BOOST_SPIRIT_DEFINE(name_ascii, name_code_point);
- int main(int argc, const char** argv) {
- namespace x3 = boost::spirit::x3;
- typedef std::pair<std::string, std::string> test_data_t;
- std::string data("`foo`");
- bool result = false;
- std::string parsed;
- std::cout << "Parsing `foo` with name_code_point parser: ";
- result = x3::phrase_parse(data.begin(),
- data.end(),
- name_code_point,
- x3::ascii::space,
- parsed);
- std::cout << result << std::endl;
- std::cout << "Parsing `foo` with name_ascii parser: ";
- result = x3::phrase_parse(data.begin(),
- data.end(),
- name_ascii,
- x3::ascii::space,
- parsed);
- std::cout << result << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement