@spyglassmc/mcdoc 0.1.0 → 0.3.0

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