Note that there are some explanatory texts on larger screens.

plurals
  1. POBoost.Spirit semantic action to parse a string does not work
    primarykey
    data
    text
    <p>I try to write a Boost.Spirit parser that parses a string that should represent a simple command like "print foo.txt". Each time the input fulfills the grammar a semantic action should be called.</p> <p>Here is the code:</p> <pre><code>template&lt;class Iterator&gt; struct my_parser : qi::grammar&lt;Iterator, void(), qi::ascii::space_type&gt; { void test(std::string const &amp; s) const { std::cerr &lt;&lt; s &lt;&lt; std::endl; } my_parser() : my_parser::base_type(print) { using qi::_1; using qi::char_; filename = *qi::char_("a-zA-Z_0-9./ ") ; print = qi::lit("print") &gt;&gt; filename [ boost::bind(&amp;my_parser::test, this, _1) ] ; } qi::rule&lt;Iterator, std::string()&gt; filename; qi::rule&lt;Iterator, void(), qi::ascii::space_type&gt; print; }; </code></pre> <p>If I try to compile this I get something like:</p> <pre><code>no match for call to ‘(const boost::_mfi::cmf1&lt;void, parser::my_parser&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char&gt; &gt; &gt;, const std::basic_string&lt;char&gt;&amp;&gt;) (parser::my_parser&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char&gt; &gt; &gt;* const&amp;, const boost::phoenix::actor&lt;boost::spirit::argument&lt;0&gt; &gt;&amp;)’ </code></pre> <p>If I replace _1 with <em>"abc"</em> for example the code compiles but phrase_parse() return with false for the input <em>"print foo.txt"</em>. If I comment out the <em>[ boost:bind(...) ]</em> phrase_parse() return with true.</p> <p>Does anyone know what I do wrong? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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