@bablr/helpers 0.1.6 → 0.1.8
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/trivia.js +8 -7
- package/package.json +1 -1
package/lib/trivia.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Coroutine } from './grammar.js';
|
|
|
4
4
|
|
|
5
5
|
const lookbehind = (context, s) => {
|
|
6
6
|
let token = s.result;
|
|
7
|
-
while (['OpenNode', 'CloseNode', '
|
|
7
|
+
while (['OpenNode', 'CloseNode', 'OpenFragment', 'ReferenceTag'].includes(token.type)) {
|
|
8
8
|
const prevToken = context.getPreviousTerminal(token);
|
|
9
9
|
if (!prevToken) break;
|
|
10
10
|
token = prevToken;
|
|
@@ -22,6 +22,8 @@ export const triviaEnhancer = ({ triviaIsAllowed, eatMatchTrivia }, grammar) =>
|
|
|
22
22
|
|
|
23
23
|
co.advance();
|
|
24
24
|
|
|
25
|
+
let isTerminal = false;
|
|
26
|
+
|
|
25
27
|
try {
|
|
26
28
|
while (!co.done) {
|
|
27
29
|
const instr = co.value;
|
|
@@ -42,17 +44,16 @@ export const triviaEnhancer = ({ triviaIsAllowed, eatMatchTrivia }, grammar) =>
|
|
|
42
44
|
case 'eatMatch':
|
|
43
45
|
case 'match':
|
|
44
46
|
case 'guard': {
|
|
45
|
-
if (
|
|
46
|
-
((['String', 'Pattern'].includes(matcher.type) && !s.isTerminal) ||
|
|
47
|
-
matcher.type === 'TerminalMatcher') &&
|
|
48
|
-
verbSuffix !== '#'
|
|
49
|
-
) {
|
|
47
|
+
if (verbSuffix !== '#') {
|
|
50
48
|
const previous = lookbehind(ctx, s);
|
|
51
49
|
if (triviaIsAllowed(s) && !matchedResults.has(previous)) {
|
|
52
50
|
matchedResults.add(previous);
|
|
53
51
|
yield eatMatchTrivia;
|
|
54
52
|
matchedResults.add(s.result);
|
|
55
53
|
}
|
|
54
|
+
if (['String', 'Pattern'].includes(matcher.type)) {
|
|
55
|
+
isTerminal = true;
|
|
56
|
+
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
returnValue = returnValue || (yield instr);
|
|
@@ -67,7 +68,7 @@ export const triviaEnhancer = ({ triviaIsAllowed, eatMatchTrivia }, grammar) =>
|
|
|
67
68
|
co.advance(returnValue);
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
if (!
|
|
71
|
+
if (!isTerminal) {
|
|
71
72
|
const previous = lookbehind(ctx, s);
|
|
72
73
|
if (triviaIsAllowed(s) && !matchedResults.has(previous)) {
|
|
73
74
|
matchedResults.add(previous);
|