我正在使用 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( "\\}" );
但甚至不编译。任何的想法?