NoSenseEtAl NoSenseEtAl - 1 month ago 7
C++ Question

How to do no_case in Spirit x3

I have a problem that IDK how to do no_case in spirit X3.
There is no_case in Spirit, but when I use it I get:


// 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.



It is possible I am confused and I am trying to mix apples and oranges (qi and x3, for example IDK the difference between x3::parse and qi::parse)

So tl;dr my question is how to make this work:

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


(without no_case it works)

Answer

Yes, you are likely mixing x3 and qi. Here's the simplest example that works:

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;
}
Comments