@bablr/helpers 0.20.6 → 0.21.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/builders.js +732 -500
- package/lib/decorators.js +2 -1
- package/lib/enhancers.js +4 -36
- package/lib/grammar.js +117 -11
- package/lib/productions.js +29 -92
- package/lib/productions.macro.js +46 -21
- package/lib/shorthand.js +1 -3
- package/lib/source.js +45 -3
- package/lib/stream.js +7 -9
- package/lib/trivia.js +19 -13
- package/package.json +10 -7
package/lib/trivia.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Coroutine } from '@bablr/coroutine';
|
|
2
2
|
import { reifyExpression } from '@bablr/agast-vm-helpers';
|
|
3
|
-
import { mapProductions } from './
|
|
4
|
-
import { OpenNodeTag, CloseNodeTag, ReferenceTag } from './symbols.js';
|
|
3
|
+
import { mapProductions } from './grammar.js';
|
|
4
|
+
import { OpenNodeTag, CloseNodeTag, ReferenceTag, EmbeddedMatcher } from './symbols.js';
|
|
5
|
+
import { getEmbeddedMatcher } from '@bablr/agast-vm-helpers/deembed';
|
|
6
|
+
import { getCooked, isFragmentNode } from '@bablr/agast-helpers/tree';
|
|
5
7
|
|
|
6
8
|
const lookbehind = (context, s) => {
|
|
7
|
-
let token = s.
|
|
9
|
+
let token = s.resultPath;
|
|
8
10
|
while (token && [OpenNodeTag, CloseNodeTag, ReferenceTag].includes(token.type)) {
|
|
9
|
-
const prevToken = context.
|
|
11
|
+
const prevToken = context.getPreviousTagPath(token);
|
|
10
12
|
if (!prevToken) break;
|
|
11
13
|
token = prevToken;
|
|
12
14
|
}
|
|
@@ -26,9 +28,8 @@ export const triviaEnhancer = ({ triviaIsAllowed, eatMatchTrivia }, grammar) =>
|
|
|
26
28
|
|
|
27
29
|
try {
|
|
28
30
|
while (!co.done) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const { verb, arguments: { 0: matcher } = [] } = instr;
|
|
31
|
+
const instr = co.value;
|
|
32
|
+
const { verb, arguments: args = [] } = instr;
|
|
32
33
|
let returnValue = undefined;
|
|
33
34
|
|
|
34
35
|
switch (verb) {
|
|
@@ -36,33 +37,38 @@ export const triviaEnhancer = ({ triviaIsAllowed, eatMatchTrivia }, grammar) =>
|
|
|
36
37
|
case 'eatMatch':
|
|
37
38
|
case 'match':
|
|
38
39
|
case 'guard': {
|
|
39
|
-
|
|
40
|
+
const { 0: matcher, 1: props, 2: options } = args;
|
|
41
|
+
if (
|
|
42
|
+
matcher &&
|
|
43
|
+
matcher.type === EmbeddedMatcher &&
|
|
44
|
+
getCooked(matcher.value.properties.refMatcher?.node.properties.name.node) !== '#'
|
|
45
|
+
) {
|
|
40
46
|
const previous = lookbehind(ctx, s);
|
|
41
47
|
if (triviaIsAllowed(s) && (!previous || !matchedResults.has(previous))) {
|
|
42
48
|
matchedResults.add(previous);
|
|
43
49
|
yield* eatMatchTrivia();
|
|
44
|
-
matchedResults.add(s.
|
|
50
|
+
matchedResults.add(s.resultPath);
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
returnValue = returnValue || (yield
|
|
54
|
+
returnValue = returnValue || (yield instr);
|
|
49
55
|
break;
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
default:
|
|
53
|
-
returnValue = yield
|
|
59
|
+
returnValue = yield instr;
|
|
54
60
|
break;
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
co.advance(returnValue);
|
|
58
64
|
}
|
|
59
65
|
|
|
60
|
-
if (!s.node?.flags.token) {
|
|
66
|
+
if (!s.node?.flags.token && s.node.isFragmentNode) {
|
|
61
67
|
const previous = lookbehind(ctx, s);
|
|
62
68
|
if (triviaIsAllowed(s) && !matchedResults.has(previous)) {
|
|
63
69
|
matchedResults.add(previous);
|
|
64
70
|
yield* eatMatchTrivia();
|
|
65
|
-
matchedResults.add(s.
|
|
71
|
+
matchedResults.add(s.resultPath);
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/helpers",
|
|
3
3
|
"description": "Command helpers for use in writing BABLR grammars",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.21.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
|
"./builders": "./lib/builders.js",
|
|
10
12
|
"./decorators": "./lib/decorators.js",
|
|
11
13
|
"./enhancers": "./lib/enhancers.js",
|
|
12
14
|
"./grammar": "./lib/grammar.js",
|
|
13
15
|
"./object": "./lib/object.js",
|
|
16
|
+
"./path": "./lib/path.js",
|
|
14
17
|
"./productions": "./lib/productions.js",
|
|
15
18
|
"./shorthand": "./lib/shorthand.js",
|
|
16
19
|
"./source": "./lib/source.js",
|
|
@@ -27,16 +30,16 @@
|
|
|
27
30
|
"clean": "macrome clean"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@bablr/language_enhancer-debug-log": "
|
|
31
|
-
"@bablr/strategy_enhancer-debug-log": "
|
|
32
|
-
"@bablr/agast-helpers": "
|
|
33
|
-
"@bablr/agast-vm-helpers": "
|
|
33
|
+
"@bablr/language_enhancer-debug-log": "0.8.0",
|
|
34
|
+
"@bablr/strategy_enhancer-debug-log": "0.7.0",
|
|
35
|
+
"@bablr/agast-helpers": "0.6.0",
|
|
36
|
+
"@bablr/agast-vm-helpers": "0.6.0",
|
|
34
37
|
"@bablr/coroutine": "0.1.0",
|
|
35
38
|
"@iter-tools/imm-stack": "1.1.0",
|
|
36
39
|
"iter-tools-es": "^7.5.3"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
|
-
"@bablr/boot": "^0.6.
|
|
42
|
+
"@bablr/boot": "^0.6.0",
|
|
40
43
|
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#d834ccc52795d6c3b96ecc6c419960fceed221a6",
|
|
41
44
|
"@bablr/macrome": "0.1.3",
|
|
42
45
|
"@bablr/macrome-generator-bablr": "0.3.2",
|