parseh: support octal in C macro string literal

This commit is contained in:
Andrew Kelley
2016-07-09 12:17:31 -07:00
parent 100e8e15fa
commit a5251a1c10
4 changed files with 79 additions and 6 deletions

View File

@@ -251,7 +251,7 @@ static bool is_digit(uint8_t c) {
}
static bool is_printable(uint8_t c) {
return is_alpha_under(c) || is_digit(c);
return is_alpha_under(c) || is_digit(c) || c == ' ';
}
static void string_literal_escape(Buf *source, Buf *dest) {
@@ -463,10 +463,14 @@ static void render_node(AstRender *ar, AstNode *node) {
}
break;
case NodeTypeStringLiteral:
if (node->data.string_literal.c) {
fprintf(ar->f, "c");
{
if (node->data.string_literal.c) {
fprintf(ar->f, "c");
}
Buf tmp_buf = BUF_INIT;
string_literal_escape(&node->data.string_literal.buf, &tmp_buf);
fprintf(ar->f, "\"%s\"", buf_ptr(&tmp_buf));
}
fprintf(ar->f, "\"%s\"", buf_ptr(&node->data.string_literal.buf));
break;
case NodeTypeCharLiteral:
{