Is it possible to create a rule in Spirit X3 that parses a single character and generates a string?
I'd like to use this in the context of a parser for version numbers, where each numeric identifier can be either a single digit, or a non-zero digit followed by one or more digits:
auto const positive_digit = char_(L"123456789");
auto const digit = char_(L"0123456789");
auto const digits = x3::rule<class digits, std::wstring>{"digits"} = +digit;
auto const numeric_identifier = (positive_digit >> digits) | digit;
The problem I see is that the type numeric_identifier
synthesizes is not compatible with a string (see full example here).
To solve this, I would need to create a rule that matches a digit and synthesizes a string. The only solution that I can think of is to use semantic actions, but this causes errors when the rule is used in a situation where backtracking is necessary (see full example here).