@dallaylaen/ski-interpreter 2.6.2 → 2.6.3

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.
@@ -15608,14 +15608,6 @@ var Case = class {
15608
15608
  parse(src) {
15609
15609
  return new Subst(this.engine.parse(src, { env: this.env, scope: this }), this.input);
15610
15610
  }
15611
- /**
15612
- * @param {Expr} expr
15613
- * @return {CaseResult}
15614
- */
15615
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
15616
- check(..._expr) {
15617
- throw new Error("not implemented");
15618
- }
15619
15611
  };
15620
15612
  var ExprCase = class extends Case {
15621
15613
  /**
@@ -15624,6 +15616,7 @@ var ExprCase = class extends Case {
15624
15616
  * max?: number,
15625
15617
  * note?: string,
15626
15618
  * env?: {string: Expr},
15619
+ * canonize?: { max?: number, maxSize?: number, maxArgs?: number },
15627
15620
  * engine?: Parser
15628
15621
  * }} options
15629
15622
  * @param {[e1: string, e2: string]} terms
@@ -15632,6 +15625,7 @@ var ExprCase = class extends Case {
15632
15625
  if (terms.length !== 2)
15633
15626
  throw new Error("Case accepts exactly 2 strings");
15634
15627
  super(input, options);
15628
+ this.canonize = options.canonize;
15635
15629
  [this.e1, this.e2] = terms.map((s) => this.parse(s));
15636
15630
  }
15637
15631
  check(...args) {
@@ -15642,8 +15636,9 @@ var ExprCase = class extends Case {
15642
15636
  let reason = null;
15643
15637
  if (!r1.final || !r2.final)
15644
15638
  reason = "failed to reach normal form in " + this.max + " steps";
15645
- else
15646
- reason = r1.expr.diff(r2.expr);
15639
+ else {
15640
+ reason = this.canonize ? canonize(r1.expr, this.canonize).diff(canonize(r2.expr, this.canonize)) : r1.expr.diff(r2.expr);
15641
+ }
15647
15642
  return {
15648
15643
  pass: !reason,
15649
15644
  reason: reason ?? void 0,
@@ -15805,6 +15800,11 @@ function checkHtml(str) {
15805
15800
  }
15806
15801
  Quest.Group = Group;
15807
15802
  Quest.Case = Case;
15803
+ function canonize(term, options = {}) {
15804
+ return term.traverse({}, (e) => {
15805
+ return e.infer(options).expr;
15806
+ }) ?? term;
15807
+ }
15808
15808
 
15809
15809
  // src/extras.ts
15810
15810
  function search(seed, options, predicate) {