Boost logo

Boost :

From: Seth (bugs_at_[hidden])
Date: 2022-07-18 21:00:46


A literal b in a parser expression created `qi::lit(b)`. `qi::lit` does not "have" (synthesize/expose) an attribute. You want either `qi::alpha | qi::char_("._")`, or `qi::char_("a-zA-Z0-9_.")` or even (as you're in a lexeme anyways) `raw[alpha >> *(alnum|'.'|'_')]` because for `raw[]` the synthesized attribute is the source iterator range.

First fix: http://coliru.stacked-crooked.com/a/c5d9ee594370ac91

Seeing that your `identifier` is a lexeme, you should just drop the skipper (see https://stackoverflow.com/a/17073965/85371).

In the absense of semantic actions `%=` is redundant.

I don't recommend using classic spirit features in 2022.

All in all: https://godbolt.org/z/r6MPvK5aK

On Mon, Jul 18, 2022, at 9:24 AM, Olaf van der Spek via Boost wrote:
> Hi,
>
> The underscore is parsed as a null character. Is this expected. A bug?
>
> If a full repro is needed I can create one.
>
>
> qi::rule<iterator_t, std::string(), Skip> identifier;
> identifier %= lexeme[alpha >> *(alnum | '.' | '_')];
>
> typedef boost::spirit::classic::position_iterator<const char*> iterator_t;
>
> std::string s = "a_b blah";
> iterator_t is(s.c_str(), s.c_str() + s.size(), "<name>");
>
> std::string out;
> bool res = qi::phrase_parse(is, iterator_t(), identifier, skip, out);
> if (!res && is != iterator_t()) error_handler_::err(is);
> cout << out.size() << "|" << out << "|\n";
> cout << int(out[0]) << " " << int(out[1]) << " " << int(out[2]) << "\n";
>
> Output:
> // 3|ab|
> // 97 0 98
>
> Greetings,
> --
> Olaf
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk