@graffiticode/basis 1.5.7 → 1.5.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graffiticode/basis",
3
3
  "type": "module",
4
- "version": "1.5.7",
4
+ "version": "1.5.9",
5
5
  "description": "The basis library for creating Graffiticode languages",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/src/compiler.js CHANGED
@@ -35,9 +35,10 @@ class Visitor {
35
35
  }
36
36
  // console.log(
37
37
  // "Visitor/visit()",
38
+ // "nodePool=" + JSON.stringify(this.nodePool, null, 2),
38
39
  // "node.tag=" + node.tag,
39
40
  // );
40
- const fn = (this[node.tag] || this["CATCH_ALL"]).bind(this);
41
+ const fn = (this[node.tag] || this["CATCH_ALL"])?.bind(this);
41
42
  assert(node && node.tag && node.elts, "2000: Visitor.visit() tag=" + node.tag + " elts= " + JSON.stringify(node.elts));
42
43
  assert(fn, "2000: Visitor function not defined for: " + node.tag);
43
44
  assert(typeof resume === "function", message(1003));
@@ -48,6 +49,10 @@ class Visitor {
48
49
  fn(node, options, resume);
49
50
  }
50
51
  } catch (x) {
52
+ console.log(
53
+ "Vistor/visit()",
54
+ "ERROR: " + x
55
+ );
51
56
  resume(error(x.stack));
52
57
  }
53
58
  }
@@ -277,6 +282,11 @@ export class Checker extends Visitor {
277
282
  const val = node;
278
283
  resume(err, val);
279
284
  }
285
+ IF(node, options, resume) {
286
+ const err = [];
287
+ const val = node;
288
+ resume(err, val);
289
+ }
280
290
  OF(node, options, resume) {
281
291
  const err = [];
282
292
  const val = node;
@@ -364,6 +374,11 @@ export class Transformer extends Visitor {
364
374
  return nid;
365
375
  }
366
376
  match(options, patterns, node) {
377
+ // console.log(
378
+ // "match()",
379
+ // "patterns=" + JSON.stringify(patterns, null, 2),
380
+ // "node=" + JSON.stringify(node, null, 2),
381
+ // );
367
382
  if (patterns.size === 0 || node === undefined) {
368
383
  return false;
369
384
  }
@@ -680,9 +695,14 @@ export class Transformer extends Visitor {
680
695
  CASE(node, options, resume) {
681
696
  // FIXME this isn't ASYNC compatible
682
697
  options.SYNC = true;
683
- this.visit(node.elts[0], options, (err, e0) => {
698
+ this.visit(node.elts[0], options, (e0, v0) => {
684
699
  const e0Node = this.node(node.elts[0]);
685
- const expr = (e0Node.tag === 'NUM' || e0Node.tag === 'NUM') && e0Node || {tag: 'STR', elts: [`${e0}`]};
700
+ const expr = (
701
+ e0Node.tag === 'NUM' ||
702
+ e0Node.tag === 'NUM'
703
+ ) && e0Node || {
704
+ tag: 'STR', elts: [`${v0}`]
705
+ };
686
706
  let foundMatch = false;
687
707
  const patterns = [];
688
708
  for (var i = 1; i < node.elts.length; i++) {
@@ -710,6 +730,29 @@ export class Transformer extends Visitor {
710
730
  });
711
731
  });
712
732
  }
733
+ IF(node, options, resume) {
734
+ this.visit(node.elts[0], options, (e0, v0) => {
735
+ if (!!v0) {
736
+ this.visit(node.elts[1], options, (e1, v1) => {
737
+ const err = [
738
+ ...e0,
739
+ ...e1,
740
+ ];
741
+ const val = v1;
742
+ resume(err, val);
743
+ });
744
+ } else {
745
+ this.visit(node.elts[2], options, (e2, v2) => {
746
+ const err = [
747
+ ...e0,
748
+ ...e2,
749
+ ];
750
+ const val = v2;
751
+ resume(err, val);
752
+ });
753
+ }
754
+ });
755
+ }
713
756
  }
714
757
 
715
758
  export class Renderer {