Re: How to escape the hyphen char in set by char parser?
Henri Menke <[email protected]> Tue, 17 Jul 2018 11:47:58 +1200
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
As you noted a range can be written as
'a' | 'b' | 'c' | 'd' | '-' | '+' | 'x'
Since '-' has a special meaning (and '+' might as well), you could just
write it as a superposition of
match any of the set "abcdx"
OR
match '-'
OR
match '+'
which is in Boost.Spirit syntax
char_("abcdx") | char_('-') | char_('+');
Below is a full example (using X3 rather than Qi, because of compilation
time).
#include <iostream>
#include <string>
#include <boost/spirit/home/x3.hpp>
int main() {
using namespace boost::spirit::x3;
auto rule = char_("abcdx") | char_('-') | char_('+');
std::string input{"-"};
auto first = input.begin();
auto last = input.end();
bool r = parse(first, last, rule);
if (!r || first != last) {
std::cerr << "Parsing failed at: " << std::string{first,last}
<< '\n';
}
}
On 17/07/18 04:37, Yi Leong wrote:
> As following:
> qi::char_("abcd-+x")
> what i need just matches the char 'a' | 'b' | 'c' | 'd' | ‘-’ | ‘+’ | ‘x’,
> and the char parser takes hyphen '-' as the range matching from 'd' to
> '+'....
> and how to escape the hyphen char?
> I read this doc :
> https://www.boost.org/doc/libs/1_46_0/libs/spirit/doc/html/spirit/qi/reference/char/char.html
> and got nothing....
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> Spirit-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/spirit-general
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general