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