@bablr/boot 0.1.8 → 0.1.9
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/index.js +1 -1
- package/lib/languages/cstml.js +3 -6
- package/lib/languages/number.js +3 -3
- package/lib/languages/string.js +3 -5
- package/package.json +1 -1
- package/shorthand.macro.js +20 -6
package/lib/index.js
CHANGED
|
@@ -34,7 +34,7 @@ const i = buildTag(instruction, 'Call');
|
|
|
34
34
|
const spam = buildTag(spamex, 'Matcher');
|
|
35
35
|
const re = buildTag(regex, 'Pattern');
|
|
36
36
|
const str = buildTag(string, 'String');
|
|
37
|
-
const num = buildTag(number, '
|
|
37
|
+
const num = buildTag(number, 'Integer');
|
|
38
38
|
const cst = buildTag(cstml, 'Fragment');
|
|
39
39
|
|
|
40
40
|
module.exports = { re, spam, str, num, i, cst };
|
package/lib/languages/cstml.js
CHANGED
|
@@ -20,7 +20,7 @@ const covers = buildCovers({
|
|
|
20
20
|
'TagType',
|
|
21
21
|
'Node',
|
|
22
22
|
'OpenFragmentNodeTag',
|
|
23
|
-
'
|
|
23
|
+
'TerminalNodeShorthandTag',
|
|
24
24
|
'OpenNodeTag',
|
|
25
25
|
'CloseNodeTag',
|
|
26
26
|
'Terminal',
|
|
@@ -56,7 +56,7 @@ const grammar = class CSTMLMiniparserGrammar {
|
|
|
56
56
|
|
|
57
57
|
// @Node
|
|
58
58
|
Node(p) {
|
|
59
|
-
const openType = p.match('<|') ? '
|
|
59
|
+
const openType = p.match('<|') ? 'TerminalNodeShorthandTag' : 'OpenNodeTag';
|
|
60
60
|
const childrenType = openType === 'OpenNodeTag' ? 'NodeChildren' : 'TerminalNodeChildren';
|
|
61
61
|
|
|
62
62
|
if (p.match('<>')) throw new Error('Fragment is not a node');
|
|
@@ -134,7 +134,7 @@ const grammar = class CSTMLMiniparserGrammar {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// @Node
|
|
137
|
-
|
|
137
|
+
TerminalNodeShorthandTag(p) {
|
|
138
138
|
p.eat('<|', PN, { path: 'open', startSpan: 'Tag', balanced: '>' });
|
|
139
139
|
p.eatMatchTrivia(_);
|
|
140
140
|
p.eatProduction('TagType', { path: 'type' });
|
|
@@ -154,14 +154,11 @@ const grammar = class CSTMLMiniparserGrammar {
|
|
|
154
154
|
|
|
155
155
|
p.eatMatchTrivia(_);
|
|
156
156
|
p.eat('|>', PN, { path: 'close', endSpan: 'Tag', balancer: true });
|
|
157
|
-
|
|
158
|
-
return { attrs: { selfClosing: !!value } };
|
|
159
157
|
}
|
|
160
158
|
|
|
161
159
|
// @Node
|
|
162
160
|
CloseNodeTag(p) {
|
|
163
161
|
p.eat('</', PN, { path: 'open', startSpan: 'Tag', balanced: '>' });
|
|
164
|
-
// TODO permit .type
|
|
165
162
|
p.eat('>', PN, { path: 'close', endSpan: 'Tag', balancer: true });
|
|
166
163
|
}
|
|
167
164
|
|
package/lib/languages/number.js
CHANGED
|
@@ -7,18 +7,18 @@ const dependencies = {};
|
|
|
7
7
|
|
|
8
8
|
const covers = buildCovers({
|
|
9
9
|
[sym.node]: ['Number', 'Digit'],
|
|
10
|
-
Number: ['
|
|
10
|
+
Number: ['Integer', 'Infinity'],
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
const grammar = class NumberMiniparserGrammar {
|
|
14
14
|
// @Node
|
|
15
|
-
|
|
15
|
+
Integer(p) {
|
|
16
16
|
p.eatMatch('-', 'Punctuator', { path: 'negative' });
|
|
17
17
|
p.eatProduction('Digits', { path: 'digits[]' });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// @Node
|
|
21
|
-
|
|
21
|
+
Infinity(p) {
|
|
22
22
|
p.eatMatch('-', 'Punctuator', { path: 'negative' });
|
|
23
23
|
p.eat('Infinity', 'Keyword', { path: 'value' });
|
|
24
24
|
}
|
package/lib/languages/string.js
CHANGED
|
@@ -28,9 +28,7 @@ const cookEscape = (escape, span) => {
|
|
|
28
28
|
throw new Error('string escape must start with \\');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
if ((hexMatch = /\\
|
|
32
|
-
//continue
|
|
33
|
-
} else if ((hexMatch = /\\u([0-9a-f]{4})/iy.exec(escape))) {
|
|
31
|
+
if ((hexMatch = /\\u([0-9a-f]{4})/iy.exec(escape))) {
|
|
34
32
|
//continue
|
|
35
33
|
} else if ((hexMatch = /\\u{([0-9a-f]+)}/iy.exec(escape))) {
|
|
36
34
|
//continue
|
|
@@ -71,8 +69,8 @@ const grammar = class StringMiniparserGrammar {
|
|
|
71
69
|
do {
|
|
72
70
|
esc =
|
|
73
71
|
p.span.type === 'Single'
|
|
74
|
-
? p.eatMatchEscape(/\\(u(\{\d{1,6}\}|\d{4})|
|
|
75
|
-
: p.eatMatchEscape(/\\(u(\{\d{1,6}\}|\d{4})|
|
|
72
|
+
? p.eatMatchEscape(/\\(u(\{\d{1,6}\}|\d{4})|[\\nrt0'])/y)
|
|
73
|
+
: p.eatMatchEscape(/\\(u(\{\d{1,6}\}|\d{4})|[\\nrt0"])/y);
|
|
76
74
|
lit =
|
|
77
75
|
p.span.type === 'Single'
|
|
78
76
|
? p.eatMatchLiteral(/[^\r\n\0\\']+/y)
|
package/package.json
CHANGED
package/shorthand.macro.js
CHANGED
|
@@ -63,20 +63,34 @@ const getASTValue = (v, exprs, bindings) => {
|
|
|
63
63
|
: generateNode(v, exprs, bindings);
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
+
const escapeReplacer = (esc) => {
|
|
67
|
+
if (esc === '\r') {
|
|
68
|
+
return '\\r';
|
|
69
|
+
} else if (esc === '\n') {
|
|
70
|
+
return '\\n';
|
|
71
|
+
} else if (esc === '\0') {
|
|
72
|
+
return '\\0';
|
|
73
|
+
} else {
|
|
74
|
+
return `\\${esc}`;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const printTemplateString = (str) => {
|
|
78
|
+
return `\`${str.replace(/[`\\\0\r\n]/g, escapeReplacer)}\``;
|
|
79
|
+
};
|
|
80
|
+
|
|
66
81
|
const generateNodeChild = (child, bindings) => {
|
|
67
82
|
if (child.type === 'Reference') {
|
|
68
83
|
const { pathName, pathIsArray } = child.value;
|
|
69
84
|
const printedRef = pathIsArray ? `${pathName}[]` : pathName;
|
|
70
85
|
return expression(`%%t%%.ref\`${printedRef}\``)({ t: bindings.t });
|
|
71
86
|
} else if (child.type === 'Literal') {
|
|
72
|
-
return expression(`%%t%%.lit
|
|
87
|
+
return expression(`%%t%%.lit${printTemplateString(child.value)}`)({ t: bindings.t });
|
|
73
88
|
} else if (child.type === 'Trivia') {
|
|
74
|
-
return expression(`%%t%%.trivia
|
|
89
|
+
return expression(`%%t%%.trivia${printTemplateString(child.value)}`)({ t: bindings.t });
|
|
75
90
|
} else if (child.type === 'Escape') {
|
|
76
|
-
|
|
91
|
+
const {cooked, raw} = child.value
|
|
92
|
+
return expression(`%%t%%.esc(${printTemplateString(raw)}, ${printTemplateString(cooked)})`)({
|
|
77
93
|
t: bindings.t,
|
|
78
|
-
cooked: child.cooked,
|
|
79
|
-
raw: child.raw,
|
|
80
94
|
});
|
|
81
95
|
} else {
|
|
82
96
|
throw new Error(`Unknown child type ${child.type}`);
|
|
@@ -159,7 +173,7 @@ const topTypes = {
|
|
|
159
173
|
re: 'Pattern',
|
|
160
174
|
spam: 'Matcher',
|
|
161
175
|
str: 'String',
|
|
162
|
-
num: '
|
|
176
|
+
num: 'Integer',
|
|
163
177
|
cst: 'Fragment',
|
|
164
178
|
};
|
|
165
179
|
|