@spyglassmc/mcdoc 0.1.0 → 0.3.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/binder/index.d.ts +10 -2
- package/lib/binder/index.js +705 -18
- package/lib/colorizer/index.d.ts +1 -1
- package/lib/colorizer/index.js +8 -14
- package/lib/{binder/util.d.ts → common.d.ts} +4 -1
- package/lib/common.js +11 -0
- package/lib/index.d.ts +9 -6
- package/lib/index.js +14 -42
- package/lib/node/index.d.ts +191 -27
- package/lib/node/index.js +401 -88
- package/lib/parser/index.d.ts +4 -2
- package/lib/parser/index.js +227 -243
- package/lib/type/index.d.ts +70 -41
- package/lib/type/index.js +47 -44
- package/lib/uri_processors.d.ts +4 -0
- package/lib/{binder/uriBinder.js → uri_processors.js} +19 -16
- package/package.json +4 -3
- package/lib/binder/uriBinder.d.ts +0 -3
- package/lib/binder/util.js +0 -16
- package/lib/checker/CheckerContext.d.ts +0 -18
- package/lib/checker/CheckerContext.js +0 -3
- package/lib/checker/entry.d.ts +0 -4
- package/lib/checker/entry.js +0 -358
- package/lib/checker/index.d.ts +0 -2
- package/lib/checker/index.js +0 -18
package/lib/parser/index.js
CHANGED
|
@@ -1,40 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.type = exports.pathType = exports.unionType = exports.dispatcherType = exports.tupleType = exports.listType = exports.primitiveArrayType = exports.numericType = exports.literalType = exports.stringType = exports.integer = exports.booleanType = exports.anyType = exports.module_ = exports.useStatement = exports.typeAlias = exports.injection = exports.struct = exports.enum_ = exports.typedNumber = exports.float = exports.docComments = exports.docComment = exports.dispatchStatement = exports.attribute = exports.path = exports.identifier = exports.string = exports.resLoc = exports.literal = exports.comment = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const core_1 = require("@spyglassmc/core");
|
|
29
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { any, Arrayable, failOnEmpty, failOnError, Failure, map, optional, Range, repeat, ResourceLocation, select, sequence, setType, stopBefore, validate } from '@spyglassmc/core';
|
|
3
|
+
import { arrayToMessage, localeQuote, localize } from '@spyglassmc/locales';
|
|
4
|
+
import { RangeExclusiveChar } from '../node/index.js';
|
|
5
|
+
import { LiteralNumberCaseInsensitiveSuffixes, NumericTypeFloatKinds, NumericTypeIntKinds, PrimitiveArrayValueKinds, StaticIndexKeywords } from '../type/index.js';
|
|
30
6
|
/**
|
|
31
7
|
* @returns A comment parser that accepts normal comments (`//`) and reports an error if it's a doc comment (`///`).
|
|
32
8
|
*
|
|
33
9
|
* `Failure` when there isn't a comment.
|
|
34
10
|
*/
|
|
35
|
-
|
|
11
|
+
export const comment = validate(core.comment({
|
|
36
12
|
singleLinePrefixes: new Set(['//']),
|
|
37
|
-
}), (res, src) => !src.slice(res).startsWith('///'),
|
|
13
|
+
}), (res, src) => !src.slice(res).startsWith('///'), localize('mcdoc.parser.syntax.doc-comment-unexpected'));
|
|
38
14
|
/**
|
|
39
15
|
* @returns A parser that parses the gap between **SYNTAX** rules, which may contains whitespace and regular comments.
|
|
40
16
|
*/
|
|
@@ -45,7 +21,7 @@ delegatesDocComments = false) {
|
|
|
45
21
|
const ans = [];
|
|
46
22
|
src.skipWhitespace();
|
|
47
23
|
while (src.canRead() && src.peek(2) === '//' && (!delegatesDocComments || src.peek(3) !== '///')) {
|
|
48
|
-
const result =
|
|
24
|
+
const result = comment(src, ctx);
|
|
49
25
|
ans.push(result);
|
|
50
26
|
src.skipWhitespace();
|
|
51
27
|
}
|
|
@@ -55,36 +31,35 @@ delegatesDocComments = false) {
|
|
|
55
31
|
function syntax(parsers, delegatesDocComments = false) {
|
|
56
32
|
return (src, ctx) => {
|
|
57
33
|
src.skipWhitespace();
|
|
58
|
-
const ans =
|
|
34
|
+
const ans = sequence(parsers, syntaxGap(delegatesDocComments))(src, ctx);
|
|
59
35
|
src.skipWhitespace();
|
|
60
36
|
return ans;
|
|
61
37
|
};
|
|
62
38
|
}
|
|
63
39
|
function syntaxRepeat(parser, delegatesDocComments = false) {
|
|
64
|
-
return
|
|
40
|
+
return repeat(parser, syntaxGap(delegatesDocComments));
|
|
65
41
|
}
|
|
66
|
-
function literal(literal, options) {
|
|
42
|
+
export function literal(literal, options) {
|
|
67
43
|
return (src, ctx) => {
|
|
68
44
|
const ans = {
|
|
69
45
|
type: 'mcdoc:literal',
|
|
70
|
-
range:
|
|
46
|
+
range: Range.create(src),
|
|
71
47
|
value: '',
|
|
72
48
|
colorTokenType: options?.colorTokenType,
|
|
73
49
|
};
|
|
74
50
|
ans.value = src.readIf(c => options?.allowedChars?.has(c) ?? (options?.specialChars?.has(c) || /[a-z]/i.test(c)));
|
|
75
51
|
ans.range.end = src.cursor;
|
|
76
|
-
if (
|
|
77
|
-
ctx.err.report(
|
|
52
|
+
if (Arrayable.toArray(literal).every(l => l !== ans.value)) {
|
|
53
|
+
ctx.err.report(localize('expected-got', arrayToMessage(literal), localeQuote(ans.value)), ans);
|
|
78
54
|
}
|
|
79
55
|
return ans;
|
|
80
56
|
};
|
|
81
57
|
}
|
|
82
|
-
exports.literal = literal;
|
|
83
58
|
function keyword(keyword, options = { colorTokenType: 'keyword' }) {
|
|
84
59
|
return (src, ctx) => {
|
|
85
60
|
const result = literal(keyword, options)(src, ctx);
|
|
86
|
-
if (!
|
|
87
|
-
return
|
|
61
|
+
if (!Arrayable.toArray(keyword).includes(result.value)) {
|
|
62
|
+
return Failure;
|
|
88
63
|
}
|
|
89
64
|
return result;
|
|
90
65
|
};
|
|
@@ -93,7 +68,7 @@ function punctuation(punctuation) {
|
|
|
93
68
|
return (src, ctx) => {
|
|
94
69
|
src.skipWhitespace();
|
|
95
70
|
if (!src.trySkip(punctuation)) {
|
|
96
|
-
ctx.err.report(
|
|
71
|
+
ctx.err.report(localize('expected-got', localeQuote(punctuation), localeQuote(src.peek())), src);
|
|
97
72
|
}
|
|
98
73
|
return undefined;
|
|
99
74
|
};
|
|
@@ -102,32 +77,31 @@ function marker(punctuation) {
|
|
|
102
77
|
return (src, _ctx) => {
|
|
103
78
|
src.skipWhitespace();
|
|
104
79
|
if (!src.trySkip(punctuation)) {
|
|
105
|
-
return
|
|
80
|
+
return Failure;
|
|
106
81
|
}
|
|
107
82
|
return undefined;
|
|
108
83
|
};
|
|
109
84
|
}
|
|
110
|
-
function resLoc(options) {
|
|
111
|
-
return
|
|
85
|
+
export function resLoc(options) {
|
|
86
|
+
return validate(core.resourceLocation(options), res => res.namespace !== undefined, localize('mcdoc.parser.resource-location.colon-expected', localeQuote(ResourceLocation.NamespacePathSep)));
|
|
112
87
|
}
|
|
113
|
-
exports.resLoc = resLoc;
|
|
114
88
|
const UnicodeControlCharacters = Object.freeze([
|
|
115
89
|
'\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06',
|
|
116
90
|
'\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D',
|
|
117
91
|
'\x0E', '\x0F', '\x7F',
|
|
118
92
|
]);
|
|
119
|
-
|
|
93
|
+
export const string = stopBefore(core.string({
|
|
120
94
|
escapable: { characters: ['b', 'f', 'n', 'r', 't', '\\', '"'], unicode: true },
|
|
121
95
|
quotes: ['"'],
|
|
122
96
|
}), ...UnicodeControlCharacters);
|
|
123
|
-
const identifier = (src, ctx) => {
|
|
97
|
+
export const identifier = (src, ctx) => {
|
|
124
98
|
// https://spyglassmc.com/user/mcdoc/#identifier
|
|
125
99
|
const IdentifierStart = /^[\p{L}\p{Nl}]$/u;
|
|
126
100
|
const IdentifierContinue = /^[\p{L}\p{Nl}\u200C\u200D\p{Mn}\p{Mc}\p{Nd}\p{Pc}]$/u;
|
|
127
101
|
const ReservedWords = new Set(['any', 'boolean', 'byte', 'double', 'enum', 'false', 'float', 'int', 'long', 'short', 'string', 'struct', 'super', 'true']);
|
|
128
102
|
const ans = {
|
|
129
103
|
type: 'mcdoc:identifier',
|
|
130
|
-
range:
|
|
104
|
+
range: Range.create(src),
|
|
131
105
|
options: { category: 'mcdoc' },
|
|
132
106
|
value: '',
|
|
133
107
|
};
|
|
@@ -139,73 +113,74 @@ const identifier = (src, ctx) => {
|
|
|
139
113
|
}
|
|
140
114
|
}
|
|
141
115
|
else {
|
|
142
|
-
ctx.err.report(
|
|
116
|
+
ctx.err.report(localize('expected', localize('mcdoc.node.identifier')), src);
|
|
143
117
|
}
|
|
144
118
|
ans.value = src.string.slice(start, src.innerCursor);
|
|
145
119
|
ans.range.end = src.cursor;
|
|
146
120
|
if (ReservedWords.has(ans.value)) {
|
|
147
|
-
ctx.err.report(
|
|
121
|
+
ctx.err.report(localize('mcdoc.parser.identifier.reserved-word', localeQuote(ans.value)), ans);
|
|
148
122
|
}
|
|
149
123
|
return ans;
|
|
150
124
|
};
|
|
151
|
-
exports.identifier = identifier;
|
|
152
125
|
function indexBody(options) {
|
|
153
|
-
const accessorKey =
|
|
126
|
+
const accessorKey = select([
|
|
154
127
|
{
|
|
155
128
|
prefix: '%',
|
|
156
129
|
parser: literal(['%key', '%parent'], { specialChars: new Set(['%']) }),
|
|
157
130
|
},
|
|
158
131
|
{
|
|
159
132
|
prefix: '"',
|
|
160
|
-
parser:
|
|
133
|
+
parser: string,
|
|
161
134
|
},
|
|
162
135
|
{
|
|
163
|
-
parser:
|
|
136
|
+
parser: identifier,
|
|
164
137
|
},
|
|
165
138
|
]);
|
|
166
|
-
const dynamicIndex =
|
|
139
|
+
const dynamicIndex = setType('mcdoc:dynamic_index', syntax([
|
|
167
140
|
punctuation('['),
|
|
168
141
|
accessorKey,
|
|
169
|
-
|
|
142
|
+
repeat(sequence([marker('.'), accessorKey])),
|
|
170
143
|
punctuation(']'),
|
|
171
144
|
]));
|
|
172
|
-
const index =
|
|
145
|
+
const index = select([
|
|
173
146
|
{
|
|
174
147
|
prefix: '%',
|
|
175
|
-
parser: literal(
|
|
148
|
+
parser: literal(StaticIndexKeywords.map(v => `%${v}`), { specialChars: new Set(['%']) }),
|
|
176
149
|
},
|
|
177
150
|
{
|
|
178
151
|
prefix: '"',
|
|
179
|
-
parser:
|
|
152
|
+
parser: string,
|
|
180
153
|
},
|
|
181
154
|
{
|
|
182
155
|
prefix: '[',
|
|
183
|
-
parser:
|
|
156
|
+
parser: options?.noDynamic
|
|
157
|
+
? validate(dynamicIndex, () => false, localize('mcdoc.parser.index-body.dynamic-index-not-allowed'))
|
|
158
|
+
: dynamicIndex,
|
|
184
159
|
},
|
|
185
160
|
{
|
|
186
|
-
parser:
|
|
161
|
+
parser: any([resLoc({ category: 'mcdoc/dispatcher', accessType: options?.accessType }), identifier]),
|
|
187
162
|
},
|
|
188
163
|
]);
|
|
189
|
-
return
|
|
164
|
+
return setType('mcdoc:index_body', syntax([
|
|
190
165
|
punctuation('['),
|
|
191
166
|
index,
|
|
192
|
-
syntaxRepeat(syntax([marker(','),
|
|
193
|
-
|
|
167
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(index)])),
|
|
168
|
+
optional(marker(',')),
|
|
194
169
|
punctuation(']'),
|
|
195
170
|
]));
|
|
196
171
|
}
|
|
197
|
-
const pathSegment =
|
|
172
|
+
const pathSegment = select([
|
|
198
173
|
{ prefix: 'super', parser: literal('super') },
|
|
199
|
-
{ parser:
|
|
174
|
+
{ parser: identifier },
|
|
200
175
|
]);
|
|
201
|
-
const path = (src, ctx) => {
|
|
176
|
+
export const path = (src, ctx) => {
|
|
202
177
|
let isAbsolute;
|
|
203
178
|
if (src.trySkip('::')) {
|
|
204
179
|
isAbsolute = true;
|
|
205
180
|
}
|
|
206
|
-
return
|
|
181
|
+
return map(sequence([
|
|
207
182
|
pathSegment,
|
|
208
|
-
|
|
183
|
+
repeat(sequence([marker('::'), pathSegment])),
|
|
209
184
|
]), res => {
|
|
210
185
|
const ans = {
|
|
211
186
|
type: 'mcdoc:path',
|
|
@@ -216,29 +191,28 @@ const path = (src, ctx) => {
|
|
|
216
191
|
return ans;
|
|
217
192
|
})(src, ctx);
|
|
218
193
|
};
|
|
219
|
-
|
|
220
|
-
const attributeTreePosValues = (0, core_1.setType)('mcdoc:attribute/tree/pos', syntax([
|
|
194
|
+
const attributeTreePosValues = setType('mcdoc:attribute/tree/pos', syntax([
|
|
221
195
|
{ get: () => attributeValue },
|
|
222
|
-
syntaxRepeat(syntax([marker(','), { get: () =>
|
|
196
|
+
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(attributeValue) }], true), true),
|
|
223
197
|
], true));
|
|
224
198
|
const attributeNamedValue = syntax([
|
|
225
|
-
|
|
226
|
-
{ prefix: '"', parser:
|
|
227
|
-
{ parser:
|
|
199
|
+
select([
|
|
200
|
+
{ prefix: '"', parser: string },
|
|
201
|
+
{ parser: identifier },
|
|
228
202
|
]),
|
|
229
|
-
|
|
203
|
+
select([
|
|
230
204
|
{ prefix: '=', parser: syntax([punctuation('='), { get: () => attributeValue }], true) },
|
|
231
205
|
{ parser: { get: () => attributeTree } },
|
|
232
206
|
]),
|
|
233
207
|
], true);
|
|
234
|
-
const attributeTreeNamedValues =
|
|
208
|
+
const attributeTreeNamedValues = setType('mcdoc:attribute/tree/named', syntax([
|
|
235
209
|
attributeNamedValue,
|
|
236
|
-
syntaxRepeat(syntax([marker(','),
|
|
210
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(attributeNamedValue)], true), true),
|
|
237
211
|
], true));
|
|
238
|
-
const treeBody =
|
|
239
|
-
syntax([
|
|
240
|
-
syntax([
|
|
241
|
-
syntax([attributeTreePosValues,
|
|
212
|
+
const treeBody = any([
|
|
213
|
+
syntax([attributeTreeNamedValues, optional(marker(','))]),
|
|
214
|
+
syntax([attributeTreePosValues, punctuation(','), attributeTreeNamedValues, optional(marker(','))]),
|
|
215
|
+
syntax([attributeTreePosValues, optional(marker(','))]),
|
|
242
216
|
]);
|
|
243
217
|
const AttributeTreeClosure = Object.freeze({
|
|
244
218
|
'(': ')',
|
|
@@ -246,7 +220,10 @@ const AttributeTreeClosure = Object.freeze({
|
|
|
246
220
|
'{': '}',
|
|
247
221
|
});
|
|
248
222
|
const attributeTree = (src, ctx) => {
|
|
249
|
-
const delim = src.trySkip('(') ? '(' : (src.trySkip('[') ? '[' : '{');
|
|
223
|
+
const delim = src.trySkip('(') ? '(' : (src.trySkip('[') ? '[' : (src.trySkip('{') ? '{' : undefined));
|
|
224
|
+
if (!delim) {
|
|
225
|
+
return Failure;
|
|
226
|
+
}
|
|
250
227
|
const res = treeBody(src, ctx);
|
|
251
228
|
const ans = {
|
|
252
229
|
type: 'mcdoc:attribute/tree',
|
|
@@ -257,38 +234,38 @@ const attributeTree = (src, ctx) => {
|
|
|
257
234
|
src.trySkip(AttributeTreeClosure[delim]);
|
|
258
235
|
return ans;
|
|
259
236
|
};
|
|
260
|
-
const attributeValue =
|
|
237
|
+
const attributeValue = select([
|
|
261
238
|
{ predicate: src => ['(', '[', '{'].includes(src.peek()), parser: attributeTree },
|
|
262
|
-
{ parser: { get: () =>
|
|
239
|
+
{ parser: { get: () => type } },
|
|
263
240
|
]);
|
|
264
|
-
|
|
241
|
+
export const attribute = setType('mcdoc:attribute', syntax([
|
|
265
242
|
marker('#['),
|
|
266
|
-
|
|
267
|
-
|
|
243
|
+
identifier,
|
|
244
|
+
select([
|
|
268
245
|
{ prefix: '=', parser: syntax([punctuation('='), attributeValue, punctuation(']')], true) },
|
|
269
246
|
{ predicate: src => ['(', '[', '{'].includes(src.peek()), parser: syntax([attributeTree, punctuation(']')], true) },
|
|
270
247
|
{ parser: punctuation(']') },
|
|
271
248
|
]),
|
|
272
249
|
], true));
|
|
273
|
-
const attributes =
|
|
274
|
-
|
|
250
|
+
const attributes = repeat(attribute);
|
|
251
|
+
export const dispatchStatement = setType('mcdoc:dispatch_statement', syntax([
|
|
275
252
|
attributes,
|
|
276
253
|
keyword('dispatch'),
|
|
277
254
|
resLoc({ category: 'mcdoc/dispatcher', accessType: 1 /* SymbolAccessType.Write */ }),
|
|
278
255
|
indexBody({ noDynamic: true }),
|
|
279
256
|
literal('to'),
|
|
280
|
-
{ get: () =>
|
|
257
|
+
{ get: () => type },
|
|
281
258
|
], true));
|
|
282
|
-
|
|
259
|
+
export const docComment = core.comment({
|
|
283
260
|
singleLinePrefixes: new Set(['///']),
|
|
284
261
|
includesEol: true,
|
|
285
262
|
});
|
|
286
|
-
|
|
263
|
+
export const docComments = setType('mcdoc:doc_comments', repeat(docComment, src => {
|
|
287
264
|
src.skipWhitespace();
|
|
288
265
|
return [];
|
|
289
266
|
}));
|
|
290
267
|
const prelim = syntax([
|
|
291
|
-
|
|
268
|
+
optional(failOnEmpty(docComments)),
|
|
292
269
|
attributes,
|
|
293
270
|
]);
|
|
294
271
|
const enumType = literal([
|
|
@@ -300,78 +277,55 @@ const enumType = literal([
|
|
|
300
277
|
'float',
|
|
301
278
|
'double',
|
|
302
279
|
], { colorTokenType: 'type' });
|
|
303
|
-
|
|
280
|
+
export const float = core.float({
|
|
304
281
|
pattern: /^[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)?|[0-9]*\.[0-9]+(?:[eE][-+]?[0-9]+)?)$/,
|
|
305
282
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
283
|
+
export const typedNumber = setType('mcdoc:typed_number', sequence([
|
|
284
|
+
float,
|
|
285
|
+
optional(keyword(LiteralNumberCaseInsensitiveSuffixes, { colorTokenType: 'keyword' })),
|
|
309
286
|
]));
|
|
310
|
-
const enumValue =
|
|
311
|
-
{ prefix: '"', parser:
|
|
312
|
-
{ parser:
|
|
287
|
+
const enumValue = select([
|
|
288
|
+
{ prefix: '"', parser: string },
|
|
289
|
+
{ parser: typedNumber },
|
|
313
290
|
]);
|
|
314
|
-
const enumField =
|
|
291
|
+
const enumField = setType('mcdoc:enum/field', syntax([
|
|
315
292
|
prelim,
|
|
316
|
-
|
|
293
|
+
identifier,
|
|
317
294
|
punctuation('='),
|
|
318
295
|
enumValue,
|
|
319
296
|
], true));
|
|
320
|
-
const enumBlock =
|
|
297
|
+
const enumBlock = setType('mcdoc:enum/block', syntax([
|
|
321
298
|
punctuation('{'),
|
|
322
|
-
|
|
299
|
+
select([
|
|
323
300
|
{ prefix: '}', parser: punctuation('}') },
|
|
324
301
|
{
|
|
325
302
|
parser: syntax([
|
|
326
303
|
enumField,
|
|
327
|
-
syntaxRepeat(syntax([marker(','),
|
|
328
|
-
|
|
304
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(enumField)], true), true),
|
|
305
|
+
optional(marker(',')),
|
|
329
306
|
punctuation('}'),
|
|
330
307
|
], true),
|
|
331
308
|
},
|
|
332
309
|
]),
|
|
333
310
|
], true));
|
|
334
|
-
|
|
311
|
+
export const enum_ = setType('mcdoc:enum', syntax([
|
|
335
312
|
prelim,
|
|
336
313
|
keyword('enum'),
|
|
337
314
|
punctuation('('),
|
|
338
315
|
enumType,
|
|
339
316
|
punctuation(')'),
|
|
340
|
-
|
|
317
|
+
optional(failOnError(identifier)),
|
|
341
318
|
enumBlock,
|
|
342
319
|
], true));
|
|
343
|
-
const
|
|
344
|
-
exports.identifier,
|
|
345
|
-
(0, core_1.optional)(syntax([(0, core_1.failOnError)(literal('extends')), exports.path])),
|
|
346
|
-
]));
|
|
347
|
-
const typeParamBlock = (0, core_1.setType)('mcdoc:type_param_block', syntax([
|
|
348
|
-
punctuation('<'),
|
|
349
|
-
(0, core_1.select)([
|
|
350
|
-
{ prefix: '>', parser: punctuation('>') },
|
|
351
|
-
{
|
|
352
|
-
parser: syntax([
|
|
353
|
-
typeParam,
|
|
354
|
-
syntaxRepeat(syntax([marker(','), (0, core_1.failOnEmpty)(typeParam)])),
|
|
355
|
-
(0, core_1.optional)(marker(',')),
|
|
356
|
-
punctuation('>'),
|
|
357
|
-
]),
|
|
358
|
-
},
|
|
359
|
-
]),
|
|
360
|
-
]));
|
|
361
|
-
const noop = () => undefined;
|
|
362
|
-
const optionalTypeParamBlock = (0, core_1.select)([
|
|
363
|
-
{ prefix: '<', parser: typeParamBlock },
|
|
364
|
-
{ parser: noop },
|
|
365
|
-
]);
|
|
366
|
-
const structMapKey = (0, core_1.setType)('mcdoc:struct/map_key', syntax([
|
|
320
|
+
const structMapKey = setType('mcdoc:struct/map_key', syntax([
|
|
367
321
|
punctuation('['),
|
|
368
|
-
{ get: () =>
|
|
322
|
+
{ get: () => type },
|
|
369
323
|
punctuation(']'),
|
|
370
324
|
], true));
|
|
371
|
-
const structKey =
|
|
372
|
-
{ prefix: '"', parser:
|
|
325
|
+
const structKey = select([
|
|
326
|
+
{ prefix: '"', parser: string },
|
|
373
327
|
{ prefix: '[', parser: structMapKey },
|
|
374
|
-
{ parser:
|
|
328
|
+
{ parser: identifier },
|
|
375
329
|
]);
|
|
376
330
|
const structPairField = (src, ctx) => {
|
|
377
331
|
let isOptional;
|
|
@@ -384,124 +338,154 @@ const structPairField = (src, ctx) => {
|
|
|
384
338
|
}
|
|
385
339
|
const result1 = syntax([
|
|
386
340
|
punctuation(':'),
|
|
387
|
-
{ get: () =>
|
|
341
|
+
{ get: () => type },
|
|
388
342
|
], true)(src, ctx);
|
|
389
343
|
const ans = {
|
|
390
344
|
type: 'mcdoc:struct/field/pair',
|
|
391
345
|
children: [...result0.children, ...result1.children],
|
|
392
|
-
range:
|
|
346
|
+
range: Range.span(result0, result1),
|
|
393
347
|
isOptional,
|
|
394
348
|
};
|
|
395
349
|
return ans;
|
|
396
350
|
};
|
|
397
|
-
const structSpreadField =
|
|
351
|
+
const structSpreadField = setType('mcdoc:struct/field/spread', syntax([
|
|
398
352
|
attributes,
|
|
399
353
|
marker('...'),
|
|
400
|
-
{ get: () =>
|
|
354
|
+
{ get: () => type },
|
|
401
355
|
], true));
|
|
402
|
-
const structField =
|
|
356
|
+
const structField = any([
|
|
403
357
|
structSpreadField,
|
|
404
358
|
structPairField,
|
|
405
359
|
]);
|
|
406
|
-
const structBlock =
|
|
360
|
+
const structBlock = setType('mcdoc:struct/block', syntax([
|
|
407
361
|
punctuation('{'),
|
|
408
|
-
|
|
362
|
+
select([
|
|
409
363
|
{ prefix: '}', parser: punctuation('}') },
|
|
410
364
|
{
|
|
411
365
|
parser: syntax([
|
|
412
366
|
structField,
|
|
413
|
-
syntaxRepeat(syntax([marker(','),
|
|
414
|
-
|
|
367
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(structField)], true), true),
|
|
368
|
+
optional(marker(',')),
|
|
415
369
|
punctuation('}'),
|
|
416
370
|
], true),
|
|
417
371
|
},
|
|
418
372
|
]),
|
|
419
373
|
], true));
|
|
420
|
-
|
|
374
|
+
export const struct = setType('mcdoc:struct', syntax([
|
|
421
375
|
prelim,
|
|
422
376
|
keyword('struct'),
|
|
423
|
-
|
|
424
|
-
optionalTypeParamBlock,
|
|
377
|
+
optional(failOnEmpty(identifier)),
|
|
425
378
|
structBlock,
|
|
426
379
|
], true));
|
|
427
|
-
const enumInjection =
|
|
380
|
+
const enumInjection = setType('mcdoc:injection/enum', syntax([
|
|
428
381
|
literal('enum'),
|
|
429
382
|
punctuation('('),
|
|
430
383
|
enumType,
|
|
431
384
|
punctuation(')'),
|
|
432
|
-
|
|
385
|
+
path,
|
|
433
386
|
enumBlock,
|
|
434
387
|
]));
|
|
435
|
-
const structInjection =
|
|
388
|
+
const structInjection = setType('mcdoc:injection/struct', syntax([
|
|
436
389
|
literal('struct'),
|
|
437
|
-
|
|
438
|
-
optionalTypeParamBlock,
|
|
390
|
+
path,
|
|
439
391
|
structBlock,
|
|
440
392
|
]));
|
|
441
|
-
|
|
393
|
+
export const injection = setType('mcdoc:injection', syntax([
|
|
442
394
|
keyword('inject'),
|
|
443
|
-
|
|
395
|
+
select([
|
|
444
396
|
{ prefix: 'enum', parser: enumInjection },
|
|
445
397
|
{ parser: structInjection },
|
|
446
398
|
]),
|
|
447
399
|
]));
|
|
448
|
-
|
|
449
|
-
|
|
400
|
+
const typeParam = setType('mcdoc:type_param', syntax([
|
|
401
|
+
identifier,
|
|
402
|
+
// optional(syntax([failOnError(literal('extends')), { get: () => type }])),
|
|
403
|
+
]));
|
|
404
|
+
const typeParamBlock = setType('mcdoc:type_param_block', syntax([
|
|
405
|
+
punctuation('<'),
|
|
406
|
+
select([
|
|
407
|
+
{ prefix: '>', parser: punctuation('>') },
|
|
408
|
+
{
|
|
409
|
+
parser: syntax([
|
|
410
|
+
typeParam,
|
|
411
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(typeParam)])),
|
|
412
|
+
optional(marker(',')),
|
|
413
|
+
punctuation('>'),
|
|
414
|
+
]),
|
|
415
|
+
},
|
|
416
|
+
]),
|
|
417
|
+
]));
|
|
418
|
+
const noop = () => undefined;
|
|
419
|
+
const optionalTypeParamBlock = select([
|
|
420
|
+
{ prefix: '<', parser: typeParamBlock },
|
|
421
|
+
{ parser: noop },
|
|
422
|
+
]);
|
|
423
|
+
export const typeAlias = setType('mcdoc:type_alias', syntax([
|
|
424
|
+
docComments,
|
|
450
425
|
keyword('type'),
|
|
451
|
-
|
|
426
|
+
identifier,
|
|
452
427
|
optionalTypeParamBlock,
|
|
453
428
|
punctuation('='),
|
|
454
|
-
{ get: () =>
|
|
429
|
+
{ get: () => type },
|
|
455
430
|
], true));
|
|
456
|
-
|
|
431
|
+
export const useStatement = setType('mcdoc:use_statement', syntax([
|
|
457
432
|
keyword('use'),
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
{ prefix: 'as', parser: syntax([literal('as'),
|
|
433
|
+
path,
|
|
434
|
+
select([
|
|
435
|
+
{ prefix: 'as', parser: syntax([literal('as'), identifier]) },
|
|
461
436
|
{ parser: noop },
|
|
462
437
|
]),
|
|
463
|
-
]));
|
|
464
|
-
const topLevel =
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
438
|
+
], true));
|
|
439
|
+
const topLevel = any([
|
|
440
|
+
comment,
|
|
441
|
+
dispatchStatement,
|
|
442
|
+
enum_,
|
|
443
|
+
injection,
|
|
444
|
+
struct,
|
|
445
|
+
typeAlias,
|
|
446
|
+
useStatement,
|
|
472
447
|
]);
|
|
473
|
-
|
|
448
|
+
export const module_ = setType('mcdoc:module', syntaxRepeat(topLevel, true));
|
|
474
449
|
/* eslint-enable @typescript-eslint/indent */
|
|
475
450
|
function typeBase(type, parser) {
|
|
476
|
-
return
|
|
451
|
+
return setType(type, syntax([
|
|
477
452
|
attributes,
|
|
478
453
|
parser,
|
|
479
|
-
syntaxRepeat(
|
|
454
|
+
syntaxRepeat(failOnError(indexBody())),
|
|
480
455
|
], true));
|
|
481
456
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
457
|
+
export const anyType = typeBase('mcdoc:type/any', keyword('any', { colorTokenType: 'type' }));
|
|
458
|
+
export const booleanType = typeBase('mcdoc:type/boolean', keyword('boolean', { colorTokenType: 'type' }));
|
|
459
|
+
export const integer = core.integer({
|
|
485
460
|
pattern: /^(?:0|[-+]?[1-9][0-9]*)$/,
|
|
486
461
|
});
|
|
487
462
|
function range(type, number) {
|
|
488
|
-
|
|
463
|
+
const delimiterPredicate = (src) => src.tryPeek('..') || src.tryPeek(`${RangeExclusiveChar}..`);
|
|
464
|
+
const delimiterParser = literal([
|
|
465
|
+
'..',
|
|
466
|
+
`..${RangeExclusiveChar}`,
|
|
467
|
+
`${RangeExclusiveChar}..`,
|
|
468
|
+
`${RangeExclusiveChar}..${RangeExclusiveChar}`,
|
|
469
|
+
], {
|
|
470
|
+
allowedChars: new Set(['.', RangeExclusiveChar]),
|
|
471
|
+
});
|
|
472
|
+
return setType(type, select([
|
|
489
473
|
{
|
|
490
|
-
|
|
491
|
-
parser:
|
|
492
|
-
|
|
474
|
+
predicate: delimiterPredicate,
|
|
475
|
+
parser: sequence([
|
|
476
|
+
delimiterParser,
|
|
493
477
|
number,
|
|
494
478
|
]),
|
|
495
479
|
},
|
|
496
480
|
{
|
|
497
|
-
parser:
|
|
498
|
-
|
|
499
|
-
|
|
481
|
+
parser: sequence([
|
|
482
|
+
stopBefore(number, '..'),
|
|
483
|
+
select([
|
|
500
484
|
{
|
|
501
|
-
|
|
502
|
-
parser:
|
|
503
|
-
|
|
504
|
-
|
|
485
|
+
predicate: delimiterPredicate,
|
|
486
|
+
parser: sequence([
|
|
487
|
+
delimiterParser,
|
|
488
|
+
optional(failOnEmpty(number)),
|
|
505
489
|
]),
|
|
506
490
|
},
|
|
507
491
|
{ parser: noop },
|
|
@@ -510,122 +494,122 @@ function range(type, number) {
|
|
|
510
494
|
},
|
|
511
495
|
]));
|
|
512
496
|
}
|
|
513
|
-
const intRange = range('mcdoc:int_range',
|
|
514
|
-
const atIntRange =
|
|
497
|
+
export const intRange = range('mcdoc:int_range', integer);
|
|
498
|
+
const atIntRange = optional((src, ctx) => {
|
|
515
499
|
if (!src.trySkip('@')) {
|
|
516
|
-
return
|
|
500
|
+
return Failure;
|
|
517
501
|
}
|
|
518
502
|
src.skipWhitespace();
|
|
519
503
|
return intRange(src, ctx);
|
|
520
504
|
});
|
|
521
|
-
|
|
505
|
+
export const stringType = typeBase('mcdoc:type/string', syntax([
|
|
522
506
|
keyword('string', { colorTokenType: 'type' }),
|
|
523
507
|
atIntRange,
|
|
524
508
|
]));
|
|
525
|
-
|
|
509
|
+
export const literalType = typeBase('mcdoc:type/literal', select([
|
|
526
510
|
{ predicate: src => src.tryPeek('false') || src.tryPeek('true'), parser: keyword(['false', 'true'], { colorTokenType: 'type' }) },
|
|
527
|
-
{ prefix: '"', parser:
|
|
528
|
-
{ parser:
|
|
511
|
+
{ prefix: '"', parser: failOnEmpty(string) },
|
|
512
|
+
{ parser: failOnError(typedNumber) },
|
|
529
513
|
]));
|
|
530
|
-
const floatRange = range('mcdoc:float_range',
|
|
531
|
-
const atFloatRange =
|
|
514
|
+
export const floatRange = range('mcdoc:float_range', float);
|
|
515
|
+
const atFloatRange = optional((src, ctx) => {
|
|
532
516
|
if (!src.trySkip('@')) {
|
|
533
|
-
return
|
|
517
|
+
return Failure;
|
|
534
518
|
}
|
|
535
519
|
src.skipWhitespace();
|
|
536
520
|
return floatRange(src, ctx);
|
|
537
521
|
});
|
|
538
|
-
|
|
522
|
+
export const numericType = typeBase('mcdoc:type/numeric_type', select([
|
|
539
523
|
{
|
|
540
|
-
predicate: src =>
|
|
524
|
+
predicate: src => NumericTypeFloatKinds.some(k => src.tryPeek(k)),
|
|
541
525
|
parser: syntax([
|
|
542
|
-
keyword(
|
|
526
|
+
keyword(NumericTypeFloatKinds, { colorTokenType: 'type' }),
|
|
543
527
|
atFloatRange,
|
|
544
528
|
]),
|
|
545
529
|
},
|
|
546
530
|
{
|
|
547
531
|
parser: syntax([
|
|
548
|
-
keyword(
|
|
532
|
+
keyword(NumericTypeIntKinds, { colorTokenType: 'type' }),
|
|
549
533
|
atIntRange,
|
|
550
534
|
]),
|
|
551
535
|
},
|
|
552
536
|
]));
|
|
553
|
-
|
|
554
|
-
literal(
|
|
537
|
+
export const primitiveArrayType = typeBase('mcdoc:type/primitive_array', syntax([
|
|
538
|
+
literal(PrimitiveArrayValueKinds),
|
|
555
539
|
atIntRange,
|
|
556
540
|
keyword('[]', { allowedChars: new Set(['[', ']']), colorTokenType: 'type' }),
|
|
557
541
|
atIntRange,
|
|
558
542
|
]));
|
|
559
|
-
|
|
543
|
+
export const listType = typeBase('mcdoc:type/list', syntax([
|
|
560
544
|
marker('['),
|
|
561
|
-
{ get: () =>
|
|
545
|
+
{ get: () => type },
|
|
562
546
|
punctuation(']'),
|
|
563
547
|
atIntRange,
|
|
564
548
|
], true));
|
|
565
|
-
|
|
549
|
+
export const tupleType = typeBase('mcdoc:type/tuple', syntax([
|
|
566
550
|
marker('['),
|
|
567
|
-
{ get: () =>
|
|
551
|
+
{ get: () => type },
|
|
568
552
|
marker(','),
|
|
569
|
-
|
|
553
|
+
select([
|
|
570
554
|
{ prefix: ']', parser: punctuation(']') },
|
|
571
555
|
{
|
|
572
556
|
parser: syntax([
|
|
573
|
-
{ get: () =>
|
|
574
|
-
syntaxRepeat(syntax([marker(','), { get: () =>
|
|
575
|
-
|
|
557
|
+
{ get: () => type },
|
|
558
|
+
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(type) }], true), true),
|
|
559
|
+
optional(marker(',')),
|
|
576
560
|
punctuation(']'),
|
|
577
561
|
], true),
|
|
578
562
|
},
|
|
579
563
|
]),
|
|
580
564
|
], true));
|
|
581
|
-
|
|
582
|
-
|
|
565
|
+
export const dispatcherType = typeBase('mcdoc:type/dispatcher', syntax([
|
|
566
|
+
failOnError(resLoc({ category: 'mcdoc/dispatcher' })),
|
|
583
567
|
indexBody(),
|
|
584
568
|
]));
|
|
585
|
-
|
|
569
|
+
export const unionType = typeBase('mcdoc:type/union', syntax([
|
|
586
570
|
marker('('),
|
|
587
|
-
|
|
571
|
+
select([
|
|
588
572
|
{ prefix: ')', parser: punctuation(')') },
|
|
589
573
|
{
|
|
590
574
|
parser: syntax([
|
|
591
|
-
{ get: () =>
|
|
592
|
-
syntaxRepeat(syntax([marker('|'), { get: () =>
|
|
593
|
-
|
|
575
|
+
{ get: () => type },
|
|
576
|
+
syntaxRepeat(syntax([marker('|'), { get: () => failOnEmpty(type) }], true), true),
|
|
577
|
+
optional(marker('|')),
|
|
594
578
|
punctuation(')'),
|
|
595
579
|
], true),
|
|
596
580
|
},
|
|
597
581
|
]),
|
|
598
582
|
]));
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
583
|
+
export const referenceType = typeBase('mcdoc:type/reference', syntax([
|
|
584
|
+
path,
|
|
585
|
+
optional(syntax([
|
|
602
586
|
marker('<'),
|
|
603
|
-
|
|
587
|
+
select([
|
|
604
588
|
{ prefix: '>', parser: punctuation('>') },
|
|
605
589
|
{
|
|
606
590
|
parser: syntax([
|
|
607
|
-
{ get: () =>
|
|
608
|
-
syntaxRepeat(syntax([marker(','), { get: () =>
|
|
609
|
-
|
|
591
|
+
{ get: () => type },
|
|
592
|
+
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(type) }], true), true),
|
|
593
|
+
optional(marker(',')),
|
|
610
594
|
punctuation('>'),
|
|
611
595
|
], true),
|
|
612
596
|
},
|
|
613
597
|
]),
|
|
614
598
|
])),
|
|
615
599
|
]));
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
600
|
+
export const type = any([
|
|
601
|
+
anyType,
|
|
602
|
+
booleanType,
|
|
603
|
+
dispatcherType,
|
|
604
|
+
enum_,
|
|
605
|
+
listType,
|
|
606
|
+
literalType,
|
|
607
|
+
numericType,
|
|
608
|
+
primitiveArrayType,
|
|
609
|
+
stringType,
|
|
610
|
+
struct,
|
|
611
|
+
tupleType,
|
|
612
|
+
unionType,
|
|
613
|
+
referenceType,
|
|
630
614
|
]);
|
|
631
615
|
//# sourceMappingURL=index.js.map
|