@bablr/bablr-vm 0.23.7 → 0.23.9

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/evaluate.js CHANGED
@@ -59,7 +59,7 @@ function* __bablr(ctx, rootSource, rootLanguage, strategy, options, registerNode
59
59
 
60
60
  let getState = () => s.getPublic();
61
61
 
62
- s = State.from(rootSource, ctx, rootLanguage, options.expressions, options.spans);
62
+ s = State.from(rootSource, ctx, rootLanguage, options.spans);
63
63
 
64
64
  s.source.advance();
65
65
 
@@ -292,16 +292,6 @@ function* __bablr(ctx, rootSource, rootLanguage, strategy, options, registerNode
292
292
  break;
293
293
  }
294
294
 
295
- if (s.expressions.size) {
296
- let expression = s.expressions.value;
297
- let node = getRoot(expression);
298
-
299
- m.advance(node);
300
-
301
- s.expressions = s.expressions.pop();
302
- break;
303
- }
304
-
305
295
  if (Tags.getSize(getTags(s.node))) {
306
296
  m.advance(tag, s);
307
297
  } else {
package/lib/state.js CHANGED
@@ -10,15 +10,8 @@ import { getOpenTag } from '@bablr/agast-helpers/path';
10
10
  export const nodeStates = new WeakMap();
11
11
 
12
12
  export const State = class BABLRState {
13
- static from(source, context, language, expressions = [], spans = Spans.fromValues([])) {
14
- return new State(
15
- null,
16
- source,
17
- context,
18
- BTree.fromValues([language]),
19
- emptyStack.push(...emptyStack.push(...expressions).valuesReverse()),
20
- spans,
21
- );
13
+ static from(source, context, language, spans = Spans.fromValues([])) {
14
+ return new State(null, source, context, BTree.fromValues([language]), spans);
22
15
  }
23
16
 
24
17
  constructor(
@@ -26,7 +19,6 @@ export const State = class BABLRState {
26
19
  source,
27
20
  context,
28
21
  languages,
29
- expressions = emptyStack,
30
22
  spans = Spans.fromValues([]),
31
23
  balanced = emptyStack,
32
24
  resultPath = null,
@@ -40,7 +32,6 @@ export const State = class BABLRState {
40
32
  this.source = source;
41
33
  this.context = context;
42
34
  this.languages = languages;
43
- this.expressions = expressions;
44
35
  this.balanced = balanced;
45
36
  this.spans = spans;
46
37
  this.resultPath = resultPath;
@@ -79,13 +70,12 @@ export const State = class BABLRState {
79
70
  return !!this.parent;
80
71
  }
81
72
 
82
- push(source, context, languages, expressions, spans, balanced, resultPath, depths, held, node) {
73
+ push(source, context, languages, spans, balanced, resultPath, depths, held, node) {
83
74
  return new State(
84
75
  this,
85
76
  source,
86
77
  context,
87
78
  languages,
88
- expressions,
89
79
  spans,
90
80
  balanced,
91
81
  resultPath,
@@ -161,24 +151,12 @@ export const State = class BABLRState {
161
151
 
162
152
  branch() {
163
153
  let baseState = this;
164
- let {
165
- source,
166
- context,
167
- spans,
168
- balanced,
169
- resultPath,
170
- depths,
171
- held,
172
- node,
173
- languages,
174
- expressions,
175
- } = baseState;
154
+ let { source, context, spans, balanced, resultPath, depths, held, node, languages } = baseState;
176
155
 
177
156
  let child = this.push(
178
157
  source.branch(),
179
158
  context,
180
159
  languages,
181
- expressions,
182
160
  spans,
183
161
  balanced,
184
162
  resultPath,
@@ -206,7 +184,6 @@ export const State = class BABLRState {
206
184
  parent.held = accepted.held;
207
185
  parent.depths = accepted.depths;
208
186
  parent.languages = accepted.languages;
209
- parent.expressions = accepted.expressions;
210
187
 
211
188
  if (parent.depths.result + 1 === accepted.depths.result) {
212
189
  parent.resultPath = parent.resultPath.siblingAt(accepted.resultPath.tagsIndex);
@@ -131,11 +131,13 @@ function* __stringEqual(str, iterable) {
131
131
  let strStep = strIter.next();
132
132
  step = iter.next();
133
133
 
134
- while (!strStep.done) {
134
+ while (true) {
135
135
  if (step instanceof Promise) {
136
136
  step = yield wait(step);
137
137
  }
138
138
 
139
+ if (strStep.done) break;
140
+
139
141
  if (step.value !== strStep.value) {
140
142
  step = iter.return();
141
143
  if (step instanceof Promise) {
@@ -166,9 +168,11 @@ export const match = (pattern, source) => {
166
168
  ? [buildOpenNodeTag(tokenFlags), buildLiteralTag(pattern), buildCloseNodeTag()]
167
169
  : null;
168
170
  } else if (typeof pattern === 'string') {
169
- return stringEqual(pattern, source)
170
- ? [buildOpenNodeTag(tokenFlags), buildLiteralTag(pattern), buildCloseNodeTag()]
171
- : null;
171
+ return maybeWait(stringEqual(pattern, source), (equal) => {
172
+ return equal
173
+ ? [buildOpenNodeTag(tokenFlags), buildLiteralTag(pattern), buildCloseNodeTag()]
174
+ : null;
175
+ });
172
176
  }
173
177
 
174
178
  const pattern_ =
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bablr/bablr-vm",
3
3
  "description": "A VM for parsing using BABLR languages",
4
- "version": "0.23.7",
4
+ "version": "0.23.9",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [