diff options
| -rw-r--r-- | parse.c | 12 | ||||
| -rw-r--r-- | typecheck.c | 1 |
2 files changed, 9 insertions, 4 deletions
@@ -1934,8 +1934,9 @@ PARSER(parse_inline_c) { spaces(&pos); if (!match_word(&pos, "C")) return NULL; spaces(&pos); - if (!match(&pos, "(")) - parser_err(ctx, start, pos, "I expected a '(' here"); + char open = *pos; + if (!match(&pos, "(") && !match(&pos, "{")) + parser_err(ctx, start, pos, "I expected a '(' or '{' here"); int64_t indent = get_indent(ctx, pos); whitespace(&pos); @@ -1947,11 +1948,14 @@ PARSER(parse_inline_c) { pos += line_len; if (whitespace(&pos) == 0) break; } - expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this inline C"); + expect_closing(ctx, &pos, open == '(' ? ")" : "}", "I wasn't able to parse the rest of this inline C"); spaces(&pos); type_ast_t *type = NULL; - if (match(&pos, ":")) + if (open == '(') { + if (!match(&pos, ":")) + parser_err(ctx, start, pos, "This inline C needs to have a type after it"); type = expect(ctx, start, &pos, parse_type, "I couldn't parse the type for this extern"); + } return NewAST(ctx->file, start, pos, InlineCCode, .code=c_code, .type=type); } diff --git a/typecheck.c b/typecheck.c index 34d62aad..8dd62c07 100644 --- a/typecheck.c +++ b/typecheck.c @@ -1120,6 +1120,7 @@ bool is_constant(env_t *env, ast_t *ast) } return true; } + case InlineCCode: return true; default: return false; } } |
