如何在Spirit x3中做no_case

How to do no_case in Spirit x3

本文关键字:no case 中做 x3 Spirit      更新时间:2023-10-16

我有一个问题,IDK如何做no_case在精神X3。在Spirit中没有_case,但是当我使用它时,我得到:

    // If you get an error no matching function for call to 'as_parser'
    // here, for either p or s, then p or s is not a parser or there is
    // no suitable conversion from p to a parser.

这是可能的我很困惑,我正试图混合苹果和橙子(qi和x3,例如IDK x3::parse和qi::parse之间的差异)

所以我的问题是如何做到这一点:

bool parsed = phrase_parse(first, last, no_case[char_('a')], space);

(没有no_case也可以)

是的,你可能把x3和qi混在一起了。下面是最简单的例子:

Live On Coliru

#include <boost/spirit/home/x3.hpp>
#include <cassert>
namespace x3 = boost::spirit::x3;
int main() {
    std::string const input = "A";
    auto first = input.begin(), last = input.end();
    bool parsed = x3::phrase_parse(first, last, x3::no_case[x3::char_('a')], x3::space);
    return parsed? 0:1;
}