#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";
@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
@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
@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
} {
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 {}