c++ - boost::spirit::qi grammer for parsing structured text file -


a) far revised full code. not running having errors such

"error: no type named 'type' in 'struct boost::spirit::traits::container_value"

#include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <iostream> #include <string> #include <complex> #include <fstream> #include <vector>  namespace opcuastackcore { namespace spirit = boost::spirit; namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii;  struct eddlvariable {     std::string identifier;     std::string label;     std::string help;     std::string classtype; };  //std::vector<eddlvariable> variablecontainer; template <typename iterator>     struct eddlvariableparser : qi::grammar<iterator, eddlvariable(), ascii::blank_type>     {         eddlvariableparser() : eddlvariableparser::base_type(start)         {             using boost::spirit::eol;              text  = +qi::graph;             start = "variable" >> text >> qi::eol                  >> '{'     >> qi::eol                  >> "label" >> text >> qi::eol                  >> "help"  >> text >> qi::eol                  >> "class" >> text >> qi::eol                  >> "type"  >> text >> qi::eol                 >> '}';         }         private:        qi::rule<iterator, eddlvariable(), ascii::blank_type> start;         // lexemes        qi::rule<iterator, eddlvariable()> text; }; }  boost_fusion_adapt_struct( opcuastackcore::eddlvariable, (std::string, identifier) (std::string, label) (std::string, help) (std::string, classtype) )  int main(int argc, char **argv) { using namespace opcuastackcore; using boost::property_tree::ptree; using boost::property_tree::write_xml; using boost::property_tree::xml_writer_settings;  typedef std::string::const_iterator iterator_type; typedef eddlvariableparser<iterator_type> eddl_parser; eddl_parser parser; eddlvariable storededdldata; char const* filename; if (argc > 1)     filename = argv[1]; std::ifstream filestream(filename, std::ios_base::in);  std::string storedstring; filestream.unsetf(std::ios::skipws); std::copy(std::istream_iterator<char>(filestream), std::istream_iterator<char>(), std::back_inserter(storedstring)); std::cout << "stored string is: " << storedstring << std::endl;  std::string::const_iterator begin_iter = storedstring.begin(); std::string::const_iterator end_iter = storedstring.end(); /* invoke parser */ bool r = phrase_parse(begin_iter, end_iter, parser, ascii::space, storededdldata);  if (r && begin_iter == end_iter) {     std::cout << "parsing succeeded\n"; } else {     std::cout << "parsing failed\n"; }  return 0; } 

please find full code above, perhaps make question clearer. code still not running. 1 example of data have pass shown below:

variable phys_soft_desc { label       [phys_soft_desc_label];        [phys_soft_desc_help]; class       contained; type        ascii (32) {     default_value ""; } handling    read; } 


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -