@bablr/agast-helpers 0.6.1 → 0.7.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/builders.js +15 -63
- package/lib/path.js +285 -227
- package/lib/print.js +16 -43
- package/lib/shorthand.js +2 -2
- package/lib/stream.js +6 -220
- package/lib/sumtree.js +62 -0
- package/lib/symbols.js +3 -10
- package/lib/template.js +4 -4
- package/lib/tree.js +33 -242
- package/package.json +2 -1
package/lib/builders.js
CHANGED
|
@@ -8,20 +8,16 @@ import {
|
|
|
8
8
|
ShiftTag,
|
|
9
9
|
GapTag,
|
|
10
10
|
NullTag,
|
|
11
|
-
|
|
11
|
+
InitializerTag,
|
|
12
12
|
LiteralTag,
|
|
13
|
-
EmbeddedObject,
|
|
14
|
-
EmbeddedTag,
|
|
15
13
|
TokenGroup,
|
|
16
|
-
EmbeddedMatcher,
|
|
17
|
-
EmbeddedRegex,
|
|
18
14
|
EmbeddedNode,
|
|
19
15
|
} from './symbols.js';
|
|
20
16
|
|
|
21
17
|
const { freeze } = Object;
|
|
22
18
|
const { isArray } = Array;
|
|
23
19
|
|
|
24
|
-
const isObject = (val) => val !== null && typeof
|
|
20
|
+
const isObject = (val) => val !== null && typeof val === 'object';
|
|
25
21
|
|
|
26
22
|
function* relatedNodes(properties) {
|
|
27
23
|
for (const value of Object.values(properties)) {
|
|
@@ -41,9 +37,8 @@ const find = (predicate, iterable) => {
|
|
|
41
37
|
}
|
|
42
38
|
};
|
|
43
39
|
|
|
44
|
-
export const
|
|
45
|
-
|
|
46
|
-
return freeze({ type: EmbeddedObject, value: expr });
|
|
40
|
+
export const buildTokenGroup = (tokens) => {
|
|
41
|
+
return freeze({ type: TokenGroup, value: tokens });
|
|
47
42
|
};
|
|
48
43
|
|
|
49
44
|
export const buildEmbeddedNode = (node) => {
|
|
@@ -51,57 +46,6 @@ export const buildEmbeddedNode = (node) => {
|
|
|
51
46
|
return freeze({ type: EmbeddedNode, value: node });
|
|
52
47
|
};
|
|
53
48
|
|
|
54
|
-
export const buildEmbeddedMatcher = (node) => {
|
|
55
|
-
if (!isObject(node)) throw new Error();
|
|
56
|
-
return freeze({ type: EmbeddedMatcher, value: node });
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const buildEmbeddedRegex = (node) => {
|
|
60
|
-
if (!isObject(node)) throw new Error();
|
|
61
|
-
return freeze({ type: EmbeddedRegex, value: node });
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const buildEmbeddedTag = (tag) => {
|
|
65
|
-
if (!isObject(tag)) throw new Error();
|
|
66
|
-
return freeze({ type: EmbeddedTag, value: tag });
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const buildEffect = (value) => {
|
|
70
|
-
return freeze({ type: 'Effect', value });
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const buildWriteEffect = (text, options = {}) => {
|
|
74
|
-
return buildEffect(
|
|
75
|
-
freeze({
|
|
76
|
-
verb: 'write',
|
|
77
|
-
value: buildEmbeddedObject(freeze({ text, options: buildEmbeddedObject(freeze(options)) })),
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const buildAnsiPushEffect = (spans = '') => {
|
|
83
|
-
return buildEffect(
|
|
84
|
-
freeze({
|
|
85
|
-
verb: 'ansi-push',
|
|
86
|
-
value: buildEmbeddedObject(
|
|
87
|
-
freeze({ spans: spans === '' ? freeze([]) : freeze(spans.split(' ')) }),
|
|
88
|
-
),
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const buildAnsiPopEffect = () => {
|
|
94
|
-
return buildEffect(freeze({ verb: 'ansi-pop', value: undefined }));
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const buildTokenGroup = (tokens) => {
|
|
98
|
-
return freeze({ type: TokenGroup, value: tokens });
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const buildCall = (verb, ...args) => {
|
|
102
|
-
return { verb, arguments: args };
|
|
103
|
-
};
|
|
104
|
-
|
|
105
49
|
export const buildBeginningOfStreamToken = () => {
|
|
106
50
|
return freeze({ type: Symbol.for('@bablr/beginning-of-stream'), value: undefined });
|
|
107
51
|
};
|
|
@@ -109,15 +53,23 @@ export const buildBeginningOfStreamToken = () => {
|
|
|
109
53
|
export const buildReferenceTag = (name, isArray = false, flags = referenceFlags, index = null) => {
|
|
110
54
|
if (name == null || !/[a-zA-Z.#@]/.test(name)) throw new Error('reference must have a name');
|
|
111
55
|
if (index != null && !Number.isFinite(index)) throw new Error();
|
|
112
|
-
|
|
56
|
+
let { hasGap, expression } = flags;
|
|
57
|
+
|
|
58
|
+
hasGap = !!hasGap;
|
|
59
|
+
expression = !!expression;
|
|
60
|
+
|
|
61
|
+
return freeze({
|
|
62
|
+
type: ReferenceTag,
|
|
63
|
+
value: freeze({ name, isArray, index, flags: freeze({ hasGap, expression }) }),
|
|
64
|
+
});
|
|
113
65
|
};
|
|
114
66
|
|
|
115
67
|
export const buildNullTag = () => {
|
|
116
68
|
return freeze({ type: NullTag, value: undefined });
|
|
117
69
|
};
|
|
118
70
|
|
|
119
|
-
export const
|
|
120
|
-
return freeze({ type:
|
|
71
|
+
export const buildInitializerTag = (isArray = false) => {
|
|
72
|
+
return freeze({ type: InitializerTag, value: { isArray } });
|
|
121
73
|
};
|
|
122
74
|
|
|
123
75
|
export const buildGapTag = () => {
|