1 // Logic for parsing path literals
14 ast_t *parse_path(parse_ctx_t *ctx, const char *pos) {
15 // [~./] ("\" . / [^ \r\n\t])*
16 const char *start = pos;
18 if (!(*pos == '~' || *pos == '.' || *pos == '/')) return NULL;
21 const char *path_start = pos;
23 while (pos + len < ctx->file->text + ctx->file->len - 1) {
24 if (pos[len] == '\\') {
27 } else if (pos[len] == '(') {
29 } else if (pos[len] == ')') {
31 if (paren_depth < 0) {
35 } else if ((pos[len] == ' ' || pos[len] == '\t') && paren_depth == 0) {
38 } else if (pos[len] == '\r' || pos[len] == '\n') {
39 if (paren_depth == 0) {
43 parser_err(ctx, path_start, &pos[len], "This path was not closed");
47 char *path = String(string_slice(path_start, .length = len));
48 for (char *src = path, *dest = path;;) {
59 return NewAST(ctx->file, start, pos, Path, .path = path);