@bablr/helpers 0.15.4 → 0.17.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/lib/enhancers.js +7 -11
- package/lib/productions.js +1 -3
- package/lib/source.js +24 -15
- package/lib/trivia.js +2 -2
- package/package.json +7 -14
- package/lib/.babelrc.json +0 -7
package/lib/enhancers.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
enhanceStrategyBuilderWithEmittedLogging as logEmitted,
|
|
4
4
|
} from '@bablr/strategy_enhancer-debug-log';
|
|
5
5
|
import { enhanceProductionWithDebugLogging as createProductionLogger } from '@bablr/language_enhancer-debug-log';
|
|
6
|
-
import { getPrototypeOf } from './object.js';
|
|
6
|
+
import { getOwnPropertySymbols, getPrototypeOf } from './object.js';
|
|
7
7
|
|
|
8
8
|
const { getOwnPropertyNames, hasOwn } = Object;
|
|
9
9
|
|
|
@@ -47,8 +47,8 @@ export const mapProductions = (fn, Grammar) => {
|
|
|
47
47
|
|
|
48
48
|
const mapped = MappedGrammar.prototype;
|
|
49
49
|
|
|
50
|
-
while (prototype) {
|
|
51
|
-
for (const key of getOwnPropertyNames(prototype)) {
|
|
50
|
+
while (prototype && prototype !== Object.prototype) {
|
|
51
|
+
for (const key of [...getOwnPropertyNames(prototype), ...getOwnPropertySymbols(prototype)]) {
|
|
52
52
|
if (!hasOwn(mapped, key)) {
|
|
53
53
|
mapped[key] = fn(prototype[key], key);
|
|
54
54
|
}
|
|
@@ -59,16 +59,12 @@ export const mapProductions = (fn, Grammar) => {
|
|
|
59
59
|
return MappedGrammar;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
export const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
bablrProduction: createProductionLogger(' ', log),
|
|
67
|
-
};
|
|
62
|
+
export const debugEnhancers = {
|
|
63
|
+
agast: (strategy) => logEmitted(strategy, '<<< '),
|
|
64
|
+
createBablrStrategy: (strategy) => logStrategy(strategy, ' >>> '),
|
|
65
|
+
bablrProduction: createProductionLogger('>>> '),
|
|
68
66
|
};
|
|
69
67
|
|
|
70
|
-
export const debugEnhancers = buildDebugEnhancers();
|
|
71
|
-
|
|
72
68
|
export const stateEnhancer = (hooks, grammar) => {
|
|
73
69
|
let state;
|
|
74
70
|
return mapProductions((production) => {
|
package/lib/productions.js
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
* This file is autogenerated. Please do not edit it directly.
|
|
5
5
|
* When editing run `npx macrome watch` then change the file this is generated from.
|
|
6
6
|
*/
|
|
7
|
-
import { interpolateString as _interpolateString } from "@bablr/agast-helpers/template";
|
|
8
|
-
import { interpolateArrayChildren as _interpolateArrayChildren } from "@bablr/agast-helpers/template";
|
|
9
|
-
import { interpolateArray as _interpolateArray } from "@bablr/agast-helpers/template";
|
|
7
|
+
import { interpolateArray as _interpolateArray, interpolateArrayChildren as _interpolateArrayChildren, interpolateString as _interpolateString } from "@bablr/agast-helpers/template";
|
|
10
8
|
import * as _l from "@bablr/agast-vm-helpers/languages";
|
|
11
9
|
import * as _t from "@bablr/agast-helpers/shorthand";
|
|
12
10
|
export function* List({
|
package/lib/source.js
CHANGED
|
@@ -9,7 +9,7 @@ const escapables = {
|
|
|
9
9
|
0: '\0',
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
function*
|
|
12
|
+
function* __readFromStream(stream) {
|
|
13
13
|
let iter = stream[Symbol.asyncIterator]();
|
|
14
14
|
let step;
|
|
15
15
|
|
|
@@ -26,12 +26,12 @@ function* __sourceFromReadStream(stream) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export const
|
|
29
|
+
export const readFromStream = (stream) => new StreamIterable(__readFromStream(stream));
|
|
30
30
|
|
|
31
31
|
const gapStr = '<//>';
|
|
32
32
|
|
|
33
|
-
function*
|
|
34
|
-
let iter = getStreamIterator(
|
|
33
|
+
function* __embeddedSourceFrom(iterable) {
|
|
34
|
+
let iter = getStreamIterator(iterable);
|
|
35
35
|
let step;
|
|
36
36
|
let escape = false;
|
|
37
37
|
let gapMatchIdx = 0;
|
|
@@ -89,8 +89,7 @@ function* __embeddedSourceFromReadStream(stream) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export const
|
|
93
|
-
new StreamIterable(__embeddedSourceFromReadStream(stream));
|
|
92
|
+
export const embeddedSourceFrom = (iterable) => new StreamIterable(__embeddedSourceFrom(iterable));
|
|
94
93
|
|
|
95
94
|
function* __sourceFromTokenStream(terminals) {
|
|
96
95
|
let iter = getStreamIterator(terminals);
|
|
@@ -142,10 +141,10 @@ function* __sourceFromQuasis(quasis) {
|
|
|
142
141
|
|
|
143
142
|
export const sourceFromQuasis = (quasis) => new StreamIterable(__sourceFromQuasis(quasis));
|
|
144
143
|
|
|
145
|
-
export function* fillGapsWith(expressions,
|
|
144
|
+
export function* fillGapsWith(expressions, iterable) {
|
|
146
145
|
let exprIdx = 0;
|
|
147
|
-
let iter = getStreamIterator(
|
|
148
|
-
let
|
|
146
|
+
let iter = getStreamIterator(iterable);
|
|
147
|
+
let holding = false;
|
|
149
148
|
|
|
150
149
|
for (;;) {
|
|
151
150
|
let step = iter.next();
|
|
@@ -158,10 +157,19 @@ export function* fillGapsWith(expressions, stream) {
|
|
|
158
157
|
|
|
159
158
|
const token = step.value;
|
|
160
159
|
|
|
160
|
+
if (token.type === 'Shift') {
|
|
161
|
+
holding = true;
|
|
162
|
+
}
|
|
163
|
+
|
|
161
164
|
if (token.type === 'Gap') {
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
if (holding) {
|
|
166
|
+
holding = false;
|
|
167
|
+
yield token;
|
|
168
|
+
} else {
|
|
169
|
+
if (exprIdx >= expressions.length) throw new Error('not enough gaps for expressions');
|
|
170
|
+
yield* slice(2, -1, streamFromTree(expressions[exprIdx]));
|
|
171
|
+
exprIdx++;
|
|
172
|
+
}
|
|
165
173
|
} else {
|
|
166
174
|
yield token;
|
|
167
175
|
}
|
|
@@ -174,8 +182,8 @@ export function* fillGapsWith(expressions, stream) {
|
|
|
174
182
|
|
|
175
183
|
const none = Symbol('none');
|
|
176
184
|
|
|
177
|
-
function* __stripTrailingNewline(
|
|
178
|
-
const iter = getStreamIterator(
|
|
185
|
+
function* __stripTrailingNewline(iterable) {
|
|
186
|
+
const iter = getStreamIterator(iterable);
|
|
179
187
|
let step = iter.next();
|
|
180
188
|
let lastValue = none;
|
|
181
189
|
|
|
@@ -205,4 +213,5 @@ function* __stripTrailingNewline(stream) {
|
|
|
205
213
|
}
|
|
206
214
|
}
|
|
207
215
|
|
|
208
|
-
export const stripTrailingNewline = (
|
|
216
|
+
export const stripTrailingNewline = (iterable) =>
|
|
217
|
+
new StreamIterable(__stripTrailingNewline(iterable));
|
package/lib/trivia.js
CHANGED
|
@@ -6,7 +6,7 @@ const lookbehind = (context, s) => {
|
|
|
6
6
|
let token = s.result;
|
|
7
7
|
while (
|
|
8
8
|
token &&
|
|
9
|
-
['OpenNodeTag', 'CloseNodeTag', '
|
|
9
|
+
['OpenNodeTag', 'CloseNodeTag', 'Reference'].includes(token.type) &&
|
|
10
10
|
(token.type !== 'OpenNodeTag' || !token.value.intrinsicValue)
|
|
11
11
|
) {
|
|
12
12
|
const prevToken = context.getPreviousTerminal(token);
|
|
@@ -39,7 +39,7 @@ export const triviaEnhancer = ({ triviaIsAllowed, eatMatchTrivia }, grammar) =>
|
|
|
39
39
|
case 'eatMatch':
|
|
40
40
|
case 'match':
|
|
41
41
|
case 'guard': {
|
|
42
|
-
if (matcher &&
|
|
42
|
+
if (matcher && !matcher.flags?.trivia) {
|
|
43
43
|
const previous = lookbehind(ctx, s);
|
|
44
44
|
if (triviaIsAllowed(s) && (!previous || !matchedResults.has(previous))) {
|
|
45
45
|
matchedResults.add(previous);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/helpers",
|
|
3
3
|
"description": "Command helpers for use in writing BABLR grammars",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"author": "Conrad Buck<conartist6@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -26,25 +26,18 @@
|
|
|
26
26
|
"clean": "macrome clean"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@bablr/language_enhancer-debug-log": "0.
|
|
30
|
-
"@bablr/strategy_enhancer-debug-log": "0.
|
|
31
|
-
"@bablr/agast-helpers": "0.
|
|
32
|
-
"@bablr/agast-vm-helpers": "0.
|
|
29
|
+
"@bablr/language_enhancer-debug-log": "0.4.0",
|
|
30
|
+
"@bablr/strategy_enhancer-debug-log": "0.3.0",
|
|
31
|
+
"@bablr/agast-helpers": "0.2.0",
|
|
32
|
+
"@bablr/agast-vm-helpers": "0.2.0",
|
|
33
33
|
"@bablr/coroutine": "0.1.0",
|
|
34
34
|
"iter-tools-es": "^7.5.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@babel/core": "7.22.20",
|
|
39
|
-
"@babel/plugin-proposal-decorators": "7.22.15",
|
|
40
|
-
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
|
|
41
|
-
"@babel/plugin-transform-runtime": "^7.22.15",
|
|
42
|
-
"@babel/runtime": "^7.23.2",
|
|
43
|
-
"@bablr/boot": "0.2.3",
|
|
37
|
+
"@bablr/boot": "0.3.0",
|
|
44
38
|
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#d834ccc52795d6c3b96ecc6c419960fceed221a6",
|
|
45
39
|
"@bablr/macrome": "0.1.1",
|
|
46
|
-
"@bablr/macrome-generator-bablr": "0.
|
|
47
|
-
"babel-plugin-macros": "3.1.0",
|
|
40
|
+
"@bablr/macrome-generator-bablr": "0.3.1",
|
|
48
41
|
"enhanced-resolve": "^5.12.0",
|
|
49
42
|
"eslint": "^7.32.0",
|
|
50
43
|
"eslint-import-resolver-enhanced-resolve": "^1.0.5",
|