Tweak matcher
This commit is contained in:
parent
c3100f158e
commit
88bfb1373b
18
actor.ts
18
actor.ts
|
@ -176,7 +176,7 @@ export class Turn {
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
export function match(p: Pattern, v: Assertion): Bindings | null {
|
||||
const bindings: Bindings = {};
|
||||
let bindings: Bindings = {};
|
||||
|
||||
function walk(p: Pattern, v: Assertion): boolean {
|
||||
return fold(p, {
|
||||
|
@ -218,12 +218,20 @@ export function match(p: Pattern, v: Assertion): Bindings | null {
|
|||
if ('type' in t) {
|
||||
switch (t.type) {
|
||||
case 'bind':
|
||||
bindings[t.name] = v;
|
||||
return walk(t.pattern, v);
|
||||
if (walk(t.pattern, v)) {
|
||||
bindings[t.name] = v;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case 'discard':
|
||||
return true;
|
||||
case 'not':
|
||||
return !walk(t.pattern, v);
|
||||
case 'not': {
|
||||
const savedBindings = bindings;
|
||||
bindings = {};
|
||||
const result = !walk(t.pattern, v)
|
||||
bindings = savedBindings;
|
||||
return result;
|
||||
}
|
||||
case 'and':
|
||||
for (const p of t.patterns) {
|
||||
if (!walk(p, v)) return false;
|
||||
|
|
Loading…
Reference in New Issue