boost-spirit

How to verify algebraic statements using boost::spirit?

…衆ロ難τιáo~ 提交于 2019-12-30 10:12:14
问题 I'm trying to extend the calculator example so that instead of parsing and evaluating an algebraic expression, the parser will determine if an algebraic statement is true or not. By this I mean statements like 1 + 5 * 5 - 10 = 19 - 3 (desired parser result is true ) and 3 - 1 = 9 (desired parser result is false ). I've got to admit I'm new to boost::spirit and it's all kind of overwhelming at the moment. However, I do feel I understand the calculator example good enough to at least make some

boost::spirit parsing into a fusion adapted structure optional but exclusive

烂漫一生 提交于 2019-12-30 10:06:23
问题 If there's a structure: struct record { std::string type; std::string delimiter; uint32_t length; std::string name; record() { type = ""; delimiter = ""; length = 0; name = ""; } }; Which is adapted using boost::fusion, and the below grammar: struct record_parser : qi::grammar<Iterator, record(), ascii::space_type> { record_parser() : record_parser::base_type(start) { using qi::lit; using qi::uint_; using qi::lexeme; using ascii::char_; using ascii::blank; using ascii::string; using qi::attr;

Spirit Lex: Which token definition generated this token?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-30 07:10:29
问题 Sorry if this is a newbie question, but I need to know which token definition produced a certain token. When I print the token ID, I just get an integer. I need to know which regex generated this token. Edit: Here's how I define my tokens: template <typename LexerT> class Tokens: public lex::lexer<LexerT> { public: Tokens(const std::string& input): lineNo_(1) { using boost::spirit::lex::_start; using boost::spirit::lex::_end; using boost::spirit::lex::_pass; using boost::phoenix::ref; using

How do I capture the original input into the synthesized output from a spirit grammar?

本秂侑毒 提交于 2019-12-30 07:09:09
问题 I'm working on a boost::spirit::qi::grammar and would like to copy a portion of the original text into the synthesized output structure of the grammar (more specifically, the portion that matched one of the components of the rule). The grammar would ultimately be used as a sub-grammar for a more complicated grammar, so I don't really have access to the original input. I'm guessing that this can be done through semantic actions or the grammar context, but I can't find an example that does this

Filter the synthesized attribute through a std::map in a boost spirit semantic action

醉酒当歌 提交于 2019-12-29 09:22:06
问题 I have a case where I'd like to filter the value that comes up as a synthesized attribute inside of a rule through a std::map. The map is pre-generated and will not change during the parsing. The nature of the map and the real parser means that the lookup should never fail (although the actual number of elements may be quite large) The usual approach perfectly suited to this problem (use a symbol table) isn't appropriate for the real case. In the real problem, the lookup is conditional based

Filter the synthesized attribute through a std::map in a boost spirit semantic action

我们两清 提交于 2019-12-29 09:22:01
问题 I have a case where I'd like to filter the value that comes up as a synthesized attribute inside of a rule through a std::map. The map is pre-generated and will not change during the parsing. The nature of the map and the real parser means that the lookup should never fail (although the actual number of elements may be quite large) The usual approach perfectly suited to this problem (use a symbol table) isn't appropriate for the real case. In the real problem, the lookup is conditional based

Boost.Spirit SQL grammar/lexer failure

ぐ巨炮叔叔 提交于 2019-12-29 08:03:36
问题 I have two problems with the following SQL grammar: #define BOOST_SPIRIT_QI_DEBUG #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/karma.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/algorithm/string.hpp> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <boost/lexical_cast.hpp> #include

Boost.Spirit SQL grammar/lexer failure

元气小坏坏 提交于 2019-12-29 08:03:11
问题 I have two problems with the following SQL grammar: #define BOOST_SPIRIT_QI_DEBUG #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/karma.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/algorithm/string.hpp> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <boost/lexical_cast.hpp> #include

boost::spirit::x3 attribute compatibility rules, intuition or code?

余生长醉 提交于 2019-12-29 07:19:09
问题 Is there a document somewhere which describes how various spirit::x3 rule definition operations affect attribute compatibility? I was surprised when: x3::lexeme[ x3::alpha > *(x3::alnum | x3::char_('_')) ] could not be moved into a fusion-adapted struct: struct Name { std::string value; }; For the time being, I got rid of the first mandatory alphabetical character, but I would still like to express a rule which defines that the name string must begin with a letter. Is this one of those

how to customise default Boost xml Serialisation default node naming to make it more readable

只愿长相守 提交于 2019-12-29 01:46:30
问题 The code below generates a xml file but , when it loops theough a map , it always names the map key as first and value as second Is there a way that we can customise tag names first and second to groupid and groupType as shown in desired output #include <fstream> #include <boost/serialization/map.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/xml_oarchive.hpp> #include <string> #include <iostream> #include <map> using namespace std; class MyConnections { public: