@spyglassmc/mcdoc 0.1.1 → 0.3.1
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 +194 -27
- package/lib/node/index.js +404 -88
- package/lib/parser/index.d.ts +4 -2
- package/lib/parser/index.js +223 -242
- 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([attributeTreeNamedValues,
|
|
240
|
-
syntax([attributeTreePosValues, punctuation(','), attributeTreeNamedValues,
|
|
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
|
'(': ')',
|
|
@@ -248,7 +222,7 @@ const AttributeTreeClosure = Object.freeze({
|
|
|
248
222
|
const attributeTree = (src, ctx) => {
|
|
249
223
|
const delim = src.trySkip('(') ? '(' : (src.trySkip('[') ? '[' : (src.trySkip('{') ? '{' : undefined));
|
|
250
224
|
if (!delim) {
|
|
251
|
-
return
|
|
225
|
+
return Failure;
|
|
252
226
|
}
|
|
253
227
|
const res = treeBody(src, ctx);
|
|
254
228
|
const ans = {
|
|
@@ -260,38 +234,38 @@ const attributeTree = (src, ctx) => {
|
|
|
260
234
|
src.trySkip(AttributeTreeClosure[delim]);
|
|
261
235
|
return ans;
|
|
262
236
|
};
|
|
263
|
-
const attributeValue =
|
|
237
|
+
const attributeValue = select([
|
|
264
238
|
{ predicate: src => ['(', '[', '{'].includes(src.peek()), parser: attributeTree },
|
|
265
|
-
{ parser: { get: () =>
|
|
239
|
+
{ parser: { get: () => type } },
|
|
266
240
|
]);
|
|
267
|
-
|
|
241
|
+
export const attribute = setType('mcdoc:attribute', syntax([
|
|
268
242
|
marker('#['),
|
|
269
|
-
|
|
270
|
-
|
|
243
|
+
identifier,
|
|
244
|
+
select([
|
|
271
245
|
{ prefix: '=', parser: syntax([punctuation('='), attributeValue, punctuation(']')], true) },
|
|
272
246
|
{ predicate: src => ['(', '[', '{'].includes(src.peek()), parser: syntax([attributeTree, punctuation(']')], true) },
|
|
273
247
|
{ parser: punctuation(']') },
|
|
274
248
|
]),
|
|
275
249
|
], true));
|
|
276
|
-
const attributes =
|
|
277
|
-
|
|
250
|
+
const attributes = repeat(attribute);
|
|
251
|
+
export const dispatchStatement = setType('mcdoc:dispatch_statement', syntax([
|
|
278
252
|
attributes,
|
|
279
253
|
keyword('dispatch'),
|
|
280
254
|
resLoc({ category: 'mcdoc/dispatcher', accessType: 1 /* SymbolAccessType.Write */ }),
|
|
281
255
|
indexBody({ noDynamic: true }),
|
|
282
256
|
literal('to'),
|
|
283
|
-
{ get: () =>
|
|
257
|
+
{ get: () => type },
|
|
284
258
|
], true));
|
|
285
|
-
|
|
259
|
+
export const docComment = core.comment({
|
|
286
260
|
singleLinePrefixes: new Set(['///']),
|
|
287
261
|
includesEol: true,
|
|
288
262
|
});
|
|
289
|
-
|
|
263
|
+
export const docComments = setType('mcdoc:doc_comments', repeat(docComment, src => {
|
|
290
264
|
src.skipWhitespace();
|
|
291
265
|
return [];
|
|
292
266
|
}));
|
|
293
267
|
const prelim = syntax([
|
|
294
|
-
|
|
268
|
+
optional(failOnEmpty(docComments)),
|
|
295
269
|
attributes,
|
|
296
270
|
]);
|
|
297
271
|
const enumType = literal([
|
|
@@ -303,78 +277,55 @@ const enumType = literal([
|
|
|
303
277
|
'float',
|
|
304
278
|
'double',
|
|
305
279
|
], { colorTokenType: 'type' });
|
|
306
|
-
|
|
280
|
+
export const float = core.float({
|
|
307
281
|
pattern: /^[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)?|[0-9]*\.[0-9]+(?:[eE][-+]?[0-9]+)?)$/,
|
|
308
282
|
});
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
283
|
+
export const typedNumber = setType('mcdoc:typed_number', sequence([
|
|
284
|
+
float,
|
|
285
|
+
optional(keyword(LiteralNumberCaseInsensitiveSuffixes, { colorTokenType: 'keyword' })),
|
|
312
286
|
]));
|
|
313
|
-
const enumValue =
|
|
314
|
-
{ prefix: '"', parser:
|
|
315
|
-
{ parser:
|
|
287
|
+
const enumValue = select([
|
|
288
|
+
{ prefix: '"', parser: string },
|
|
289
|
+
{ parser: typedNumber },
|
|
316
290
|
]);
|
|
317
|
-
const enumField =
|
|
291
|
+
const enumField = setType('mcdoc:enum/field', syntax([
|
|
318
292
|
prelim,
|
|
319
|
-
|
|
293
|
+
identifier,
|
|
320
294
|
punctuation('='),
|
|
321
295
|
enumValue,
|
|
322
296
|
], true));
|
|
323
|
-
const enumBlock =
|
|
297
|
+
const enumBlock = setType('mcdoc:enum/block', syntax([
|
|
324
298
|
punctuation('{'),
|
|
325
|
-
|
|
299
|
+
select([
|
|
326
300
|
{ prefix: '}', parser: punctuation('}') },
|
|
327
301
|
{
|
|
328
302
|
parser: syntax([
|
|
329
303
|
enumField,
|
|
330
|
-
syntaxRepeat(syntax([marker(','),
|
|
331
|
-
|
|
304
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(enumField)], true), true),
|
|
305
|
+
optional(marker(',')),
|
|
332
306
|
punctuation('}'),
|
|
333
307
|
], true),
|
|
334
308
|
},
|
|
335
309
|
]),
|
|
336
310
|
], true));
|
|
337
|
-
|
|
311
|
+
export const enum_ = setType('mcdoc:enum', syntax([
|
|
338
312
|
prelim,
|
|
339
313
|
keyword('enum'),
|
|
340
314
|
punctuation('('),
|
|
341
315
|
enumType,
|
|
342
316
|
punctuation(')'),
|
|
343
|
-
|
|
317
|
+
optional(failOnError(identifier)),
|
|
344
318
|
enumBlock,
|
|
345
319
|
], true));
|
|
346
|
-
const
|
|
347
|
-
exports.identifier,
|
|
348
|
-
(0, core_1.optional)(syntax([(0, core_1.failOnError)(literal('extends')), exports.path])),
|
|
349
|
-
]));
|
|
350
|
-
const typeParamBlock = (0, core_1.setType)('mcdoc:type_param_block', syntax([
|
|
351
|
-
punctuation('<'),
|
|
352
|
-
(0, core_1.select)([
|
|
353
|
-
{ prefix: '>', parser: punctuation('>') },
|
|
354
|
-
{
|
|
355
|
-
parser: syntax([
|
|
356
|
-
typeParam,
|
|
357
|
-
syntaxRepeat(syntax([marker(','), (0, core_1.failOnEmpty)(typeParam)])),
|
|
358
|
-
(0, core_1.optional)(marker(',')),
|
|
359
|
-
punctuation('>'),
|
|
360
|
-
]),
|
|
361
|
-
},
|
|
362
|
-
]),
|
|
363
|
-
]));
|
|
364
|
-
const noop = () => undefined;
|
|
365
|
-
const optionalTypeParamBlock = (0, core_1.select)([
|
|
366
|
-
{ prefix: '<', parser: typeParamBlock },
|
|
367
|
-
{ parser: noop },
|
|
368
|
-
]);
|
|
369
|
-
const structMapKey = (0, core_1.setType)('mcdoc:struct/map_key', syntax([
|
|
320
|
+
const structMapKey = setType('mcdoc:struct/map_key', syntax([
|
|
370
321
|
punctuation('['),
|
|
371
|
-
{ get: () =>
|
|
322
|
+
{ get: () => type },
|
|
372
323
|
punctuation(']'),
|
|
373
324
|
], true));
|
|
374
|
-
const structKey =
|
|
375
|
-
{ prefix: '"', parser:
|
|
325
|
+
const structKey = select([
|
|
326
|
+
{ prefix: '"', parser: string },
|
|
376
327
|
{ prefix: '[', parser: structMapKey },
|
|
377
|
-
{ parser:
|
|
328
|
+
{ parser: identifier },
|
|
378
329
|
]);
|
|
379
330
|
const structPairField = (src, ctx) => {
|
|
380
331
|
let isOptional;
|
|
@@ -387,124 +338,154 @@ const structPairField = (src, ctx) => {
|
|
|
387
338
|
}
|
|
388
339
|
const result1 = syntax([
|
|
389
340
|
punctuation(':'),
|
|
390
|
-
{ get: () =>
|
|
341
|
+
{ get: () => type },
|
|
391
342
|
], true)(src, ctx);
|
|
392
343
|
const ans = {
|
|
393
344
|
type: 'mcdoc:struct/field/pair',
|
|
394
345
|
children: [...result0.children, ...result1.children],
|
|
395
|
-
range:
|
|
346
|
+
range: Range.span(result0, result1),
|
|
396
347
|
isOptional,
|
|
397
348
|
};
|
|
398
349
|
return ans;
|
|
399
350
|
};
|
|
400
|
-
const structSpreadField =
|
|
351
|
+
const structSpreadField = setType('mcdoc:struct/field/spread', syntax([
|
|
401
352
|
attributes,
|
|
402
353
|
marker('...'),
|
|
403
|
-
{ get: () =>
|
|
354
|
+
{ get: () => type },
|
|
404
355
|
], true));
|
|
405
|
-
const structField =
|
|
356
|
+
const structField = any([
|
|
406
357
|
structSpreadField,
|
|
407
358
|
structPairField,
|
|
408
359
|
]);
|
|
409
|
-
const structBlock =
|
|
360
|
+
const structBlock = setType('mcdoc:struct/block', syntax([
|
|
410
361
|
punctuation('{'),
|
|
411
|
-
|
|
362
|
+
select([
|
|
412
363
|
{ prefix: '}', parser: punctuation('}') },
|
|
413
364
|
{
|
|
414
365
|
parser: syntax([
|
|
415
366
|
structField,
|
|
416
|
-
syntaxRepeat(syntax([marker(','),
|
|
417
|
-
|
|
367
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(structField)], true), true),
|
|
368
|
+
optional(marker(',')),
|
|
418
369
|
punctuation('}'),
|
|
419
370
|
], true),
|
|
420
371
|
},
|
|
421
372
|
]),
|
|
422
373
|
], true));
|
|
423
|
-
|
|
374
|
+
export const struct = setType('mcdoc:struct', syntax([
|
|
424
375
|
prelim,
|
|
425
376
|
keyword('struct'),
|
|
426
|
-
|
|
427
|
-
optionalTypeParamBlock,
|
|
377
|
+
optional(failOnEmpty(identifier)),
|
|
428
378
|
structBlock,
|
|
429
379
|
], true));
|
|
430
|
-
const enumInjection =
|
|
380
|
+
const enumInjection = setType('mcdoc:injection/enum', syntax([
|
|
431
381
|
literal('enum'),
|
|
432
382
|
punctuation('('),
|
|
433
383
|
enumType,
|
|
434
384
|
punctuation(')'),
|
|
435
|
-
|
|
385
|
+
path,
|
|
436
386
|
enumBlock,
|
|
437
387
|
]));
|
|
438
|
-
const structInjection =
|
|
388
|
+
const structInjection = setType('mcdoc:injection/struct', syntax([
|
|
439
389
|
literal('struct'),
|
|
440
|
-
|
|
441
|
-
optionalTypeParamBlock,
|
|
390
|
+
path,
|
|
442
391
|
structBlock,
|
|
443
392
|
]));
|
|
444
|
-
|
|
393
|
+
export const injection = setType('mcdoc:injection', syntax([
|
|
445
394
|
keyword('inject'),
|
|
446
|
-
|
|
395
|
+
select([
|
|
447
396
|
{ prefix: 'enum', parser: enumInjection },
|
|
448
397
|
{ parser: structInjection },
|
|
449
398
|
]),
|
|
450
399
|
]));
|
|
451
|
-
|
|
452
|
-
|
|
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,
|
|
453
425
|
keyword('type'),
|
|
454
|
-
|
|
426
|
+
identifier,
|
|
455
427
|
optionalTypeParamBlock,
|
|
456
428
|
punctuation('='),
|
|
457
|
-
{ get: () =>
|
|
429
|
+
{ get: () => type },
|
|
458
430
|
], true));
|
|
459
|
-
|
|
431
|
+
export const useStatement = setType('mcdoc:use_statement', syntax([
|
|
460
432
|
keyword('use'),
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
{ prefix: 'as', parser: syntax([literal('as'),
|
|
433
|
+
path,
|
|
434
|
+
select([
|
|
435
|
+
{ prefix: 'as', parser: syntax([literal('as'), identifier]) },
|
|
464
436
|
{ parser: noop },
|
|
465
437
|
]),
|
|
466
438
|
], true));
|
|
467
|
-
const topLevel =
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
439
|
+
const topLevel = any([
|
|
440
|
+
comment,
|
|
441
|
+
dispatchStatement,
|
|
442
|
+
enum_,
|
|
443
|
+
injection,
|
|
444
|
+
struct,
|
|
445
|
+
typeAlias,
|
|
446
|
+
useStatement,
|
|
475
447
|
]);
|
|
476
|
-
|
|
448
|
+
export const module_ = setType('mcdoc:module', syntaxRepeat(topLevel, true));
|
|
477
449
|
/* eslint-enable @typescript-eslint/indent */
|
|
478
450
|
function typeBase(type, parser) {
|
|
479
|
-
return
|
|
451
|
+
return setType(type, syntax([
|
|
480
452
|
attributes,
|
|
481
453
|
parser,
|
|
482
|
-
syntaxRepeat(
|
|
454
|
+
syntaxRepeat(failOnError(indexBody())),
|
|
483
455
|
], true));
|
|
484
456
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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({
|
|
488
460
|
pattern: /^(?:0|[-+]?[1-9][0-9]*)$/,
|
|
489
461
|
});
|
|
490
462
|
function range(type, number) {
|
|
491
|
-
|
|
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([
|
|
492
473
|
{
|
|
493
|
-
|
|
494
|
-
parser:
|
|
495
|
-
|
|
474
|
+
predicate: delimiterPredicate,
|
|
475
|
+
parser: sequence([
|
|
476
|
+
delimiterParser,
|
|
496
477
|
number,
|
|
497
478
|
]),
|
|
498
479
|
},
|
|
499
480
|
{
|
|
500
|
-
parser:
|
|
501
|
-
|
|
502
|
-
|
|
481
|
+
parser: sequence([
|
|
482
|
+
stopBefore(number, '..'),
|
|
483
|
+
select([
|
|
503
484
|
{
|
|
504
|
-
|
|
505
|
-
parser:
|
|
506
|
-
|
|
507
|
-
|
|
485
|
+
predicate: delimiterPredicate,
|
|
486
|
+
parser: sequence([
|
|
487
|
+
delimiterParser,
|
|
488
|
+
optional(failOnEmpty(number)),
|
|
508
489
|
]),
|
|
509
490
|
},
|
|
510
491
|
{ parser: noop },
|
|
@@ -513,122 +494,122 @@ function range(type, number) {
|
|
|
513
494
|
},
|
|
514
495
|
]));
|
|
515
496
|
}
|
|
516
|
-
const intRange = range('mcdoc:int_range',
|
|
517
|
-
const atIntRange =
|
|
497
|
+
export const intRange = range('mcdoc:int_range', integer);
|
|
498
|
+
const atIntRange = optional((src, ctx) => {
|
|
518
499
|
if (!src.trySkip('@')) {
|
|
519
|
-
return
|
|
500
|
+
return Failure;
|
|
520
501
|
}
|
|
521
502
|
src.skipWhitespace();
|
|
522
503
|
return intRange(src, ctx);
|
|
523
504
|
});
|
|
524
|
-
|
|
505
|
+
export const stringType = typeBase('mcdoc:type/string', syntax([
|
|
525
506
|
keyword('string', { colorTokenType: 'type' }),
|
|
526
507
|
atIntRange,
|
|
527
508
|
]));
|
|
528
|
-
|
|
509
|
+
export const literalType = typeBase('mcdoc:type/literal', select([
|
|
529
510
|
{ predicate: src => src.tryPeek('false') || src.tryPeek('true'), parser: keyword(['false', 'true'], { colorTokenType: 'type' }) },
|
|
530
|
-
{ prefix: '"', parser:
|
|
531
|
-
{ parser:
|
|
511
|
+
{ prefix: '"', parser: failOnEmpty(string) },
|
|
512
|
+
{ parser: failOnError(typedNumber) },
|
|
532
513
|
]));
|
|
533
|
-
const floatRange = range('mcdoc:float_range',
|
|
534
|
-
const atFloatRange =
|
|
514
|
+
export const floatRange = range('mcdoc:float_range', float);
|
|
515
|
+
const atFloatRange = optional((src, ctx) => {
|
|
535
516
|
if (!src.trySkip('@')) {
|
|
536
|
-
return
|
|
517
|
+
return Failure;
|
|
537
518
|
}
|
|
538
519
|
src.skipWhitespace();
|
|
539
520
|
return floatRange(src, ctx);
|
|
540
521
|
});
|
|
541
|
-
|
|
522
|
+
export const numericType = typeBase('mcdoc:type/numeric_type', select([
|
|
542
523
|
{
|
|
543
|
-
predicate: src =>
|
|
524
|
+
predicate: src => NumericTypeFloatKinds.some(k => src.tryPeek(k)),
|
|
544
525
|
parser: syntax([
|
|
545
|
-
keyword(
|
|
526
|
+
keyword(NumericTypeFloatKinds, { colorTokenType: 'type' }),
|
|
546
527
|
atFloatRange,
|
|
547
528
|
]),
|
|
548
529
|
},
|
|
549
530
|
{
|
|
550
531
|
parser: syntax([
|
|
551
|
-
keyword(
|
|
532
|
+
keyword(NumericTypeIntKinds, { colorTokenType: 'type' }),
|
|
552
533
|
atIntRange,
|
|
553
534
|
]),
|
|
554
535
|
},
|
|
555
536
|
]));
|
|
556
|
-
|
|
557
|
-
literal(
|
|
537
|
+
export const primitiveArrayType = typeBase('mcdoc:type/primitive_array', syntax([
|
|
538
|
+
literal(PrimitiveArrayValueKinds),
|
|
558
539
|
atIntRange,
|
|
559
540
|
keyword('[]', { allowedChars: new Set(['[', ']']), colorTokenType: 'type' }),
|
|
560
541
|
atIntRange,
|
|
561
542
|
]));
|
|
562
|
-
|
|
543
|
+
export const listType = typeBase('mcdoc:type/list', syntax([
|
|
563
544
|
marker('['),
|
|
564
|
-
{ get: () =>
|
|
545
|
+
{ get: () => type },
|
|
565
546
|
punctuation(']'),
|
|
566
547
|
atIntRange,
|
|
567
548
|
], true));
|
|
568
|
-
|
|
549
|
+
export const tupleType = typeBase('mcdoc:type/tuple', syntax([
|
|
569
550
|
marker('['),
|
|
570
|
-
{ get: () =>
|
|
551
|
+
{ get: () => type },
|
|
571
552
|
marker(','),
|
|
572
|
-
|
|
553
|
+
select([
|
|
573
554
|
{ prefix: ']', parser: punctuation(']') },
|
|
574
555
|
{
|
|
575
556
|
parser: syntax([
|
|
576
|
-
{ get: () =>
|
|
577
|
-
syntaxRepeat(syntax([marker(','), { get: () =>
|
|
578
|
-
|
|
557
|
+
{ get: () => type },
|
|
558
|
+
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(type) }], true), true),
|
|
559
|
+
optional(marker(',')),
|
|
579
560
|
punctuation(']'),
|
|
580
561
|
], true),
|
|
581
562
|
},
|
|
582
563
|
]),
|
|
583
564
|
], true));
|
|
584
|
-
|
|
585
|
-
|
|
565
|
+
export const dispatcherType = typeBase('mcdoc:type/dispatcher', syntax([
|
|
566
|
+
failOnError(resLoc({ category: 'mcdoc/dispatcher' })),
|
|
586
567
|
indexBody(),
|
|
587
568
|
]));
|
|
588
|
-
|
|
569
|
+
export const unionType = typeBase('mcdoc:type/union', syntax([
|
|
589
570
|
marker('('),
|
|
590
|
-
|
|
571
|
+
select([
|
|
591
572
|
{ prefix: ')', parser: punctuation(')') },
|
|
592
573
|
{
|
|
593
574
|
parser: syntax([
|
|
594
|
-
{ get: () =>
|
|
595
|
-
syntaxRepeat(syntax([marker('|'), { get: () =>
|
|
596
|
-
|
|
575
|
+
{ get: () => type },
|
|
576
|
+
syntaxRepeat(syntax([marker('|'), { get: () => failOnEmpty(type) }], true), true),
|
|
577
|
+
optional(marker('|')),
|
|
597
578
|
punctuation(')'),
|
|
598
579
|
], true),
|
|
599
580
|
},
|
|
600
581
|
]),
|
|
601
582
|
]));
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
583
|
+
export const referenceType = typeBase('mcdoc:type/reference', syntax([
|
|
584
|
+
path,
|
|
585
|
+
optional(syntax([
|
|
605
586
|
marker('<'),
|
|
606
|
-
|
|
587
|
+
select([
|
|
607
588
|
{ prefix: '>', parser: punctuation('>') },
|
|
608
589
|
{
|
|
609
590
|
parser: syntax([
|
|
610
|
-
{ get: () =>
|
|
611
|
-
syntaxRepeat(syntax([marker(','), { get: () =>
|
|
612
|
-
|
|
591
|
+
{ get: () => type },
|
|
592
|
+
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(type) }], true), true),
|
|
593
|
+
optional(marker(',')),
|
|
613
594
|
punctuation('>'),
|
|
614
595
|
], true),
|
|
615
596
|
},
|
|
616
597
|
]),
|
|
617
598
|
])),
|
|
618
599
|
]));
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
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,
|
|
633
614
|
]);
|
|
634
615
|
//# sourceMappingURL=index.js.map
|