]> Cypherpunks repositories - keks.git/commitdiff
More compact commands encoding
authorSergey Matveev <stargrave@stargrave.org>
Fri, 4 Apr 2025 18:22:25 +0000 (21:22 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 4 Apr 2025 18:22:25 +0000 (21:22 +0300)
c/lib/schema.c
go/schema/check.go
spec/schema/cmds.texi
tcl/schema2bin

index 6324b6b0e6193a20d50104f65c431eb060bdb8b216430183d6314345bc0aa4db..2d8c1eb456a1e8b9607932105c8b3d250e847ffdc0ec2ccd94b4a694bc7b07e4 100644 (file)
 #include "items.h"
 #include "schema.h"
 
-static const char CmdEach[] = "EACH";
-static const char CmdExists[] = "EXISTS";
-static const char CmdGT[] = "GT";
-static const char CmdLT[] = "LT";
-static const char CmdNotExists[] = "!EXISTS";
-static const char CmdSchema[] = "SCHEMA";
-static const char CmdTake[] = "TAKE";
-static const char CmdTimeMaxPrec[] = "TIMEMAXPREC";
-static const char CmdType[] = "TYPE";
+static const char CmdEach[] = "*";
+static const char CmdExists[] = "E";
+static const char CmdGT[] = ">";
+static const char CmdLT[] = "<";
+static const char CmdNotExists[] = "!E";
+static const char CmdSchema[] = "S";
+static const char CmdTake[] = ".";
+static const char CmdTimeMaxPrec[] = "TMP";
+static const char CmdType[] = "T";
 
 static const char TypeBin[] = "BIN";
 static const char TypeBlob[] = "BLOB";
index a147234c9ff45f696ef1ba8474eae4a4a7ceef83d1113c99d7559a7028315b48..df779be5205d37255441fecc76236693c152577580cd66d7369a1477cff78f76 100644 (file)
@@ -29,15 +29,15 @@ import (
 )
 
 const (
-       CmdTake        = "TAKE"
-       CmdEach        = "EACH"
-       CmdExists      = "EXISTS"
-       CmdNotExists   = "!EXISTS"
-       CmdType        = "TYPE"
-       CmdLT          = "LT"
-       CmdGT          = "GT"
-       CmdSchema      = "SCHEMA"
-       CmdTimeMaxPrec = "TIMEMAXPREC"
+       CmdEach        = "*"
+       CmdExists      = "E"
+       CmdGT          = ">"
+       CmdLT          = "<"
+       CmdNotExists   = "!E"
+       CmdSchema      = "S"
+       CmdTake        = "."
+       CmdTimeMaxPrec = "TMP"
+       CmdType        = "T"
 
        Magic = "schema"
 )
index 4487cedab5c61bfeeb81cc5d9342b665f8c8c97bdbe96df45ad6e66298c9700d..4d1d90e29da5446f8abc6a6a263e0148e2d7af212acdf2068f0b9bb915993da6 100644 (file)
@@ -14,50 +14,50 @@ generated from higher level schema descriptions.
 
 @table @code
 
-@item TAKE k
-Choose the value of the "k" key in the map, if "k" is a string.
+@item . k
+Take/choose the value of the "k" key in the map, if "k" is a string.
 If "k" is integer, then choose the k-th value in a list.
 If "k" equals to ".", then choose the element you are currently in
 (current map or list). Command never fails, but key can be non-existent.
 
-@item EXISTS
-Check that TAKEn element exists.
+@item E
+Check that chosen element exists.
 
-@item !EXISTS
-Check that TAKEn element does not exist.
+@item !E
+Check that chosen element does not exist.
 
-@item EACH
-Execute the next command against every element of the TAKEn list, of
-every value of the map. Do nothing if taken list/map is empty.
-
-@item TYPE T0 [T1 ...]
-Check that TAKEn element's type is in (T0[, T1 ...]) set.
-Do nothing if no element was taken.
+@item *
+Execute the next command against every element of the chosen (if it
+exists) list, or every value of the map.
 
+@item T T0 [T1 ...]
+Check that chosen (if it exists) element's type is in (T0[, T1 ...]) set.
 Possible types: BIN, BLOB, BOOL, HEXLET, INT, LIST, MAGIC, MAP, NIL,
 STR, TAI64.
 
-@item GT n
-Check that TAKEn integer value is greater than "n". If taken value is
-either list or map, then check their length. If the value is a string,
-then check its length. Do nothing if no element was taken.
-
-@item LT n
-Same as @code{GT}, but check that value is less than "n".
-
-@item SCHEMA s
-Check TAKEn element against schema with the name equal to "s".
-Do nothing if no element was taken.
-
-@item TIMEMAXPREC p
-Check maximal allowable time precision. "p" is integer with following
-possible values: 0 -- only full seconds allowed, no parts;
-3 -- only up to milliseconds;
-6 -- only up to microseconds;
-9 -- only up to nanoseconds;
-12 -- only up to picoseconds;
-15 -- only up to femtoseconds;
-18 -- up to attoseconds;
+@item > n
+Check that chosen (if it exists) integer value is greater than "n".
+If chosen value is either list or map, then check their length.
+If the value is a string, then check its length.
+
+@item < n
+Same as @code{>}, but check that value is less than "n".
+
+@item S s
+Check chosen (if it exists) element against schema named "s".
+
+@item TMP p
+Check that chosen (if it exists) element, of time type, has value below
+maximal time precision. "p" is integer with following possible values:
+    @itemize
+    @item 0 -- only full seconds allowed, no parts;
+    @item 3 -- only up to milliseconds;
+    @item 6 -- only up to microseconds;
+    @item 9 -- only up to nanoseconds;
+    @item 12 -- only up to picoseconds;
+    @item 15 -- only up to femtoseconds;
+    @item 18 -- up to attoseconds;
+    @end itemize
 
 @end table
 
@@ -75,29 +75,29 @@ Corresponding schema can be:
 
 @verbatim
 {"our": [
-    ["TAKE", "a"],
-    ["EXISTS"],
-    ["TAKE", "a"],
-    ["TYPE", "STR"],
-    ["TAKE", "a"],
-    ["GT", 0],
-
-    ["TAKE", "v"],
-    ["EXISTS"],
-    ["TAKE", "v"],
-    ["TYPE", "BIN", "STR"],
-
-    ["TAKE", "fpr"],
-    ["EXISTS"],
-    ["TAKE", "fpr"],
-    ["TYPE", "BIN"],
-    ["TAKE", "fpr"],
-    ["GT", 31],
-    ["TAKE", "fpr"],
-    ["LT", 33],
-
-    ["TAKE", "comment"],
-    ["TYPE", "STR"],
+    [".", "a"],
+    ["E"],
+    [".", "a"],
+    ["T", "STR"],
+    [".", "a"],
+    [">", 0],
+
+    [".", "v"],
+    ["E"],
+    [".", "v"],
+    ["T", "BIN", "STR"],
+
+    [".", "fpr"],
+    ["E"],
+    [".", "fpr"],
+    ["T", "BIN"],
+    [".", "fpr"],
+    [">", 31],
+    [".", "fpr"],
+    ["<", 33],
+
+    [".", "comment"],
+    ["T", "STR"],
 ]}
 @end verbatim
 
@@ -113,32 +113,32 @@ wheres = [+ where]
 @verbatim
 {
     "where": [
-        ["TAKE", "."],
-        ["TYPE", "LIST"],
-        ["TAKE", "."],
-        ["GT", 1],
-        ["TAKE", "."],
-        ["LT", 3],
-        ["TAKE", "."],
-        ["EACH"],
-        ["TAKE", "INT"],
-        ["TAKE", 0],
-        ["GT", -91],
-        ["TAKE", 0],
-        ["LT", 91],
-        ["TAKE", 1],
-        ["GT", -181],
-        ["TAKE", 1],
-        ["LT", 181],
+        [".", "."],
+        ["T", "LIST"],
+        [".", "."],
+        [">", 1],
+        [".", "."],
+        ["<", 3],
+        [".", "."],
+        ["*"],
+        [".", "INT"],
+        [".", 0],
+        [">", -91],
+        [".", 0],
+        ["<", 91],
+        [".", 1],
+        [">", -181],
+        [".", 1],
+        ["<", 181],
     ],
     "wheres": [
-        ["TAKE", "."],
-        ["TYPE", "LIST"],
-        ["TAKE", "."],
-        ["GT", 0],
-        ["TAKE", "."],
-        ["EACH"],
-        ["SCHEMA", "where"],
+        [".", "."],
+        ["T", "LIST"],
+        [".", "."],
+        [">", 0],
+        [".", "."],
+        ["*"],
+        ["S", "where"],
     ],
 }
 @end verbatim
index e345f488f587f382bc660b21fc4896e2503c92ed8cb5f4111c516365b4652b20..6df461e7f87fefa7df1ce7ccd0fb39d502132ba41ea86763fe09a71a04ddb9c2 100755 (executable)
@@ -23,22 +23,22 @@ proc TAKE {v} {
     } {
         set v [list STR $v]
     }
-    subst {{LIST {{STR TAKE} {$v}}}}
+    subst {{LIST {{STR .} {$v}}}}
 }
