I work with Spirit 2.4, and I would like to parse such a structure:
Text {text_field};
The fact is that there is an escaped string in the text field with the characters '{', '}' and '\'. I would like to create a parser for this using qi. I tried this:
using boost::spirit::standard::char_;
using boost::spirit::standard::string;
using qi::lexeme;
using qi::lit;
qi::rule< IteratorT, std::string(), ascii::space_type > text;
qi::rule< IteratorT, std::string(), ascii::space_type > content;
qi::rule< IteratorT, std::string(), ascii::space_type > escChar;
text %=
lit( "Text" ) >> '{' >>
content >>
"};"
;
content %= lexeme[ +( +(char_ - ( lit( '\\' ) | '}' ) ) >> escChar ) ];
escChar %= string( "\\\\" )
| string( "\\{" )
| string( "\\}" );
But it doesn't even compile. Any idea?
Bruno source
share