@bablr/bablr-vm 0.23.2 → 0.23.3

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/context.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { buildDependentLanguages } from '@bablr/helpers/grammar';
2
2
  import { getGapNode } from './facades.js';
3
3
 
4
+ let facades = new WeakMap();
5
+
4
6
  export const Context = class BABLRContext {
5
7
  static from(language, productionEnhancer) {
6
8
  return new Context(buildDependentLanguages(language), productionEnhancer);
@@ -25,12 +27,19 @@ export const Context = class BABLRContext {
25
27
  }
26
28
 
27
29
  getPublic() {
30
+ let value = facades.get(this);
31
+ if (value) return value;
32
+
28
33
  let { productionEnhancer, getGrammar } = this;
29
34
 
30
- return Object.freeze({
35
+ value = Object.freeze({
31
36
  getGrammar,
32
37
  getGapNode,
33
38
  productionEnhancer,
34
39
  });
40
+
41
+ facades.set(this, value);
42
+
43
+ return value;
35
44
  }
36
45
  };
package/lib/evaluate.js CHANGED
@@ -1,6 +1,11 @@
1
1
  /* global WeakSet */
2
2
  import { Coroutine } from '@bablr/coroutine';
3
- import { buildAttributeDefinition, buildCloseNodeTag } from '@bablr/agast-helpers/builders';
3
+ import {
4
+ buildAttributeDefinition,
5
+ buildCloseNodeTag,
6
+ buildTypedSpan,
7
+ deepFreeze,
8
+ } from '@bablr/agast-helpers/builders';
4
9
  import { getStreamIterator, printType, StreamIterable, wait } from '@bablr/agast-helpers/stream';
5
10
  import { State } from './state.js';
6
11
  import {
@@ -21,8 +26,7 @@ import { buildWriteEffect } from '@bablr/agast-vm-helpers/builders';
21
26
  import { has } from '@bablr/agast-helpers/object';
22
27
  import { reifyBablrOptions } from '@bablr/agast-vm-helpers';
23
28
  import { buildNode, getTags } from '@bablr/agast-helpers/path';
24
- import * as BTree from '@bablr/agast-helpers/btree';
25
- import { resolveLanguage } from '@bablr/helpers/grammar';
29
+ import * as Spans from '@bablr/agast-helpers/spans';
26
30
 
27
31
  const getSourceLength = (tags) => {
28
32
  let i = 0;
@@ -55,7 +59,7 @@ function* __bablr(ctx, rootSource, rootLanguage, strategy, options, registerNode
55
59
 
56
60
  let getState = () => s.getPublic();
57
61
 
58
- s = State.from(rootSource, ctx, rootLanguage, options.expressions);
62
+ s = State.from(rootSource, ctx, rootLanguage, options.expressions, options.spans);
59
63
 
60
64
  s.source.advance();
61
65
 
@@ -337,14 +341,15 @@ function* __bablr(ctx, rootSource, rootLanguage, strategy, options, registerNode
337
341
  }
338
342
 
339
343
  case 'startSpan': {
340
- let { arguments: { 0: name, 1: guard = null } = [] } = instr;
341
- s.spans = s.spans.push({ type: 'Instruction', name, guard });
344
+ let { arguments: { 0: name, 1: guard = null, 2: { value: props } } = [] } = instr;
345
+ deepFreeze(props);
346
+ s.spans = Spans.push(s.spans, buildTypedSpan('Instruction', name, guard, props));
342
347
  break;
343
348
  }
344
349
 
345
350
  case 'endSpan': {
346
- if (s.spans.value.type !== 'Instruction') throw new Error();
347
- s.spans = s.spans.pop();
351
+ if (s.span.type !== 'Instruction') throw new Error();
352
+ s.spans = Spans.pop(s.spans);
348
353
  break;
349
354
  }
350
355
 
package/lib/spans.js CHANGED
@@ -1,26 +1,13 @@
1
1
  import { ReferenceTag } from '@bablr/agast-helpers/symbols';
2
- import * as BTree from '@bablr/agast-helpers/btree';
2
+ import * as Spans from '@bablr/agast-helpers/spans';
3
+ import { buildTypedSpan } from '@bablr/agast-helpers/builders';
3
4
 
4
5
  const popSpan = (s) => {
5
- s.spans = s.spans.pop();
6
+ s.spans = Spans.pop(s.spans);
6
7
  };
7
8
 
8
9
  const pushSpan = (s, type, name, guard) => {
9
- let isSubspan = name[0] === '.';
10
- let topFrame = s.spans.value;
11
-
12
- // if (isSubspan) {
13
- // let buildGuard = () => {
14
- // return buildPattern();
15
- // };
16
- // let name_ = topFrame.name + name;
17
- // let subframes = BTree.push(topFrame.subframes, topFrame);
18
- // let guard_ = guard;
19
-
20
- // s.spans = s.spans.push({ type, name: name_, guard: guard_, subframes });
21
- // } else {
22
- s.spans = s.spans.push({ type, name, guard, subframes: BTree.fromValues([]) });
23
- // }
10
+ s.spans = Spans.push(s.spans, buildTypedSpan(type, name, guard));
24
11
  };
25
12
 
26
13
  export function updateSpans(m, phase) {
package/lib/state.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import emptyStack from '@iter-tools/imm-stack';
2
2
  import { maybeWait } from '@bablr/agast-helpers/stream';
3
3
  import * as BTree from '@bablr/agast-helpers/btree';
4
+ import * as Spans from '@bablr/agast-helpers/spans';
4
5
  import { reifyExpression } from '@bablr/agast-vm-helpers';
5
6
  import { Matcher, Node, Regex } from '@bablr/agast-vm-helpers/symbols';
6
7
  import { match, guardWithPattern } from './utils/pattern.js';
@@ -9,13 +10,14 @@ import { getOpenTag } from '@bablr/agast-helpers/path';
9
10
  export const nodeStates = new WeakMap();
10
11
 
11
12
  export const State = class BABLRState {
12
- static from(source, context, language, expressions = []) {
13
+ static from(source, context, language, expressions = [], spans = Spans.fromValues([])) {
13
14
  return new State(
14
15
  null,
15
16
  source,
16
17
  context,
17
18
  BTree.fromValues([language]),
18
19
  emptyStack.push(...emptyStack.push(...expressions).valuesReverse()),
20
+ spans,
19
21
  );
20
22
  }
21
23
 
@@ -25,8 +27,8 @@ export const State = class BABLRState {
25
27
  context,
26
28
  languages,
27
29
  expressions = emptyStack,
30
+ spans = Spans.fromValues([]),
28
31
  balanced = emptyStack,
29
- spans = emptyStack,
30
32
  resultPath = null,
31
33
  depths = { path: -1, result: -1, emitted: -1, shift: 0, nodeShift: 0 },
32
34
  held = null,
@@ -62,7 +64,7 @@ export const State = class BABLRState {
62
64
  }
63
65
 
64
66
  get span() {
65
- return this.spans.value;
67
+ return Spans.getAt(-1, this.spans);
66
68
  }
67
69
 
68
70
  get result() {
@@ -77,15 +79,15 @@ export const State = class BABLRState {
77
79
  return !!this.parent;
78
80
  }
79
81
 
80
- push(source, context, languages, expressions, balanced, spans, resultPath, depths, held, node) {
82
+ push(source, context, languages, expressions, spans, balanced, resultPath, depths, held, node) {
81
83
  return new State(
82
84
  this,
83
85
  source,
84
86
  context,
85
87
  languages,
86
88
  expressions,
87
- balanced,
88
89
  spans,
90
+ balanced,
89
91
  resultPath,
90
92
  depths,
91
93
  held,
@@ -98,7 +100,8 @@ export const State = class BABLRState {
98
100
 
99
101
  return Object.freeze({
100
102
  languages,
101
- span: spans.value?.name,
103
+ span: Spans.getAt(-1, spans),
104
+ spans: spans,
102
105
  depths: Object.freeze({ ...depths }),
103
106
  holding: !!held,
104
107
  held,
@@ -161,8 +164,8 @@ export const State = class BABLRState {
161
164
  let {
162
165
  source,
163
166
  context,
164
- balanced,
165
167
  spans,
168
+ balanced,
166
169
  resultPath,
167
170
  depths,
168
171
  held,
@@ -176,8 +179,8 @@ export const State = class BABLRState {
176
179
  context,
177
180
  languages,
178
181
  expressions,
179
- balanced,
180
182
  spans,
183
+ balanced,
181
184
  resultPath,
182
185
  { ...depths },
183
186
  held,
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.2",
4
+ "version": "0.23.3",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -12,12 +12,12 @@
12
12
  },
13
13
  "sideEffects": false,
14
14
  "dependencies": {
15
- "@bablr/agast-helpers": "0.10.2",
16
- "@bablr/agast-vm": "0.11.1",
17
- "@bablr/agast-vm-helpers": "0.10.2",
15
+ "@bablr/agast-helpers": "0.10.4",
16
+ "@bablr/agast-vm": "0.11.2",
17
+ "@bablr/agast-vm-helpers": "0.10.4",
18
18
  "@bablr/coroutine": "0.1.0",
19
- "@bablr/helpers": "0.25.1",
20
- "@bablr/regex-vm": "0.14.1",
19
+ "@bablr/helpers": "0.25.2",
20
+ "@bablr/regex-vm": "0.14.2",
21
21
  "@bablr/stream-iterator": "2.0.0",
22
22
  "@iter-tools/imm-stack": "1.2.0",
23
23
  "iter-tools-es": "7.5.3"