@bablr/bablr-vm 0.21.0 → 0.22.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.
@@ -1,9 +1,13 @@
1
1
  import isString from 'iter-tools-es/methods/is-string';
2
2
  import isEmpty from 'iter-tools-es/methods/is-empty';
3
3
  import { generateMatches } from '@bablr/regex-vm';
4
- import { getStreamIterator, maybeWait, printType } from '@bablr/agast-helpers/stream';
5
- import * as sumtree from '@bablr/agast-helpers/children';
6
- import * as l from '@bablr/agast-vm-helpers/languages';
4
+ import {
5
+ getStreamIterator,
6
+ maybeWait,
7
+ printType,
8
+ StreamIterable,
9
+ } from '@bablr/agast-helpers/stream';
10
+ import * as Tags from '@bablr/agast-helpers/tags';
7
11
  import {
8
12
  buildAlternative,
9
13
  buildAlternatives,
@@ -20,6 +24,33 @@ import {
20
24
  buildOpenNodeTag,
21
25
  tokenFlags,
22
26
  } from '@bablr/agast-helpers/builders';
27
+ import { streamIteratorSymbol } from '@bablr/stream-iterator';
28
+
29
+ function* __wrapSource(source) {
30
+ let source_ = source.source || source;
31
+ if ('\r\n'.includes(source_.prevValue)) {
32
+ yield '\n';
33
+ } else if (source_.index === 0) {
34
+ yield Symbol.for('BOS');
35
+ } else {
36
+ yield '';
37
+ }
38
+ let iter = getStreamIterator(source);
39
+
40
+ let step = iter.next();
41
+ while (!step.done) {
42
+ yield step.value;
43
+ step = iter.next();
44
+ }
45
+
46
+ iter.return();
47
+
48
+ yield Symbol.for('EOS');
49
+ }
50
+
51
+ export const wrapSource = (source) => {
52
+ return new StreamIterable(__wrapSource(source));
53
+ };
23
54
 
24
55
  export const assertValidRegex = (expr) => {
25
56
  if (!expr.language === 'Spamex' && expr.type === 'Regex') {
@@ -42,7 +73,7 @@ const buildFragmentRegex = (frag) => {
42
73
  buildAlternatives([
43
74
  buildAlternative(
44
75
  buildElements(
45
- [...sumtree.traverse(frag.children)].flatMap((tag) => {
76
+ [...Tags.traverse(frag.tags)].flatMap((tag) => {
46
77
  if (tag.type === LiteralTag) {
47
78
  let str = tag.value;
48
79
  return [...str].map((chr) => buildToken('Character', chr));
@@ -127,7 +158,7 @@ export const match = (pattern, source) => {
127
158
 
128
159
  assertValidRegex(pattern_);
129
160
 
130
- const iter = getStreamIterator(generateMatches(buildEmbeddedRegex(pattern_), source));
161
+ const iter = getStreamIterator(generateMatches(buildEmbeddedRegex(pattern_), wrapSource(source)));
131
162
 
132
163
  const step = iter.next();
133
164
 
@@ -170,7 +201,7 @@ class GuardedIterator {
170
201
  this.source.release();
171
202
  }
172
203
 
173
- [Symbol.for('@@streamIterator')]() {
204
+ [streamIteratorSymbol]() {
174
205
  return this;
175
206
  }
176
207
  }
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.21.0",
4
+ "version": "0.22.0",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -12,14 +12,14 @@
12
12
  },
13
13
  "sideEffects": false,
14
14
  "dependencies": {
15
- "@bablr/agast-helpers": "0.8.0",
16
- "@bablr/agast-vm": "0.9.0",
17
- "@bablr/agast-vm-helpers": "0.8.0",
15
+ "@bablr/agast-helpers": "0.9.0",
16
+ "@bablr/agast-vm": "0.10.0",
17
+ "@bablr/agast-vm-helpers": "0.9.0",
18
18
  "@bablr/coroutine": "0.1.0",
19
- "@bablr/helpers": "0.23.0",
20
- "@bablr/regex-vm": "0.12.0",
19
+ "@bablr/helpers": "0.24.0",
20
+ "@bablr/regex-vm": "0.13.0",
21
21
  "@bablr/weak-stack": "1.0.1",
22
- "@iter-tools/imm-stack": "1.1.0",
22
+ "@iter-tools/imm-stack": "1.2.0",
23
23
  "iter-tools-es": "7.5.3"
24
24
  },
25
25
  "devDependencies": {