@bablr/language_enhancer-debug-log 0.7.1 → 0.8.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/lib/index.js +40 -41
- package/package.json +5 -4
package/lib/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* global console */
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { buildCall, buildNumber, buildObject, buildString } from '@bablr/helpers/builders';
|
|
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
|
|
35
|
+
return { verb: 'write', arguments: [text, buildEmbeddedObject({ stream: 2 })] };
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
const mapProduction = (production, type, indentation) => {
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
+
yield writeError(`--> ${printType(type)}`);
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
let earlyReturn = true;
|
|
49
|
+
try {
|
|
50
|
+
const generator = production(props);
|
|
51
|
+
let current = generator.next();
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
let anyResult = false;
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
while (!current.done) {
|
|
56
|
+
const instr = current.value;
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
yield writeError(`>>> ${printCall(instr)}`);
|
|
59
59
|
|
|
60
|
-
|
|
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
|
-
|
|
62
|
+
const result = yield instr;
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
anyResult = anyResult || (eats && result);
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
current = generator.next(result);
|
|
67
|
+
}
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
const allowEmpty = grammar.emptyables?.has(type);
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
if (current.value) {
|
|
79
|
+
yield writeError(indent`${printCall(current.value)}`);
|
|
80
|
+
}
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/language_enhancer-debug-log",
|
|
3
3
|
"description": "A BABLR language enhancer that logs production execution",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"author": "Conrad Buck<conartist6@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
8
10
|
"exports": {
|
|
9
11
|
".": "./lib/index.js"
|
|
10
12
|
},
|
|
11
13
|
"sideEffects": false,
|
|
12
14
|
"dependencies": {
|
|
13
|
-
"@bablr/agast-helpers": "
|
|
14
|
-
"@bablr/agast-vm-helpers": "^0.5.0"
|
|
15
|
+
"@bablr/agast-helpers": "0.6.1"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
|