@spyglassmc/mcdoc 0.3.6 → 0.3.8

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.
@@ -739,9 +739,11 @@ function convertLiteralValue(node, ctx) {
739
739
  else if (TypedNumberNode.is(node)) {
740
740
  const { suffix, value } = TypedNumberNode.destruct(node);
741
741
  return {
742
- kind: 'number',
742
+ kind: convertLiteralNumberSuffix(suffix, ctx) ??
743
+ (value.type === 'integer'
744
+ ? 'int'
745
+ : 'double'),
743
746
  value: value.value,
744
- suffix: convertLiteralNumberSuffix(suffix, ctx),
745
747
  };
746
748
  }
747
749
  else {
@@ -753,7 +755,20 @@ function convertLiteralValue(node, ctx) {
753
755
  }
754
756
  function convertLiteralNumberSuffix(node, ctx) {
755
757
  const suffix = node?.value;
756
- return suffix?.toLowerCase();
758
+ switch (suffix?.toLowerCase()) {
759
+ case 'b':
760
+ return 'byte';
761
+ case 's':
762
+ return 'short';
763
+ case 'l':
764
+ return 'long';
765
+ case 'f':
766
+ return 'float';
767
+ case 'd':
768
+ return 'double';
769
+ default:
770
+ return undefined;
771
+ }
757
772
  }
758
773
  function convertNumericType(node, ctx) {
759
774
  const { numericKind, valueRange } = NumericTypeNode.destruct(node);
@@ -1,5 +1,5 @@
1
- import type { AstNode, ColorTokenType, IntegerNode, SymbolBaseNode } from '@spyglassmc/core';
2
- import { CommentNode, FloatNode, ResourceLocationNode, StringNode } from '@spyglassmc/core';
1
+ import type { AstNode, ColorTokenType, SymbolBaseNode } from '@spyglassmc/core';
2
+ import { CommentNode, FloatNode, IntegerNode, ResourceLocationNode, StringNode } from '@spyglassmc/core';
3
3
  export interface ModuleNode extends AstNode {
4
4
  type: 'mcdoc:module';
5
5
  children: TopLevelNode[];
@@ -185,11 +185,11 @@ export declare namespace LiteralTypeValueNode {
185
185
  }
186
186
  export interface TypedNumberNode extends AstNode {
187
187
  type: 'mcdoc:typed_number';
188
- children: (FloatNode | LiteralNode)[];
188
+ children: (FloatNode | IntegerNode | LiteralNode)[];
189
189
  }
190
190
  export declare namespace TypedNumberNode {
191
191
  function destruct(node: TypedNumberNode): {
192
- value: FloatNode;
192
+ value: FloatNode | IntegerNode;
193
193
  suffix?: LiteralNode;
194
194
  };
195
195
  function is(node: AstNode | undefined): node is TypedNumberNode;
package/lib/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { atArray, CommentNode, FloatNode, ResourceLocationNode, StringNode, } from '@spyglassmc/core';
1
+ import { atArray, CommentNode, FloatNode, IntegerNode, ResourceLocationNode, StringNode, } from '@spyglassmc/core';
2
2
  export var ModuleNode;
3
3
  (function (ModuleNode) {
4
4
  function is(node) {
@@ -272,7 +272,8 @@ export var TypedNumberNode;
272
272
  (function (TypedNumberNode) {
273
273
  function destruct(node) {
274
274
  return {
275
- value: node.children.find(FloatNode.is),
275
+ value: node.children.find(FloatNode.is) ??
276
+ node.children.find(IntegerNode.is),
276
277
  suffix: node.children.find(LiteralNode.is),
277
278
  };
278
279
  }
@@ -21,6 +21,19 @@ export declare const docComment: Parser<CommentNode>;
21
21
  export declare const docComments: InfallibleParser<DocCommentsNode>;
22
22
  export declare const dispatchStatement: Parser<DispatchStatementNode>;
23
23
  export declare const float: InfallibleParser<FloatNode>;
24
+ export declare const integer: InfallibleParser<IntegerNode>;
25
+ export declare const LiteralIntSuffixes: readonly ["b", "s", "l"];
26
+ export type LiteralIntSuffix = (typeof LiteralIntSuffixes)[number];
27
+ export declare const LiteralIntCaseInsensitiveSuffixes: readonly ["b", "s", "l", "B", "S", "L"];
28
+ export type LiteralIntCaseInsensitiveSuffix = (typeof LiteralIntCaseInsensitiveSuffixes)[number];
29
+ export declare const LiteralFloatSuffixes: readonly ["f", "d"];
30
+ export type LiteralFloatSuffix = (typeof LiteralFloatSuffixes)[number];
31
+ export declare const LiteralFloatCaseInsensitiveSuffixes: readonly ["f", "d", "F", "D"];
32
+ export type LiteralFloatCaseInsensitiveSuffix = (typeof LiteralFloatCaseInsensitiveSuffixes)[number];
33
+ export declare const LiteralNumberSuffixes: readonly ["b", "s", "l", "f", "d"];
34
+ export type LiteralNumberSuffix = (typeof LiteralNumberSuffixes)[number];
35
+ export declare const LiteralNumberCaseInsensitiveSuffixes: readonly ["b", "s", "l", "f", "d", "b", "s", "l", "B", "S", "L", "f", "d", "F", "D"];
36
+ export type LiteralNumberCaseInsensitiveSuffix = (typeof LiteralNumberCaseInsensitiveSuffixes)[number];
24
37
  export declare const typedNumber: InfallibleParser<TypedNumberNode>;
25
38
  export declare const enum_: Parser<EnumNode>;
26
39
  export declare const struct: Parser<StructNode>;
@@ -30,7 +43,6 @@ export declare const useStatement: Parser<UseStatementNode>;
30
43
  export declare const module_: Parser<ModuleNode>;
31
44
  export declare const anyType: Parser<AnyTypeNode>;
32
45
  export declare const booleanType: Parser<BooleanTypeNode>;
33
- export declare const integer: InfallibleParser<IntegerNode>;
34
46
  export declare const intRange: InfallibleParser<IntRangeNode>;
35
47
  export declare const stringType: Parser<StringTypeNode>;
36
48
  export declare const literalType: Parser<LiteralTypeNode>;
@@ -2,7 +2,7 @@ import * as core from '@spyglassmc/core';
2
2
  import { any, Arrayable, failOnEmpty, failOnError, Failure, map, optional, Range, repeat, ResourceLocation, select, sequence, setType, stopBefore, validate, } from '@spyglassmc/core';
3
3
  import { arrayToMessage, localeQuote, localize } from '@spyglassmc/locales';
4
4
  import { RangeExclusiveChar } from '../node/index.js';
5
- import { LiteralNumberCaseInsensitiveSuffixes, NumericTypeFloatKinds, NumericTypeIntKinds, PrimitiveArrayValueKinds, StaticIndexKeywords, } from '../type/index.js';
5
+ import { NumericTypeFloatKinds, NumericTypeIntKinds, PrimitiveArrayValueKinds, StaticIndexKeywords, } from '../type/index.js';
6
6
  /**
7
7
  * @returns A comment parser that accepts normal comments (`//`) and reports an error if it's a doc comment (`///`).
8
8
  *
@@ -354,11 +354,56 @@ const enumType = literal(['byte', 'short', 'int', 'long', 'string', 'float', 'do
354
354
  export const float = core.float({
355
355
  pattern: /^[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)?|[0-9]*\.[0-9]+(?:[eE][-+]?[0-9]+)?)$/,
356
356
  });
357
- export const typedNumber = setType('mcdoc:typed_number', sequence([
358
- float,
359
- optional(keyword(LiteralNumberCaseInsensitiveSuffixes, {
360
- colorTokenType: 'keyword',
361
- })),
357
+ export const integer = core.integer({
358
+ pattern: /^(?:0|[-+]?[1-9][0-9]*)$/,
359
+ });
360
+ export const LiteralIntSuffixes = Object.freeze([
361
+ 'b',
362
+ 's',
363
+ 'l',
364
+ ]);
365
+ export const LiteralIntCaseInsensitiveSuffixes = Object.freeze([
366
+ ...LiteralIntSuffixes,
367
+ 'B',
368
+ 'S',
369
+ 'L',
370
+ ]);
371
+ export const LiteralFloatSuffixes = Object.freeze([
372
+ 'f',
373
+ 'd',
374
+ ]);
375
+ export const LiteralFloatCaseInsensitiveSuffixes = Object.freeze([
376
+ ...LiteralFloatSuffixes,
377
+ 'F',
378
+ 'D',
379
+ ]);
380
+ export const LiteralNumberSuffixes = Object.freeze([
381
+ ...LiteralIntSuffixes,
382
+ ...LiteralFloatSuffixes,
383
+ ]);
384
+ export const LiteralNumberCaseInsensitiveSuffixes = Object.freeze([
385
+ ...LiteralNumberSuffixes,
386
+ ...LiteralIntCaseInsensitiveSuffixes,
387
+ ...LiteralFloatCaseInsensitiveSuffixes,
388
+ ]);
389
+ export const typedNumber = setType('mcdoc:typed_number', select([
390
+ {
391
+ regex: /^(?:\+|-)?\d+(?!\d|[.dfe])/i,
392
+ parser: sequence([
393
+ integer,
394
+ optional(keyword(LiteralIntCaseInsensitiveSuffixes, {
395
+ colorTokenType: 'keyword',
396
+ })),
397
+ ]),
398
+ },
399
+ {
400
+ parser: sequence([
401
+ float,
402
+ optional(keyword(LiteralFloatCaseInsensitiveSuffixes, {
403
+ colorTokenType: 'keyword',
404
+ })),
405
+ ]),
406
+ },
362
407
  ]));
363
408
  const enumValue = select([
364
409
  { prefix: '"', parser: string },
@@ -500,9 +545,6 @@ function typeBase(type, parser) {
500
545
  }
501
546
  export const anyType = typeBase('mcdoc:type/any', keyword('any', { colorTokenType: 'type' }));
502
547
  export const booleanType = typeBase('mcdoc:type/boolean', keyword('boolean', { colorTokenType: 'type' }));
503
- export const integer = core.integer({
504
- pattern: /^(?:0|[-+]?[1-9][0-9]*)$/,
505
- });
506
548
  function range(type, number) {
507
549
  const delimiterPredicate = (src) => src.tryPeek('..') || src.tryPeek(`${RangeExclusiveChar}..`);
508
550
  const delimiterParser = literal([
@@ -16,7 +16,7 @@ export type NumericRange = {
16
16
  min?: number;
17
17
  max?: number;
18
18
  };
19
- export declare const StaticIndexKeywords: readonly ["fallback", "none", "unknown", "spawnitem"];
19
+ export declare const StaticIndexKeywords: readonly ["fallback", "none", "unknown", "spawnitem", "blockitem"];
20
20
  export type StaticIndexKeyword = (typeof StaticIndexKeywords)[number];
21
21
  export interface StaticIndex {
22
22
  kind: 'static';
@@ -106,25 +106,23 @@ export interface StringType {
106
106
  kind: 'string';
107
107
  lengthRange?: NumericRange;
108
108
  }
109
- export type LiteralValue = {
109
+ export type LiteralValue = LiteralBooleanValue | LiteralStringValue | LiteralNumericValue;
110
+ export interface LiteralBooleanValue {
110
111
  kind: 'boolean';
111
112
  value: boolean;
112
- } | {
113
+ }
114
+ export interface LiteralStringValue {
113
115
  kind: 'string';
114
116
  value: string;
115
- } | {
116
- kind: 'number';
117
+ }
118
+ export interface LiteralNumericValue {
119
+ kind: NumericTypeKind;
117
120
  value: number;
118
- suffix: 'b' | 's' | 'l' | 'f' | 'd' | undefined;
119
- };
121
+ }
120
122
  export interface LiteralType {
121
123
  kind: 'literal';
122
124
  value: LiteralValue;
123
125
  }
124
- export declare const LiteralNumberSuffixes: readonly ["b", "s", "l", "f", "d"];
125
- export type LiteralNumberSuffix = (typeof LiteralNumberSuffixes)[number];
126
- export declare const LiteralNumberCaseInsensitiveSuffixes: readonly ["b", "s", "l", "f", "d", "B", "S", "L", "F", "D"];
127
- export type LiteralNumberCaseInsensitiveSuffix = (typeof LiteralNumberCaseInsensitiveSuffixes)[number];
128
126
  export interface NumericType {
129
127
  kind: NumericTypeKind;
130
128
  valueRange?: NumericRange;
package/lib/type/index.js CHANGED
@@ -6,6 +6,7 @@ export const StaticIndexKeywords = Object.freeze([
6
6
  'none',
7
7
  'unknown',
8
8
  'spawnitem',
9
+ 'blockitem',
9
10
  ]);
10
11
  export const EmptyUnion = Object.freeze({
11
12
  kind: 'union',
@@ -17,21 +18,6 @@ export function createEmptyUnion(attributes) {
17
18
  // attributes,
18
19
  };
19
20
  }
20
- export const LiteralNumberSuffixes = Object.freeze([
21
- 'b',
22
- 's',
23
- 'l',
24
- 'f',
25
- 'd',
26
- ]);
27
- export const LiteralNumberCaseInsensitiveSuffixes = Object.freeze([
28
- ...LiteralNumberSuffixes,
29
- 'B',
30
- 'S',
31
- 'L',
32
- 'F',
33
- 'D',
34
- ]);
35
21
  export const NumericTypeIntKinds = Object.freeze([
36
22
  'byte',
37
23
  'short',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/mcdoc",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",