@patterkit/runtime 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/engine.ts
2
2
  import { evaluate, deserialiseAst } from "@wildwinter/expr";
3
+ import { matchedSpecificity as scoreSpecificity } from "@wildwinter/expr-specificity";
3
4
  import { ScopeRegistry } from "@wildwinter/scoperegistry";
4
5
  import { patterDialect, interpolate, splitRef, stripCaptions } from "@patterkit/dialect";
5
6
  import { walkNodes, effectiveGameId, castStringKey, DEFAULT_CAPTION_DELIMITERS, DEFAULT_CAPTION_CHARACTER } from "@patterkit/model";
@@ -1005,21 +1006,8 @@ var Flow = class {
1005
1006
  * node (comparisons, scoped vars, literals, other calls) is an atom, evaluated whole.
1006
1007
  */
1007
1008
  matchedSpec(node, want) {
1008
- if (node.kind === "binary" && (node.op === "and" || node.op === "or")) {
1009
- const behaveAsAnd = node.op === "and" === want;
1010
- const l = this.matchedSpec(node.left, want);
1011
- const r = this.matchedSpec(node.right, want);
1012
- return behaveAsAnd ? l > 0 && r > 0 ? l + r : 0 : Math.max(l, r);
1013
- }
1014
- if (node.kind === "unary" && node.op === "not") {
1015
- return this.matchedSpec(node.operand, !want);
1016
- }
1017
- if (node.kind === "call" && node.name === "check_flags") {
1018
- const operands = Math.max(1, node.args.length - 1);
1019
- const hit = truthy(evaluate(node, this.evalCtx, patterDialect));
1020
- return want ? hit ? operands : 0 : hit ? 0 : 1;
1021
- }
1022
- return truthy(evaluate(node, this.evalCtx, patterDialect)) === want ? 1 : 0;
1009
+ const evalTruthy = (n) => truthy(evaluate(n, this.evalCtx, patterDialect));
1010
+ return scoreSpecificity(node, evalTruthy, { want });
1023
1011
  }
1024
1012
  /** A selector's cursor state - shared across flows (`group.shared`) or this flow's own. */
1025
1013
  selectorState(group) {