Skip to content

Commit 15750ae

Browse files
Rename MATCH to VALIDATE (closes #243)
1 parent 08a0b9f commit 15750ae

8 files changed

Lines changed: 142 additions & 142 deletions

File tree

docs/specification/3-statements.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
For `int` and `float` types, a declaration MAY name a specific numeric base by writing `TYPE{base} name`, where `base` is an `int` literal in the range `2` through `64`. A named-base type is a subtype of its parent numeric type: `int{base}` values are `int`s and `float{base}` values are `float`s, but an assignment to a named-base binding requires the value's base to match the declared base. The parent types `int` and `float` (equivalent to `int{0}` and `float{0}`) accept values of any valid numeric base.
3737

38-
For `map` types, a declaration MAY specify a schema `map` by writing `map{schema} name`, where `schema` is any expression that evaluates to a `map`. A named-`map` type is a subtype of its parent `map` type: `map{schema}` values are `map`s, but an assignment to a named-`map` binding requires the assigned value to match the schema according to the default key-presence rules of the `MATCH` operator. The parent type `map` accepts any `map` value.
38+
For `map` types, a declaration MAY specify a schema `map` by writing `map{schema} name`, where `schema` is any expression that evaluates to a `map`. A named-`map` type is a subtype of its parent `map` type: `map{schema}` values are `map`s, but an assignment to a named-`map` binding requires the assigned value to match the schema according to the default key-presence rules of the `VALIDATE` operator. The parent type `map` accepts any `map` value.
3939

4040
The first assignment to a symbol MUST use a typed form such as `TYPE name = expression`, `TYPE{base} name = expression`, or `map{schema} name = expression`, with one or more spaces between the type annotation and the name and optional spaces around `=`. Subsequent assignments MAY omit the type annotation, but the symbol's type MUST remain unchanged for the lifetime of that name, including after deletion and re-assignment.
4141

docs/specification/4-types.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
`int` and `float` additionally support named-base variants written `int{base}` and `float{base}`, where `base` is a numeric base in the range `2` through `64` or `0` to denote the parent type. A named-base type and its parent are the same runtime type, but static type checking treats mismatched bases as incompatible. `int` and `float` (base `0`) accept any valid numeric base; `int{base}` and `float{base}` only accept values whose stored base equals the declared base.
2323

24-
`map` additionally supports named-schema variants written `map{schema}`, where `schema` is any expression that evaluates to a `map`. A named-schema type and its parent are the same runtime type, but static type checking treats mismatched schemas as incompatible. `map` accepts any `map` value; `map{schema}` only accepts values whose entries satisfy the schema under the default key-presence rules of the `MATCH` operator. Named `map` types with different schemas are treated as distinct types.
24+
`map` additionally supports named-schema variants written `map{schema}`, where `schema` is any expression that evaluates to a `map`. A named-schema type and its parent are the same runtime type, but static type checking treats mismatched schemas as incompatible. `map` accepts any `map` value; `map{schema}` only accepts values whose entries satisfy the schema under the default key-presence rules of the `VALIDATE` operator. Named `map` types with different schemas are treated as distinct types.
2525

2626
---
2727

docs/specification/9-built-ins.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
168168
- `bool KEYIN(int|float|str key, map map)` and `bool VALUEIN(ANY value, map map)` = MUST return `true` when the given key or value occurs in `map` and `false` otherwise.
169169
170-
- `bool MATCH(map map, map schema, int typing = 0, int recurse = 0, int shape = 0)` = MUST return `true` if every key in `schema` is present in `map` and, when `typing`, `shape`, or `recurse` is nonzero, the corresponding matched values also satisfy type, shape, and recursive nesting constraints. If `schema` contains a key `"match"` whose value is a `map`, that entry is metadata and is not itself required in `map`: the effective value of each parameter is the explicit keyword argument if supplied, otherwise the metadata subkey if present and valid, otherwise the implicit default `0`. Each metadata key MUST be an `int`, and an invalid `"match"` entry, unknown metadata subkey name, or metadata subkey value that is not `int` MUST cause `MATCH` to return `false` rather than raising an error. A non-`map` `"match"` value is matched as an ordinary key.
170+
- `bool VALIDATE(map map, map schema, int typing = 0, int recurse = 0, int shape = 0)` = MUST return `true` if every key in `schema` is present in `map` and, when `typing`, `shape`, or `recurse` is nonzero, the corresponding matched values also satisfy type, shape, and recursive nesting constraints. If `schema` contains a key `"validate"` whose value is a `map`, that entry is metadata and is not itself required in `map`: the effective value of each parameter is the explicit keyword argument if supplied, otherwise the metadata subkey if present and valid, otherwise the implicit default `0`. Each metadata key MUST be an `int`, and an invalid `"validate"` entry, unknown metadata subkey name, or metadata subkey value that is not `int` MUST cause `VALIDATE` to return `false` rather than raising an error. A non-`map` `"validate"` value is matched as an ordinary key.
171171
172172
- `map INV(map map)` = MUST return a new map whose keys and values are reversed. Every value in `map` MUST be a scalar key type (`int`, `float`, or `str`), and duplicate values MUST raise a runtime error.
173173

src/builtins.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9509,22 +9509,22 @@ static Value builtin_valuein(Interpreter *interp, Value *args, int argc, Expr **
95099509
return value_bool(false);
95109510
}
95119511

9512-
static int match_read_metadata(Map *tpl, int *typing, int *recurse, int *shape, int explicit_typing,
9512+
static int validate_read_metadata(Map *tpl, int *typing, int *recurse, int *shape, int explicit_typing,
95139513
int explicit_recurse, int explicit_shape);
95149514

9515-
// Helper: recursive match implementation
9516-
static int match_map_internal(Map *m, Map *tpl, int typing, int recurse, int shape, int explicit_typing,
9515+
// Helper: recursive validate implementation
9516+
static int validate_map_internal(Map *m, Map *tpl, int typing, int recurse, int shape, int explicit_typing,
95179517
int explicit_recurse, int explicit_shape) {
95189518
if (!tpl) {
95199519
return 1;
95209520
}
9521-
if (!match_read_metadata(tpl, &typing, &recurse, &shape, explicit_typing, explicit_recurse, explicit_shape)) {
9521+
if (!validate_read_metadata(tpl, &typing, &recurse, &shape, explicit_typing, explicit_recurse, explicit_shape)) {
95229522
return 0;
95239523
}
95249524
for (size_t i = 0; i < tpl->count; i++) {
95259525
Value tkey = tpl->items[i].key;
95269526
Value tval = tpl->items[i].value;
9527-
if (tkey.type == VAL_STR && tkey.as.s && strcmp(tkey.as.s, "match") == 0) {
9527+
if (tkey.type == VAL_STR && tkey.as.s && strcmp(tkey.as.s, "validate") == 0) {
95289528
if (tval.type == VAL_MAP && tval.as.map) {
95299529
continue;
95309530
}
@@ -9571,7 +9571,7 @@ static int match_map_internal(Map *m, Map *tpl, int typing, int recurse, int sha
95719571
Map *mm = mval.as.map;
95729572
Map *tt = tval.as.map;
95739573
int ok =
9574-
match_map_internal(mm, tt, typing, recurse, shape, explicit_typing, explicit_recurse, explicit_shape);
9574+
validate_map_internal(mm, tt, typing, recurse, shape, explicit_typing, explicit_recurse, explicit_shape);
95759575
value_free(mval);
95769576
if (!ok) {
95779577
return 0;
@@ -9583,25 +9583,25 @@ static int match_map_internal(Map *m, Map *tpl, int typing, int recurse, int sha
95839583
return 1;
95849584
}
95859585

9586-
static int match_read_metadata(Map *tpl, int *typing, int *recurse, int *shape, int explicit_typing,
9586+
static int validate_read_metadata(Map *tpl, int *typing, int *recurse, int *shape, int explicit_typing,
95879587
int explicit_recurse, int explicit_shape) {
9588-
Value match_key = value_str("match");
9588+
Value validate_key = value_str("validate");
95899589
int found = 0;
9590-
Value match_value = value_map_get((Value){.type = VAL_MAP, .as.map = tpl}, match_key, &found);
9591-
value_free(match_key);
9590+
Value validate_value = value_map_get((Value){.type = VAL_MAP, .as.map = tpl}, validate_key, &found);
9591+
value_free(validate_key);
95929592
if (!found) {
95939593
return 1;
95949594
}
9595-
if (match_value.type != VAL_MAP) {
9596-
value_free(match_value);
9595+
if (validate_value.type != VAL_MAP) {
9596+
value_free(validate_value);
95979597
return 1;
95989598
}
9599-
if (!match_value.as.map) {
9600-
value_free(match_value);
9599+
if (!validate_value.as.map) {
9600+
value_free(validate_value);
96019601
return 0;
96029602
}
96039603

9604-
Map *metadata = match_value.as.map;
9604+
Map *metadata = validate_value.as.map;
96059605
for (size_t i = 0; i < metadata->count; i++) {
96069606
Value subkey = metadata->items[i].key;
96079607
Value subval = metadata->items[i].value;
@@ -9617,28 +9617,28 @@ static int match_read_metadata(Map *tpl, int *typing, int *recurse, int *shape,
96179617
target = shape;
96189618
explicit = explicit_shape;
96199619
} else {
9620-
value_free(match_value);
9620+
value_free(validate_value);
96219621
return 0;
96229622
}
96239623
if (subval.type != VAL_INT) {
9624-
value_free(match_value);
9624+
value_free(validate_value);
96259625
return 0;
96269626
}
96279627
if (!explicit) {
96289628
*target = subval.as.i ? 1 : 0;
96299629
}
96309630
}
9631-
value_free(match_value);
9631+
value_free(validate_value);
96329632
return 1;
96339633
}
96349634

9635-
// MATCH(map, schema, typing=0, recurse=0, shape=0):int
9636-
static Value builtin_match(Interpreter *interp, Value *args, int argc, Expr **arg_nodes, Env *env, int line, int col) {
9635+
// VALIDATE(map, schema, typing=0, recurse=0, shape=0):int
9636+
static Value builtin_validate(Interpreter *interp, Value *args, int argc, Expr **arg_nodes, Env *env, int line, int col) {
96379637
(void)arg_nodes;
96389638
(void)env;
96399639
(void)argc;
96409640
if (args[0].type != VAL_MAP || args[1].type != VAL_MAP) {
9641-
RUNTIME_ERROR(interp, "MATCH expects two map arguments", line, col);
9641+
RUNTIME_ERROR(interp, "VALIDATE expects two map arguments", line, col);
96429642
}
96439643
int typing = 0;
96449644
int recurse = 0;
@@ -9647,23 +9647,23 @@ static Value builtin_match(Interpreter *interp, Value *args, int argc, Expr **ar
96479647
int explicit_recurse = 0;
96489648
int explicit_shape = 0;
96499649
if (argc >= 3 && args[2].type != VAL_NULL) {
9650-
EXPECT_INT(args[2], "MATCH", interp, line, col);
9650+
EXPECT_INT(args[2], "VALIDATE", interp, line, col);
96519651
typing = args[2].as.i ? 1 : 0;
96529652
explicit_typing = 1;
96539653
}
96549654
if (argc >= 4 && args[3].type != VAL_NULL) {
9655-
EXPECT_INT(args[3], "MATCH", interp, line, col);
9655+
EXPECT_INT(args[3], "VALIDATE", interp, line, col);
96569656
recurse = args[3].as.i ? 1 : 0;
96579657
explicit_recurse = 1;
96589658
}
96599659
if (argc >= 5 && args[4].type != VAL_NULL) {
9660-
EXPECT_INT(args[4], "MATCH", interp, line, col);
9660+
EXPECT_INT(args[4], "VALIDATE", interp, line, col);
96619661
shape = args[4].as.i ? 1 : 0;
96629662
explicit_shape = 1;
96639663
}
96649664
Map *m = args[0].as.map;
96659665
Map *tpl = args[1].as.map;
9666-
int ok = match_map_internal(m, tpl, typing, recurse, shape, explicit_typing, explicit_recurse, explicit_shape);
9666+
int ok = validate_map_internal(m, tpl, typing, recurse, shape, explicit_typing, explicit_recurse, explicit_shape);
96679667
return value_bool(ok != 0);
96689668
}
96699669

@@ -11693,7 +11693,7 @@ static Value builtin_parallel(Interpreter *interp, Value *args, int argc, Expr *
1169311693
static const char *builtin_params_round[] = {"x", "ndigits", "mode"};
1169411694
static const char *builtin_params_bytes[] = {"x", "endian"};
1169511695
static const char *builtin_params_split[] = {"s", "delimiter"};
11696-
static const char *builtin_params_match[] = {"value", "schema", "typing", "recurse", "shape"};
11696+
static const char *builtin_params_validate[] = {"value", "schema", "typing", "recurse", "shape"};
1169711697
static const char *builtin_params_readfile[] = {"path", "coding"};
1169811698
static const char *builtin_params_writefile[] = {"data", "path", "coding"};
1169911699
static const char *builtin_params_pause[] = {"thr", "seconds"};
@@ -11815,7 +11815,7 @@ static BuiltinFunction builtins_table[] = {
1181511815
{"VALUES", 1, 1, builtin_values},
1181611816
{"KEYIN", 2, 2, builtin_keyin},
1181711817
{"VALUEIN", 2, 2, builtin_valuein},
11818-
{"MATCH", 2, 5, builtin_match, builtin_params_match, 5},
11818+
{"VALIDATE", 2, 5, builtin_validate, builtin_params_validate, 5},
1181911819
{"ILEN", 1, 1, builtin_ilen},
1182011820
{"LEN", 0, -1, builtin_len},
1182111821

src/value.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,8 @@ static Value value_map_get_locked(Value mapval, Value key, int *found) {
10891089
return value_copy(m->items[idx].value);
10901090
}
10911091

1092-
// Minimal match implementation for env-check path (defaults: typing=0, recurse=0, shape=0).
1093-
// Supports "match" metadata override from the schema.
1092+
// Minimal validate implementation for env-check path (defaults: typing=0, recurse=0, shape=0).
1093+
// Supports "validate" metadata override from the schema.
10941094
// Thread-safe: acquires locks on both maps during comparison.
10951095
bool value_map_matches(Value map, Value templ) {
10961096
if (map.type != VAL_MAP || templ.type != VAL_MAP) {
@@ -1113,7 +1113,7 @@ bool value_map_matches(Value map, Value templ) {
11131113
Value tkey = t->items[i].key;
11141114
Value tval = t->items[i].value;
11151115
if (tkey.type == VAL_STR && tkey.as.s && tval.type == VAL_MAP && tval.as.map &&
1116-
strcmp(tkey.as.s, "match") == 0) {
1116+
strcmp(tkey.as.s, "validate") == 0) {
11171117
continue;
11181118
}
11191119
int found = 0;

src/value.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ bool decl_type_accepts_value(DeclType expected, int expected_base, Value value);
134134
// Format a type name including base for int/float. Returns buf.
135135
const char *decl_type_name_base(DeclType type, int base, char *buf, size_t buf_size);
136136

137-
// Match a map value against a map schema (same semantics as MATCH with defaults).
138-
// Returns true if all keys in `templ` exist in `map` and satisfy the match (typing=0, recurse=0, shape=0).
139-
// Supports "match" metadata override in the schema.
137+
// Validate a map value against a map schema (same semantics as VALIDATE with defaults).
138+
// Returns true if all keys in `templ` exist in `map` and satisfy the validate (typing=0, recurse=0, shape=0).
139+
// Supports "validate" metadata override in the schema.
140140
bool value_map_matches(Value map, Value templ);
141141

142142
#endif // VALUE_H

0 commit comments

Comments
 (0)