@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.
@@ -1,40 +1,16 @@
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");
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
- exports.comment = (0, core_1.validate)(core.comment({
11
+ export const comment = validate(core.comment({
36
12
  singleLinePrefixes: new Set(['//']),
37
- }), (res, src) => !src.slice(res).startsWith('///'), (0, locales_1.localize)('mcdoc.parser.syntax.doc-comment-unexpected'));
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 = (0, exports.comment)(src, ctx);
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 = (0, core_1.sequence)(parsers, syntaxGap(delegatesDocComments))(src, ctx);
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 (0, core_1.repeat)(parser, syntaxGap(delegatesDocComments));
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: core_1.Range.create(src),
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 (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);
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 (!core_1.Arrayable.toArray(keyword).includes(result.value)) {
87
- return core_1.Failure;
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((0, locales_1.localize)('expected-got', (0, locales_1.localeQuote)(punctuation), (0, locales_1.localeQuote)(src.peek())), src);
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 core_1.Failure;
80
+ return Failure;
106
81
  }
107
82
  return undefined;
108
83
  };
109
84
  }
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)));
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
- exports.string = (0, core_1.stopBefore)(core.string({
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: core_1.Range.create(src),
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((0, locales_1.localize)('expected', (0, locales_1.localize)('mcdoc.node.identifier')), src);
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((0, locales_1.localize)('mcdoc.parser.identifier.reserved-word', (0, locales_1.localeQuote)(ans.value)), ans);
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 = (0, core_1.select)([
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: exports.string,
133
+ parser: string,
161
134
  },
162
135
  {
163
- parser: exports.identifier,
136
+ parser: identifier,
164
137
  },
165
138
  ]);
166
- const dynamicIndex = (0, core_1.setType)('mcdoc:dynamic_index', syntax([
139
+ const dynamicIndex = setType('mcdoc:dynamic_index', syntax([
167
140
  punctuation('['),
168
141
  accessorKey,
169
- (0, core_1.repeat)((0, core_1.sequence)([marker('.'), accessorKey])),
142
+ repeat(sequence([marker('.'), accessorKey])),
170
143
  punctuation(']'),
171
144
  ]));
172
- const index = (0, core_1.select)([
145
+ const index = select([
173
146
  {
174
147
  prefix: '%',
175
- parser: literal(['%fallback', '%none', '%unknown'], { specialChars: new Set(['%']) }),
148
+ parser: literal(StaticIndexKeywords.map(v => `%${v}`), { specialChars: new Set(['%']) }),
176
149
  },
177
150
  {
178
151
  prefix: '"',
179
- parser: exports.string,
152
+ parser: string,
180
153
  },
181
154
  {
182
155
  prefix: '[',
183
- parser: dynamicIndex,
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: (0, core_1.any)([resLoc({ category: 'mcdoc/dispatcher', accessType: options?.accessType }), exports.identifier]),
161
+ parser: any([resLoc({ category: 'mcdoc/dispatcher', accessType: options?.accessType }), identifier]),
187
162
  },
188
163
  ]);
189
- return (0, core_1.setType)('mcdoc:index_body', syntax([
164
+ return setType('mcdoc:index_body', syntax([
190
165
  punctuation('['),
191
166
  index,
192
- syntaxRepeat(syntax([marker(','), (0, core_1.failOnEmpty)(index)])),
193
- (0, core_1.optional)(marker(',')),
167
+ syntaxRepeat(syntax([marker(','), failOnEmpty(index)])),
168
+ optional(marker(',')),
194
169
  punctuation(']'),
195
170
  ]));
196
171
  }
197
- const pathSegment = (0, core_1.select)([
172
+ const pathSegment = select([
198
173
  { prefix: 'super', parser: literal('super') },
199
- { parser: exports.identifier },
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 (0, core_1.map)((0, core_1.sequence)([
181
+ return map(sequence([
207
182
  pathSegment,
208
- (0, core_1.repeat)((0, core_1.sequence)([marker('::'), pathSegment])),
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
- exports.path = path;
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: () => (0, core_1.failOnEmpty)(attributeValue) }], true), true),
196
+ syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(attributeValue) }], true), true),
223
197
  ], true));
224
198
  const attributeNamedValue = syntax([
225
- (0, core_1.select)([
226
- { prefix: '"', parser: exports.string },
227
- { parser: exports.identifier },
199
+ select([
200
+ { prefix: '"', parser: string },
201
+ { parser: identifier },
228
202
  ]),
229
- (0, core_1.select)([
203
+ select([
230
204
  { prefix: '=', parser: syntax([punctuation('='), { get: () => attributeValue }], true) },
231
205
  { parser: { get: () => attributeTree } },
232
206
  ]),
233
207
  ], true);
234
- const attributeTreeNamedValues = (0, core_1.setType)('mcdoc:attribute/tree/named', syntax([
208
+ const attributeTreeNamedValues = setType('mcdoc:attribute/tree/named', syntax([
235
209
  attributeNamedValue,
236
- syntaxRepeat(syntax([marker(','), (0, core_1.failOnEmpty)(attributeNamedValue)], true), true),
210
+ syntaxRepeat(syntax([marker(','), failOnEmpty(attributeNamedValue)], true), true),
237
211
  ], true));
238
- const treeBody = (0, core_1.any)([
239
- syntax([attributeTreeNamedValues, (0, core_1.optional)(marker(','))]),
240
- syntax([attributeTreePosValues, punctuation(','), attributeTreeNamedValues, (0, core_1.optional)(marker(','))]),
241
- syntax([attributeTreePosValues, (0, core_1.optional)(marker(','))]),
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 core_1.Failure;
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 = (0, core_1.select)([
237
+ const attributeValue = select([
264
238
  { predicate: src => ['(', '[', '{'].includes(src.peek()), parser: attributeTree },
265
- { parser: { get: () => exports.type } },
239
+ { parser: { get: () => type } },
266
240
  ]);
267
- exports.attribute = (0, core_1.setType)('mcdoc:attribute', syntax([
241
+ export const attribute = setType('mcdoc:attribute', syntax([
268
242
  marker('#['),
269
- exports.identifier,
270
- (0, core_1.select)([
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 = (0, core_1.repeat)(exports.attribute);
277
- exports.dispatchStatement = (0, core_1.setType)('mcdoc:dispatch_statement', syntax([
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: () => exports.type },
257
+ { get: () => type },
284
258
  ], true));
285
- exports.docComment = core.comment({
259
+ export const docComment = core.comment({
286
260
  singleLinePrefixes: new Set(['///']),
287
261
  includesEol: true,
288
262
  });
289
- exports.docComments = (0, core_1.setType)('mcdoc:doc_comments', (0, core_1.repeat)(exports.docComment, src => {
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
- (0, core_1.optional)((0, core_1.failOnEmpty)(exports.docComments)),
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
- exports.float = core.float({
280
+ export const float = core.float({
307
281
  pattern: /^[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)?|[0-9]*\.[0-9]+(?:[eE][-+]?[0-9]+)?)$/,
308
282
  });
309
- exports.typedNumber = (0, core_1.setType)('mcdoc:typed_number', (0, core_1.sequence)([
310
- exports.float,
311
- (0, core_1.optional)(keyword(['b', 'B', 'd', 'D', 'f', 'F', 'l', 'L', 's', 'S'], { colorTokenType: 'keyword' })),
283
+ export const typedNumber = setType('mcdoc:typed_number', sequence([
284
+ float,
285
+ optional(keyword(LiteralNumberCaseInsensitiveSuffixes, { colorTokenType: 'keyword' })),
312
286
  ]));
313
- const enumValue = (0, core_1.select)([
314
- { prefix: '"', parser: exports.string },
315
- { parser: exports.typedNumber },
287
+ const enumValue = select([
288
+ { prefix: '"', parser: string },
289
+ { parser: typedNumber },
316
290
  ]);
317
- const enumField = (0, core_1.setType)('mcdoc:enum/field', syntax([
291
+ const enumField = setType('mcdoc:enum/field', syntax([
318
292
  prelim,
319
- exports.identifier,
293
+ identifier,
320
294
  punctuation('='),
321
295
  enumValue,
322
296
  ], true));
323
- const enumBlock = (0, core_1.setType)('mcdoc:enum/block', syntax([
297
+ const enumBlock = setType('mcdoc:enum/block', syntax([
324
298
  punctuation('{'),
325
- (0, core_1.select)([
299
+ select([
326
300
  { prefix: '}', parser: punctuation('}') },
327
301
  {
328
302
  parser: syntax([
329
303
  enumField,
330
- syntaxRepeat(syntax([marker(','), (0, core_1.failOnEmpty)(enumField)], true), true),
331
- (0, core_1.optional)(marker(',')),
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
- exports.enum_ = (0, core_1.setType)('mcdoc:enum', syntax([
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
- (0, core_1.optional)((0, core_1.failOnError)(exports.identifier)),
317
+ optional(failOnError(identifier)),
344
318
  enumBlock,
345
319
  ], true));
346
- const typeParam = (0, core_1.setType)('mcdoc:type_param', syntax([
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: () => exports.type },
322
+ { get: () => type },
372
323
  punctuation(']'),
373
324
  ], true));
374
- const structKey = (0, core_1.select)([
375
- { prefix: '"', parser: exports.string },
325
+ const structKey = select([
326
+ { prefix: '"', parser: string },
376
327
  { prefix: '[', parser: structMapKey },
377
- { parser: exports.identifier },
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: () => exports.type },
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: core_1.Range.span(result0, result1),
346
+ range: Range.span(result0, result1),
396
347
  isOptional,
397
348
  };
398
349
  return ans;
399
350
  };
400
- const structSpreadField = (0, core_1.setType)('mcdoc:struct/field/spread', syntax([
351
+ const structSpreadField = setType('mcdoc:struct/field/spread', syntax([
401
352
  attributes,
402
353
  marker('...'),
403
- { get: () => exports.type },
354
+ { get: () => type },
404
355
  ], true));
405
- const structField = (0, core_1.any)([
356
+ const structField = any([
406
357
  structSpreadField,
407
358
  structPairField,
408
359
  ]);
409
- const structBlock = (0, core_1.setType)('mcdoc:struct/block', syntax([
360
+ const structBlock = setType('mcdoc:struct/block', syntax([
410
361
  punctuation('{'),
411
- (0, core_1.select)([
362
+ select([
412
363
  { prefix: '}', parser: punctuation('}') },
413
364
  {
414
365
  parser: syntax([
415
366
  structField,
416
- syntaxRepeat(syntax([marker(','), (0, core_1.failOnEmpty)(structField)], true), true),
417
- (0, core_1.optional)(marker(',')),
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
- exports.struct = (0, core_1.setType)('mcdoc:struct', syntax([
374
+ export const struct = setType('mcdoc:struct', syntax([
424
375
  prelim,
425
376
  keyword('struct'),
426
- (0, core_1.optional)((0, core_1.failOnEmpty)(exports.identifier)),
427
- optionalTypeParamBlock,
377
+ optional(failOnEmpty(identifier)),
428
378
  structBlock,
429
379
  ], true));
430
- const enumInjection = (0, core_1.setType)('mcdoc:injection/enum', syntax([
380
+ const enumInjection = setType('mcdoc:injection/enum', syntax([
431
381
  literal('enum'),
432
382
  punctuation('('),
433
383
  enumType,
434
384
  punctuation(')'),
435
- exports.path,
385
+ path,
436
386
  enumBlock,
437
387
  ]));
438
- const structInjection = (0, core_1.setType)('mcdoc:injection/struct', syntax([
388
+ const structInjection = setType('mcdoc:injection/struct', syntax([
439
389
  literal('struct'),
440
- exports.path,
441
- optionalTypeParamBlock,
390
+ path,
442
391
  structBlock,
443
392
  ]));
444
- exports.injection = (0, core_1.setType)('mcdoc:injection', syntax([
393
+ export const injection = setType('mcdoc:injection', syntax([
445
394
  keyword('inject'),
446
- (0, core_1.select)([
395
+ select([
447
396
  { prefix: 'enum', parser: enumInjection },
448
397
  { parser: structInjection },
449
398
  ]),
450
399
  ]));
451
- exports.typeAlias = (0, core_1.setType)('mcdoc:type_alias', syntax([
452
- prelim,
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
- exports.identifier,
426
+ identifier,
455
427
  optionalTypeParamBlock,
456
428
  punctuation('='),
457
- { get: () => exports.type },
429
+ { get: () => type },
458
430
  ], true));
459
- exports.useStatement = (0, core_1.setType)('mcdoc:use_statement', syntax([
431
+ export const useStatement = setType('mcdoc:use_statement', syntax([
460
432
  keyword('use'),
461
- exports.path,
462
- (0, core_1.select)([
463
- { prefix: 'as', parser: syntax([literal('as'), exports.identifier]) },
433
+ path,
434
+ select([
435
+ { prefix: 'as', parser: syntax([literal('as'), identifier]) },
464
436
  { parser: noop },
465
437
  ]),
466
438
  ], true));
467
- const topLevel = (0, core_1.any)([
468
- exports.comment,
469
- exports.dispatchStatement,
470
- exports.enum_,
471
- exports.injection,
472
- exports.struct,
473
- exports.typeAlias,
474
- exports.useStatement,
439
+ const topLevel = any([
440
+ comment,
441
+ dispatchStatement,
442
+ enum_,
443
+ injection,
444
+ struct,
445
+ typeAlias,
446
+ useStatement,
475
447
  ]);
476
- exports.module_ = (0, core_1.setType)('mcdoc:module', syntaxRepeat(topLevel, true));
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 (0, core_1.setType)(type, syntax([
451
+ return setType(type, syntax([
480
452
  attributes,
481
453
  parser,
482
- syntaxRepeat((0, core_1.failOnError)(indexBody())),
454
+ syntaxRepeat(failOnError(indexBody())),
483
455
  ], true));
484
456
  }
485
- exports.anyType = typeBase('mcdoc:type/any', keyword('any', { colorTokenType: 'type' }));
486
- exports.booleanType = typeBase('mcdoc:type/boolean', keyword('boolean', { colorTokenType: 'type' }));
487
- exports.integer = core.integer({
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
- return (0, core_1.setType)(type, (0, core_1.select)([
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
- prefix: '..',
494
- parser: (0, core_1.sequence)([
495
- literal('..', { allowedChars: new Set('.') }),
474
+ predicate: delimiterPredicate,
475
+ parser: sequence([
476
+ delimiterParser,
496
477
  number,
497
478
  ]),
498
479
  },
499
480
  {
500
- parser: (0, core_1.sequence)([
501
- (0, core_1.stopBefore)(number, '..'),
502
- (0, core_1.select)([
481
+ parser: sequence([
482
+ stopBefore(number, '..'),
483
+ select([
503
484
  {
504
- prefix: '..',
505
- parser: (0, core_1.sequence)([
506
- literal('..', { allowedChars: new Set('.') }),
507
- (0, core_1.optional)((0, core_1.failOnEmpty)(number)),
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', exports.integer);
517
- const atIntRange = (0, core_1.optional)((src, ctx) => {
497
+ export const intRange = range('mcdoc:int_range', integer);
498
+ const atIntRange = optional((src, ctx) => {
518
499
  if (!src.trySkip('@')) {
519
- return core_1.Failure;
500
+ return Failure;
520
501
  }
521
502
  src.skipWhitespace();
522
503
  return intRange(src, ctx);
523
504
  });
524
- exports.stringType = typeBase('mcdoc:type/string', syntax([
505
+ export const stringType = typeBase('mcdoc:type/string', syntax([
525
506
  keyword('string', { colorTokenType: 'type' }),
526
507
  atIntRange,
527
508
  ]));
528
- exports.literalType = typeBase('mcdoc:type/literal', (0, core_1.select)([
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: (0, core_1.failOnEmpty)(exports.string) },
531
- { parser: (0, core_1.failOnError)(exports.typedNumber) },
511
+ { prefix: '"', parser: failOnEmpty(string) },
512
+ { parser: failOnError(typedNumber) },
532
513
  ]));
533
- const floatRange = range('mcdoc:float_range', exports.float);
534
- const atFloatRange = (0, core_1.optional)((src, ctx) => {
514
+ export const floatRange = range('mcdoc:float_range', float);
515
+ const atFloatRange = optional((src, ctx) => {
535
516
  if (!src.trySkip('@')) {
536
- return core_1.Failure;
517
+ return Failure;
537
518
  }
538
519
  src.skipWhitespace();
539
520
  return floatRange(src, ctx);
540
521
  });
541
- exports.numericType = typeBase('mcdoc:type/numeric_type', (0, core_1.select)([
522
+ export const numericType = typeBase('mcdoc:type/numeric_type', select([
542
523
  {
543
- predicate: src => src.tryPeek('float') || src.tryPeek('double'),
524
+ predicate: src => NumericTypeFloatKinds.some(k => src.tryPeek(k)),
544
525
  parser: syntax([
545
- keyword(['float', 'double'], { colorTokenType: 'type' }),
526
+ keyword(NumericTypeFloatKinds, { colorTokenType: 'type' }),
546
527
  atFloatRange,
547
528
  ]),
548
529
  },
549
530
  {
550
531
  parser: syntax([
551
- keyword(['byte', 'short', 'int', 'long'], { colorTokenType: 'type' }),
532
+ keyword(NumericTypeIntKinds, { colorTokenType: 'type' }),
552
533
  atIntRange,
553
534
  ]),
554
535
  },
555
536
  ]));
556
- exports.primitiveArrayType = typeBase('mcdoc:type/primitive_array', syntax([
557
- literal(['byte', 'int', 'long']),
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
- exports.listType = typeBase('mcdoc:type/list', syntax([
543
+ export const listType = typeBase('mcdoc:type/list', syntax([
563
544
  marker('['),
564
- { get: () => exports.type },
545
+ { get: () => type },
565
546
  punctuation(']'),
566
547
  atIntRange,
567
548
  ], true));
568
- exports.tupleType = typeBase('mcdoc:type/tuple', syntax([
549
+ export const tupleType = typeBase('mcdoc:type/tuple', syntax([
569
550
  marker('['),
570
- { get: () => exports.type },
551
+ { get: () => type },
571
552
  marker(','),
572
- (0, core_1.select)([
553
+ select([
573
554
  { prefix: ']', parser: punctuation(']') },
574
555
  {
575
556
  parser: syntax([
576
- { get: () => exports.type },
577
- syntaxRepeat(syntax([marker(','), { get: () => (0, core_1.failOnEmpty)(exports.type) }], true), true),
578
- (0, core_1.optional)(marker(',')),
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
- exports.dispatcherType = typeBase('mcdoc:type/dispatcher', syntax([
585
- (0, core_1.failOnError)(resLoc({ category: 'mcdoc/dispatcher' })),
565
+ export const dispatcherType = typeBase('mcdoc:type/dispatcher', syntax([
566
+ failOnError(resLoc({ category: 'mcdoc/dispatcher' })),
586
567
  indexBody(),
587
568
  ]));
588
- exports.unionType = typeBase('mcdoc:type/union', syntax([
569
+ export const unionType = typeBase('mcdoc:type/union', syntax([
589
570
  marker('('),
590
- (0, core_1.select)([
571
+ select([
591
572
  { prefix: ')', parser: punctuation(')') },
592
573
  {
593
574
  parser: syntax([
594
- { get: () => exports.type },
595
- syntaxRepeat(syntax([marker('|'), { get: () => (0, core_1.failOnEmpty)(exports.type) }], true), true),
596
- (0, core_1.optional)(marker('|')),
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
- exports.pathType = typeBase('mcdoc:type/path', syntax([
603
- exports.path,
604
- (0, core_1.optional)(syntax([
583
+ export const referenceType = typeBase('mcdoc:type/reference', syntax([
584
+ path,
585
+ optional(syntax([
605
586
  marker('<'),
606
- (0, core_1.select)([
587
+ select([
607
588
  { prefix: '>', parser: punctuation('>') },
608
589
  {
609
590
  parser: syntax([
610
- { get: () => exports.type },
611
- syntaxRepeat(syntax([marker(','), { get: () => (0, core_1.failOnEmpty)(exports.type) }], true), true),
612
- (0, core_1.optional)(marker(',')),
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
- exports.type = (0, core_1.any)([
620
- exports.anyType,
621
- exports.booleanType,
622
- exports.dispatcherType,
623
- exports.enum_,
624
- exports.listType,
625
- exports.literalType,
626
- exports.numericType,
627
- exports.primitiveArrayType,
628
- exports.stringType,
629
- exports.struct,
630
- exports.tupleType,
631
- exports.unionType,
632
- exports.pathType,
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