@bablr/bablr-vm 0.16.3 → 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/spans.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { getAt } from '@bablr/agast-helpers/btree';
2
+ import { getOpenTag } from '@bablr/agast-helpers/tree';
3
+
1
4
  export function updateSpans(ctx, s, node, phase) {
2
5
  switch (phase) {
3
6
  case 'open': {
@@ -37,7 +40,7 @@ export function updateSpans(ctx, s, node, phase) {
37
40
 
38
41
  if (!s.balanced.size) throw new Error();
39
42
 
40
- if (!balancedNode.children[0].value.attributes.balanced) {
43
+ if (!getOpenTag(balancedNode).value.attributes.balanced) {
41
44
  throw new Error();
42
45
  }
43
46
 
package/lib/state.js CHANGED
@@ -4,6 +4,7 @@ import { getCooked } from '@bablr/agast-helpers/stream';
4
4
  import { match, guardWithPattern } from './utils/pattern.js';
5
5
  import { facades, actuals } from './facades.js';
6
6
  import { reifyExpression } from '@bablr/agast-vm-helpers';
7
+ import { EmbeddedNode } from '@bablr/agast-helpers/symbols';
7
8
 
8
9
  export const StateFacade = class BABLRStateFacade {
9
10
  constructor(state) {
@@ -138,7 +139,7 @@ export const State = class BABLRState extends WeakStackFrame {
138
139
  let { span, spans, source, node } = this;
139
140
  let { guard } = span;
140
141
 
141
- if (pattern.type === 'EmbeddedNode') {
142
+ if (pattern.type === EmbeddedNode) {
142
143
  pattern = reifyExpression(pattern.value);
143
144
  }
144
145
 
@@ -153,7 +154,7 @@ export const State = class BABLRState extends WeakStackFrame {
153
154
  }
154
155
 
155
156
  if (pattern?.intrinsicValue) {
156
- // if (pattern.type === 'OpenNodeTag') {
157
+ // if (pattern.type === OpenNodeTag) {
157
158
 
158
159
  // // TODO differntiate better between self-closing tags and matchers
159
160
  // pattern = pattern.value;
package/lib/strategy.js CHANGED
@@ -2,17 +2,27 @@ import size from 'iter-tools-es/methods/size';
2
2
  import { Coroutine } from '@bablr/coroutine';
3
3
  import {
4
4
  buildCall,
5
- buildReference,
6
- buildNull,
5
+ buildReferenceTag,
6
+ buildNullTag,
7
7
  buildEmbeddedTag,
8
+ buildArrayTag,
8
9
  } from '@bablr/agast-helpers/builders';
9
10
  import { StreamGenerator } from '@bablr/agast-helpers/stream';
10
- import { getOpenTag } from '@bablr/agast-helpers/tree';
11
11
  import { buildTokens } from './utils/token.js';
12
12
  import { formatType } from './utils/format.js';
13
13
  import { facades } from './facades.js';
14
14
  import { State } from './state.js';
15
15
  import { updateSpans } from './spans.js';
16
+ import {
17
+ DoctypeTag,
18
+ OpenNodeTag,
19
+ CloseNodeTag,
20
+ ReferenceTag,
21
+ ShiftTag,
22
+ GapTag,
23
+ NullTag,
24
+ LiteralTag,
25
+ } from '@bablr/agast-helpers/symbols';
16
26
 
17
27
  const { hasOwn } = Object;
18
28
 
@@ -55,20 +65,20 @@ const __strategy = function* bablrStrategy(ctx, rootSource, agastState, strategy
55
65
 
56
66
  switch (verb) {
57
67
  case 'advance': {
58
- const { arguments: { 0: embeddedTerminal } = [] } = instr;
68
+ const { arguments: { 0: embeddedTag } = [] } = instr;
59
69
 
60
- const terminal = embeddedTerminal.value;
70
+ const tag = embeddedTag.value;
61
71
 
62
- switch (terminal?.type || 'Null') {
63
- case 'DoctypeTag': {
72
+ switch (tag?.type || NullTag) {
73
+ case DoctypeTag: {
64
74
  const doctypeTag = yield instr;
65
75
 
66
76
  returnValue = doctypeTag;
67
77
  break;
68
78
  }
69
79
 
70
- case 'OpenNodeTag': {
71
- const { type } = terminal.value;
80
+ case OpenNodeTag: {
81
+ const { type } = tag.value;
72
82
 
73
83
  const openTag = yield instr;
74
84
 
@@ -80,7 +90,7 @@ const __strategy = function* bablrStrategy(ctx, rootSource, agastState, strategy
80
90
  break;
81
91
  }
82
92
 
83
- case 'CloseNodeTag': {
93
+ case CloseNodeTag: {
84
94
  const { node } = s;
85
95
 
86
96
  const endTag = yield instr;
@@ -101,8 +111,8 @@ const __strategy = function* bablrStrategy(ctx, rootSource, agastState, strategy
101
111
  break;
102
112
  }
103
113
 
104
- case 'Literal': {
105
- const { value: pattern } = terminal;
114
+ case LiteralTag: {
115
+ const { value: pattern } = tag;
106
116
 
107
117
  let result = s.guardedMatch(pattern);
108
118
 
@@ -124,7 +134,7 @@ const __strategy = function* bablrStrategy(ctx, rootSource, agastState, strategy
124
134
  break;
125
135
  }
126
136
 
127
- case 'Gap': {
137
+ case GapTag: {
128
138
  if (s.source.value == null && !s.source.done) {
129
139
  if (s.source.holding) {
130
140
  s.source.unshift();
@@ -143,7 +153,7 @@ const __strategy = function* bablrStrategy(ctx, rootSource, agastState, strategy
143
153
  break;
144
154
  }
145
155
 
146
- case 'Shift': {
156
+ case ShiftTag: {
147
157
  s.source.shift();
148
158
 
149
159
  returnValue = yield instr;
@@ -228,7 +238,7 @@ const __strategy = function* bablrStrategy(ctx, rootSource, agastState, strategy
228
238
  s.nodeForPath(s.path) && !s.nodeForPath(rejectedState.path.at(s.path.depth));
229
239
  const lowPath = rejectedState.path.at(
230
240
  Math.min(
231
- s.path.depth + (didShift || s.result.type === 'Reference' ? 0 : 1),
241
+ s.path.depth + (didShift || s.result.type === ReferenceTag ? 0 : 1),
232
242
  rejectedState.path.depth,
233
243
  ),
234
244
  );
@@ -239,16 +249,15 @@ const __strategy = function* bablrStrategy(ctx, rootSource, agastState, strategy
239
249
  if (
240
250
  !didShift &&
241
251
  !hasOwn(lowNode.properties, name) &&
242
- !(s.result.type === 'Reference' && s.result.value.name === name)
252
+ !(s.result.type === ReferenceTag && s.result.value.name === name)
243
253
  ) {
244
- if (
245
- !getOpenTag(lowNode)?.value.flags.trivia &&
246
- !getOpenTag(lowNode)?.value.flags.escape
247
- ) {
248
- yield buildCall('advance', buildEmbeddedTag(buildReference(name, isArray)));
254
+ if (isArray) {
255
+ yield buildCall('advance', buildEmbeddedTag(buildReferenceTag(name, true)));
256
+ yield buildCall('advance', buildEmbeddedTag(buildArrayTag()));
257
+ } else {
258
+ yield buildCall('advance', buildEmbeddedTag(buildReferenceTag(name)));
259
+ yield buildCall('advance', buildEmbeddedTag(buildNullTag()));
249
260
  }
250
-
251
- yield buildCall('advance', buildEmbeddedTag(buildNull()));
252
261
  }
253
262
  }
254
263
 
@@ -1,4 +1,4 @@
1
- import { buildLiteral, buildGap } from '@bablr/agast-helpers/builders';
1
+ import { buildLiteralTag, buildGapTag } from '@bablr/agast-helpers/builders';
2
2
 
3
3
  export const isNewlineToken = (token) => /^\r|\r\n|\n$/.test(token.value);
4
4
 
@@ -15,16 +15,16 @@ export function* buildTokens(chrs) {
15
15
  for (const chr of chrs) {
16
16
  if (chr == null) {
17
17
  if (str) {
18
- yield buildLiteral(str);
18
+ yield buildLiteralTag(str);
19
19
  str = '';
20
20
  }
21
- yield buildGap();
21
+ yield buildGapTag();
22
22
  } else {
23
23
  str += chr;
24
24
  }
25
25
  }
26
26
 
27
27
  if (str) {
28
- yield buildLiteral(str);
28
+ yield buildLiteralTag(str);
29
29
  }
30
30
  }
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.16.3",
4
+ "version": "0.17.0",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -12,11 +12,11 @@
12
12
  },
13
13
  "sideEffects": false,
14
14
  "dependencies": {
15
- "@bablr/agast-helpers": "0.3.2",
16
- "@bablr/agast-vm-helpers": "0.3.2",
15
+ "@bablr/agast-helpers": "0.4.0",
16
+ "@bablr/agast-vm-helpers": "0.4.0",
17
17
  "@bablr/coroutine": "0.1.0",
18
- "@bablr/helpers": "0.18.0",
19
- "@bablr/regex-vm": "0.7.0",
18
+ "@bablr/helpers": "0.19.0",
19
+ "@bablr/regex-vm": "0.8.1",
20
20
  "@bablr/weak-stack": "0.1.0",
21
21
  "@iter-tools/imm-stack": "1.1.0",
22
22
  "iter-tools-es": "^7.5.3"
package/lib/symbols.js DELETED
@@ -1 +0,0 @@
1
- export const node = Symbol.for('@bablr/node');