string_view and c.insert(c.end(), std::move(val)) compile error

Olaf Peter <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Hello,

for my x3 parser I replaced string with string_view, but failed in this 
concrete case. For some reasons it want to insert into a container which 
must fail in this case. I separated the raw rule, but no luck. Setting 
x3::raw outside works, but the double quotes are embedded which isn't 
intended. What do I overlook here? '"' is handled as literal, isn't it? 
Explicit use of x3::lit('"') doesn't change it. How to fix the rule? 
Note, I'm using an older compiler not fully C++17 aware :(


Thanks,

Olaf

---8<---

#include <iostream>
#include <vector>


#include <experimental/string_view>

namespace boost { namespace spirit { namespace x3 { namespace traits {

template <typename It>
void move_to(It b, It e, std::experimental::string_view& v)
{
     // Note storage is contiguous, requires a concept check for input 
range, how to?
     v = std::experimental::string_view(&*b, e - b);
}

} } } }


//#define BOOST_SPIRIT_X3_DEBUG
#include <boost/spirit/home/x3.hpp>

#if 1
// XXX basic_string_view<char>« has no member named »insert« XXX
typedef std::experimental::string_view  attribute_type;
#else
typedef std::string                     attribute_type;
#endif

namespace parser {

     namespace x3 = boost::spirit::x3;
     namespace iso8859_1 = boost::spirit::x3::iso8859_1;

     using iso8859_1::char_;

     auto const string_literal_atom = x3::rule<struct _, attribute_type> 
{ "string_literal" } =
         x3::raw[ x3::lexeme [
             *(  (char_ - '"')
              | "\"\""
              )
         ]]
         ;

     auto const string_literal = x3::rule<struct _, attribute_type> { 
"string_literal" } =
         x3::no_skip[
            '"'
         >> string_literal_atom
         >> '"'
         ]
         ;
}


int main()
{
     namespace x3 = boost::spirit::x3;

     std::vector<std::string> const test_cases {
         R"("FooBar")",
         R"("FooBar"  )",
         R"(    "FooBar"  )",
         R"(" "" FooBarBaz "" ")"       // with ""inner escaped"" quotes
         };

     typedef std::string::const_iterator iterator_type;

     for(auto str: test_cases) {
         iterator_type iter = str.begin();
         iterator_type const end = str.end();

         attribute_type attr;

         auto& rule = parser::string_literal;

         std::cout << "parse '" << str << "': ";

         bool r = phrase_parse(iter, end, *x3::space >> rule, x3::space, 
attr);

         if (r && iter == end) {
             std::cout << "succeeded: '" << attr << "'\n";
         } else {
             std::cout << "*** failed ***\n";
         }
     }

     return 0;
}

--->8---


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.