Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting attributes from semantic action(s) for expression passed into qi::phrase_parse
    primarykey
    data
    text
    <p>During parsing I have a few attributes that I need to set in semantic action only ( as they are derived from data being parsed and I want to avoid <code>global</code> variables and dependency on <code>BOOST_FUSION_ADAPT_STRUCT</code> as well as my code should be generic so that I can reuse it for multiple types). If I use more than one variable passed into <code>qi::phrase_parse</code> I get very long list of compilation errors. I need a help badly :-)</p> <pre><code>#define BOOST_RESULT_OF_USE_DECLTYPE #define BOOST_SPIRIT_USE_PHOENIX_V3 #include &lt;boost/function.hpp&gt; #include &lt;boost/phoenix/fusion.hpp&gt; #include &lt;boost/spirit/include/phoenix.hpp&gt; #include &lt;boost/spirit/include/qi.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;climits&gt; namespace qi = boost::spirit::qi; namespace ph = boost::phoenix; namespace ascii = boost::spirit::ascii; int main( int argc, char**argv ) { bool rc; std::string input(""); //Test case 1 works fine { auto iter( input.begin() ); auto last( input.end() ); int val1=33; rc = qi::phrase_parse( iter, last, qi::eps[ qi::_val=11 ] , ascii::space, val1 ) &amp;&amp; iter==last; if( rc ) std::cout &lt;&lt; "val1=" &lt;&lt; val1 &lt;&lt; std::endl; } //Test case 2 does not compile { auto iter( input.begin() ); auto last( input.end() ); int val1=33; int val2=0; rc = qi::phrase_parse( iter, last, qi::eps[ ph::at_c&lt;0&gt;(qi::_val)=1,ph::at_c&lt;1&gt;(qi::_val)=2 ], ascii::space, val1,val2 ) &amp;&amp; iter==last; if( rc ) std::cout &lt;&lt; "val1=" &lt;&lt; val1 &lt;&lt; " val2=" &lt;&lt; val2 &lt;&lt; std::endl; } //Test case 3 works fine { auto iter( input.begin() ); auto last( input.end() ); int val1=33; int val2=0; rc = qi::phrase_parse( iter, last, qi::attr(1)&gt;&gt;qi::attr(2), ascii::space, val1,val2 ) &amp;&amp; iter==last; if( rc ) std::cout &lt;&lt; "val1=" &lt;&lt; val1 &lt;&lt; " val2=" &lt;&lt; val2 &lt;&lt; std::endl; } return 0; } </code></pre> <p>I took the "customized" my_phrase_parse from <code>cv_and_he</code> but it breaks compilation on the full test case that I want to get running:</p> <pre><code>template&lt;typename T,typename R&gt; void testParser( R rule ) { for ( const auto input : std::vector&lt; std::string &gt;{ "5 1.0 2.0 3.0 4.0 5.0", "1 1.0", "0" , "", "2 3 ab" } ) { bool rc; T maxValue; T minValue; auto iter( input.begin() ); auto last( input.end() ); std::vector&lt; T &gt; v; rc = my_phrase_parse( iter, last, qi::eps[ ph::at_c&lt;0&gt;(qi::_val)=std::numeric_limits&lt;T&gt;::max(), ph::at_c&lt;1&gt;(qi::_val)=std::numeric_limits&lt;T&gt;::min() ] &gt;&gt; -( qi::omit[ qi::int_] &gt;&gt; *rule[ ph::if_(ph::at_c&lt;0&gt;(qi::_val)&gt;qi::_1)[ ph::at_c&lt;0&gt;(qi::_val)=qi::_1 ], ph::if_(ph::at_c&lt;1&gt;(qi::_val)&lt;qi::_1)[ ph::at_c&lt;1&gt;(qi::_val)=qi::_1 ] ] ) ,ascii::space, minValue, maxValue,v ) &amp;&amp; iter==last; std::cout &lt;&lt; ( rc ? "ok :`" : "err:`" ) &lt;&lt; input &lt;&lt; "` -&gt; "; if( rc ) { std::cout &lt;&lt; "min=" &lt;&lt; minValue &lt;&lt; " max=" &lt;&lt; maxValue &lt;&lt; "\t"; std::copy( v.begin(), v.end(), std::ostream_iterator&lt;T&gt;( std::cout," " )); } else std::cout &lt;&lt; *iter; std::cout &lt;&lt; std::endl; } } ... testParser&lt;double&gt;( qi::double_ ); </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