2021-03-10 22:15:53 +00:00
|
|
|
import * as _ from "@preserves/core";
|
|
|
|
|
|
|
|
export const $1 = 1;
|
|
|
|
export const $Boolean = Symbol.for("Boolean");
|
|
|
|
export const $ByteString = Symbol.for("ByteString");
|
|
|
|
export const $Double = Symbol.for("Double");
|
|
|
|
export const $Float = Symbol.for("Float");
|
|
|
|
export const $SignedInteger = Symbol.for("SignedInteger");
|
|
|
|
export const $String = Symbol.for("String");
|
|
|
|
export const $Symbol = Symbol.for("Symbol");
|
|
|
|
export const $and = Symbol.for("and");
|
|
|
|
export const $atom = Symbol.for("atom");
|
|
|
|
export const $definitions = Symbol.for("definitions");
|
|
|
|
export const $dict = Symbol.for("dict");
|
|
|
|
export const $dictof = Symbol.for("dictof");
|
|
|
|
export const $lit = Symbol.for("lit");
|
|
|
|
export const $named = Symbol.for("named");
|
|
|
|
export const $or = Symbol.for("or");
|
|
|
|
export const $pointer = Symbol.for("pointer");
|
|
|
|
export const $rec = Symbol.for("rec");
|
|
|
|
export const $ref = Symbol.for("ref");
|
|
|
|
export const $schema = Symbol.for("schema");
|
|
|
|
export const $setof = Symbol.for("setof");
|
|
|
|
export const $tuple = Symbol.for("tuple");
|
|
|
|
export const $tuple_STAR_ = Symbol.for("tuple*");
|
|
|
|
export const $version = Symbol.for("version");
|
2021-03-11 16:59:40 +00:00
|
|
|
export const __lit5 = false;
|
2021-03-10 22:15:53 +00:00
|
|
|
|
2021-03-17 15:25:29 +00:00
|
|
|
export type _ptr = never;
|
|
|
|
|
|
|
|
export type _val = _.Value<_ptr>;
|
|
|
|
|
2021-03-10 22:15:53 +00:00
|
|
|
export const Schema = _.Record.makeConstructor<{
|
2021-03-17 13:36:44 +00:00
|
|
|
"_field0": (
|
2021-03-10 22:15:53 +00:00
|
|
|
{
|
|
|
|
get(k: typeof $version): Version;
|
2021-03-11 16:59:40 +00:00
|
|
|
get(k: typeof $pointer): PointerName;
|
2021-03-17 18:17:19 +00:00
|
|
|
get(k: typeof $definitions): Definitions;
|
2021-03-10 22:15:53 +00:00
|
|
|
has(k: typeof $version): true;
|
2021-03-11 16:59:40 +00:00
|
|
|
has(k: typeof $pointer): true;
|
2021-03-10 22:15:53 +00:00
|
|
|
has(k: typeof $definitions): true;
|
2021-03-17 11:20:50 +00:00
|
|
|
} & _.Dictionary<_ptr>
|
2021-03-10 22:15:53 +00:00
|
|
|
)
|
2021-03-17 13:36:44 +00:00
|
|
|
}, _ptr>()($schema, ["_field0"]);
|
2021-03-10 22:15:53 +00:00
|
|
|
|
|
|
|
export type Schema = _.Record<
|
|
|
|
(typeof $schema),
|
|
|
|
[
|
|
|
|
(
|
|
|
|
{
|
|
|
|
get(k: typeof $version): Version;
|
2021-03-11 16:59:40 +00:00
|
|
|
get(k: typeof $pointer): PointerName;
|
2021-03-17 18:17:19 +00:00
|
|
|
get(k: typeof $definitions): Definitions;
|
2021-03-10 22:15:53 +00:00
|
|
|
has(k: typeof $version): true;
|
2021-03-11 16:59:40 +00:00
|
|
|
has(k: typeof $pointer): true;
|
2021-03-10 22:15:53 +00:00
|
|
|
has(k: typeof $definitions): true;
|
2021-03-17 11:20:50 +00:00
|
|
|
} & _.Dictionary<_ptr>
|
2021-03-10 22:15:53 +00:00
|
|
|
)
|
2021-03-11 16:59:40 +00:00
|
|
|
],
|
|
|
|
_ptr
|
2021-03-10 22:15:53 +00:00
|
|
|
>;
|
|
|
|
|
|
|
|
export type Version = (typeof $1);
|
|
|
|
|
2021-03-11 16:59:40 +00:00
|
|
|
export type PointerName = (Ref | (typeof __lit5));
|
|
|
|
|
2021-03-17 18:17:19 +00:00
|
|
|
export type Definitions = _.KeyedDictionary<symbol, Definition, _ptr>;
|
|
|
|
|
2021-03-17 13:36:44 +00:00
|
|
|
export type Definition = (_.Record<(typeof $or), [Array<NamedAlternative>], _ptr> | Alternative);
|
|
|
|
|
|
|
|
export type NamedAlternative = [symbol, Alternative];
|
2021-03-17 11:20:50 +00:00
|
|
|
|
2021-03-17 15:25:29 +00:00
|
|
|
export type Alternative = (_.Record<(typeof $and), [Array<NamedPattern>], _ptr> | Pattern);
|
2021-03-17 11:20:50 +00:00
|
|
|
|
2021-03-17 13:36:44 +00:00
|
|
|
export type Pattern = (SimplePattern | CompoundPattern);
|
|
|
|
|
|
|
|
export type SimplePattern = (
|
2021-03-17 11:20:50 +00:00
|
|
|
_.Record<(typeof $atom), [AtomKind], _ptr> |
|
2021-03-11 16:59:40 +00:00
|
|
|
_.Record<(typeof $pointer), [], _ptr> |
|
|
|
|
_.Record<(typeof $lit), [_val], _ptr> |
|
2021-03-17 13:36:44 +00:00
|
|
|
Ref
|
|
|
|
);
|
|
|
|
|
|
|
|
export type CompoundPattern = (
|
2021-03-17 18:17:19 +00:00
|
|
|
_.Record<(typeof $rec), [NamedPattern, NamedPattern], _ptr> |
|
2021-03-11 16:59:40 +00:00
|
|
|
_.Record<(typeof $tuple), [Array<NamedPattern>], _ptr> |
|
|
|
|
_.Record<(typeof $tuple_STAR_), [Array<NamedPattern>, NamedPattern], _ptr> |
|
2021-03-17 13:36:44 +00:00
|
|
|
_.Record<(typeof $setof), [SimplePattern], _ptr> |
|
|
|
|
_.Record<(typeof $dictof), [SimplePattern, SimplePattern], _ptr> |
|
|
|
|
_.Record<(typeof $dict), [DictionaryEntries], _ptr>
|
2021-03-10 22:15:53 +00:00
|
|
|
);
|
|
|
|
|
2021-03-17 18:17:19 +00:00
|
|
|
export type DictionaryEntries = _.KeyedDictionary<_val, DictionaryEntryPattern, _ptr>;
|
|
|
|
|
|
|
|
export type DictionaryEntryPattern = (NamedSimplePattern | SimplePattern);
|
2021-03-17 13:36:44 +00:00
|
|
|
|
2021-03-17 11:20:50 +00:00
|
|
|
export type AtomKind = (
|
|
|
|
(typeof $Boolean) |
|
|
|
|
(typeof $Float) |
|
|
|
|
(typeof $Double) |
|
|
|
|
(typeof $SignedInteger) |
|
|
|
|
(typeof $String) |
|
|
|
|
(typeof $ByteString) |
|
|
|
|
(typeof $Symbol)
|
|
|
|
);
|
|
|
|
|
2021-03-17 18:17:19 +00:00
|
|
|
export type NamedPattern = (NamedSimplePattern | Pattern);
|
|
|
|
|
|
|
|
export const NamedSimplePattern = _.Record.makeConstructor<{"name": symbol, "pattern": SimplePattern}, _ptr>()($named, ["name","pattern"]);
|
|
|
|
|
|
|
|
export type NamedSimplePattern = _.Record<(typeof $named), [symbol, SimplePattern], _ptr>;
|
2021-03-10 22:15:53 +00:00
|
|
|
|
2021-03-14 21:59:53 +00:00
|
|
|
export const Ref = _.Record.makeConstructor<{"module": ModulePath, "name": symbol}, _ptr>()($ref, ["module","name"]);
|
2021-03-11 09:56:49 +00:00
|
|
|
|
2021-03-14 21:59:53 +00:00
|
|
|
export type Ref = _.Record<(typeof $ref), [ModulePath, symbol], _ptr>;
|
2021-03-11 09:56:49 +00:00
|
|
|
|
|
|
|
export type ModulePath = Array<symbol>;
|
2021-03-12 10:14:39 +00:00
|
|
|
|
2021-03-11 09:56:49 +00:00
|
|
|
|
2021-03-17 15:25:29 +00:00
|
|
|
export const _decodePtr = () => { throw new _.DecodeError("Pointers forbidden"); };
|
2021-03-10 22:15:53 +00:00
|
|
|
|
|
|
|
export function isSchema(v: any): v is Schema {
|
2021-03-11 16:59:40 +00:00
|
|
|
let _tmp0, _tmp1, _tmp2: any;
|
2021-03-10 22:15:53 +00:00
|
|
|
return (
|
2021-03-11 16:59:40 +00:00
|
|
|
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
2021-03-14 20:13:40 +00:00
|
|
|
_.is(v.label, $schema) &&
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
|
|
|
(v.length === 1) &&
|
|
|
|
(
|
2021-03-17 11:20:50 +00:00
|
|
|
_.Dictionary.isDictionary<_ptr>(v[0]) &&
|
2021-03-10 22:15:53 +00:00
|
|
|
((_tmp0 = v[0].get($version)) !== void 0 && isVersion(_tmp0)) &&
|
2021-03-11 16:59:40 +00:00
|
|
|
((_tmp1 = v[0].get($pointer)) !== void 0 && isPointerName(_tmp1)) &&
|
2021-03-17 18:17:19 +00:00
|
|
|
((_tmp2 = v[0].get($definitions)) !== void 0 && isDefinitions(_tmp2))
|
2021-03-10 22:15:53 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-11 16:59:40 +00:00
|
|
|
export function asSchema(v: any): Schema {
|
|
|
|
if (!isSchema(v)) {throw new TypeError(`Invalid Schema: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
2021-03-11 08:25:17 +00:00
|
|
|
|
2021-03-12 19:41:35 +00:00
|
|
|
export function decodeSchema(d: _.TypedDecoder<_ptr>): Schema | undefined {
|
2021-03-14 20:10:47 +00:00
|
|
|
let result;
|
|
|
|
if (d.openRecord()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
|
|
|
_tmp0 = _.asLiteral(d.nextSymbol(), $schema);
|
|
|
|
if (_tmp0 !== void 0) {
|
|
|
|
let _tmp1, _tmp2, _tmp3, _tmp4, _tmp5: any;
|
|
|
|
_tmp2 = d.next();
|
|
|
|
if (_tmp2 !== void 0 && !((
|
|
|
|
_.Dictionary.isDictionary<_ptr>(_tmp2) &&
|
|
|
|
((_tmp3 = _tmp2.get($version)) !== void 0 && isVersion(_tmp3)) &&
|
|
|
|
((_tmp4 = _tmp2.get($pointer)) !== void 0 && isPointerName(_tmp4)) &&
|
2021-03-17 18:17:19 +00:00
|
|
|
((_tmp5 = _tmp2.get($definitions)) !== void 0 && isDefinitions(_tmp5))
|
2021-03-17 14:59:46 +00:00
|
|
|
))) _tmp2 = void 0;
|
|
|
|
if (_tmp2 !== void 0) {
|
|
|
|
if (d.closeCompound()) _tmp1 = [_tmp2] as [
|
2021-03-17 13:36:44 +00:00
|
|
|
(
|
|
|
|
{
|
|
|
|
get(k: typeof $version): Version;
|
|
|
|
get(k: typeof $pointer): PointerName;
|
2021-03-17 18:17:19 +00:00
|
|
|
get(k: typeof $definitions): Definitions;
|
2021-03-17 13:36:44 +00:00
|
|
|
has(k: typeof $version): true;
|
|
|
|
has(k: typeof $pointer): true;
|
|
|
|
has(k: typeof $definitions): true;
|
|
|
|
} & _.Dictionary<_ptr>
|
|
|
|
)
|
|
|
|
];
|
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp1 !== void 0) result = _.Record<
|
2021-03-14 20:10:47 +00:00
|
|
|
(typeof $schema),
|
|
|
|
[
|
|
|
|
(
|
|
|
|
{
|
|
|
|
get(k: typeof $version): Version;
|
|
|
|
get(k: typeof $pointer): PointerName;
|
2021-03-17 18:17:19 +00:00
|
|
|
get(k: typeof $definitions): Definitions;
|
2021-03-14 20:10:47 +00:00
|
|
|
has(k: typeof $version): true;
|
|
|
|
has(k: typeof $pointer): true;
|
|
|
|
has(k: typeof $definitions): true;
|
2021-03-17 11:20:50 +00:00
|
|
|
} & _.Dictionary<_ptr>
|
2021-03-14 20:10:47 +00:00
|
|
|
)
|
|
|
|
]
|
2021-03-17 14:59:46 +00:00
|
|
|
>(_tmp0 as any, _tmp1 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
2021-03-12 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 20:13:40 +00:00
|
|
|
export function isVersion(v: any): v is Version {return _.is(v, $1);}
|
2021-03-10 22:15:53 +00:00
|
|
|
|
2021-03-11 16:59:40 +00:00
|
|
|
export function asVersion(v: any): Version {
|
|
|
|
if (!isVersion(v)) {throw new TypeError(`Invalid Version: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
2021-03-14 20:10:47 +00:00
|
|
|
export function decodeVersion(d: _.TypedDecoder<_ptr>): Version | undefined {let result; result = _.asLiteral(d.nextSignedInteger(), $1); return result;}
|
2021-03-12 19:41:35 +00:00
|
|
|
|
2021-03-14 20:13:40 +00:00
|
|
|
export function isPointerName(v: any): v is PointerName {return (isRef(v) || _.is(v, __lit5));}
|
2021-03-11 16:59:40 +00:00
|
|
|
|
|
|
|
export function asPointerName(v: any): PointerName {
|
|
|
|
if (!isPointerName(v)) {throw new TypeError(`Invalid PointerName: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
2021-03-11 08:25:17 +00:00
|
|
|
|
2021-03-14 20:10:47 +00:00
|
|
|
export function decodePointerName(d: _.TypedDecoder<_ptr>): PointerName | undefined {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
2021-03-14 20:10:47 +00:00
|
|
|
let result;
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = d.mark();
|
2021-03-14 20:10:47 +00:00
|
|
|
result = decodeRef(d);
|
2021-03-17 14:59:46 +00:00
|
|
|
if (result === void 0) {d.restoreMark(_tmp0); result = _.asLiteral(d.nextBoolean(), __lit5);};
|
2021-03-14 20:10:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
2021-03-12 19:41:35 +00:00
|
|
|
|
2021-03-17 18:17:19 +00:00
|
|
|
export function isDefinitions(v: any): v is Definitions {
|
|
|
|
return (
|
|
|
|
_.Dictionary.isDictionary<_ptr>(v) &&
|
|
|
|
((() => {
|
|
|
|
for (const e of v) {
|
|
|
|
if (!(typeof e[0] === 'symbol')) return false;
|
|
|
|
if (!(isDefinition(e[1]))) return false;
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
})())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asDefinitions(v: any): Definitions {
|
|
|
|
if (!isDefinitions(v)) {throw new TypeError(`Invalid Definitions: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeDefinitions(d: _.TypedDecoder<_ptr>): Definitions | undefined {
|
|
|
|
let result;
|
|
|
|
if (d.openDictionary()) {
|
|
|
|
let r: _.KeyedDictionary<symbol, Definition, _ptr> | undefined = new _.KeyedDictionary();
|
|
|
|
while (!d.closeCompound()) {
|
|
|
|
let K: undefined | symbol = void 0;
|
|
|
|
K = d.nextSymbol();
|
|
|
|
if (K === void 0) { r = void 0; break; };
|
|
|
|
let V: undefined | Definition = void 0;
|
|
|
|
V = decodeDefinition(d);
|
|
|
|
if (V === void 0) { r = void 0; break; };
|
|
|
|
r.set(K, V);
|
|
|
|
};
|
|
|
|
result = r;
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-17 11:20:50 +00:00
|
|
|
export function isDefinition(v: any): v is Definition {
|
|
|
|
return (
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
2021-03-17 11:20:50 +00:00
|
|
|
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
|
|
|
_.is(v.label, $or) &&
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
2021-03-17 11:20:50 +00:00
|
|
|
(v.length === 1) &&
|
|
|
|
(
|
|
|
|
_.Array.isArray(v[0]) &&
|
|
|
|
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
2021-03-17 13:36:44 +00:00
|
|
|
v[0].every(v => (isNamedAlternative(v)))
|
2021-03-10 22:15:53 +00:00
|
|
|
)
|
2021-03-17 11:20:50 +00:00
|
|
|
)
|
|
|
|
) ||
|
|
|
|
isAlternative(v)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asDefinition(v: any): Definition {
|
|
|
|
if (!isDefinition(v)) {throw new TypeError(`Invalid Definition: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeDefinition(d: _.TypedDecoder<_ptr>): Definition | undefined {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
2021-03-17 11:20:50 +00:00
|
|
|
let result;
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = d.mark();
|
2021-03-17 11:20:50 +00:00
|
|
|
if (d.openRecord()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp1: any;
|
|
|
|
_tmp1 = _.asLiteral(d.nextSymbol(), $or);
|
|
|
|
if (_tmp1 !== void 0) {
|
|
|
|
let _tmp2, _tmp3: any;
|
2021-03-17 11:20:50 +00:00
|
|
|
if (d.openSequence()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp4: any;
|
2021-03-17 11:20:50 +00:00
|
|
|
{
|
2021-03-17 13:36:44 +00:00
|
|
|
let vN: Array<NamedAlternative> | undefined = [];
|
2021-03-17 11:20:50 +00:00
|
|
|
while (!d.closeCompound()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp4 = void 0;
|
|
|
|
_tmp4 = decodeNamedAlternative(d);
|
|
|
|
if (_tmp4 === void 0) {vN = void 0; break;};
|
|
|
|
vN.push(_tmp4);
|
2021-03-17 11:20:50 +00:00
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp3 = vN;
|
2021-03-17 11:20:50 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp3 !== void 0) {if (d.closeCompound()) _tmp2 = [_tmp3] as [Array<NamedAlternative>];};
|
|
|
|
if (_tmp2 !== void 0) result = _.Record<(typeof $or), [Array<NamedAlternative>]>(_tmp1 as any, _tmp2 as any);
|
2021-03-17 11:20:50 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (result === void 0) {d.restoreMark(_tmp0); result = decodeAlternative(d);};
|
2021-03-17 11:20:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-17 13:36:44 +00:00
|
|
|
export function isNamedAlternative(v: any): v is NamedAlternative {
|
|
|
|
return (
|
|
|
|
_.Array.isArray(v) &&
|
|
|
|
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
|
|
|
(v.length === 2) &&
|
|
|
|
typeof v[0] === 'symbol' &&
|
|
|
|
isAlternative(v[1])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asNamedAlternative(v: any): NamedAlternative {
|
|
|
|
if (!isNamedAlternative(v)) {throw new TypeError(`Invalid NamedAlternative: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeNamedAlternative(d: _.TypedDecoder<_ptr>): NamedAlternative | undefined {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0, _tmp1: any;
|
2021-03-17 13:36:44 +00:00
|
|
|
let result;
|
|
|
|
if (d.openSequence()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = d.nextSymbol();
|
|
|
|
if (_tmp0 !== void 0) {
|
|
|
|
_tmp1 = decodeAlternative(d);
|
|
|
|
if (_tmp1 !== void 0) {if (d.closeCompound()) result = [_tmp0, _tmp1] as [symbol, Alternative];};
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-17 11:20:50 +00:00
|
|
|
export function isAlternative(v: any): v is Alternative {
|
|
|
|
return (
|
|
|
|
(
|
|
|
|
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
|
|
|
_.is(v.label, $and) &&
|
|
|
|
(
|
|
|
|
(v.length === 1) &&
|
|
|
|
(
|
|
|
|
_.Array.isArray(v[0]) &&
|
|
|
|
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
2021-03-17 15:25:29 +00:00
|
|
|
v[0].every(v => (isNamedPattern(v)))
|
2021-03-17 11:20:50 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
isPattern(v)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asAlternative(v: any): Alternative {
|
|
|
|
if (!isAlternative(v)) {throw new TypeError(`Invalid Alternative: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeAlternative(d: _.TypedDecoder<_ptr>): Alternative | undefined {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
2021-03-17 11:20:50 +00:00
|
|
|
let result;
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = d.mark();
|
2021-03-17 11:20:50 +00:00
|
|
|
if (d.openRecord()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp1: any;
|
|
|
|
_tmp1 = _.asLiteral(d.nextSymbol(), $and);
|
|
|
|
if (_tmp1 !== void 0) {
|
|
|
|
let _tmp2, _tmp3: any;
|
2021-03-17 11:20:50 +00:00
|
|
|
if (d.openSequence()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp4: any;
|
2021-03-17 11:20:50 +00:00
|
|
|
{
|
2021-03-17 15:25:29 +00:00
|
|
|
let vN: Array<NamedPattern> | undefined = [];
|
2021-03-17 11:20:50 +00:00
|
|
|
while (!d.closeCompound()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp4 = void 0;
|
2021-03-17 15:25:29 +00:00
|
|
|
_tmp4 = decodeNamedPattern(d);
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp4 === void 0) {vN = void 0; break;};
|
|
|
|
vN.push(_tmp4);
|
2021-03-17 11:20:50 +00:00
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp3 = vN;
|
2021-03-17 11:20:50 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-17 15:25:29 +00:00
|
|
|
if (_tmp3 !== void 0) {if (d.closeCompound()) _tmp2 = [_tmp3] as [Array<NamedPattern>];};
|
|
|
|
if (_tmp2 !== void 0) result = _.Record<(typeof $and), [Array<NamedPattern>]>(_tmp1 as any, _tmp2 as any);
|
2021-03-17 11:20:50 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (result === void 0) {d.restoreMark(_tmp0); result = decodePattern(d);};
|
2021-03-17 11:20:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-17 13:36:44 +00:00
|
|
|
export function isPattern(v: any): v is Pattern {return (isSimplePattern(v) || isCompoundPattern(v));}
|
|
|
|
|
|
|
|
export function asPattern(v: any): Pattern {
|
|
|
|
if (!isPattern(v)) {throw new TypeError(`Invalid Pattern: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
2021-03-17 13:36:44 +00:00
|
|
|
let result;
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = d.mark();
|
2021-03-17 13:36:44 +00:00
|
|
|
result = decodeSimplePattern(d);
|
2021-03-17 14:59:46 +00:00
|
|
|
if (result === void 0) {d.restoreMark(_tmp0); result = decodeCompoundPattern(d);};
|
2021-03-17 13:36:44 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isSimplePattern(v: any): v is SimplePattern {
|
2021-03-17 11:20:50 +00:00
|
|
|
return _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && (
|
|
|
|
(
|
|
|
|
(_.is(v.label, $atom) && ((v.length === 1) && isAtomKind(v[0]))) ||
|
2021-03-14 20:13:40 +00:00
|
|
|
(_.is(v.label, $pointer) && ((v.length === 0))) ||
|
|
|
|
(_.is(v.label, $lit) && ((v.length === 1) && true)) ||
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
2021-03-14 21:59:53 +00:00
|
|
|
_.is(v.label, $ref) && ((v.length === 2) && isModulePath(v[0]) && typeof v[1] === 'symbol')
|
2021-03-17 13:36:44 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asSimplePattern(v: any): SimplePattern {
|
|
|
|
if (!isSimplePattern(v)) {throw new TypeError(`Invalid SimplePattern: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeSimplePattern(d: _.TypedDecoder<_ptr>): SimplePattern | undefined {
|
|
|
|
let result;
|
|
|
|
if (d.openRecord()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0, _tmp1: any;
|
|
|
|
_tmp0 = d.next();
|
|
|
|
_tmp1 = d.mark();
|
|
|
|
if (_.is(_tmp0, $atom)) {
|
|
|
|
let _tmp2, _tmp3: any;
|
|
|
|
_tmp3 = decodeAtomKind(d);
|
|
|
|
if (_tmp3 !== void 0) {if (d.closeCompound()) _tmp2 = [_tmp3] as [AtomKind];};
|
|
|
|
if (_tmp2 !== void 0) result = _.Record<(typeof $atom), [AtomKind]>(_tmp0 as any, _tmp2 as any);
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $pointer)) {
|
|
|
|
let _tmp4: any;
|
|
|
|
if (d.closeCompound()) _tmp4 = [] as [];
|
|
|
|
if (_tmp4 !== void 0) result = _.Record<(typeof $pointer), []>(_tmp0 as any, _tmp4 as any);
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $lit)) {
|
|
|
|
let _tmp5, _tmp6: any;
|
|
|
|
_tmp6 = d.next();
|
|
|
|
if (_tmp6 !== void 0) {if (d.closeCompound()) _tmp5 = [_tmp6] as [_val];};
|
|
|
|
if (_tmp5 !== void 0) result = _.Record<(typeof $lit), [_val]>(_tmp0 as any, _tmp5 as any);
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $ref)) {
|
|
|
|
let _tmp7, _tmp8, _tmp9: any;
|
|
|
|
_tmp8 = decodeModulePath(d);
|
|
|
|
if (_tmp8 !== void 0) {
|
|
|
|
_tmp9 = d.nextSymbol();
|
|
|
|
if (_tmp9 !== void 0) {if (d.closeCompound()) _tmp7 = [_tmp8, _tmp9] as [ModulePath, symbol];};
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp7 !== void 0) result = _.Record<(typeof $ref), [ModulePath, symbol]>(_tmp0 as any, _tmp7 as any);
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isCompoundPattern(v: any): v is CompoundPattern {
|
|
|
|
return _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && (
|
|
|
|
(
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
2021-03-17 18:17:19 +00:00
|
|
|
_.is(v.label, $rec) && ((v.length === 2) && isNamedPattern(v[0]) && isNamedPattern(v[1]))
|
2021-03-14 20:10:47 +00:00
|
|
|
) ||
|
|
|
|
(
|
2021-03-14 20:13:40 +00:00
|
|
|
_.is(v.label, $tuple) && (
|
2021-03-14 20:10:47 +00:00
|
|
|
(v.length === 1) &&
|
|
|
|
(
|
|
|
|
_.Array.isArray(v[0]) &&
|
|
|
|
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
|
|
|
v[0].every(v => (isNamedPattern(v)))
|
|
|
|
)
|
2021-03-10 22:15:53 +00:00
|
|
|
)
|
2021-03-14 20:10:47 +00:00
|
|
|
) ||
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
2021-03-14 20:13:40 +00:00
|
|
|
_.is(v.label, $tuple_STAR_) && (
|
2021-03-14 20:10:47 +00:00
|
|
|
(v.length === 2) &&
|
|
|
|
(
|
|
|
|
_.Array.isArray(v[0]) &&
|
|
|
|
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
|
|
|
v[0].every(v => (isNamedPattern(v)))
|
|
|
|
) &&
|
|
|
|
isNamedPattern(v[1])
|
|
|
|
)
|
|
|
|
) ||
|
2021-03-17 13:36:44 +00:00
|
|
|
(_.is(v.label, $setof) && ((v.length === 1) && isSimplePattern(v[0]))) ||
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
2021-03-17 13:36:44 +00:00
|
|
|
_.is(v.label, $dictof) && ((v.length === 2) && isSimplePattern(v[0]) && isSimplePattern(v[1]))
|
2021-03-14 20:10:47 +00:00
|
|
|
) ||
|
2021-03-17 13:36:44 +00:00
|
|
|
(_.is(v.label, $dict) && ((v.length === 1) && isDictionaryEntries(v[0])))
|
2021-03-10 22:15:53 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-17 13:36:44 +00:00
|
|
|
export function asCompoundPattern(v: any): CompoundPattern {
|
|
|
|
if (!isCompoundPattern(v)) {throw new TypeError(`Invalid CompoundPattern: ${_.stringify(v)}`);} else {return v;};
|
2021-03-11 16:59:40 +00:00
|
|
|
}
|
2021-03-11 08:25:17 +00:00
|
|
|
|
2021-03-17 13:36:44 +00:00
|
|
|
export function decodeCompoundPattern(d: _.TypedDecoder<_ptr>): CompoundPattern | undefined {
|
2021-03-14 20:10:47 +00:00
|
|
|
let result;
|
|
|
|
if (d.openRecord()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0, _tmp1: any;
|
|
|
|
_tmp0 = d.next();
|
|
|
|
_tmp1 = d.mark();
|
|
|
|
if (_.is(_tmp0, $rec)) {
|
|
|
|
let _tmp2, _tmp3, _tmp4: any;
|
2021-03-17 18:17:19 +00:00
|
|
|
_tmp3 = decodeNamedPattern(d);
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp3 !== void 0) {
|
2021-03-17 18:17:19 +00:00
|
|
|
_tmp4 = decodeNamedPattern(d);
|
|
|
|
if (_tmp4 !== void 0) {if (d.closeCompound()) _tmp2 = [_tmp3, _tmp4] as [NamedPattern, NamedPattern];};
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
2021-03-17 18:17:19 +00:00
|
|
|
if (_tmp2 !== void 0) result = _.Record<(typeof $rec), [NamedPattern, NamedPattern]>(_tmp0 as any, _tmp2 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $tuple)) {
|
|
|
|
let _tmp5, _tmp6: any;
|
2021-03-17 13:36:44 +00:00
|
|
|
if (d.openSequence()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp7: any;
|
2021-03-17 13:36:44 +00:00
|
|
|
{
|
|
|
|
let vN: Array<NamedPattern> | undefined = [];
|
|
|
|
while (!d.closeCompound()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp7 = void 0;
|
|
|
|
_tmp7 = decodeNamedPattern(d);
|
|
|
|
if (_tmp7 === void 0) {vN = void 0; break;};
|
|
|
|
vN.push(_tmp7);
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp6 = vN;
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp6 !== void 0) {if (d.closeCompound()) _tmp5 = [_tmp6] as [Array<NamedPattern>];};
|
|
|
|
if (_tmp5 !== void 0) result = _.Record<(typeof $tuple), [Array<NamedPattern>]>(_tmp0 as any, _tmp5 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $tuple_STAR_)) {
|
|
|
|
let _tmp8, _tmp9, _tmp10: any;
|
2021-03-17 13:36:44 +00:00
|
|
|
if (d.openSequence()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp11: any;
|
2021-03-17 13:36:44 +00:00
|
|
|
{
|
|
|
|
let vN: Array<NamedPattern> | undefined = [];
|
|
|
|
while (!d.closeCompound()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp11 = void 0;
|
|
|
|
_tmp11 = decodeNamedPattern(d);
|
|
|
|
if (_tmp11 === void 0) {vN = void 0; break;};
|
|
|
|
vN.push(_tmp11);
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp9 = vN;
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp9 !== void 0) {
|
|
|
|
_tmp10 = decodeNamedPattern(d);
|
|
|
|
if (_tmp10 !== void 0) {
|
|
|
|
if (d.closeCompound()) _tmp8 = [_tmp9, _tmp10] as [Array<NamedPattern>, NamedPattern];
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp8 !== void 0) result = _.Record<(typeof $tuple_STAR_), [Array<NamedPattern>, NamedPattern]>(_tmp0 as any, _tmp8 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $setof)) {
|
|
|
|
let _tmp12, _tmp13: any;
|
|
|
|
_tmp13 = decodeSimplePattern(d);
|
|
|
|
if (_tmp13 !== void 0) {if (d.closeCompound()) _tmp12 = [_tmp13] as [SimplePattern];};
|
|
|
|
if (_tmp12 !== void 0) result = _.Record<(typeof $setof), [SimplePattern]>(_tmp0 as any, _tmp12 as any);
|
2021-03-12 19:41:35 +00:00
|
|
|
};
|
2021-03-14 20:10:47 +00:00
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $dictof)) {
|
|
|
|
let _tmp14, _tmp15, _tmp16: any;
|
|
|
|
_tmp15 = decodeSimplePattern(d);
|
|
|
|
if (_tmp15 !== void 0) {
|
|
|
|
_tmp16 = decodeSimplePattern(d);
|
|
|
|
if (_tmp16 !== void 0) {
|
|
|
|
if (d.closeCompound()) _tmp14 = [_tmp15, _tmp16] as [SimplePattern, SimplePattern];
|
2021-03-17 13:36:44 +00:00
|
|
|
};
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp14 !== void 0) result = _.Record<(typeof $dictof), [SimplePattern, SimplePattern]>(_tmp0 as any, _tmp14 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp1);
|
|
|
|
if (_.is(_tmp0, $dict)) {
|
|
|
|
let _tmp17, _tmp18: any;
|
|
|
|
_tmp18 = decodeDictionaryEntries(d);
|
|
|
|
if (_tmp18 !== void 0) {if (d.closeCompound()) _tmp17 = [_tmp18] as [DictionaryEntries];};
|
|
|
|
if (_tmp17 !== void 0) result = _.Record<(typeof $dict), [DictionaryEntries]>(_tmp0 as any, _tmp17 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
2021-03-12 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 13:36:44 +00:00
|
|
|
export function isDictionaryEntries(v: any): v is DictionaryEntries {
|
|
|
|
return (
|
|
|
|
_.Dictionary.isDictionary<_ptr>(v) &&
|
|
|
|
((() => {
|
2021-03-17 18:17:19 +00:00
|
|
|
for (const e of v) {
|
|
|
|
if (!(true)) return false;
|
|
|
|
if (!(isDictionaryEntryPattern(e[1]))) return false;
|
|
|
|
};
|
2021-03-17 13:36:44 +00:00
|
|
|
return true;
|
|
|
|
})())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asDictionaryEntries(v: any): DictionaryEntries {
|
|
|
|
if (!isDictionaryEntries(v)) {throw new TypeError(`Invalid DictionaryEntries: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeDictionaryEntries(d: _.TypedDecoder<_ptr>): DictionaryEntries | undefined {
|
|
|
|
let result;
|
|
|
|
if (d.openDictionary()) {
|
2021-03-17 18:17:19 +00:00
|
|
|
let r: _.KeyedDictionary<_val, DictionaryEntryPattern, _ptr> | undefined = new _.KeyedDictionary();
|
2021-03-17 13:36:44 +00:00
|
|
|
while (!d.closeCompound()) {
|
|
|
|
let K: undefined | _val = void 0;
|
|
|
|
K = d.next();
|
|
|
|
if (K === void 0) { r = void 0; break; };
|
2021-03-17 18:17:19 +00:00
|
|
|
let V: undefined | DictionaryEntryPattern = void 0;
|
|
|
|
V = decodeDictionaryEntryPattern(d);
|
2021-03-17 13:36:44 +00:00
|
|
|
if (V === void 0) { r = void 0; break; };
|
|
|
|
r.set(K, V);
|
|
|
|
};
|
|
|
|
result = r;
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-17 18:17:19 +00:00
|
|
|
export function isDictionaryEntryPattern(v: any): v is DictionaryEntryPattern {return (isNamedSimplePattern(v) || isSimplePattern(v));}
|
|
|
|
|
|
|
|
export function asDictionaryEntryPattern(v: any): DictionaryEntryPattern {
|
|
|
|
if (!isDictionaryEntryPattern(v)) {throw new TypeError(`Invalid DictionaryEntryPattern: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeDictionaryEntryPattern(d: _.TypedDecoder<_ptr>): DictionaryEntryPattern | undefined {
|
|
|
|
let _tmp0: any;
|
|
|
|
let result;
|
|
|
|
_tmp0 = d.mark();
|
|
|
|
result = decodeNamedSimplePattern(d);
|
|
|
|
if (result === void 0) {d.restoreMark(_tmp0); result = decodeSimplePattern(d);};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-17 11:20:50 +00:00
|
|
|
export function isAtomKind(v: any): v is AtomKind {
|
|
|
|
return (
|
|
|
|
_.is(v, $Boolean) ||
|
|
|
|
_.is(v, $Float) ||
|
|
|
|
_.is(v, $Double) ||
|
|
|
|
_.is(v, $SignedInteger) ||
|
|
|
|
_.is(v, $String) ||
|
|
|
|
_.is(v, $ByteString) ||
|
|
|
|
_.is(v, $Symbol)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asAtomKind(v: any): AtomKind {
|
|
|
|
if (!isAtomKind(v)) {throw new TypeError(`Invalid AtomKind: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeAtomKind(d: _.TypedDecoder<_ptr>): AtomKind | undefined {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
2021-03-17 11:20:50 +00:00
|
|
|
let result;
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = d.mark();
|
2021-03-17 11:20:50 +00:00
|
|
|
result = _.asLiteral(d.nextSymbol(), $Boolean);
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp0);
|
2021-03-17 11:20:50 +00:00
|
|
|
result = _.asLiteral(d.nextSymbol(), $Float);
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp0);
|
2021-03-17 11:20:50 +00:00
|
|
|
result = _.asLiteral(d.nextSymbol(), $Double);
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp0);
|
2021-03-17 11:20:50 +00:00
|
|
|
result = _.asLiteral(d.nextSymbol(), $SignedInteger);
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp0);
|
2021-03-17 11:20:50 +00:00
|
|
|
result = _.asLiteral(d.nextSymbol(), $String);
|
|
|
|
if (result === void 0) {
|
2021-03-17 14:59:46 +00:00
|
|
|
d.restoreMark(_tmp0);
|
2021-03-17 11:20:50 +00:00
|
|
|
result = _.asLiteral(d.nextSymbol(), $ByteString);
|
2021-03-17 14:59:46 +00:00
|
|
|
if (result === void 0) {d.restoreMark(_tmp0); result = _.asLiteral(d.nextSymbol(), $Symbol);};
|
2021-03-17 11:20:50 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-17 18:17:19 +00:00
|
|
|
export function isNamedPattern(v: any): v is NamedPattern {return (isNamedSimplePattern(v) || isPattern(v));}
|
2021-03-10 22:15:53 +00:00
|
|
|
|
2021-03-11 08:25:17 +00:00
|
|
|
export function asNamedPattern(v: any): NamedPattern {
|
2021-03-11 16:59:40 +00:00
|
|
|
if (!isNamedPattern(v)) {throw new TypeError(`Invalid NamedPattern: ${_.stringify(v)}`);} else {return v;};
|
2021-03-11 08:25:17 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:41:35 +00:00
|
|
|
export function decodeNamedPattern(d: _.TypedDecoder<_ptr>): NamedPattern | undefined {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
2021-03-14 20:10:47 +00:00
|
|
|
let result;
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = d.mark();
|
2021-03-17 18:17:19 +00:00
|
|
|
result = decodeNamedSimplePattern(d);
|
|
|
|
if (result === void 0) {d.restoreMark(_tmp0); result = decodePattern(d);};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isNamedSimplePattern(v: any): v is NamedSimplePattern {
|
|
|
|
return (
|
|
|
|
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
|
|
|
_.is(v.label, $named) &&
|
|
|
|
((v.length === 2) && typeof v[0] === 'symbol' && isSimplePattern(v[1]))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function asNamedSimplePattern(v: any): NamedSimplePattern {
|
|
|
|
if (!isNamedSimplePattern(v)) {throw new TypeError(`Invalid NamedSimplePattern: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeNamedSimplePattern(d: _.TypedDecoder<_ptr>): NamedSimplePattern | undefined {
|
|
|
|
let result;
|
2021-03-14 20:10:47 +00:00
|
|
|
if (d.openRecord()) {
|
2021-03-17 18:17:19 +00:00
|
|
|
let _tmp0: any;
|
|
|
|
_tmp0 = _.asLiteral(d.nextSymbol(), $named);
|
|
|
|
if (_tmp0 !== void 0) {
|
|
|
|
let _tmp1, _tmp2, _tmp3: any;
|
|
|
|
_tmp2 = d.nextSymbol();
|
|
|
|
if (_tmp2 !== void 0) {
|
|
|
|
_tmp3 = decodeSimplePattern(d);
|
|
|
|
if (_tmp3 !== void 0) {if (d.closeCompound()) _tmp1 = [_tmp2, _tmp3] as [symbol, SimplePattern];};
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
2021-03-17 18:17:19 +00:00
|
|
|
if (_tmp1 !== void 0) result = _.Record<(typeof $named), [symbol, SimplePattern]>(_tmp0 as any, _tmp1 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
2021-03-12 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 09:56:49 +00:00
|
|
|
export function isRef(v: any): v is Ref {
|
|
|
|
return (
|
2021-03-11 16:59:40 +00:00
|
|
|
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
2021-03-14 20:13:40 +00:00
|
|
|
_.is(v.label, $ref) &&
|
2021-03-14 21:59:53 +00:00
|
|
|
((v.length === 2) && isModulePath(v[0]) && typeof v[1] === 'symbol')
|
2021-03-11 09:56:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-11 16:59:40 +00:00
|
|
|
export function asRef(v: any): Ref {
|
|
|
|
if (!isRef(v)) {throw new TypeError(`Invalid Ref: ${_.stringify(v)}`);} else {return v;};
|
|
|
|
}
|
2021-03-11 09:56:49 +00:00
|
|
|
|
2021-03-12 19:41:35 +00:00
|
|
|
export function decodeRef(d: _.TypedDecoder<_ptr>): Ref | undefined {
|
2021-03-14 20:10:47 +00:00
|
|
|
let result;
|
|
|
|
if (d.openRecord()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
|
|
|
_tmp0 = _.asLiteral(d.nextSymbol(), $ref);
|
|
|
|
if (_tmp0 !== void 0) {
|
|
|
|
let _tmp1, _tmp2, _tmp3: any;
|
|
|
|
_tmp2 = decodeModulePath(d);
|
|
|
|
if (_tmp2 !== void 0) {
|
|
|
|
_tmp3 = d.nextSymbol();
|
|
|
|
if (_tmp3 !== void 0) {if (d.closeCompound()) _tmp1 = [_tmp2, _tmp3] as [ModulePath, symbol];};
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
2021-03-17 14:59:46 +00:00
|
|
|
if (_tmp1 !== void 0) result = _.Record<(typeof $ref), [ModulePath, symbol]>(_tmp0 as any, _tmp1 as any);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
2021-03-12 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 09:56:49 +00:00
|
|
|
export function isModulePath(v: any): v is ModulePath {
|
|
|
|
return (
|
|
|
|
_.Array.isArray(v) &&
|
2021-03-11 16:59:40 +00:00
|
|
|
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
2021-03-11 09:56:49 +00:00
|
|
|
(v.length >= 0) &&
|
2021-03-14 20:10:47 +00:00
|
|
|
v.every(v => (typeof v === 'symbol'))
|
2021-03-11 09:56:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-11 13:43:58 +00:00
|
|
|
export function asModulePath(v: any): ModulePath {
|
2021-03-11 16:59:40 +00:00
|
|
|
if (!isModulePath(v)) {throw new TypeError(`Invalid ModulePath: ${_.stringify(v)}`);} else {return v;};
|
2021-03-11 13:43:58 +00:00
|
|
|
}
|
2021-03-10 22:15:53 +00:00
|
|
|
|
2021-03-12 19:41:35 +00:00
|
|
|
export function decodeModulePath(d: _.TypedDecoder<_ptr>): ModulePath | undefined {
|
2021-03-14 20:10:47 +00:00
|
|
|
let result;
|
|
|
|
if (d.openSequence()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
let _tmp0: any;
|
2021-03-14 20:10:47 +00:00
|
|
|
{
|
|
|
|
let vN: Array<symbol> | undefined = [];
|
|
|
|
while (!d.closeCompound()) {
|
2021-03-17 14:59:46 +00:00
|
|
|
_tmp0 = void 0;
|
|
|
|
_tmp0 = d.nextSymbol();
|
|
|
|
if (_tmp0 === void 0) {vN = void 0; break;};
|
|
|
|
vN.push(_tmp0);
|
2021-03-14 20:10:47 +00:00
|
|
|
};
|
|
|
|
result = vN;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return result;
|
2021-03-12 19:41:35 +00:00
|
|
|
}
|
|
|
|
|