VBスタイルの二重引用符で囲まれた文字列を解析することを目的としたこの単純なパーサーがあります。したがって、パーサーは次のようになります。
"This is a quoted string containing quotes ("" "")"
の出力に
This is a quoted string containing quotes (" ")
これが私がこれのために思いついた文法です:
namespace qi = boost::spirit::qi;
namespace wide = qi::standard_wide;
class ConfigurationParser : public qi::grammar<std::wstring::iterator, std::wstring()>
{
qi::rule<std::wstring::iterator, std::wstring()> quotedString;
qi::rule<std::wstring::iterator> doubleQuote;
public:
ConfigurationParser() : ConfigurationParser::base_type(quotedString, "vFind Command Line")
{
doubleQuote = (wide::char_(L'"') >> wide::char_(L'"'));
quotedString = L'"' >> +(doubleQuote[qi::_val = L'"'] | (wide::char_ - L'"'))>> L'"';
}
};
ただし、取得している属性は、完全に解析されたメッセージではなく、一重引用符( ")です。