-proc EXISTS {} {subst {{LIST {{STR EXISTS}}}}}
-proc !EXISTS {} {subst {{LIST {{STR !EXISTS}}}}}
-proc EACH {} {subst {{LIST {{STR EACH}}}}}
+proc EXISTS {} {return {{LIST {{STR E}}}}}
+proc !EXISTS {} {return {{LIST {{STR !E}}}}}
+proc EACH {} {return {{LIST {{STR *}}}}}
 proc TYPE {vs} {
-    set l {{STR TYPE}}
+    set l {{STR T}}
     foreach v $vs {
         lappend l "STR $v"
     }
     subst {{LIST {$l}}}
 }
-proc GT {v} {subst {{LIST {{STR GT} {INT $v}}}}}
-proc LT {v} {subst {{LIST {{STR LT} {INT $v}}}}}
-proc SCHEMA {v} {subst {{LIST {{STR SCHEMA} {STR $v}}}}}
-proc TIMEMAXPREC {v} {subst {{LIST {{STR TIMEMAXPREC} {INT $v}}}}}
+proc GT {v} {subst {{LIST {{STR >} {INT $v}}}}}
+proc LT {v} {subst {{LIST {{STR <} {INT $v}}}}}
+proc SCHEMA {v} {subst {{LIST {{STR S} {STR $v}}}}}
+proc TIMEMAXPREC {v} {subst {{LIST {{STR TMP} {INT $v}}}}}
 
 proc evals {cmds} {
     set rv {}