Если вы не хотите шкипера, просто используйте qi::parse
вместо qi::phrase_parse
:
qi::parse(
begin,end,
*(*~qi::char_(";=") >> '=' >> *~qi::char_(';') >> -qi::lit(';')),
dict);
Однако вы, скорее всего, НЕ хотите выборочно пропускать пробелы. Самый простой способ, как правило, состоит в том, чтобы иметь общего шкипера, а затем отметить области лексемы (где вы не разрешаете шкипера):
qi::phrase_parse(
begin, end,
*(qi::lexeme[+(qi::graph - '=')]
>> '='
>> qi::lexeme[*~qi::char_(';')] >> (qi::eoi|';')),
qi::ascii::space, dict);
Связанный ответ действительно дает больше приемов / фоны о том, как работать со шкиперами в Ци
DEMO TIME
Live On Coliru
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/adapted/std_pair.hpp>
#include <map>
#include <iomanip>
namespace qi = boost::spirit::qi;
int main() {
for (std::string const& input : {
R"()",
R"(foo=bar)",
R"(foo=bar;)",
R"( foo = bar ; )",
R"( foo = bar ;
foo
= qux; baz =
quux
corge grault
thud
; x=)",
// failing:
R"(;foo = bar;)",
})
{
std::cout << "-------------------------\n";
auto f=begin(input), l=end(input);
std::multimap<std::string, std::string> dict;
bool ok = qi::phrase_parse(f, l,
(qi::lexeme[+(qi::graph - '=' - ';')]
>> '='
>> qi::lexeme[*~qi::char_(';')]
) % ';',
qi::space,
dict);
if (ok) {
std::cout << "Parsed " << dict.size() << " elements:\n";
for (auto& [k,v]: dict) {
std::cout << " - " << std::quoted(k) << " -> " << std::quoted(v) << "\n";
}
} else {
std::cout << "Parse failed\n";
}
if (f!=l) {
std::cout << "Remaining input: " << std::quoted(std::string(f,l)) << "\n";
}
}
}
Prints
-------------------------
Parse failed
-------------------------
Parsed 1 elements:
- "foo" -> "bar"
-------------------------
Parsed 1 elements:
- "foo" -> "bar"
Remaining input: ";"
-------------------------
Parsed 1 elements:
- "foo" -> "bar "
Remaining input: "; "
-------------------------
Parsed 4 elements:
- "baz" -> "quux
corge grault
thud
"
- "foo" -> "bar "
- "foo" -> "qux"
- "x" -> ""
-------------------------
Parse failed
Remaining input: ";foo = bar;"