ucg/std/schema.ucg
Jeremy Wall 6321828006 FEATURE: The begnnings of some schema definition utilities.
Also allow failure messages to be generated from any expression.
2019-01-20 08:32:05 -06:00

16 lines
352 B
Plaintext

let one_of = module {
val=NULL,
types=[],
} => {
let reducer = macro(acc, t) => acc{
ok = acc.ok || (acc.val is t),
};
let any = macro(val, types) => reduce reducer {ok=false, val=val}, types;
let result = any(mod.val, mod.types).ok;
};
let must = macro(m, msg) => select m.result, fail msg, {
true = m.result,
};