@bablr/helpers 0.23.0 → 0.25.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,89 +0,0 @@
1
- import { spam as m } from '@bablr/boot';
2
- import { getCooked } from '@bablr/agast-helpers/tree';
3
- import { eat, eatMatch } from './grammar.js';
4
- import { EmbeddedMatcher } from './symbols.js';
5
- import { getEmbeddedMatcher } from '@bablr/agast-vm-helpers/deembed';
6
- import { buildPropertyMatcher } from './builders.js';
7
- import { buildEmbeddedMatcher } from '@bablr/agast-vm-helpers/builders';
8
-
9
- export function* List({ props }) {
10
- const { element, separator, allowHoles = false, allowTrailingSeparator = true } = props;
11
-
12
- if (
13
- !['#', '@'].includes(
14
- getCooked(getEmbeddedMatcher(separator).properties.refMatcher?.node.properties.type?.node),
15
- )
16
- ) {
17
- yield eat(
18
- buildEmbeddedMatcher(
19
- buildPropertyMatcher(
20
- getEmbeddedMatcher(separator).properties.refMatcher?.node,
21
- null,
22
- m.ArrayNodeMatcher`[]`,
23
- ),
24
- ),
25
- );
26
- }
27
-
28
- yield eat(
29
- buildEmbeddedMatcher(
30
- buildPropertyMatcher(
31
- getEmbeddedMatcher(Array.isArray(element) ? element[0] : element).properties.refMatcher
32
- ?.node,
33
- null,
34
- m.ArrayNodeMatcher`[]`,
35
- ),
36
- ),
37
- );
38
-
39
- let sep,
40
- it,
41
- anySep = false;
42
- for (;;) {
43
- it = yield eatMatch(...(Array.isArray(element) ? element : [element]));
44
- if (it || allowTrailingSeparator) {
45
- sep = yield eatMatch(separator);
46
- anySep ||= sep;
47
- } else {
48
- sep = null;
49
- }
50
- if (!(sep || allowHoles)) break;
51
- }
52
- }
53
-
54
- export function* Any({ props: { value: alternatives } }) {
55
- for (const alternative of alternatives) {
56
- if (Array.isArray(alternative)) {
57
- if (yield eatMatch(...alternative)) break;
58
- } else if (alternative.type === EmbeddedMatcher) {
59
- if (yield eatMatch(alternative)) break;
60
- } else {
61
- throw new Error();
62
- }
63
- }
64
- }
65
-
66
- export function* All({ props: { value: matchers } }) {
67
- for (const matcher of matchers) {
68
- if (Array.isArray(matcher)) {
69
- yield eat(...matcher);
70
- } else {
71
- yield eat(matcher);
72
- }
73
- }
74
- }
75
-
76
- export function* Optional({ props: { value: matcher } }) {
77
- yield eatMatch(matcher);
78
- }
79
-
80
- export function* Literal({ ctx, intrinsicValue }) {
81
- if (!intrinsicValue) throw new Error('Intrinsic productions must have value');
82
-
83
- yield eat(ctx.sourceTextFor(intrinsicValue.value));
84
- }
85
- export const Keyword = Literal;
86
-
87
- export const Punctuator = Literal;
88
-
89
- export const Space = Literal;