Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <boost/spirit/home/qi.hpp>
- #include <vector>
- #include <string>
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
- struct escapedDoubleQuote_ : qi::symbols<char, std::string >
- {
- escapedDoubleQuote_()
- {
- add("""", "\"");
- }
- } escapedDoubleQuote;
- template<typename Iterator>
- struct MyGrammar : qi::grammar<Iterator, std::string()>
- {
- MyGrammar() : MyGrammar::base_type(escapedField)
- {
- subField = +(~qi::char_("""));
- escapedField =
- qi::lexeme[ // or qi::as<std::string> ... both seems to do nothing.
- subField
- >> -(escapedDoubleQuote >> escapedField)
- ];
- }
- qi::rule<Iterator, std::string()> subField;
- qi::rule<Iterator, std::string()> escapedField;
- };
- int main()
- {
- typedef std::string::const_iterator iterator_type;
- typedef MyGrammar<iterator_type> parser_type;
- parser_type parser;
- std::string input = "123""456""789";
- std::string output;
- iterator_type it = input.begin();
- bool parsed = parse(
- it,
- input.cend(),
- parser,
- output
- );
- if(parsed && it == input.end())
- {
- std::cout << output << std::endl;
- // expected: 123"456"789
- // actual : "789
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement