From 09708980656ee93c4a51afbab11bd187f1ab0b52 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 19 Mar 2021 20:42:52 +0100 Subject: [PATCH] Prepare for removing base environment: special support for any --- .../javascript/packages/schema/src/gen/schema.ts | 9 +++++++++ schema/schema.prs | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/implementations/javascript/packages/schema/src/gen/schema.ts b/implementations/javascript/packages/schema/src/gen/schema.ts index 681deb8..b443f1d 100644 --- a/implementations/javascript/packages/schema/src/gen/schema.ts +++ b/implementations/javascript/packages/schema/src/gen/schema.ts @@ -9,6 +9,7 @@ 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 $any = Symbol.for('any'); export const $atom = Symbol.for("atom"); export const $definitions = Symbol.for("definitions"); export const $dict = Symbol.for("dict"); @@ -75,6 +76,7 @@ export type Alternative = (_.Record<(typeof $and), [Array], _ptr> export type Pattern = (SimplePattern | CompoundPattern); export type SimplePattern = ( + _.Record<(typeof $any), [], _ptr> | _.Record<(typeof $atom), [AtomKind], _ptr> | _.Record<(typeof $pointer), [], _ptr> | _.Record<(typeof $lit), [_val], _ptr> | @@ -397,6 +399,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined { export function isSimplePattern(v: any): v is SimplePattern { return _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && ( ( + (_.is(v.label, $any) && ((v.length === 0))) || (_.is(v.label, $atom) && ((v.length === 1) && isAtomKind(v[0]))) || (_.is(v.label, $pointer) && ((v.length === 0))) || (_.is(v.label, $lit) && ((v.length === 1) && true)) || @@ -417,6 +420,12 @@ export function decodeSimplePattern(d: _.TypedDecoder<_ptr>): SimplePattern | un let _tmp0, _tmp1: any; _tmp0 = d.next(); _tmp1 = d.mark(); + { + if (_.is(_tmp0, $any)) { + if (d.closeCompound()) return _.Record<(typeof $any), []>($any, []); + d.restoreMark(_tmp1); + } + } if (_.is(_tmp0, $atom)) { let _tmp2, _tmp3: any; _tmp3 = decodeAtomKind(d); diff --git a/schema/schema.prs b/schema/schema.prs index 1cc15fa..2ed14d8 100644 --- a/schema/schema.prs +++ b/schema/schema.prs @@ -28,10 +28,13 @@ Alternative = / Pattern . Pattern = SimplePattern / CompoundPattern . SimplePattern = - ; special builtins + ; any + / =any + + ; special builtins: bool, float, double, int, string, bytes, symbol / - ; matches a pointer in the input + ; matches a pointer in the input: ref / ; =symbol, < any>, or plain non-symbol atom