Re: How to escape the hyphen char in set by char parser?
Yi Leong <[email protected]> Tue, 17 Jul 2018 08:54:24 +0800
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAMFq=pbE0gH8ftxbkmxUmtYJ7atGkqcZXVSrWfK0y7QrZNok1w@mail.gmail.com> |
Ok, i will separate the set . Thanks for help~ On Tue, Jul 17, 2018 at 7:47 AM, Henri Menke <[email protected]> wrote: > 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 > ------------------------------------------------------------------------------ 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