मैं boost::spirit
सीखने की कोशिश कर रहा हूं। उदाहरण के तौर पर, मैं vector<string>
में शब्दों के अनुक्रम को पार्स करने का प्रयास कर रहा हूं।वेक्टर में शब्दों के अनुक्रम को पार्स करने के लिए boost :: spirit का उपयोग कैसे करें?
#include <boost/spirit/include/qi.hpp>
#include <boost/foreach.hpp>
namespace qi = boost::spirit::qi;
int main() {
std::vector<std::string> words;
std::string input = "this is a test";
bool result = qi::phrase_parse(
input.begin(), input.end(),
+(+qi::char_),
qi::space,
words);
BOOST_FOREACH(std::string str, words) {
std::cout << "'" << str << "'" << std::endl;
}
}
जो मुझे इस उत्पादन देता है:
'thisisatest'
लेकिन मैं निम्नलिखित उत्पादन है, जहां प्रत्येक शब्द अलग से मिलान किया जाता है चाहता था:
'this'
'is'
'a'
'test'
संभव हो तो, मैं मैं इस कोशिश की डी इस साधारण मामले के लिए अपने qi::grammar
सबक्लास को परिभाषित करने से बचने के लिए पसंद है।
अच्छी तरह से समझाया गया, +1 – sehe