aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-02 16:14:20 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-02 16:14:20 -0400
commit6ec8f20fc506af4af5513803fb9a708e4f7b5040 (patch)
tree8b952073f6eda5b85c375a65c73647a85fa16f27 /src
parentecaf34247eb0728a913804033cf302dada417028 (diff)
Syntax change: table types are now: `{K=V; default=...}` and tables
use `{:K=V, ...; default=...}`
Diffstat (limited to 'src')
-rw-r--r--src/environment.c2
-rw-r--r--src/parse.c26
2 files changed, 17 insertions, 11 deletions
diff --git a/src/environment.c b/src/environment.c
index af697c5b..18818a9c 100644
--- a/src/environment.c
+++ b/src/environment.c
@@ -355,7 +355,7 @@ env_t *global_env(void)
{"starts_with", "Text$starts_with", "func(text,prefix:Text -> Bool)"},
{"title", "Text$title", "func(text:Text, language='C' -> Text)"},
{"to", "Text$to", "func(text:Text, last:Int -> Text)"},
- {"translate", "Text$translate", "func(text:Text, translations:{Text,Text} -> Text)"},
+ {"translate", "Text$translate", "func(text:Text, translations:{Text=Text} -> Text)"},
{"trim", "Text$trim", "func(text:Text, to_trim=\" \t\r\n\", left=yes, right=yes -> Text)"},
{"upper", "Text$upper", "func(text:Text, language='C' -> Text)"},
{"utf32_codepoints", "Text$utf32_codepoints", "func(text:Text -> [Int32])"},
diff --git a/src/parse.c b/src/parse.c
index 97576131..a3c68410 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -503,14 +503,17 @@ type_ast_t *parse_table_type(parse_ctx_t *ctx, const char *pos) {
pos = key_type->end;
whitespace(&pos);
type_ast_t *value_type = NULL;
- ast_t *default_value = NULL;
- if (match(&pos, ",")) {
+ if (match(&pos, "=")) {
value_type = expect(ctx, start, &pos, parse_type, "I couldn't parse the rest of this table type");
- } else if (match(&pos, "=")) {
- default_value = expect(ctx, start, &pos, parse_extended_expr, "I couldn't parse the rest of this table type");
} else {
return NULL;
}
+ spaces(&pos);
+ ast_t *default_value = NULL;
+ if (match(&pos, ";") && match_word(&pos, "default")) {
+ expect_str(ctx, pos, &pos, "=", "I expected an '=' here");
+ default_value = expect(ctx, start, &pos, parse_extended_expr, "I couldn't parse the default value for this table");
+ }
whitespace(&pos);
expect_closing(ctx, &pos, "}", "I wasn't able to parse the rest of this table type");
return NewTypeAST(ctx->file, start, pos, TableTypeAST, .key=key_type, .value=value_type, .default_value=default_value);
@@ -722,15 +725,12 @@ PARSER(parse_table) {
ast_list_t *entries = NULL;
type_ast_t *key_type = NULL, *value_type = NULL;
- ast_t *default_value = NULL;
if (match(&pos, ":")) {
whitespace(&pos);
key_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse a key type for this table");
whitespace(&pos);
- if (match(&pos, ",")) {
+ if (match(&pos, "=")) {
value_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse the value type for this table");
- } else if (match(&pos, "=")) {
- default_value = expect(ctx, pos-1, &pos, parse_extended_expr, "I couldn't parse the default value for this table");
} else {
return NULL;
}
@@ -764,7 +764,7 @@ PARSER(parse_table) {
whitespace(&pos);
- ast_t *fallback = NULL;
+ ast_t *fallback = NULL, *default_value = NULL;
if (match(&pos, ";")) {
for (;;) {
whitespace(&pos);
@@ -775,11 +775,17 @@ PARSER(parse_table) {
if (fallback)
parser_err(ctx, attr_start, pos, "This table already has a fallback");
fallback = expect(ctx, attr_start, &pos, parse_expr, "I expected a fallback table");
+ } else if (match_word(&pos, "default")) {
+ whitespace(&pos);
+ if (!match(&pos, "=")) parser_err(ctx, attr_start, pos, "I expected an '=' after 'default'");
+ if (default_value)
+ parser_err(ctx, attr_start, pos, "This table already has a default");
+ default_value = expect(ctx, attr_start, &pos, parse_expr, "I expected a default value");
} else {
break;
}
whitespace(&pos);
- if (!match(&pos, ";")) break;
+ if (!match(&pos, ",")) break;
}
}