aboutsummaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-03 15:40:57 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-03 15:40:57 -0400
commit8ab991fba503f446c70f877969e4314d0cc7d2f3 (patch)
tree77bc0cf33af92de8dea4ad0965518d8dee79bb5e /src/parse.c
parent8d173710fe8cfd96bd54f9dd1cf0eccacfdd6e73 (diff)
Allow using an untyped empty array/set/table literal for places where
the expected type is known
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/parse.c b/src/parse.c
index 04e35953..43cd150d 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -710,15 +710,13 @@ PARSER(parse_array) {
whitespace(&pos);
expect_closing(ctx, &pos, "]", "I wasn't able to parse the rest of this array");
- if (!item_type && !items)
- parser_err(ctx, start, pos, "Empty arrays must specify what type they would contain (e.g. [:Int])");
-
REVERSE_LIST(items);
return NewAST(ctx->file, start, pos, Array, .item_type=item_type, .items=items);
}
PARSER(parse_table) {
const char *start = pos;
+ if (match(&pos, "{/}")) return NULL;
if (!match(&pos, "{")) return NULL;
whitespace(&pos);
@@ -759,9 +757,6 @@ PARSER(parse_table) {
REVERSE_LIST(entries);
- if (!key_type && !value_type && !entries)
- return NULL;
-
whitespace(&pos);
ast_t *fallback = NULL, *default_value = NULL;
@@ -798,6 +793,9 @@ PARSER(parse_table) {
PARSER(parse_set) {
const char *start = pos;
+ if (match(&pos, "{/}"))
+ return NewAST(ctx->file, start, pos, Set);
+
if (!match(&pos, "{")) return NULL;
whitespace(&pos);
@@ -833,9 +831,6 @@ PARSER(parse_set) {
REVERSE_LIST(items);
- if (!item_type && !items)
- return NULL;
-
whitespace(&pos);
expect_closing(ctx, &pos, "}", "I wasn't able to parse the rest of this set");