Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing quoted string only works in some cases
    primarykey
    data
    text
    <p>I've encountered something weird when trying to parse simple quoted strings. So I've written this simple parser that successfully parses quoted strings like <code>"string"</code> or <code>""</code>.</p> <pre><code>#include &lt;iostream&gt; #include "boost/spirit/include/qi.hpp" namespace qi = boost::spirit::qi; namespace iso8859 = boost::spirit::iso8859_1; int main( int argc, char* argv[] ) { using namespace qi; std::string input = "\"\""; std::string::const_iterator front = input.cbegin(); std::string::const_iterator end = input.cend(); bool parseSuccess = phrase_parse( front, end, '\"' &gt;&gt; *~char_('\"') &gt;&gt; '\"', iso8859::space ); if ( front != end ) { std::string trail( front, end ); std::cout &lt;&lt; "String parsing trail: " &lt;&lt; trail &lt;&lt; std::endl; } if ( !parseSuccess ) std::cout &lt;&lt; "Error parsing input string" &lt;&lt; std::endl; std::cout &lt;&lt; "Press enter to exit" &lt;&lt; std::endl; std::cin.get(); return 0; } </code></pre> <p>This all works perfectly fine, but when I extend the parsing rules to also parse things before the quoted string, it suddenly breaks..</p> <p>So, of example, this parses successfully:</p> <p><code>std::string input = "normalString 10.0 1.5 1.0 1.0 1.0 1.0"</code> With parsing rule:</p> <p><code>*char_ &gt;&gt; *double_</code></p> <p>And now if I combine this rule with the quoted string rule:</p> <p><code>std::string input = "normalString 10.0 1.5 1.0 1.0 1.0 1.0 \"quotedString\""</code></p> <p>With parsing rule:</p> <p><code>*char_ &gt;&gt; *double_ &gt;&gt; '\"' &gt;&gt; *~char_('\"') &gt;&gt; '\"'</code></p> <p>It suddenly doesn't work anymore and parsing fails. I have no idea why. Can anyone explain this?</p> <p>EDIT: Just in case it matters, I'm using Boost 1.53</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload