@bablr/language_enhancer-debug-log 0.11.1 → 0.12.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.
- package/README.md +1 -1
- package/lib/index.js +14 -18
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ This langauge enhancer `console.log`s productions as they are evaluated. It is h
|
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
import { parse } from '@bablr/vm';
|
|
9
|
-
import
|
|
9
|
+
import langauge from 'some-langauge';
|
|
10
10
|
import { logEnhancer } from '@bablr/hol-debug-log';
|
|
11
11
|
|
|
12
12
|
parse(
|
package/lib/index.js
CHANGED
|
@@ -7,10 +7,6 @@ import { printCall } from '@bablr/agast-vm-helpers/print';
|
|
|
7
7
|
|
|
8
8
|
const { getOwnPropertyNames, getOwnPropertySymbols, hasOwn } = Object;
|
|
9
9
|
|
|
10
|
-
const printType = (type) => {
|
|
11
|
-
return type == Symbol.for('@bablr/fragment') ? '_' : printIdentifier(type);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
10
|
// TODO this lives in bablr-helpers but I can't use it there
|
|
15
11
|
// it would create a circular dep at the module level
|
|
16
12
|
const mapProductions = (fn, Grammar) => {
|
|
@@ -36,14 +32,14 @@ const writeError = (text) => {
|
|
|
36
32
|
return { verb: 'write', arguments: [text, buildEmbeddedObject({ stream: 2 })] };
|
|
37
33
|
};
|
|
38
34
|
|
|
39
|
-
const mapProduction = (production,
|
|
35
|
+
const mapProduction = (production, name, indentation) => {
|
|
40
36
|
return {
|
|
41
|
-
*[
|
|
37
|
+
*[name](args) {
|
|
42
38
|
const indent = (strings, ...args) => {
|
|
43
39
|
return `${indentation}${String.raw(strings, ...args)}`;
|
|
44
40
|
};
|
|
45
41
|
|
|
46
|
-
yield writeError(`--> ${
|
|
42
|
+
yield writeError(`--> ${printIdentifier(name)}`);
|
|
47
43
|
|
|
48
44
|
let earlyReturn = true;
|
|
49
45
|
try {
|
|
@@ -66,31 +62,31 @@ const mapProduction = (production, type, indentation) => {
|
|
|
66
62
|
current = generator.next(result);
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
const { allowEmpty } = args;
|
|
65
|
+
const { allowEmpty, s } = args;
|
|
70
66
|
|
|
71
|
-
if ((anyResult || allowEmpty) &&
|
|
72
|
-
yield writeError(`<-- ${
|
|
67
|
+
if ((anyResult || allowEmpty) && s().status === 'active') {
|
|
68
|
+
yield writeError(`<-- ${printIdentifier(name)}`);
|
|
73
69
|
} else {
|
|
74
|
-
yield writeError(`x-- ${
|
|
70
|
+
yield writeError(`x-- ${printIdentifier(name)}`);
|
|
75
71
|
}
|
|
76
72
|
earlyReturn = false;
|
|
77
73
|
|
|
78
|
-
if (current.value) {
|
|
79
|
-
yield writeError(indent`${printCall(current.value)}`);
|
|
74
|
+
if (current.value?.shift) {
|
|
75
|
+
yield writeError(indent`${printCall(current.value.shift)}`);
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
return current.value;
|
|
83
79
|
} finally {
|
|
84
80
|
if (earlyReturn) {
|
|
85
|
-
yield writeError(`x-- ${
|
|
81
|
+
yield writeError(`x-- ${printIdentifier(name)}`);
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
},
|
|
89
|
-
}[
|
|
85
|
+
}[name];
|
|
90
86
|
};
|
|
91
87
|
|
|
92
88
|
export const enhanceGrammarWithDebugLogging = (grammar, indentation = '') => {
|
|
93
|
-
return mapProductions((
|
|
89
|
+
return mapProductions((name, prod) => mapProduction(name, prod, indentation), grammar);
|
|
94
90
|
};
|
|
95
91
|
|
|
96
92
|
export const enhanceLanguageWithDebugLogging = (language, indentation = '') => {
|
|
@@ -103,8 +99,8 @@ export const enhanceLanguageWithDebugLogging = (language, indentation = '') => {
|
|
|
103
99
|
export const enhanceWithDebugLogging = enhanceLanguageWithDebugLogging;
|
|
104
100
|
|
|
105
101
|
export const enhanceProductionWithDebugLogging = (indentation = '') => {
|
|
106
|
-
return (production,
|
|
107
|
-
return mapProduction(production,
|
|
102
|
+
return (production, name) => {
|
|
103
|
+
return mapProduction(production, name, indentation);
|
|
108
104
|
};
|
|
109
105
|
};
|
|
110
106
|
|
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.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"author": "Conrad Buck<conartist6@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@bablr/agast-helpers": "0.
|
|
16
|
-
"@bablr/agast-vm-helpers": "0.
|
|
15
|
+
"@bablr/agast-helpers": "0.10.0",
|
|
16
|
+
"@bablr/agast-vm-helpers": "0.10.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#c97bfa4b3663f8378e9b3e42bb5a41e685406cf9",
|
|
@@ -23,7 +23,10 @@
|
|
|
23
23
|
"eslint-plugin-import": "^2.27.5",
|
|
24
24
|
"prettier": "^2.6.2"
|
|
25
25
|
},
|
|
26
|
-
"repository":
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/bablr-lang/language_enhancer-debug-log.git"
|
|
29
|
+
},
|
|
27
30
|
"homepage": "https://github.com/bablr-lang/language_enhancer-debug-log",
|
|
28
31
|
"license": "MIT"
|
|
29
32
|
}
|