@spyglassmc/json 0.3.6 → 0.3.7

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.
@@ -21,11 +21,12 @@ const object = (node, ctx) => {
21
21
  });
22
22
  return `{\n${fields.join(',\n')}\n${ctx.indent()}}`;
23
23
  };
24
+ const number = (node, ctx) => ctx.meta.getFormatter(node.value.type)(node.value, ctx);
24
25
  export function register(meta) {
25
26
  meta.registerFormatter('json:array', array);
26
27
  meta.registerFormatter('json:boolean', core.formatter.boolean);
27
28
  meta.registerFormatter('json:null', () => 'null');
28
- meta.registerFormatter('json:number', core.formatter.float);
29
+ meta.registerFormatter('json:number', number);
29
30
  meta.registerFormatter('json:object', object);
30
31
  meta.registerFormatter('json:string', core.formatter.string);
31
32
  }
@@ -71,9 +71,10 @@ export declare namespace JsonStringNode {
71
71
  export interface JsonNumberExpectation extends JsonBaseExpectation {
72
72
  readonly type: 'json:number';
73
73
  }
74
- export interface JsonNumberNode extends core.FloatBaseNode, JsonBaseAstNode {
74
+ export interface JsonNumberNode extends JsonBaseAstNode, core.AstNode {
75
75
  readonly type: 'json:number';
76
- readonly value: number;
76
+ readonly children: [core.LongNode | core.FloatNode];
77
+ readonly value: core.LongNode | core.FloatNode;
77
78
  }
78
79
  export declare namespace JsonNumberNode {
79
80
  function is(obj: object): obj is JsonNumberNode;
@@ -1,15 +1,10 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import { entry } from './entry.js';
3
- export const array = (src, ctx) => {
4
- const parser = core.list({
5
- start: '[',
6
- value: entry,
7
- sep: ',',
8
- trailingSep: false,
9
- end: ']',
10
- });
11
- const ans = parser(src, ctx);
12
- ans.type = 'json:array';
13
- return ans;
14
- };
3
+ export const array = (ctx, src) => core.setType('json:array', core.list({
4
+ start: '[',
5
+ value: entry,
6
+ sep: ',',
7
+ trailingSep: false,
8
+ end: ']',
9
+ }))(ctx, src);
15
10
  //# sourceMappingURL=array.js.map
@@ -1,6 +1,6 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import { Range } from '@spyglassmc/core';
3
- export const boolean = (src, ctx) => {
3
+ export const boolean = (src, _ctx) => {
4
4
  const start = src.cursor;
5
5
  if (src.trySkip('false')) {
6
6
  return {
@@ -1,11 +1,24 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  export const number = (src, ctx) => {
3
- const parser = core.float({
4
- // Regex form of the chart from https://www.json.org.
5
- pattern: /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?$/,
6
- });
7
- const ans = parser(src, ctx);
8
- ans.type = 'json:number';
9
- return ans;
3
+ const value = core.select([
4
+ {
5
+ regex: /^-?(?:0|[1-9]\d*)(?!\d|[.eE])/,
6
+ parser: core.long({
7
+ pattern: /^-?(?:0|[1-9]\d*)$/,
8
+ }),
9
+ },
10
+ {
11
+ parser: core.float({
12
+ // Regex form of the chart from https://www.json.org.
13
+ pattern: /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?$/,
14
+ }),
15
+ },
16
+ ])(src, ctx);
17
+ return {
18
+ type: 'json:number',
19
+ children: [value],
20
+ value: value,
21
+ range: value.range,
22
+ };
10
23
  };
11
24
  //# sourceMappingURL=number.js.map
@@ -1,17 +1,15 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import { entry } from './entry.js';
3
3
  import { string } from './string.js';
4
- export const object = (src, ctx) => {
5
- return core.setType('json:object', core.record({
6
- start: '{',
7
- pair: {
8
- key: string,
9
- sep: ':',
10
- value: entry,
11
- end: ',',
12
- trailingEnd: false,
13
- },
14
- end: '}',
15
- }))(src, ctx);
16
- };
4
+ export const object = (src, ctx) => core.setType('json:object', core.record({
5
+ start: '{',
6
+ pair: {
7
+ key: string,
8
+ sep: ':',
9
+ value: entry,
10
+ end: ',',
11
+ trailingEnd: false,
12
+ },
13
+ end: '}',
14
+ }))(src, ctx);
17
15
  //# sourceMappingURL=object.js.map
@@ -6,10 +6,5 @@ export const JsonStringOptions = {
6
6
  },
7
7
  quotes: ['"'],
8
8
  };
9
- export const string = (src, ctx) => {
10
- const parser = core.string(JsonStringOptions);
11
- const ans = parser(src, ctx);
12
- ans.type = 'json:string';
13
- return ans;
14
- };
9
+ export const string = (src, ctx) => core.setType('json:string', core.string(JsonStringOptions))(src, ctx);
15
10
  //# sourceMappingURL=string.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/json",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",