@bablr/language_enhancer-debug-log 0.7.0 → 0.8.0

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.
Files changed (2) hide show
  1. package/lib/index.js +40 -41
  2. package/package.json +2 -3
package/lib/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  /* global console */
2
2
 
3
- import { printSource, getCooked, getRoot } from '@bablr/agast-helpers/tree';
4
- import * as sym from '@bablr/agast-helpers/symbols';
5
- import { buildCall, buildNumber, buildObject, buildString } from '@bablr/agast-vm-helpers';
3
+ import { buildEmbeddedObject, printCall } from '@bablr/agast-helpers/tree';
4
+
6
5
  import { printType as printType_ } from '@bablr/agast-helpers/print';
7
6
 
8
7
  const { getOwnPropertyNames, getOwnPropertySymbols, hasOwn } = Object;
@@ -33,61 +32,61 @@ const mapProductions = (fn, Grammar) => {
33
32
  };
34
33
 
35
34
  const writeError = (text) => {
36
- return buildCall('write', buildString(text), buildObject({ stream: buildNumber(2) }));
35
+ return { verb: 'write', arguments: [text, buildEmbeddedObject({ stream: 2 })] };
37
36
  };
38
37
 
39
38
  const mapProduction = (production, type, indentation) => {
40
- return function* mappedProduction(props) {
41
- const { grammar } = props;
42
- const indent = (strings, ...args) => {
43
- return `${indentation}${String.raw(strings, ...args)}`;
44
- };
39
+ return {
40
+ *[type](props) {
41
+ const { grammar } = props;
42
+ const indent = (strings, ...args) => {
43
+ return `${indentation}${String.raw(strings, ...args)}`;
44
+ };
45
45
 
46
- yield writeError(`--> ${printType(type)}`);
46
+ yield writeError(`--> ${printType(type)}`);
47
47
 
48
- let earlyReturn = true;
49
- try {
50
- const generator = production(props);
51
- let current = generator.next();
48
+ let earlyReturn = true;
49
+ try {
50
+ const generator = production(props);
51
+ let current = generator.next();
52
52
 
53
- let anyResult = false;
53
+ let anyResult = false;
54
54
 
55
- while (!current.done) {
56
- const instr = current.value;
55
+ while (!current.done) {
56
+ const instr = current.value;
57
57
 
58
- yield writeError(`>>> ` + indent`${printSource(instr)}`.slice(indentation.length));
58
+ yield writeError(`>>> ${printCall(instr)}`);
59
59
 
60
- const eats =
61
- getRoot(instr).type === 'Call' &&
62
- ['eat', 'eatMatch'].includes(getCooked(getRoot(instr).properties.verb));
60
+ const eats = ['eat', 'eatMatch'].includes(instr.verb);
63
61
 
64
- const result = yield instr;
62
+ const result = yield instr;
65
63
 
66
- anyResult = anyResult || (eats && result && result.type !== sym.null);
64
+ anyResult = anyResult || (eats && result);
67
65
 
68
- current = generator.next(result);
69
- }
66
+ current = generator.next(result);
67
+ }
70
68
 
71
- const allowEmpty = grammar.emptyables?.has(type);
69
+ const allowEmpty = grammar.emptyables?.has(type);
72
70
 
73
- if ((anyResult || allowEmpty) && props.s.status === 'active') {
74
- yield writeError(`<-- ${printType(type)}`);
75
- } else {
76
- yield writeError(`x-- ${printType(type)}`);
77
- }
78
- earlyReturn = false;
71
+ if ((anyResult || allowEmpty) && props.s.status === 'active') {
72
+ yield writeError(`<-- ${printType(type)}`);
73
+ } else {
74
+ yield writeError(`x-- ${printType(type)}`);
75
+ }
76
+ earlyReturn = false;
79
77
 
80
- if (current.value) {
81
- yield writeError(indent`${printSource(current.value)}`);
82
- }
78
+ if (current.value) {
79
+ yield writeError(indent`${printCall(current.value)}`);
80
+ }
83
81
 
84
- return current.value;
85
- } finally {
86
- if (earlyReturn) {
87
- yield writeError(`x-- ${printType(type)}`);
82
+ return current.value;
83
+ } finally {
84
+ if (earlyReturn) {
85
+ yield writeError(`x-- ${printType(type)}`);
86
+ }
88
87
  }
89
- }
90
- };
88
+ },
89
+ }[type];
91
90
  };
92
91
 
93
92
  export const enhanceGrammarWithDebugLogging = (grammar, indentation = '') => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bablr/language_enhancer-debug-log",
3
3
  "description": "A BABLR language enhancer that logs production execution",
4
- "version": "0.7.0",
4
+ "version": "0.8.0",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -12,8 +12,7 @@
12
12
  },
13
13
  "sideEffects": false,
14
14
  "dependencies": {
15
- "@bablr/agast-helpers": "^0.5.0",
16
- "@bablr/agast-vm-helpers": "^0.5.0"
15
+ "@bablr/agast-helpers": "0.6.0"
17
16
  },
18
17
  "devDependencies": {
19
18
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",