aontu 0.50.0 → 0.51.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.
- package/dist/aontu.d.ts +4 -2
- package/dist/aontu.js +18 -2
- package/dist/aontu.js.map +1 -1
- package/dist/cli.js +33 -7
- package/dist/cli.js.map +1 -1
- package/dist/exactjson.d.ts +37 -0
- package/dist/exactjson.js +228 -0
- package/dist/exactjson.js.map +1 -0
- package/dist/hints.js +61 -4
- package/dist/hints.js.map +1 -1
- package/dist/keyorder.d.ts +9 -0
- package/dist/keyorder.js +65 -0
- package/dist/keyorder.js.map +1 -0
- package/dist/lang.js +200 -4
- package/dist/lang.js.map +1 -1
- package/dist/lsp.js +12 -2
- package/dist/lsp.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/val/BagVal.js +8 -5
- package/dist/val/BagVal.js.map +1 -1
- package/dist/val/BigDecimalVal.d.ts +13 -0
- package/dist/val/BigDecimalVal.js +80 -0
- package/dist/val/BigDecimalVal.js.map +1 -0
- package/dist/val/BigIntegerVal.d.ts +11 -0
- package/dist/val/BigIntegerVal.js +75 -0
- package/dist/val/BigIntegerVal.js.map +1 -0
- package/dist/val/Decimal.d.ts +32 -0
- package/dist/val/Decimal.js +318 -0
- package/dist/val/Decimal.js.map +1 -0
- package/dist/val/IntegerVal.d.ts +2 -0
- package/dist/val/IntegerVal.js +75 -3
- package/dist/val/IntegerVal.js.map +1 -1
- package/dist/val/KeyFuncVal.d.ts +1 -1
- package/dist/val/KeyFuncVal.js +33 -3
- package/dist/val/KeyFuncVal.js.map +1 -1
- package/dist/val/LowerFuncVal.js +20 -3
- package/dist/val/LowerFuncVal.js.map +1 -1
- package/dist/val/MapVal.js +6 -4
- package/dist/val/MapVal.js.map +1 -1
- package/dist/val/MoveFuncVal.js +25 -8
- package/dist/val/MoveFuncVal.js.map +1 -1
- package/dist/val/NumberVal.d.ts +1 -0
- package/dist/val/NumberVal.js +23 -2
- package/dist/val/NumberVal.js.map +1 -1
- package/dist/val/PathFuncVal.js +9 -1
- package/dist/val/PathFuncVal.js.map +1 -1
- package/dist/val/PlusOpVal.d.ts +3 -1
- package/dist/val/PlusOpVal.js +140 -29
- package/dist/val/PlusOpVal.js.map +1 -1
- package/dist/val/PrefVal.d.ts +2 -0
- package/dist/val/PrefVal.js +40 -4
- package/dist/val/PrefVal.js.map +1 -1
- package/dist/val/RefVal.js +57 -2
- package/dist/val/RefVal.js.map +1 -1
- package/dist/val/ScalarKindVal.d.ts +12 -2
- package/dist/val/ScalarKindVal.js +100 -11
- package/dist/val/ScalarKindVal.js.map +1 -1
- package/dist/val/ScalarVal.d.ts +1 -0
- package/dist/val/ScalarVal.js +16 -1
- package/dist/val/ScalarVal.js.map +1 -1
- package/dist/val/SuperFuncVal.d.ts +1 -1
- package/dist/val/SuperFuncVal.js +14 -1
- package/dist/val/SuperFuncVal.js.map +1 -1
- package/dist/val/UpperFuncVal.js +20 -3
- package/dist/val/UpperFuncVal.js.map +1 -1
- package/dist/val/VarVal.js +7 -1
- package/dist/val/VarVal.js.map +1 -1
- package/dist/val/numkind.d.ts +6 -0
- package/dist/val/numkind.js +224 -0
- package/dist/val/numkind.js.map +1 -0
- package/dist/val/valutil.d.ts +1 -0
- package/dist/val/valutil.js +35 -0
- package/dist/val/valutil.js.map +1 -1
- package/package.json +7 -7
- package/src/aontu.ts +23 -2
- package/src/cli.ts +36 -8
- package/src/exactjson.ts +254 -0
- package/src/hints.ts +73 -4
- package/src/keyorder.ts +73 -0
- package/src/lang.ts +229 -5
- package/src/lsp.ts +10 -2
- package/src/val/BagVal.ts +8 -5
- package/src/val/BigDecimalVal.ts +117 -0
- package/src/val/BigIntegerVal.ts +110 -0
- package/src/val/Decimal.ts +385 -0
- package/src/val/IntegerVal.ts +79 -3
- package/src/val/KeyFuncVal.ts +35 -3
- package/src/val/LowerFuncVal.ts +21 -4
- package/src/val/MapVal.ts +6 -4
- package/src/val/MoveFuncVal.ts +26 -9
- package/src/val/NumberVal.ts +25 -2
- package/src/val/PathFuncVal.ts +9 -1
- package/src/val/PlusOpVal.ts +168 -32
- package/src/val/PrefVal.ts +66 -5
- package/src/val/RefVal.ts +61 -2
- package/src/val/ScalarKindVal.ts +115 -10
- package/src/val/ScalarVal.ts +18 -1
- package/src/val/SuperFuncVal.ts +14 -1
- package/src/val/UpperFuncVal.ts +21 -4
- package/src/val/VarVal.ts +7 -1
- package/src/val/numkind.ts +256 -0
- package/src/val/valutil.ts +36 -0
package/dist/aontu.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Val, AontuOptions } from './type';
|
|
2
2
|
import { Lang } from './lang';
|
|
3
3
|
import { AontuContext, AontuContextConfig } from './ctx';
|
|
4
|
+
import { Decimal } from './val/Decimal';
|
|
5
|
+
import { exactJSON } from './exactjson';
|
|
4
6
|
import { formatExplain } from './utility';
|
|
5
7
|
import { AontuError } from './err';
|
|
6
|
-
declare const VERSION = "0.
|
|
8
|
+
declare const VERSION = "0.51.0";
|
|
7
9
|
declare class Aontu {
|
|
8
10
|
opts: AontuOptions;
|
|
9
11
|
lang: Lang;
|
|
@@ -17,5 +19,5 @@ declare function runparse(src: string, lang: Lang, ctx: AontuContext): Val;
|
|
|
17
19
|
declare const util: {
|
|
18
20
|
runparse: typeof runparse;
|
|
19
21
|
};
|
|
20
|
-
export { VERSION, Aontu, AontuOptions, AontuContext, AontuError, Val, Lang, runparse, util, formatExplain };
|
|
22
|
+
export { VERSION, Aontu, AontuOptions, AontuContext, AontuError, Val, Lang, runparse, util, formatExplain, exactJSON, Decimal, };
|
|
21
23
|
export default Aontu;
|
package/dist/aontu.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.formatExplain = exports.util = exports.Lang = exports.AontuError = exports.AontuContext = exports.Aontu = exports.VERSION = void 0;
|
|
4
|
+
exports.Decimal = exports.exactJSON = exports.formatExplain = exports.util = exports.Lang = exports.AontuError = exports.AontuContext = exports.Aontu = exports.VERSION = void 0;
|
|
5
5
|
exports.runparse = runparse;
|
|
6
6
|
const lang_1 = require("./lang");
|
|
7
7
|
Object.defineProperty(exports, "Lang", { enumerable: true, get: function () { return lang_1.Lang; } });
|
|
@@ -9,6 +9,10 @@ const unify_1 = require("./unify");
|
|
|
9
9
|
const ctx_1 = require("./ctx");
|
|
10
10
|
Object.defineProperty(exports, "AontuContext", { enumerable: true, get: function () { return ctx_1.AontuContext; } });
|
|
11
11
|
const MapVal_1 = require("./val/MapVal");
|
|
12
|
+
const Decimal_1 = require("./val/Decimal");
|
|
13
|
+
Object.defineProperty(exports, "Decimal", { enumerable: true, get: function () { return Decimal_1.Decimal; } });
|
|
14
|
+
const exactjson_1 = require("./exactjson");
|
|
15
|
+
Object.defineProperty(exports, "exactJSON", { enumerable: true, get: function () { return exactjson_1.exactJSON; } });
|
|
12
16
|
const utility_1 = require("./utility");
|
|
13
17
|
Object.defineProperty(exports, "formatExplain", { enumerable: true, get: function () { return utility_1.formatExplain; } });
|
|
14
18
|
const err_1 = require("./err");
|
|
@@ -20,7 +24,7 @@ Object.defineProperty(exports, "AontuError", { enumerable: true, get: function (
|
|
|
20
24
|
// Kept in step with package.json by the `version` npm lifecycle script,
|
|
21
25
|
// which runs on `npm version` / `npm run repo-bump`. version.test.ts
|
|
22
26
|
// fails if the two ever drift.
|
|
23
|
-
const VERSION = '0.
|
|
27
|
+
const VERSION = '0.51.0';
|
|
24
28
|
exports.VERSION = VERSION;
|
|
25
29
|
class Aontu {
|
|
26
30
|
constructor(popts) {
|
|
@@ -98,6 +102,18 @@ class Aontu {
|
|
|
98
102
|
return out;
|
|
99
103
|
}
|
|
100
104
|
// Generate output structure from source, which must parse and fully unify.
|
|
105
|
+
//
|
|
106
|
+
// The result is made of NATIVE values, and D9 puts two beyond what
|
|
107
|
+
// `JSON.stringify` can write: a `biginteger` (a `0d` literal with no
|
|
108
|
+
// fraction or exponent) generates as a native `bigint`, and a
|
|
109
|
+
// `bigdecimal` generates as a `Decimal`. Both are exact at any
|
|
110
|
+
// magnitude, which is the whole point of the leaves -- and both are
|
|
111
|
+
// confined to documents that opt in, so a `0d`-free document generates
|
|
112
|
+
// exactly what it always did.
|
|
113
|
+
//
|
|
114
|
+
// Serialise the result with `exactJSON` (exported alongside this
|
|
115
|
+
// class), NOT with `JSON.stringify`: the latter throws on a bigint and
|
|
116
|
+
// has no way to write exact digits as a JSON number.
|
|
101
117
|
generate(src, opts, ac) {
|
|
102
118
|
try {
|
|
103
119
|
let out = undefined;
|
package/dist/aontu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aontu.js","sourceRoot":"","sources":["../src/aontu.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;
|
|
1
|
+
{"version":3,"file":"aontu.js","sourceRoot":"","sources":["../src/aontu.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;QA6PvD,QAAQ;AAtPV,iCAA6B;qFAApB,WAAI;AACb,mCAA+B;AAC/B,+BAAwD;6FAA/C,kBAAY;AACrB,yCAAqC;AACrC,2CAAuC;wFAA9B,iBAAO;AAChB,2CAAuC;0FAA9B,qBAAS;AAClB,uCAAyC;8FAAhC,uBAAa;AACtB,+BAAuD;2FAAzB,gBAAU;AAGxC,wDAAwD;AACxD,8DAA8D;AAC9D,wDAAwD;AACxD,EAAE;AACF,wEAAwE;AACxE,qEAAqE;AACrE,+BAA+B;AAC/B,MAAM,OAAO,GAAG,QAAQ,CAAA;QA4NtB,OAAO;AAzNT,MAAM,KAAK;IAKT,YAAY,KAAoB;QAC9B,IAAI,CAAC,IAAI,GAAG,KAAK,IAAI,EAAE,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC;IAGD,wBAAwB;I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ACT,CAAA;QAcC,IAAI;kBAYS,KAAK"}
|
package/dist/cli.js
CHANGED
|
@@ -78,9 +78,15 @@ function version() {
|
|
|
78
78
|
// message. Never throws.
|
|
79
79
|
function evalSource(aontu, src, mode) {
|
|
80
80
|
try {
|
|
81
|
+
// exactJSON, not JSON.stringify: a document using the `0d` exact
|
|
82
|
+
// leaves generates bigints and Decimals, which JSON.stringify cannot
|
|
83
|
+
// write (D9). The CLI prints INDENTED JSON and the shared suite's
|
|
84
|
+
// `gens` mode prints COMPACT JSON, but both go through this one
|
|
85
|
+
// emitter -- an indent argument rather than a second implementation,
|
|
86
|
+
// so the two cannot drift from each other or from the Go port.
|
|
81
87
|
const text = 'canon' === mode
|
|
82
88
|
? aontu.unify(src).canon
|
|
83
|
-
:
|
|
89
|
+
: (0, aontu_1.exactJSON)(aontu.generate(src), 2);
|
|
84
90
|
return { ok: true, text };
|
|
85
91
|
}
|
|
86
92
|
catch (err) {
|
|
@@ -160,9 +166,29 @@ function runRepl(initialMode) {
|
|
|
160
166
|
});
|
|
161
167
|
rl.on('close', () => {
|
|
162
168
|
process.stdout.write('\n');
|
|
163
|
-
|
|
169
|
+
// Same reason as finish(): the REPL requires a TTY stdin, but stdout
|
|
170
|
+
// can still be a pipe (`aontu | cat`), so exiting outright could
|
|
171
|
+
// discard queued output here too.
|
|
172
|
+
process.exitCode = 0;
|
|
164
173
|
});
|
|
165
174
|
}
|
|
175
|
+
// Exit without truncating output.
|
|
176
|
+
//
|
|
177
|
+
// process.exit() terminates immediately, discarding anything still
|
|
178
|
+
// queued on stdout. A write to a PIPE is asynchronous once it exceeds
|
|
179
|
+
// the pipe buffer, so `write(big); exit(0)` silently truncated output at
|
|
180
|
+
// 65536 bytes — while a write to a TTY or a file, being synchronous,
|
|
181
|
+
// looked fine. Setting exitCode instead lets the process end naturally,
|
|
182
|
+
// after the queue drains.
|
|
183
|
+
//
|
|
184
|
+
// This predates the exact leaves but they make it trivially reachable
|
|
185
|
+
// (one long biginteger canon exceeds the buffer), and it lands squarely
|
|
186
|
+
// on the parity-probe discipline in AGENTS.md, which derives expected
|
|
187
|
+
// spec values by piping BOTH CLIs and comparing. A truncated pipe there
|
|
188
|
+
// reads as a port divergence.
|
|
189
|
+
function finish(code) {
|
|
190
|
+
process.exitCode = code;
|
|
191
|
+
}
|
|
166
192
|
function main(argv) {
|
|
167
193
|
let mode = 'json';
|
|
168
194
|
let file;
|
|
@@ -172,28 +198,28 @@ function main(argv) {
|
|
|
172
198
|
}
|
|
173
199
|
else if ('-h' === arg || '--help' === arg) {
|
|
174
200
|
process.stdout.write(HELP);
|
|
175
|
-
|
|
201
|
+
return finish(0);
|
|
176
202
|
}
|
|
177
203
|
else if ('-v' === arg || '--version' === arg) {
|
|
178
204
|
process.stdout.write(version() + '\n');
|
|
179
|
-
|
|
205
|
+
return finish(0);
|
|
180
206
|
}
|
|
181
207
|
else if (arg.startsWith('-')) {
|
|
182
208
|
process.stderr.write(`aontu: unknown option ${arg} (try --help)\n`);
|
|
183
|
-
|
|
209
|
+
return finish(2);
|
|
184
210
|
}
|
|
185
211
|
else {
|
|
186
212
|
file = arg;
|
|
187
213
|
}
|
|
188
214
|
}
|
|
189
215
|
if (null != file) {
|
|
190
|
-
|
|
216
|
+
finish(runFile(file, mode));
|
|
191
217
|
}
|
|
192
218
|
else if (process.stdin.isTTY) {
|
|
193
219
|
runRepl(mode);
|
|
194
220
|
}
|
|
195
221
|
else {
|
|
196
|
-
runStdin(mode).then((code) =>
|
|
222
|
+
runStdin(mode).then((code) => finish(code));
|
|
197
223
|
}
|
|
198
224
|
}
|
|
199
225
|
// Only run when invoked as a program, not when imported (e.g. by tests).
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AACA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot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AO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;SACI,CAAC;QACJ,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,CAAC;AACH,CAAC;AAGD,yEAAyE;AACzE,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialise a value produced by `Aontu.generate()` as JSON text,
|
|
3
|
+
* preserving EXACT numbers.
|
|
4
|
+
*
|
|
5
|
+
* Use this instead of `JSON.stringify` on generated output. A document
|
|
6
|
+
* that uses the `0d` exact leaves generates native `bigint` and
|
|
7
|
+
* `Decimal` values; `JSON.stringify` throws on the first and mangles the
|
|
8
|
+
* second, while this emitter writes both as raw JSON numbers with their
|
|
9
|
+
* exact digits -- which is what the D9 generate contract promises, and
|
|
10
|
+
* what the Go port's marshallers produce for the same document.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { Aontu, exactJSON } from 'aontu'
|
|
14
|
+
*
|
|
15
|
+
* const out = new Aontu().generate('x:0d9007199254740993')
|
|
16
|
+
* typeof out.x // 'bigint'
|
|
17
|
+
* exactJSON(out) // '{"x":9007199254740993}'
|
|
18
|
+
* exactJSON(out, 2) // '{\n "x": 9007199254740993\n}'
|
|
19
|
+
* JSON.stringify(out) // TypeError: Do not know how to serialize a BigInt
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param value The value to serialise -- normally `generate()` output:
|
|
23
|
+
* `null`, booleans, numbers, strings, `bigint`,
|
|
24
|
+
* `Decimal`, arrays and plain objects. An object with a
|
|
25
|
+
* `toJSON` method is asked for its replacement first
|
|
26
|
+
* (`Decimal` is handled as a number before that check).
|
|
27
|
+
* @param indent Optional indentation, with `JSON.stringify`'s `space`
|
|
28
|
+
* semantics: a number of spaces (clamped to 0..10) or a
|
|
29
|
+
* literal string. Omitted or `0` gives COMPACT output
|
|
30
|
+
* (no spaces, no newlines) -- the form the shared spec
|
|
31
|
+
* suite's `gens` mode compares byte for byte.
|
|
32
|
+
* @returns The JSON text. Unlike `JSON.stringify` this always
|
|
33
|
+
* returns a string: a top-level `undefined` is `null`.
|
|
34
|
+
* @throws {AontuError} if the value contains a reference cycle.
|
|
35
|
+
*/
|
|
36
|
+
declare function exactJSON(value: any, indent?: number | string): string;
|
|
37
|
+
export { exactJSON, };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2025 Richard Rodger, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.exactJSON = exactJSON;
|
|
5
|
+
/*
|
|
6
|
+
* D9 -- THE EXACT JSON EMITTER.
|
|
7
|
+
*
|
|
8
|
+
* `generate()` returns NATIVE values, and once a document opts into the
|
|
9
|
+
* exact leaves two of them are not things `JSON.stringify` can write: a
|
|
10
|
+
* biginteger generates as a native `bigint`, and a bigdecimal generates
|
|
11
|
+
* as a `Decimal`. `JSON.stringify` THROWS on a bigint ("Do not know how
|
|
12
|
+
* to serialize a BigInt") and a `replacer` cannot rescue it, because a
|
|
13
|
+
* replacer may only return another *value* -- everything it returns that
|
|
14
|
+
* is not already a JSON primitive gets quoted, so the exact digits could
|
|
15
|
+
* only come back as a JSON *string*, which is a different document.
|
|
16
|
+
*
|
|
17
|
+
* JSON itself was never the obstacle. A JSON number is arbitrary-
|
|
18
|
+
* precision decimal TEXT: `{"x":9007199254740993}` is a perfectly legal
|
|
19
|
+
* document that every conforming parser reads, and Go's `encoding/json`
|
|
20
|
+
* already emits exactly that for a `*big.Int`. Only JavaScript's
|
|
21
|
+
* serialiser stands in the way, so aontu ships its own.
|
|
22
|
+
*
|
|
23
|
+
* WHY THIS IS PUBLIC API and not a CLI internal: D9 promises that an
|
|
24
|
+
* exact value reaches JSON as exact digits. A library consumer whose
|
|
25
|
+
* document contains `0d9007199254740993` has no other supported way to
|
|
26
|
+
* keep that promise -- hiding the only implementation behind the command
|
|
27
|
+
* line would leave the contract unfulfillable from the library. The
|
|
28
|
+
* `aontu` CLI consumes this same export (with `indent`), and so does the
|
|
29
|
+
* shared suite's byte-exact `gens` mode, so there is exactly one set of
|
|
30
|
+
* bytes to keep in step with the Go port.
|
|
31
|
+
*
|
|
32
|
+
* PARITY WITH GO. The output must match Go's
|
|
33
|
+
* `json.Encoder` + `SetEscapeHTML(false)` (see specGens in
|
|
34
|
+
* go/spec_test.go) byte for byte:
|
|
35
|
+
*
|
|
36
|
+
* - Key order is the order `generate()` produced. Both ports already
|
|
37
|
+
* sort map keys (see the entries sort in BagVal.gen; Go's encoder
|
|
38
|
+
* sorts map keys), so neither has to sort again here.
|
|
39
|
+
* - Strings keep JavaScript's escaping, which is what the `gens` mode
|
|
40
|
+
* settled on when it turned Go's HTML escaping OFF so that `<`, `>`
|
|
41
|
+
* and `&` stay literal in both ports. U+2028/U+2029 are the one
|
|
42
|
+
* place JS and Go disagree by default -- Go escapes them, JS does
|
|
43
|
+
* not -- so they are escaped here too, which is both legal JSON and
|
|
44
|
+
* the safer output (it can be embedded in a JavaScript source).
|
|
45
|
+
* - Numbers keep JavaScript's `Number.prototype.toString` form, which
|
|
46
|
+
* is already what Go's encoder produces: fixed notation inside
|
|
47
|
+
* [1e-6, 1e21) and an unpadded, always-signed exponent outside it
|
|
48
|
+
* (`1e+21`, `1e-7`).
|
|
49
|
+
* - A bigint writes its digits; a Decimal writes its plain digit form
|
|
50
|
+
* (`1000.0`, `0.1`, `-1.5`) -- no `0d` marker, since that belongs to
|
|
51
|
+
* canon and is not JSON, but an integral bigdecimal keeps its `.0`
|
|
52
|
+
* so the JSON still shows a decimal. Go's `*Decimal.MarshalJSON`
|
|
53
|
+
* mirrors this.
|
|
54
|
+
*
|
|
55
|
+
* NOTE that byte-exact output CANNOT check the other half of D9: an
|
|
56
|
+
* integral bigdecimal and a biginteger can serialise to different text,
|
|
57
|
+
* but a biginteger and an ordinary integer serialise to the SAME text
|
|
58
|
+
* while `generate()` returned the wrong runtime type. Canon pins the AST
|
|
59
|
+
* kind, `gens` pins these bytes, and only the per-port API tests
|
|
60
|
+
* (ts/test/exactjson.test.ts here) pin the returned object.
|
|
61
|
+
*/
|
|
62
|
+
const Decimal_1 = require("./val/Decimal");
|
|
63
|
+
const err_1 = require("./err");
|
|
64
|
+
const keyorder_1 = require("./keyorder");
|
|
65
|
+
// JS leaves U+2028 (LINE SEPARATOR) and U+2029 (PARAGRAPH SEPARATOR)
|
|
66
|
+
// literal in a JSON string; Go's encoder escapes them. Byte parity wins.
|
|
67
|
+
const LSPS_RE = new RegExp('[\u2028\u2029]', 'g');
|
|
68
|
+
// JSON.stringify's `space` argument, normalised the way the spec does:
|
|
69
|
+
// a number is clamped to 0..10 spaces, a string is truncated to 10
|
|
70
|
+
// characters, anything else means "compact".
|
|
71
|
+
function indentUnit(indent) {
|
|
72
|
+
if ('number' === typeof indent) {
|
|
73
|
+
const n = Math.min(10, Math.floor(indent));
|
|
74
|
+
return 0 < n ? ' '.repeat(n) : '';
|
|
75
|
+
}
|
|
76
|
+
if ('string' === typeof indent) {
|
|
77
|
+
return indent.slice(0, 10);
|
|
78
|
+
}
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
function quote(s) {
|
|
82
|
+
const out = JSON.stringify(s);
|
|
83
|
+
// A raw separator can only appear as itself in the output (never
|
|
84
|
+
// inside an escape), so a straight replace is safe.
|
|
85
|
+
return out.replace(LSPS_RE, (c) => '\u2028' === c ? '\\u2028' : '\\u2029');
|
|
86
|
+
}
|
|
87
|
+
// True for a value JSON.stringify omits from an object and writes as
|
|
88
|
+
// `null` inside an array. generate() never produces one, but a consumer
|
|
89
|
+
// splicing its own data into the result might.
|
|
90
|
+
function skipped(v) {
|
|
91
|
+
return undefined === v || 'function' === typeof v || 'symbol' === typeof v;
|
|
92
|
+
}
|
|
93
|
+
// `seen` tracks the containers on the CURRENT path only (added on entry,
|
|
94
|
+
// removed on exit), so a shared subtree -- which unification can easily
|
|
95
|
+
// produce -- serialises fine and only a true cycle is refused, exactly
|
|
96
|
+
// as JSON.stringify does it.
|
|
97
|
+
function emit(v, unit, pad, seen) {
|
|
98
|
+
if (null === v) {
|
|
99
|
+
return 'null';
|
|
100
|
+
}
|
|
101
|
+
const t = typeof v;
|
|
102
|
+
if ('string' === t) {
|
|
103
|
+
return quote(v);
|
|
104
|
+
}
|
|
105
|
+
if ('number' === t) {
|
|
106
|
+
// JSON has no NaN, no Infinity and no negative zero: JSON.stringify
|
|
107
|
+
// writes `null` for the first two and `0` for the last, and gen()
|
|
108
|
+
// has already normalised -0 away (R2).
|
|
109
|
+
return JSON.stringify(v);
|
|
110
|
+
}
|
|
111
|
+
if ('bigint' === t) {
|
|
112
|
+
// THE POINT OF THIS MODULE: exact digits, as a raw JSON number.
|
|
113
|
+
return v.toString();
|
|
114
|
+
}
|
|
115
|
+
if ('boolean' === t) {
|
|
116
|
+
return v ? 'true' : 'false';
|
|
117
|
+
}
|
|
118
|
+
if (skipped(v)) {
|
|
119
|
+
return 'null';
|
|
120
|
+
}
|
|
121
|
+
// Before any other object handling: a Decimal is a value, not a
|
|
122
|
+
// structure, and its plain digit form is the JSON number.
|
|
123
|
+
if (v instanceof Decimal_1.Decimal) {
|
|
124
|
+
return v.toString();
|
|
125
|
+
}
|
|
126
|
+
if ('object' === t && 'function' === typeof v.toJSON) {
|
|
127
|
+
return emit(v.toJSON(), unit, pad, seen);
|
|
128
|
+
}
|
|
129
|
+
if (seen.has(v)) {
|
|
130
|
+
throw new err_1.AontuError('aontu: cannot convert circular structure to JSON');
|
|
131
|
+
}
|
|
132
|
+
seen.add(v);
|
|
133
|
+
const inner = pad + unit;
|
|
134
|
+
const nl = '' === unit ? '' : '\n';
|
|
135
|
+
let out;
|
|
136
|
+
if (Array.isArray(v)) {
|
|
137
|
+
if (0 === v.length) {
|
|
138
|
+
out = '[]';
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const parts = v.map((e) => inner + emit(skipped(e) ? null : e, unit, inner, seen));
|
|
142
|
+
out = '[' + nl + parts.join(',' + nl) + nl + pad + ']';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const colon = '' === unit ? ':' : ': ';
|
|
147
|
+
const parts = [];
|
|
148
|
+
// OWN enumerable keys, SORTED. A `for ... in` here would additionally
|
|
149
|
+
// walk the prototype chain.
|
|
150
|
+
//
|
|
151
|
+
// WHY THE SORT IS HERE AND NOT IN gen(). BagVal.gen already sorts map
|
|
152
|
+
// entries lexicographically -- and then writes them into a plain JS
|
|
153
|
+
// object, where ECMAScript throws that sort away. OrdinaryOwnPropertyKeys
|
|
154
|
+
// lists canonical ARRAY-INDEX keys first, in ascending NUMERIC order,
|
|
155
|
+
// and only then the remaining string keys in insertion order. So
|
|
156
|
+
// `{9:1,10:2}` came back out as 9 before 10, and `{"!":1,9:2}` put the
|
|
157
|
+
// digit key ahead of the punctuation one.
|
|
158
|
+
//
|
|
159
|
+
// This is not a V8 quirk and not a JSON.stringify quirk; it is the
|
|
160
|
+
// object's own key order, and it CANNOT be fixed upstream, because no
|
|
161
|
+
// JavaScript object can hold "10" before "9". The emitter is the last
|
|
162
|
+
// point that still has the freedom to choose, so it chooses here.
|
|
163
|
+
//
|
|
164
|
+
// The giveaway that it was never a design rule: only indices up to
|
|
165
|
+
// 2^32-2 are hoisted, so `{4294967295:1,4294967296:2,5:3}` emitted as
|
|
166
|
+
// 5, 4294967295, 4294967296 -- and TypeScript's own CANON, which builds
|
|
167
|
+
// text from a sorted list rather than from an object, was lexicographic
|
|
168
|
+
// all along. The port contradicted itself.
|
|
169
|
+
//
|
|
170
|
+
// Lexicographic by UTF-16 code unit, which is what `<` on JS strings
|
|
171
|
+
// does and what MapVal.canon/BagVal.gen already sort by. Go sorts map
|
|
172
|
+
// keys by UTF-8 byte, and the two orders agree on every key that stays
|
|
173
|
+
// inside the BMP; astral-plane keys are a separate, tracked divergence.
|
|
174
|
+
// CODE POINT order (cmpCodePoint), which is what Go's UTF-8 byte sort
|
|
175
|
+
// produces. A bare .sort() is UTF-16 code-unit order, which puts an
|
|
176
|
+
// astral key ahead of everything in U+E000-U+FFFF.
|
|
177
|
+
for (const k of Object.keys(v).sort(keyorder_1.cmpCodePoint)) {
|
|
178
|
+
const cv = v[k];
|
|
179
|
+
if (skipped(cv)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
parts.push(inner + quote(k) + colon + emit(cv, unit, inner, seen));
|
|
183
|
+
}
|
|
184
|
+
out = 0 === parts.length ? '{}' :
|
|
185
|
+
'{' + nl + parts.join(',' + nl) + nl + pad + '}';
|
|
186
|
+
}
|
|
187
|
+
seen.delete(v);
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Serialise a value produced by `Aontu.generate()` as JSON text,
|
|
192
|
+
* preserving EXACT numbers.
|
|
193
|
+
*
|
|
194
|
+
* Use this instead of `JSON.stringify` on generated output. A document
|
|
195
|
+
* that uses the `0d` exact leaves generates native `bigint` and
|
|
196
|
+
* `Decimal` values; `JSON.stringify` throws on the first and mangles the
|
|
197
|
+
* second, while this emitter writes both as raw JSON numbers with their
|
|
198
|
+
* exact digits -- which is what the D9 generate contract promises, and
|
|
199
|
+
* what the Go port's marshallers produce for the same document.
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { Aontu, exactJSON } from 'aontu'
|
|
203
|
+
*
|
|
204
|
+
* const out = new Aontu().generate('x:0d9007199254740993')
|
|
205
|
+
* typeof out.x // 'bigint'
|
|
206
|
+
* exactJSON(out) // '{"x":9007199254740993}'
|
|
207
|
+
* exactJSON(out, 2) // '{\n "x": 9007199254740993\n}'
|
|
208
|
+
* JSON.stringify(out) // TypeError: Do not know how to serialize a BigInt
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @param value The value to serialise -- normally `generate()` output:
|
|
212
|
+
* `null`, booleans, numbers, strings, `bigint`,
|
|
213
|
+
* `Decimal`, arrays and plain objects. An object with a
|
|
214
|
+
* `toJSON` method is asked for its replacement first
|
|
215
|
+
* (`Decimal` is handled as a number before that check).
|
|
216
|
+
* @param indent Optional indentation, with `JSON.stringify`'s `space`
|
|
217
|
+
* semantics: a number of spaces (clamped to 0..10) or a
|
|
218
|
+
* literal string. Omitted or `0` gives COMPACT output
|
|
219
|
+
* (no spaces, no newlines) -- the form the shared spec
|
|
220
|
+
* suite's `gens` mode compares byte for byte.
|
|
221
|
+
* @returns The JSON text. Unlike `JSON.stringify` this always
|
|
222
|
+
* returns a string: a top-level `undefined` is `null`.
|
|
223
|
+
* @throws {AontuError} if the value contains a reference cycle.
|
|
224
|
+
*/
|
|
225
|
+
function exactJSON(value, indent) {
|
|
226
|
+
return emit(value, indentUnit(indent), '', new Set());
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=exactjson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exactjson.js","sourceRoot":"","sources":["../src/exactjson.ts"],"names":[],"mappings":";AAAA,oDAAoD;;QA4PlD,SAAS;AA1PX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,2CAAuC;AACvC,+BAAkC;AAClC,yCAAyC;AAGzC,qEAAqE;AACrE,yEAAyE;AACzE,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;AAGjD,uEAAuE;AACvE,mEAAmE;AACnE,6CAA6C;AAC7C,SAAS,UAAU,CAAC,MAAmC;IACrD,IAAI,QAAQ,KAAK,OAAO,MAAM,EAAE,CAAC;QAC/B,MAAM,CAAC,G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,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;QACpE,CAAC;QACD,GAAG,GAAG,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC/B,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAA;IACpD,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAEd,OAAO,GAAG,CAAA;AACZ,CAAC;AAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAS,SAAS,CAAC,KAAU,EAAE,MAAwB;IACrD,OAAO,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,CAAA;AACvD,CAAC"}
|
package/dist/hints.js
CHANGED
|
@@ -15,12 +15,12 @@ const hints = {
|
|
|
15
15
|
' 1 & 1 -> 1 # Does unify (equal Integers);\n' +
|
|
16
16
|
' a & a -> a # Does unify (equal Strings);\n' +
|
|
17
17
|
' 1 & 2 -> nil # Does not unify (unequal Integers);\n' +
|
|
18
|
-
' 1 & 1.0 -> nil # Does not unify (kinds: Integer &
|
|
18
|
+
' 1 & 1.0 -> nil # Does not unify (kinds: Integer & Float).',
|
|
19
19
|
scalar_kind: 'Literal scalar values of different kinds cannot unify.' +
|
|
20
20
|
'\n \nExamples:\n' +
|
|
21
21
|
' 1 & 1 -> 1 # Does unify (equal Integers);\n' +
|
|
22
22
|
' 1 & a -> nil # Does not unify (Kinds: Integer & String);\n' +
|
|
23
|
-
' 1 & 1.0 -> nil # Does not unify (kinds: Integer &
|
|
23
|
+
' 1 & 1.0 -> nil # Does not unify (kinds: Integer & Float).',
|
|
24
24
|
nil_gen: 'The nil value was present after unification, and nil cannot be\n' +
|
|
25
25
|
'generated because nil is not a literal value.',
|
|
26
26
|
no_gen: 'This value was present after unification, and cannot be generated\n' +
|
|
@@ -51,14 +51,71 @@ const hints = {
|
|
|
51
51
|
'unite': 'Failed to unite two values. The values are incompatible and cannot be unified.',
|
|
52
52
|
'internal': 'Internal error during unification. This indicates an unexpected error in the unification process.',
|
|
53
53
|
// Type mismatch errors
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
decimal_budget: 'This exact decimal exceeds the exactness budget: at most 4096\n' +
|
|
55
|
+
'coefficient digits and an absolute scale of at most 4096. The\n' +
|
|
56
|
+
'budget applies to computed results as well as to literals.\n' +
|
|
57
|
+
'Aontu never rounds, so a value beyond the budget is refused\n' +
|
|
58
|
+
'rather than approximated.' +
|
|
59
|
+
'\n \nExamples:\n' +
|
|
60
|
+
' 0d1e1000000000 -> nil # Scale far beyond the budget;\n' +
|
|
61
|
+
' 0d1e4000+0d1e-4000 -> nil # An exact sum too wide to hold;\n' +
|
|
62
|
+
' 0d1e-1 -> 0d0.1 # Well within it.',
|
|
63
|
+
lossy_integer_literal: 'This integer literal, {src}, is not exactly representable in\n' +
|
|
64
|
+
'binary64, so storing it would silently round it to a DIFFERENT\n' +
|
|
65
|
+
'number. Aontu refuses rather than corrupts: write it as a `0d`\n' +
|
|
66
|
+
'literal to get the exact integer.\n' +
|
|
67
|
+
'The rule is exactness, not magnitude -- a literal far outside the\n' +
|
|
68
|
+
'int64 window is still a value when it lands exactly on a binary64.' +
|
|
69
|
+
'\n \nExamples:\n' +
|
|
70
|
+
' 9007199254740992 -> 9007199254740992 # 2^53, exact;\n' +
|
|
71
|
+
' 9007199254740993 -> nil # 2^53+1 is not;\n' +
|
|
72
|
+
' 0d9007199254740993 -> 0d9007199254740993 # ... the exact escape;\n' +
|
|
73
|
+
' 0x7fffffffffffffff -> nil # 2^63-1 rounds up to 2^63;\n' +
|
|
74
|
+
' 100000000000000000000 -> 1e20 # 10^20 is huge and exact.',
|
|
75
|
+
exact_float_mix: 'Aontu cannot mix an exact number with a binary float.\n' +
|
|
76
|
+
'Here the operands are {left} and {right}, in that order.\n' +
|
|
77
|
+
'A big type never silently becomes a binary float, in either\n' +
|
|
78
|
+
'operand order -- binary64 cannot hold every exact value, so the\n' +
|
|
79
|
+
'promotion would throw away the exactness the `0d` leaves exist to\n' +
|
|
80
|
+
'guarantee. Write both operands in the same family (`0d1.0` for the\n' +
|
|
81
|
+
'float, or a plain integer for the big).' +
|
|
82
|
+
'\n \nExamples:\n' +
|
|
83
|
+
' 0d2 + 0d0.5 -> 0d2.5 # Exact with exact (widest leaf wins);\n' +
|
|
84
|
+
' 1 + 0d0.5 -> 0d1.5 # integer is on the exact ladder;\n' +
|
|
85
|
+
' 1 + 2.0 -> 3.0 # ... and float still mixes with integer;\n' +
|
|
86
|
+
' 1.0 + 0d2 -> nil # float with biginteger;\n' +
|
|
87
|
+
' 0d0.5 + 1.0 -> nil # ... and the same the other way round.',
|
|
88
|
+
inexact_integer_sum: 'The `integer` leaf holds a value only when it is integral, within\n' +
|
|
89
|
+
'the int64 range, and exactly representable in binary64. This sum\n' +
|
|
90
|
+
'is not: {sum}.\n' +
|
|
91
|
+
'Aontu adds integers exactly and refuses to store a rounded answer\n' +
|
|
92
|
+
'-- write `0d<digits>` for an exact integer beyond that window.' +
|
|
93
|
+
'\n \nExamples:\n' +
|
|
94
|
+
' 4503599627370496 + 4503599627370496 -> 9007199254740992 # Exact;\n' +
|
|
95
|
+
' 4503599627370496 + 4503599627370497 -> nil # 2^53+1 is not;\n' +
|
|
96
|
+
' 0d4503599627370496 + 0d4503599627370497 -> 0d9007199254740993.',
|
|
97
|
+
'scalar-type': 'Scalar kinds only unify when one contains the other. `number` is\n' +
|
|
98
|
+
'the supertype of the numeric leaves (integer, float, biginteger,\n' +
|
|
99
|
+
'bigdecimal), so meeting it with a leaf gives that leaf; two distinct\n' +
|
|
100
|
+
'leaves describe disjoint sets of values and so have no common lower\n' +
|
|
101
|
+
'bound.' +
|
|
102
|
+
'\n \nExamples:\n' +
|
|
103
|
+
' number & integer -> integer # Does unify (integer is a number);\n' +
|
|
104
|
+
' number & number -> number # Does unify (same kind);\n' +
|
|
105
|
+
' float & integer -> nil # Does not unify (disjoint leaves).',
|
|
106
|
+
'no_scalar_unify': 'Cannot unify scalar values. The scalar values have incompatible types.' +
|
|
107
|
+
'\n \nExamples:\n' +
|
|
108
|
+
' number & 1 -> 1 # Does unify (1 is a number);\n' +
|
|
109
|
+
' integer & 1 -> 1 # Does unify (1 is an integer);\n' +
|
|
110
|
+
' float & 1 -> nil # Does not unify (1 is an integer, not a float);\n' +
|
|
111
|
+
' integer & 1.5 -> nil # Does not unify (1.5 is a float, not an integer).',
|
|
56
112
|
'not-scalar-type': 'Expected a scalar type but got a non-scalar type.',
|
|
57
113
|
'map': 'Type mismatch: expected a map value but got a different type.',
|
|
58
114
|
'list': 'Type mismatch: expected a list value but got a different type.',
|
|
59
115
|
// Argument errors
|
|
60
116
|
'arg': 'Missing required argument. A function requires an argument but none was provided.',
|
|
61
117
|
'invalid-arg': 'Invalid argument provided. The argument does not match the expected type or format.',
|
|
118
|
+
'key_level': 'The argument to key() is a LEVEL: how many steps up the path to look, where 0 is the key of the value itself and the default 1 is its parent. It must therefore be an integer -- `key(2)`, or `key(0d2)` for the exact leaf. A float, a decimal, a string, a boolean, a map or a list is not a level. A level beyond the top of the path is not an error; it yields the empty string.',
|
|
62
119
|
'no_first_arg': 'Missing first argument. The function requires a first argument but none was provided.',
|
|
63
120
|
// Variable errors
|
|
64
121
|
'unknown_var': 'Unknown variable reference. The variable has not been defined.',
|
package/dist/hints.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hints.js","sourceRoot":"","sources":["../src/hints.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;AAEpD;;;;;GAKG;AAEH,MAAM,KAAK,GAA2B;IAEpC,YAAY,EACV,qEAAqE;QAC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S,EAAE,+DAA+D;IAC1E,cAAc,EAAE,kFAAkF;IAElG,WAAW,EAAE,8CAA8C;IAE3D,qCAAqC;IACrC,MAAM,EAAE,wEAAwE;IAChF,MAAM,EAAE,iFAAiF;IACzF,SAAS,EAAE,wFAAwF;IACnG,SAAS,EAAE,6EAA6E;IAExF,qCAAqC;IACrC,IAAI,EAAE,wEAAwE;IAE9E,kBAAkB;IAClB,OAAO,EAAE,+DAA+D;IAExE,6CAA6C;IAC7C,OAAO,EAAE,kBAAkB;IAC3B,KAAK,EAAE,kBAAkB;IACzB,MAAM,EAAE,uBAAuB;IAC/B,MAAM,EAAE,mBAAmB;IAC3B,KAAK,EAAE,wBAAwB;CAChC,CAAA;QAIC,KAAK"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare two map keys by Unicode CODE POINT.
|
|
3
|
+
*
|
|
4
|
+
* `String.prototype[Symbol.iterator]` yields whole code points, pairing
|
|
5
|
+
* surrogates, so this is a plain lexicographic compare of code point
|
|
6
|
+
* sequences -- the order Go's UTF-8 byte sort produces.
|
|
7
|
+
*/
|
|
8
|
+
declare function cmpCodePoint(a: string, b: string): number;
|
|
9
|
+
export { cmpCodePoint, };
|