Prepare for removing base environment: special support for any

This commit is contained in:
Tony Garnock-Jones 2021-03-19 20:42:52 +01:00
parent 1c07573178
commit 0970898065
2 changed files with 14 additions and 2 deletions

View File

@ -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<NamedPattern>], _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);

View File

@ -28,10 +28,13 @@ Alternative = <and [@patterns NamedPattern ...]> / Pattern .
Pattern = SimplePattern / CompoundPattern .
SimplePattern =
; special builtins
; any
/ =any
; special builtins: bool, float, double, int, string, bytes, symbol
/ <atom @atomKind AtomKind>
; matches a pointer in the input
; matches a pointer in the input: ref
/ <pointer>
; =symbol, <<lit> any>, or plain non-symbol atom