小编Dud*_*ore的帖子

Boost :: Spirit中的复合语法

我有以下符合预期的语法。

struct query_term {
    std::string term;
    bool is_tag;

    query_term(const std::string &a, bool tag = false): term(a), is_tag(tag) { } };

template<typename Iterator> struct query_grammar: grammar<Iterator, std::vector<query_term>(), space_type> {
    query_grammar():
        query_grammar::base_type(query) {

        word %= +alnum;
        tag  =  (omit[word >> ':'] >> word[_val = phoenix::construct<query_term>(_1, true)]);
        non_tag  =  word[_val = phoenix::construct<query_term>(_1, false)];
        query = (
                  (omit[word >> ':'] >> word[push_back(_val, phoenix::construct<query_term>(_1, true))])
                |
                  word[push_back(_val,
                            phoenix::construct<query_term>(_1))
                  ]
                ) % space;
    };

    qi::rule<Iterator, std::string(), space_type> word;
    qi::rule<Iterator, query_term, space_type> tag;
    qi::rule<Iterator, query_term, space_type> non_tag; …
Run Code Online (Sandbox Code Playgroud)

c++ parsing boost boost-spirit

4
推荐指数
1
解决办法
727
查看次数

标签 统计

boost ×1

boost-spirit ×1

c++ ×1

parsing ×1