Note that there are some explanatory texts on larger screens.

plurals
  1. POGrammar parsing with Spirit::Qi fails
    primarykey
    data
    text
    <p>I'm new to Spirit::Qi and I'm trying to write a simple Wavefront Obj parser. I've followed the tutorials from the Boost::Spirit documentation site (<a href="http://www.boost.org/doc/libs/1_54_0/libs/spirit/doc/html/spirit/qi/tutorials.html" rel="nofollow">link</a>) and I got most of the inline rules working. I've started experimenting with grammars, but I cannot seem to get them working. After a while I did get it to compile, but the parsing fails. I really don't know what I am doing wrong.</p> <p>To start out simple, I've created a simple text file containing the following:</p> <pre><code>v -1.5701 33.8087 0.3592 v -24.0119 0.0050 21.7439 v 20.8717 0.0050 21.7439 v 20.8717 0.0050 -21.0255 v -24.0119 0.0050 -21.0255 v -1.5701 0.0050 0.3592 </code></pre> <p>Just to be sure: Reading the input file works fine.</p> <p>I've written a small function that should parse the input string, but for some reason it fails:</p> <pre><code>bool Model::parseObj( std::string &amp;data, std::vector&lt;float&gt; &amp;v ) { struct objGram : qi::grammar&lt;std::string::const_iterator, float()&gt; { objGram() : objGram::base_type(vertex) { vertex = 'v' &gt;&gt; qi::float_ &gt;&gt; qi::float_ &gt;&gt; qi::float_; } qi::rule&lt;std::string::const_iterator, float()&gt; vertex; }; objGram grammar; return qi::phrase_parse( data.cbegin(), data.cend(), grammar, iso8859::space, v ); } </code></pre> <p>qi::phrase_parse keeps returning false and the std::vector v is still empty at the end...</p> <p>Any suggestions?</p> <p>EDIT:</p> <p>After adding adding space skippers (is that the correct name?), only the first 'v' is added to the std::vector encoded as a float (118.0f), but the actual numbers aren't added. My guess is that my rule isn't correct. I want to only add the numbers and skip the v's.</p> <p>Here is my modified function:</p> <pre><code>bool Model::parseObj( std::string &amp;data, std::vector&lt;float&gt; &amp;v ) { struct objGram : qi::grammar&lt;std::string::const_iterator, float(), iso8859::space_type&gt; { objGram() : objGram::base_type(vertex) { vertex = qi::char_('v') &gt;&gt; qi::float_ &gt;&gt; qi::float_ &gt;&gt; qi::float_; } qi::rule&lt;std::string::const_iterator, float(), iso8859::space_type&gt; vertex; } objGrammar; return qi::phrase_parse( data.cbegin(), data.cend(), objGrammar, iso8859::space, v ); } </code></pre>
    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.
 

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