I am studying Boost Spirit (and Boost Fusion) tutorials (version 1.48.0). I played with an example of a toy employee. Link to the source is here:
http://www.boost.org/doc/libs/1_48_0/libs/spirit/example/qi/employee.cpp
Here is a grammar example:
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['"' >> +(char_ - '"') >> '"'];
start %=
lit("employee")
>> '{'
>> int_ >> ','
>> quoted_string >> ','
>> quoted_string >> ','
>> double_
>> '}'
;
}
qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
qi::rule<Iterator, employee(), ascii::space_type> start;
And my modifications eliminate the processing of quotes and simply analyze any character between the separator and assign it to the structure on which the parser is mapped.
//quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
start %=
lit("employee")
>> '{'
>> int_ >> ','
>> +(char_) >> ','
>> +(char_) >> ','
>> double_
>> '}'
;
My assumption is that char_ includes all characters before reaching the comma. However, compiling and starting with the next line returns inoperability.
./employee
employee{10,my,name,20.0}
Parsing failed
, . , - , , , !
!