title: reuse parsed variable with boost karma
body: <p>I have a code base which is quite equivalent to the code below.
  I try to generate a text file with two times the content of a variable.
  I feel that the answer is in semantic actions and _a and _val but cannot manage to get through even with the documentation.</p>
  
  <p>How will you do to have :
  "toto" in str
  and output :
  toto some stuff toto</p>
  
  <p>i.e how to reuse a parsed variable in karma ?</p>
  
  <pre><code>struct data
   {
    std::string str;
   };
  
  BOOST_FUSION_ADAPT_STRUCT(
                        data,
                        (std::string, str)
                        )
  
  template &lt;typename Iterator&gt;
  struct data: karma::grammar&lt;Iterator, data() &gt;
  {
      data():data::base_type(start)
      {
          start = karma::string &lt;&lt; karma::lit("some stuff") &lt;&lt; karma::string; //Second string is in fact the first one 
      }
      karma::rule&lt;Iterator, data()&gt; start;
  };
  </code></pre>
  
  <p>Solution (according to posts below :)</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/fusion/include/adapt_struct.hpp&gt;
  #include &lt;boost/spirit/include/karma.hpp&gt;
  #include &lt;boost/spirit/include/phoenix_core.hpp&gt;
  #include &lt;boost/spirit/include/phoenix_operator.hpp&gt;
  #include &lt;boost/spirit/include/phoenix_fusion.hpp&gt;
  #include &lt;boost/spirit/include/phoenix_stl.hpp&gt;
  #include &lt;boost/spirit/include/phoenix_object.hpp&gt;
  #include &lt;boost/spirit/include/support_istream_iterator.hpp&gt;
  #include &lt;boost/spirit/include/support_iso8859_1.hpp&gt;
  
  namespace ast
  {
      struct data
      {
          std::string str;
      };
  }
  
  BOOST_FUSION_ADAPT_STRUCT(
                            ast::data,
                            (std::string, str)
                            )
  
  namespace karma = boost::spirit::karma;
  
  namespace parser
  {
  
      template &lt;typename Iterator&gt;
      struct data: karma::grammar&lt;Iterator, ast::data() &gt;
      {
          data():data::base_type(start)
          {
              start =
                  karma::string[karma::_1 =  boost::phoenix::at_c&lt;0&gt;(karma::_val)] &lt;&lt;
                  karma::lit("some stuff") &lt;&lt;
                  karma::string[karma::_1 =  boost::phoenix::at_c&lt;0&gt;(karma::_val)]
                  ;
          }
          karma::rule&lt;Iterator, ast::data()&gt; start;
      };
  }
  
  main()
  {
      ast::data d;
      d.str = "toto";
      std::string generated;
      typedef std::back_insert_iterator&lt;std::string&gt; iterator_type;
      parser::data&lt;iterator_type&gt; d_p;
      iterator_type sink(generated);
      karma::generate(sink, d_p, d);
      std::cout &lt;&lt; generated &lt;&lt; std::endl;
  }
  </code></pre>