aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-05-18 21:18:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-05-18 21:18:08 -0400
commit4f2421aeeaa2fba490ca4d815be1414feb51c588 (patch)
treef5d1bb6b8c89155f72752c1ee5cd59c901d166be /parse.c
parente4e3186959ba37402bc7ce21c4e977ead721a93f (diff)
Tweak inline C code
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/parse.c b/parse.c
index b2c4f170..28e91b27 100644
--- a/parse.c
+++ b/parse.c
@@ -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);
}