title: boost::spirit semantic action: emit result
body: <p>I am trying to learn boost::spirit to parse a grammar, but am having trouble understanding exactly how to use the library.</p>
  
  <p>Basically, if the parser hits "Test" in the input stream, I'd like to emit 5 as the return value. (Later, I'd actually like to emit a pair, with a string member "Test" and a value member 5.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>template &lt;typename Iterator&gt;
  struct testgrammar
      : public grammar&lt;Iterator, unsigned int()&gt;
  {
  public:
  
      testgrammar() : testgrammar::base_type(start)
      {
          start = std::wstring(L"Test") [ _val = 5 ] ;
      }
  
      virtual ~testgrammar(){};
  
      rule&lt;Iterator, unsigned int()&gt; start;
  
  };
  </code></pre>
  
  <p>In main():</p>
  
  <pre><code>std::wstring strIn = L"Test";
  std::wstring::const_iterator itBegin = strIn.begin();
  std::wstring::const_iterator itEnd = strIn.end();
  unsigned int nData = 0;
  bool bRes = parse(itBegin, itEnd, avxgrammar&lt;std::wstring::const_iterator&gt;(), nData);
  </code></pre>
  
  <p>However, I'm doing it wrong, because the compiler emits the following error:</p>
  
  <pre><code>error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const boost::spirit::_val_type' (or there is no acceptable conversion)
  </code></pre>
  
  <p>My question is why can't I assign to _val?
  How should I emit such a struct from the semantic action?</p>
  
  <p><strong>Edit</strong>
  Maybe I should clarify the end goal. I want to parse a text file into pairs of Token/Literal values.</p>
  
  <p>Thank you in advance for your help!</p>