title: Boost::Spirit simple grammar example
body: <p>I'm going through the Boost Spirit (and Boost Fusion) tutorials (version 1.48.0). I've been playing with the toy employee example. The link to the source is here:</p>
  
  <p><a href="http://www.boost.org/doc/libs/1_48_0/libs/spirit/example/qi/employee.cpp" rel="nofollow">http://www.boost.org/doc/libs/1_48_0/libs/spirit/example/qi/employee.cpp</a></p>
  
  <p>Here is the example's grammar:</p>
  
  <pre><code>employee_parser() : employee_parser::base_type(start)
      {
          using qi::int_;
          using qi::lit;
          using qi::double_;
          using qi::lexeme;
          using ascii::char_;
  
          quoted_string %= lexeme['"' &gt;&gt; +(char_ - '"') &gt;&gt; '"'];
  
          start %=
              lit("employee")
              &gt;&gt; '{'
              &gt;&gt;  int_ &gt;&gt; ','
              &gt;&gt;  quoted_string &gt;&gt; ','
              &gt;&gt;  quoted_string &gt;&gt; ','
              &gt;&gt;  double_
              &gt;&gt;  '}'
              ;
      }
  
      qi::rule&lt;Iterator, std::string(), ascii::space_type&gt; quoted_string;
      qi::rule&lt;Iterator, employee(), ascii::space_type&gt; start;
  </code></pre>
  
  <p>And my modifications remove the treatment of the quotes and just parses any character between the delimiter and assigns that to the struct the parser is mapped to.</p>
  
  <pre><code>        //quoted_string %= lexeme['"' &gt;&gt; +(char_ - '"') &gt;&gt; '"'];
          start %=
              lit("employee")
              &gt;&gt; '{'
              &gt;&gt;  int_ &gt;&gt; ','
              &gt;&gt;  +(char_) &gt;&gt; ','
              &gt;&gt;  +(char_) &gt;&gt; ','
              &gt;&gt;  double_
              &gt;&gt;  '}'
              ;
  </code></pre>
  
  <p>My assumption is that char_ includes all characters until a comma is reached. However, compiling and running with the following string returns a failure to parse.</p>
  
  <pre><code>./employee
  employee{10,my,name,20.0}
  -------------------------
  Parsing failed
  -------------------------
  </code></pre>
  
  <p>I'm also attempting to write a similar parser to automatically cast to the appropriate types of my struct type. I'm sure I'm missing something fundamentally wrong as far as defining the correct grammar for an input string like above, so any help is greatly appreciated!</p>
  
  <p>Thanks!</p>