我正在使用Spirit 2.4,我想要解析这样的结构:
文字{text_field};
关键是text_field是一个带有符号'{','}'和'\'的转义字符串.我想使用qi为此创建一个解析器.我一直在尝试这个:
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( "\\}" );
Run Code Online (Sandbox Code Playgroud)
但是甚至没有编译.任何的想法?