]> Cypherpunks repositories - keks.git/commitdiff
Remove redundant "TAKE ."
authorSergey Matveev <stargrave@stargrave.org>
Wed, 18 Jun 2025 15:06:51 +0000 (18:06 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 18 Jun 2025 15:07:24 +0000 (18:07 +0300)
c/lib/schema.c
go/schema/check.go
spec/schema/cmds
tcl/schema.t/generic.t
tcl/schema.tcl

index c253b2aaf7deeca82e612ddd9394ea11ef5b98bee3119531fa656779dc616fa9..bfe5734554ad31a5c5570d867130172f1d7b492d316724ac67cbe14f9c2fb801 100644 (file)
@@ -641,7 +641,7 @@ KEKSSchemaValidate( // NOLINT(misc-no-recursion)
     }
     idxSchema = schema->list[idxSchema].atom.v.list.head;
     err.offSchema = schema->offsets[idxSchema];
-    size_t taken = SIZE_MAX;
+    size_t taken = idxData;
     bool eachInList = false;
     bool eachInMap = false;
     struct KEKSSchemaErr errCmd;
index 7edeed90acea3e8da2bf5b14dd18259f1bc8843fd5a5acd67c0834fd59a4a7fa..7daf7fdfde354ca3dd0882a5d9d6ce0d0426b8033e2b35db7a7d5000f5912ac4 100644 (file)
@@ -86,7 +86,7 @@ func Check(schemaName string, schemas map[string][][]any, data any) error {
                }}
        }
        var taken string
-       var vs []any
+       vs := []any{data}
        for cmdIdx, cmd := range cmds {
                if len(cmd) == 0 {
                        return &SchemaErr{BaseErr: BaseErr{
index 9bf4ea59fe902b0e29c1996fb8d94296809cf5ff3b4850b4b7266fe92d053f5c..eecc30c08e783a80ef8feb442eba3b707d6b9c14de381d9f8e04df273f0ea453 100644 (file)
@@ -13,6 +13,8 @@ TAKE | [".", k]
     If "k" equals to ".", then choose the element you are currently in.
     Command never fails, but key can be non-existent.
     All following commands will be applied to the taken value.
+    By default analogue of [".", "."] command is executed when schema
+    check is called.
 
 EXISTS | ["E"]
     Assure that chosen element exists.
@@ -100,7 +102,6 @@ Here is an example with multiple schemas:
 
     {
         "where": [
-            [".", "."],
             ["T", "LIST"],
             [">", 1],
             ["<", 3],
@@ -116,7 +117,6 @@ Here is an example with multiple schemas:
             ["<", 181],
         ],
         "wheres": [
-            [".", "."],
             ["T", "LIST"],
             [">", 0],
             ["*"],
index e384b3bf37568ca366c1d5cf1c909a613335a9d667e9e10c92f9119d11604381..257fff595b9d471997506ce795173cdcbb009c6d53be2ce21d46c709bfd5dca6 100755 (executable)
@@ -616,7 +616,6 @@ test_expect_success "tai64 prec=fs" "$SCHEMA_VALIDATE schema.keks e <data.keks"
 $root/keks.tcl >schema.keks.hex <<EOF
 MAGIC schema
 MAP {e {LIST {
-    {LIST {{STR .} {STR .}}}
     {LIST {{STR T} {STR LIST}}}
     {LIST {{STR *}}}
     {LIST {{STR T} {STR INT}}}
index e72711844bc51ef6c1fc2dea85a8eb996f7d12d84108b2730228ceb977451d08..4ceae5c499a03fe432006073327f1340818f6ca75c33f72c2e0fc5c486c5178a 100755 (executable)
@@ -50,7 +50,9 @@ set knownTypes {bin blob bool hexlet int list magic map nil set str tai}
 
 proc field {k types args} {
     upvar _cmds _cmds buf buf
-    lappend _cmds [TAKE $k]
+    if {$k != "."} {
+        lappend _cmds [TAKE $k]
+    }
     if {[lindex $types 0] == "with"} {
         lappend _cmds [SCHEMA [lindex $types 1]]
     } elseif {[lsearch -exact $types set] == -1} {