I would like to parse strings with escaping rules similar to that of C. I want to keep the escapes, not decode them and recode afterwards. So I thought that *(char_('\\') >> char_ | char_ - '"')
would do what I want, but it does not: it behaves as if I had written lit('\\')
to discard that guy.
#define TEST(Rule) test(input, #Rule, Rule)
int main()
{
const auto input = std::string{"\\( \\\" \\\\ \\)"};
TEST(lexeme[*(lit('\\') >> char_ | char_ - '"')]);
TEST(lexeme[*(char_('\\') >> char_ | char_ - '"')]);
TEST(lexeme[*char_]);
}
gives
\( \" \\ \): lexeme[*(lit('\\') >> char_ | char_ - '"')]: ( " \ )
\( \" \\ \): lexeme[*(char_('\\') >> char_ | char_ - '"')]: ( " \ )
\( \" \\ \): lexeme[*char_]: \( \" \\ \)
The whole example is available on Coliru.