mirror of
https://github.com/ziglang/zig.git
synced 2026-01-03 12:03:19 +00:00
fix .d file parsing and string literal ast rendering
This commit is contained in:
parent
91955dee58
commit
85d23e68ee
@ -317,7 +317,7 @@ static bool is_digit(uint8_t c) {
|
||||
|
||||
static bool is_printable(uint8_t c) {
|
||||
static const uint8_t printables[] =
|
||||
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.~`!@#$%^&*()_-+=\\{}[];'\"?/<>,";
|
||||
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.~`!@#$%^&*()_-+=\\{}[];'\"?/<>,:";
|
||||
for (size_t i = 0; i < array_length(printables); i += 1) {
|
||||
if (c == printables[i]) return true;
|
||||
}
|
||||
@ -328,9 +328,7 @@ static void string_literal_escape(Buf *source, Buf *dest) {
|
||||
buf_resize(dest, 0);
|
||||
for (size_t i = 0; i < buf_len(source); i += 1) {
|
||||
uint8_t c = *((uint8_t*)buf_ptr(source) + i);
|
||||
if (is_printable(c)) {
|
||||
buf_append_char(dest, c);
|
||||
} else if (c == '\'') {
|
||||
if (c == '\'') {
|
||||
buf_append_str(dest, "\\'");
|
||||
} else if (c == '"') {
|
||||
buf_append_str(dest, "\\\"");
|
||||
@ -350,6 +348,8 @@ static void string_literal_escape(Buf *source, Buf *dest) {
|
||||
buf_append_str(dest, "\\t");
|
||||
} else if (c == '\v') {
|
||||
buf_append_str(dest, "\\v");
|
||||
} else if (is_printable(c)) {
|
||||
buf_append_char(dest, c);
|
||||
} else {
|
||||
buf_appendf(dest, "\\x%x", (int)c);
|
||||
}
|
||||
|
||||
@ -472,10 +472,11 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
|
||||
}
|
||||
} else {
|
||||
// sometimes there are multiple files on the same line; we actually need space tokenization.
|
||||
SplitIterator line_it = memSplit(opt_line.value, str(" \t\\"));
|
||||
SplitIterator line_it = memSplit(opt_line.value, str(" \t"));
|
||||
Slice<uint8_t> filename;
|
||||
while (SplitIterator_next(&line_it).unwrap(&filename)) {
|
||||
Buf *filename_buf = buf_create_from_slice(filename);
|
||||
if (buf_eql_str(filename_buf, "\\")) continue;
|
||||
if ((err = cache_add_file(ch, filename_buf))) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "unable to add %s to cache: %s\n", buf_ptr(filename_buf), err_str(err));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user