@tabnas/transduce 0.2.12 → 0.4.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/routers.js +0 -13
- package/dist/routers.js.map +1 -1
- package/dist/transduce.d.ts +3 -4
- package/dist/transduce.js +4 -9
- package/dist/transduce.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/routers.ts +7 -31
- package/src/transduce.ts +5 -18
- package/dist/transduce-tree.d.ts +0 -16
- package/dist/transduce-tree.js +0 -234
- package/dist/transduce-tree.js.map +0 -1
- package/src/transduce-tree.ts +0 -226
package/dist/routers.js
CHANGED
|
@@ -5,29 +5,16 @@ exports.routers = void 0;
|
|
|
5
5
|
const guard_1 = require("./guard");
|
|
6
6
|
const route_1 = require("./route");
|
|
7
7
|
const scan_1 = require("./scan");
|
|
8
|
-
const table_from_json_1 = require("./table-from-json");
|
|
9
|
-
const transduce_tree_1 = require("./transduce-tree");
|
|
10
8
|
// Each method constructs the stage it names with the same parameters.
|
|
11
9
|
exports.routers = Object.freeze({
|
|
12
10
|
router(specs, limits, duplicates, metrics, downstream) {
|
|
13
11
|
return new route_1.Router(specs, limits, duplicates, metrics, downstream);
|
|
14
12
|
},
|
|
15
|
-
tableFromJson(binding, limits, duplicates, metrics, sink) {
|
|
16
|
-
return new table_from_json_1.TableFromJson(binding, limits, duplicates, metrics, sink);
|
|
17
|
-
},
|
|
18
13
|
scanEmit(initial, step, finish, out) {
|
|
19
14
|
return new scan_1.ScanEmit(initial, step, finish, out);
|
|
20
15
|
},
|
|
21
16
|
guarded(inner, limits, abort, metrics) {
|
|
22
17
|
return new guard_1.Guarded(inner, limits, abort, metrics);
|
|
23
18
|
},
|
|
24
|
-
transduceTree(spec, downstream) {
|
|
25
|
-
return new transduce_tree_1.TransduceTree(spec, downstream);
|
|
26
|
-
},
|
|
27
|
-
// TransduceTree reads a spec's `:member` and `:text`, and holds a text to
|
|
28
|
-
// the spec's `maxTextBytes` as it grows.
|
|
29
|
-
transduceTreeReadsMemberAndText() {
|
|
30
|
-
return true;
|
|
31
|
-
},
|
|
32
19
|
});
|
|
33
20
|
//# sourceMappingURL=routers.js.map
|
package/dist/routers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routers.js","sourceRoot":"","sources":["../src/routers.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;
|
|
1
|
+
{"version":3,"file":"routers.js","sourceRoot":"","sources":["../src/routers.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;AAyB5C,mCAAiC;AACjC,mCAAgC;AAChC,iCAAiC;AAEjC,sEAAsE;AACzD,QAAA,OAAO,GAAY,MAAM,CAAC,MAAM,CAAC;IAC5C,MAAM,CACJ,KAA6B,EAC7B,MAAc,EACd,UAAsB,EACtB,OAAgB,EAChB,UAAqB;QAErB,OAAO,IAAI,cAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;IACnE,CAAC;IAED,QAAQ,CACN,OAAU,EACV,IAA6C,EAC7C,MAAyB,EACzB,GAAwB;QAExB,OAAO,IAAI,eAAQ,CAAU,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1D,CAAC;IAED,OAAO,CAAC,KAAW,EAAE,MAAc,EAAE,KAAgB,EAAE,OAAgB;QACrE,OAAO,IAAI,eAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IACnD,CAAC;CACF,CAAC,CAAA"}
|
package/dist/transduce.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.4.0";
|
|
2
2
|
export { Datum, DatumBuilder, byteSize, fromJSON, fromTabnas, getPath, takePath, toJSON, toText, walkDatum, } from '@tabnas/alchemy/shared';
|
|
3
3
|
export type { Duplicates } from '@tabnas/alchemy/shared';
|
|
4
4
|
export { Code, Fail, isFail } from '@tabnas/alchemy/shared';
|
|
@@ -24,9 +24,8 @@ export type { Source } from './source';
|
|
|
24
24
|
export { Guarded } from './guard';
|
|
25
25
|
export { ParserSource } from './parser-source';
|
|
26
26
|
export { ParserEventSource } from './parser-event-source';
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export type { ParserEvent, ParserSink, PassAlt, PassToken, RulePass, TreeContainer, TreeKey, TreeRule, TreeScalar, TreeSpec, } from '@tabnas/alchemy/shared';
|
|
27
|
+
export { parserEventFromJSON, parserEventToJSON } from '@tabnas/alchemy/shared';
|
|
28
|
+
export type { ParserEvent, ParserSink, PassAlt, PassToken, RulePass } from '@tabnas/alchemy/shared';
|
|
30
29
|
export { DEFAULT_CHUNK_BYTES, LineFormat, LinesSource } from './lines';
|
|
31
30
|
export type { LinesChunk, LinesInput, LinesWriter } from './lines';
|
|
32
31
|
export { INCREMENTAL, PRUNABLE, capability, isIncremental, isPrunable } from './capability';
|
package/dist/transduce.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* Copyright (c) 2026 tabnas, MIT License */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.engineFailure = exports.ValueSource = exports.SourceMode = exports.Prune = exports.replay = exports.TreeContract = exports.FnSink = exports.EventRecorder = exports.CountSink = exports.pathText = exports.keyText = exports.Selector = exports.Path = exports.Transition = exports.ScanEmit = exports.CaptureSpec = exports.SelectedRecorder = exports.Router = exports.FnRoute = exports.Matcher = exports.utf8Bytes = exports.NODE_BYTES = exports.Metrics = exports.Limits = exports.LIMIT_NAMES = exports.AbortFlag = exports.numberText = exports.jsonString = exports.jsonNumber = exports.isJsonNumber = exports.isStart = exports.isScalar = exports.isEnd = exports.eventText = exports.eventEquals = exports.Ev = exports.isFail = exports.Fail = exports.Code = exports.walkDatum = exports.toText = exports.toJSON = exports.takePath = exports.getPath = exports.fromTabnas = exports.fromJSON = exports.byteSize = exports.DatumBuilder = exports.Datum = exports.VERSION = void 0;
|
|
5
|
-
exports.routers = exports.TableFromJson = exports.columnFromMeta = exports.boundColumn = exports.Table = exports.Schema = exports.Cell = exports.isPrunable = exports.isIncremental = exports.capability = exports.PRUNABLE = exports.INCREMENTAL = exports.LinesSource = exports.LineFormat = exports.DEFAULT_CHUNK_BYTES = exports.
|
|
5
|
+
exports.routers = exports.TableFromJson = exports.columnFromMeta = exports.boundColumn = exports.Table = exports.Schema = exports.Cell = exports.isPrunable = exports.isIncremental = exports.capability = exports.PRUNABLE = exports.INCREMENTAL = exports.LinesSource = exports.LineFormat = exports.DEFAULT_CHUNK_BYTES = exports.parserEventToJSON = exports.parserEventFromJSON = exports.ParserEventSource = exports.ParserSource = exports.Guarded = exports.walkValue = void 0;
|
|
6
6
|
// Streaming transducers over any tabnas parser.
|
|
7
7
|
//
|
|
8
8
|
// A transducer decides what a source contributes to an output model; a
|
|
@@ -14,9 +14,8 @@ exports.routers = exports.TableFromJson = exports.columnFromMeta = exports.bound
|
|
|
14
14
|
// - sources that produce it from a parsed value, from a live tabnas parse
|
|
15
15
|
// through the engine's rule events, or from line-delimited input, and
|
|
16
16
|
// the source of the parser's rule passes themselves (`ParserEventSource`,
|
|
17
|
-
// `ParserEvents/1`), what a transducer part reads
|
|
18
|
-
//
|
|
19
|
-
// passes;
|
|
17
|
+
// `ParserEvents/1`), what a transducer part reads (the part is alchemy's
|
|
18
|
+
// text, which alchemy's runtime runs over them);
|
|
20
19
|
// - `Selector`s and the matcher and router that recognize selected scopes
|
|
21
20
|
// in one pass and materialize them under a byte limit;
|
|
22
21
|
// - the table protocol `TableEvent` (`TableRows/1`) and the standard
|
|
@@ -34,7 +33,7 @@ exports.routers = exports.TableFromJson = exports.columnFromMeta = exports.bound
|
|
|
34
33
|
// under the names it always exported them by. `routers` is this package's
|
|
35
34
|
// stages as alchemy's `Routers`, for a host to pass to alchemy's `compile`.
|
|
36
35
|
// This package's version, as package.json declares it.
|
|
37
|
-
exports.VERSION = '0.
|
|
36
|
+
exports.VERSION = '0.4.0';
|
|
38
37
|
var shared_1 = require("@tabnas/alchemy/shared");
|
|
39
38
|
Object.defineProperty(exports, "Datum", { enumerable: true, get: function () { return shared_1.Datum; } });
|
|
40
39
|
Object.defineProperty(exports, "DatumBuilder", { enumerable: true, get: function () { return shared_1.DatumBuilder; } });
|
|
@@ -104,13 +103,9 @@ var parser_source_1 = require("./parser-source");
|
|
|
104
103
|
Object.defineProperty(exports, "ParserSource", { enumerable: true, get: function () { return parser_source_1.ParserSource; } });
|
|
105
104
|
var parser_event_source_1 = require("./parser-event-source");
|
|
106
105
|
Object.defineProperty(exports, "ParserEventSource", { enumerable: true, get: function () { return parser_event_source_1.ParserEventSource; } });
|
|
107
|
-
var transduce_tree_1 = require("./transduce-tree");
|
|
108
|
-
Object.defineProperty(exports, "TransduceTree", { enumerable: true, get: function () { return transduce_tree_1.TransduceTree; } });
|
|
109
106
|
var shared_10 = require("@tabnas/alchemy/shared");
|
|
110
|
-
Object.defineProperty(exports, "isTreeContainer", { enumerable: true, get: function () { return shared_10.isTreeContainer; } });
|
|
111
107
|
Object.defineProperty(exports, "parserEventFromJSON", { enumerable: true, get: function () { return shared_10.parserEventFromJSON; } });
|
|
112
108
|
Object.defineProperty(exports, "parserEventToJSON", { enumerable: true, get: function () { return shared_10.parserEventToJSON; } });
|
|
113
|
-
Object.defineProperty(exports, "treeTextRefusal", { enumerable: true, get: function () { return shared_10.treeTextRefusal; } });
|
|
114
109
|
var lines_1 = require("./lines");
|
|
115
110
|
Object.defineProperty(exports, "DEFAULT_CHUNK_BYTES", { enumerable: true, get: function () { return lines_1.DEFAULT_CHUNK_BYTES; } });
|
|
116
111
|
Object.defineProperty(exports, "LineFormat", { enumerable: true, get: function () { return lines_1.LineFormat; } });
|
package/dist/transduce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transduce.js","sourceRoot":"","sources":["../src/transduce.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;;AAE5C,gDAAgD;AAChD,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,mBAAmB;AACnB,EAAE;AACF,2EAA2E;AAC3E,YAAY;AACZ,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"transduce.js","sourceRoot":"","sources":["../src/transduce.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;;AAE5C,gDAAgD;AAChD,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,mBAAmB;AACnB,EAAE;AACF,2EAA2E;AAC3E,YAAY;AACZ,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,2EAA2E;AAC3E,mDAAmD;AACnD,0EAA0E;AAC1E,yDAAyD;AACzD,qEAAqE;AACrE,qCAAqC;AACrC,0EAA0E;AAC1E,mBAAmB;AACnB,EAAE;AACF,uEAAuE;AACvE,yEAAyE;AACzE,gEAAgE;AAChE,EAAE;AACF,wEAAwE;AACxE,6DAA6D;AAC7D,wEAAwE;AACxE,0EAA0E;AAC1E,4EAA4E;AAE5E,uDAAuD;AAC1C,QAAA,OAAO,GAAG,OAAO,CAAA;AAE9B,iDAW+B;AAV7B,+FAAA,KAAK,OAAA;AACL,sGAAA,YAAY,OAAA;AACZ,kGAAA,QAAQ,OAAA;AACR,kGAAA,QAAQ,OAAA;AACR,oGAAA,UAAU,OAAA;AACV,iGAAA,OAAO,OAAA;AACP,kGAAA,QAAQ,OAAA;AACR,gGAAA,MAAM,OAAA;AACN,gGAAA,MAAM,OAAA;AACN,mGAAA,SAAS,OAAA;AAGX,iDAA2D;AAAlD,8FAAA,IAAI,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,gGAAA,MAAM,OAAA;AAE3B,iDAA6F;AAApF,4FAAA,EAAE,OAAA;AAAE,qGAAA,WAAW,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,+FAAA,KAAK,OAAA;AAAE,kGA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AAE,mGAAA,UAAU,OAAA;AAAE,oGAAA,WAAW,OAAA;AAErD,2CAA2F;AAAlF,yGAAA,WAAW,OAAA;AAAE,sGAAA,QAAQ,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,2GAAA,aAAa,OAAA;AAAE,wGAAA,UAAU,OAAA;AACrE,kDAAyF;AAAhF,+FAAA,IAAI,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,gGAAA,KAAK,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,yGAAA,cAAc,OAAA;AAUzD,qDAAiD;AAAxC,gHAAA,aAAa,OAAA;AACtB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"7.0.2","root":["../src/capability.ts","../src/guard.ts","../src/lines.ts","../src/matcher.ts","../src/parser-event-source.ts","../src/parser-source.ts","../src/route.ts","../src/routers.ts","../src/rule-events.ts","../src/scan.ts","../src/source.ts","../src/table-from-json.ts","../src/transduce
|
|
1
|
+
{"version":"7.0.2","root":["../src/capability.ts","../src/guard.ts","../src/lines.ts","../src/matcher.ts","../src/parser-event-source.ts","../src/parser-source.ts","../src/route.ts","../src/routers.ts","../src/rule-events.ts","../src/scan.ts","../src/source.ts","../src/table-from-json.ts","../src/transduce.ts"],"packageJsons":["../node_modules/@tabnas/alchemy/package.json","../node_modules/@tabnas/csv/package.json","../node_modules/@tabnas/json/package.json","../node_modules/@tabnas/jsonic/package.json","../node_modules/@tabnas/parser/package.json","../node_modules/@types/node/package.json","../node_modules/undici-types/package.json","../package.json"],"missingPackageJsons":["../node_modules/@tabnas/alchemy/dist/package.json","../node_modules/@tabnas/alchemy/dist/shared/package.json","../node_modules/@tabnas/alchemy/shared/package.json","../node_modules/@tabnas/csv/dist/package.json","../node_modules/@tabnas/json/dist/package.json","../node_modules/@tabnas/parser/dist/package.json","../node_modules/@types/assert/package.json","../node_modules/@types/assert/strict/package.json","../node_modules/@types/async_hooks/package.json","../node_modules/@types/buffer/package.json","../node_modules/@types/child_process/package.json","../node_modules/@types/cluster/package.json","../node_modules/@types/console/package.json","../node_modules/@types/constants/package.json","../node_modules/@types/crypto/package.json","../node_modules/@types/dgram/package.json","../node_modules/@types/diagnostics_channel/package.json","../node_modules/@types/dns/package.json","../node_modules/@types/dns/promises/package.json","../node_modules/@types/domain/package.json","../node_modules/@types/events/package.json","../node_modules/@types/fs/package.json","../node_modules/@types/fs/promises/package.json","../node_modules/@types/http/package.json","../node_modules/@types/http2/package.json","../node_modules/@types/https/package.json","../node_modules/@types/inspector/package.json","../node_modules/@types/inspector/promises/package.json","../node_modules/@types/module/package.json","../node_modules/@types/net/package.json","../node_modules/@types/node/assert/package.json","../node_modules/@types/node/dns/package.json","../node_modules/@types/node/fs/package.json","../node_modules/@types/node/inspector/package.json","../node_modules/@types/node/path/package.json","../node_modules/@types/node/readline/package.json","../node_modules/@types/node/stream/package.json","../node_modules/@types/node/test/package.json","../node_modules/@types/node/timers/package.json","../node_modules/@types/node/util/package.json","../node_modules/@types/node/web-globals/package.json","../node_modules/@types/node/zlib/package.json","../node_modules/@types/os/package.json","../node_modules/@types/path/package.json","../node_modules/@types/path/posix/package.json","../node_modules/@types/path/win32/package.json","../node_modules/@types/perf_hooks/package.json","../node_modules/@types/process/package.json","../node_modules/@types/punycode/package.json","../node_modules/@types/querystring/package.json","../node_modules/@types/readline/package.json","../node_modules/@types/readline/promises/package.json","../node_modules/@types/repl/package.json","../node_modules/@types/stream/consumers/package.json","../node_modules/@types/stream/iter/package.json","../node_modules/@types/stream/package.json","../node_modules/@types/stream/promises/package.json","../node_modules/@types/stream/web/package.json","../node_modules/@types/string_decoder/package.json","../node_modules/@types/timers/package.json","../node_modules/@types/timers/promises/package.json","../node_modules/@types/tls/package.json","../node_modules/@types/trace_events/package.json","../node_modules/@types/tty/package.json","../node_modules/@types/url/package.json","../node_modules/@types/util/package.json","../node_modules/@types/util/types/package.json","../node_modules/@types/v8/package.json","../node_modules/@types/vm/package.json","../node_modules/@types/wasi/package.json","../node_modules/@types/worker_threads/package.json","../node_modules/@types/zlib/package.json","../node_modules/assert/package.json","../node_modules/assert/strict/package.json","../node_modules/async_hooks/package.json","../node_modules/buffer/package.json","../node_modules/child_process/package.json","../node_modules/cluster/package.json","../node_modules/console/package.json","../node_modules/constants/package.json","../node_modules/crypto/package.json","../node_modules/dgram/package.json","../node_modules/diagnostics_channel/package.json","../node_modules/dns/package.json","../node_modules/dns/promises/package.json","../node_modules/domain/package.json","../node_modules/events/package.json","../node_modules/fs/package.json","../node_modules/fs/promises/package.json","../node_modules/http/package.json","../node_modules/http2/package.json","../node_modules/https/package.json","../node_modules/inspector/package.json","../node_modules/inspector/promises/package.json","../node_modules/module/package.json","../node_modules/net/package.json","../node_modules/os/package.json","../node_modules/path/package.json","../node_modules/path/posix/package.json","../node_modules/path/win32/package.json","../node_modules/perf_hooks/package.json","../node_modules/process/package.json","../node_modules/punycode/package.json","../node_modules/querystring/package.json","../node_modules/readline/package.json","../node_modules/readline/promises/package.json","../node_modules/repl/package.json","../node_modules/stream/consumers/package.json","../node_modules/stream/iter/package.json","../node_modules/stream/package.json","../node_modules/stream/promises/package.json","../node_modules/stream/web/package.json","../node_modules/string_decoder/package.json","../node_modules/timers/package.json","../node_modules/timers/promises/package.json","../node_modules/tls/package.json","../node_modules/trace_events/package.json","../node_modules/tty/package.json","../node_modules/url/package.json","../node_modules/util/package.json","../node_modules/util/types/package.json","../node_modules/v8/package.json","../node_modules/vm/package.json","../node_modules/wasi/package.json","../node_modules/worker_threads/package.json","../node_modules/zlib/package.json"]}
|
package/package.json
CHANGED
package/src/routers.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/* Copyright (c) 2026 tabnas, MIT License */
|
|
2
2
|
|
|
3
3
|
// This package's stages as alchemy's `Routers`: what an alchemy program's
|
|
4
|
-
// runtime builds its routes,
|
|
5
|
-
// `
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// `
|
|
4
|
+
// runtime builds its routes, scans and guards from. Alchemy declares the
|
|
5
|
+
// interface (`@tabnas/alchemy/shared`) and imports no transducer; a host
|
|
6
|
+
// passes `routers` to its `compile`, with render's `renderers`:
|
|
7
|
+
// `compile(src, file, { routers, renderers })`. The standard library's
|
|
8
|
+
// `table-from-json`, `csv`, `transduce-tree` and `transduce-records` are
|
|
9
|
+
// alchemy's own text, run by its interpreter over these stages in every
|
|
10
|
+
// runtime; this package offers nothing in their place.
|
|
9
11
|
|
|
10
12
|
import {
|
|
11
13
|
AbortFlag,
|
|
@@ -14,22 +16,16 @@ import {
|
|
|
14
16
|
Flow,
|
|
15
17
|
Limits,
|
|
16
18
|
Metrics,
|
|
17
|
-
ParserSink,
|
|
18
19
|
RouteSink,
|
|
19
20
|
Routers,
|
|
20
21
|
Scan,
|
|
21
22
|
Sink,
|
|
22
|
-
TableBinding,
|
|
23
|
-
TableSink,
|
|
24
23
|
Transition,
|
|
25
|
-
TreeSpec,
|
|
26
24
|
} from '@tabnas/alchemy/shared'
|
|
27
25
|
|
|
28
26
|
import { Guarded } from './guard'
|
|
29
27
|
import { Router } from './route'
|
|
30
28
|
import { ScanEmit } from './scan'
|
|
31
|
-
import { TableFromJson } from './table-from-json'
|
|
32
|
-
import { TransduceTree } from './transduce-tree'
|
|
33
29
|
|
|
34
30
|
// Each method constructs the stage it names with the same parameters.
|
|
35
31
|
export const routers: Routers = Object.freeze({
|
|
@@ -43,16 +39,6 @@ export const routers: Routers = Object.freeze({
|
|
|
43
39
|
return new Router(specs, limits, duplicates, metrics, downstream)
|
|
44
40
|
},
|
|
45
41
|
|
|
46
|
-
tableFromJson(
|
|
47
|
-
binding: TableBinding,
|
|
48
|
-
limits: Limits,
|
|
49
|
-
duplicates: Duplicates,
|
|
50
|
-
metrics: Metrics,
|
|
51
|
-
sink: TableSink,
|
|
52
|
-
): Sink {
|
|
53
|
-
return new TableFromJson(binding, limits, duplicates, metrics, sink)
|
|
54
|
-
},
|
|
55
|
-
|
|
56
42
|
scanEmit<S, I, O>(
|
|
57
43
|
initial: S,
|
|
58
44
|
step: (state: S, item: I) => Transition<S, O>,
|
|
@@ -65,14 +51,4 @@ export const routers: Routers = Object.freeze({
|
|
|
65
51
|
guarded(inner: Sink, limits: Limits, abort: AbortFlag, metrics: Metrics): Sink {
|
|
66
52
|
return new Guarded(inner, limits, abort, metrics)
|
|
67
53
|
},
|
|
68
|
-
|
|
69
|
-
transduceTree(spec: TreeSpec, downstream: Sink): ParserSink {
|
|
70
|
-
return new TransduceTree(spec, downstream)
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
// TransduceTree reads a spec's `:member` and `:text`, and holds a text to
|
|
74
|
-
// the spec's `maxTextBytes` as it grows.
|
|
75
|
-
transduceTreeReadsMemberAndText(): boolean {
|
|
76
|
-
return true
|
|
77
|
-
},
|
|
78
54
|
})
|
package/src/transduce.ts
CHANGED
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
// - sources that produce it from a parsed value, from a live tabnas parse
|
|
12
12
|
// through the engine's rule events, or from line-delimited input, and
|
|
13
13
|
// the source of the parser's rule passes themselves (`ParserEventSource`,
|
|
14
|
-
// `ParserEvents/1`), what a transducer part reads
|
|
15
|
-
//
|
|
16
|
-
// passes;
|
|
14
|
+
// `ParserEvents/1`), what a transducer part reads (the part is alchemy's
|
|
15
|
+
// text, which alchemy's runtime runs over them);
|
|
17
16
|
// - `Selector`s and the matcher and router that recognize selected scopes
|
|
18
17
|
// in one pass and materialize them under a byte limit;
|
|
19
18
|
// - the table protocol `TableEvent` (`TableRows/1`) and the standard
|
|
@@ -32,7 +31,7 @@
|
|
|
32
31
|
// stages as alchemy's `Routers`, for a host to pass to alchemy's `compile`.
|
|
33
32
|
|
|
34
33
|
// This package's version, as package.json declares it.
|
|
35
|
-
export const VERSION = '0.
|
|
34
|
+
export const VERSION = '0.4.0'
|
|
36
35
|
|
|
37
36
|
export {
|
|
38
37
|
Datum,
|
|
@@ -77,20 +76,8 @@ export type { Source } from './source'
|
|
|
77
76
|
export { Guarded } from './guard'
|
|
78
77
|
export { ParserSource } from './parser-source'
|
|
79
78
|
export { ParserEventSource } from './parser-event-source'
|
|
80
|
-
export {
|
|
81
|
-
export {
|
|
82
|
-
export type {
|
|
83
|
-
ParserEvent,
|
|
84
|
-
ParserSink,
|
|
85
|
-
PassAlt,
|
|
86
|
-
PassToken,
|
|
87
|
-
RulePass,
|
|
88
|
-
TreeContainer,
|
|
89
|
-
TreeKey,
|
|
90
|
-
TreeRule,
|
|
91
|
-
TreeScalar,
|
|
92
|
-
TreeSpec,
|
|
93
|
-
} from '@tabnas/alchemy/shared'
|
|
79
|
+
export { parserEventFromJSON, parserEventToJSON } from '@tabnas/alchemy/shared'
|
|
80
|
+
export type { ParserEvent, ParserSink, PassAlt, PassToken, RulePass } from '@tabnas/alchemy/shared'
|
|
94
81
|
export { DEFAULT_CHUNK_BYTES, LineFormat, LinesSource } from './lines'
|
|
95
82
|
export type { LinesChunk, LinesInput, LinesWriter } from './lines'
|
|
96
83
|
export { INCREMENTAL, PRUNABLE, capability, isIncremental, isPrunable } from './capability'
|
package/dist/transduce-tree.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Flow, ParserEvent, ParserSink, Sink, TreeSpec } from '@tabnas/alchemy/shared';
|
|
2
|
-
export declare class TransduceTree implements ParserSink {
|
|
3
|
-
readonly spec: TreeSpec;
|
|
4
|
-
readonly down: Sink;
|
|
5
|
-
open: number;
|
|
6
|
-
carry: boolean;
|
|
7
|
-
readonly texts: string[];
|
|
8
|
-
readonly bytes: number[];
|
|
9
|
-
constructor(spec: TreeSpec, down: Sink);
|
|
10
|
-
event(ev: ParserEvent): Flow;
|
|
11
|
-
private get max();
|
|
12
|
-
private spell;
|
|
13
|
-
private write;
|
|
14
|
-
private openPass;
|
|
15
|
-
private closePass;
|
|
16
|
-
}
|
package/dist/transduce-tree.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* Copyright (c) 2026 tabnas, MIT License */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TransduceTree = void 0;
|
|
5
|
-
// `TransduceTree`: alchemy's `transduce-tree` run natively, the parser's
|
|
6
|
-
// rule passes (`ParserEvents/1`) in and a tree's `JsonEvents/1` out, as a
|
|
7
|
-
// `TreeSpec` keyed by rule name says (rs/src/transduce_tree.rs).
|
|
8
|
-
//
|
|
9
|
-
// The library's text (`stdlib/transduce.alc`) is the specification, and
|
|
10
|
-
// alchemy's `TreeSpec` documents what a native must do: each pass is looked
|
|
11
|
-
// up by its rule's name, one lookup per pass whatever the spec's size; an
|
|
12
|
-
// open pass announces its key, then begins its container or yields its
|
|
13
|
-
// scalar from one of its tokens, then announces its member; a close pass
|
|
14
|
-
// yields its text, when its rule is a `:text` rule, then ends its
|
|
15
|
-
// container, or yields its own value; and a container whose rule is
|
|
16
|
-
// replaced by a rule the spec names a container is one container, so that
|
|
17
|
-
// close ends nothing and the replacing open begins nothing. The state is
|
|
18
|
-
// the count of open containers, whether a close handed its container on,
|
|
19
|
-
// and the text each open `:text` rule has gathered, to which every pass
|
|
20
|
-
// writes its tokens' source text, so the native retains the document's
|
|
21
|
-
// nesting and an open rule's text, and nothing else of its width or
|
|
22
|
-
// length, as the library's step does. alchemy-cli's differential test
|
|
23
|
-
// holds the two to the same bytes.
|
|
24
|
-
//
|
|
25
|
-
// A text is held to the spec's `maxTextBytes` as it grows, at the joins
|
|
26
|
-
// the library's `string-join` makes and in their order: a pass's tokens
|
|
27
|
-
// together, then the innermost text with them, and a closed text with the
|
|
28
|
-
// text around it, each refused past the bound with alchemy's
|
|
29
|
-
// `treeTextRefusal`. The routers say this native reads `:member` and
|
|
30
|
-
// `:text` (routers.ts), which is what lets the lowering hand it a spec
|
|
31
|
-
// that uses either.
|
|
32
|
-
//
|
|
33
|
-
// A pass's events are worked out before the first of them is written, as
|
|
34
|
-
// the library's step returns them together: a pass that fails writes none.
|
|
35
|
-
// The failures are the library's, with its codes and texts, and in its
|
|
36
|
-
// order: an open pass's key, then what it begins or yields, then its
|
|
37
|
-
// tokens' text, then its member; a close pass's text, then what it ends or
|
|
38
|
-
// yields.
|
|
39
|
-
const shared_1 = require("@tabnas/alchemy/shared");
|
|
40
|
-
// The library's `transduce-tree`, natively, writing to `down`.
|
|
41
|
-
class TransduceTree {
|
|
42
|
-
constructor(spec, down) {
|
|
43
|
-
this.spec = spec;
|
|
44
|
-
this.down = down;
|
|
45
|
-
// Containers open.
|
|
46
|
-
this.open = 0;
|
|
47
|
-
// A close handed its container on to the rule replacing it.
|
|
48
|
-
this.carry = false;
|
|
49
|
-
// The text each open `:text` rule has gathered, the innermost last, and
|
|
50
|
-
// its length in UTF-8 bytes, which the bound is held to.
|
|
51
|
-
this.texts = [];
|
|
52
|
-
this.bytes = [];
|
|
53
|
-
}
|
|
54
|
-
event(ev) {
|
|
55
|
-
switch (ev.type) {
|
|
56
|
-
case 'open':
|
|
57
|
-
return this.openPass(ev.pass);
|
|
58
|
-
case 'close':
|
|
59
|
-
return this.closePass(ev.pass);
|
|
60
|
-
case 'end':
|
|
61
|
-
if (0 < this.open) {
|
|
62
|
-
throw new shared_1.Fail('PROTOCOL_ORDER_ERROR', "the rule passes ended inside a container, which a tree's never do");
|
|
63
|
-
}
|
|
64
|
-
return this.down.event(shared_1.Ev.end);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// The most bytes a text may hold.
|
|
68
|
-
get max() {
|
|
69
|
-
return this.spec.maxTextBytes ?? Infinity;
|
|
70
|
-
}
|
|
71
|
-
// The pass's tokens written to the innermost open text, if one is and the
|
|
72
|
-
// pass consumed any, as the library's `transduce-spell` writes them: the
|
|
73
|
-
// tokens' text joined, then written to the innermost, each join held to
|
|
74
|
-
// the bound.
|
|
75
|
-
spell(pass) {
|
|
76
|
-
if (0 === this.texts.length || 0 === pass.tokens.length)
|
|
77
|
-
return;
|
|
78
|
-
let more = '';
|
|
79
|
-
let n = 0;
|
|
80
|
-
for (const token of pass.tokens) {
|
|
81
|
-
more += token.src;
|
|
82
|
-
n += (0, shared_1.utf8Bytes)(token.src);
|
|
83
|
-
}
|
|
84
|
-
if (n > this.max)
|
|
85
|
-
throw (0, shared_1.treeTextRefusal)(n, this.max);
|
|
86
|
-
this.write(more, n);
|
|
87
|
-
}
|
|
88
|
-
// `more`, of `n` bytes, written at the end of the innermost open text, as
|
|
89
|
-
// the library's `transduce-write` joins the two, held to the bound.
|
|
90
|
-
write(more, n) {
|
|
91
|
-
const last = this.texts.length - 1;
|
|
92
|
-
const len = this.bytes[last] + n;
|
|
93
|
-
if (len > this.max)
|
|
94
|
-
throw (0, shared_1.treeTextRefusal)(len, this.max);
|
|
95
|
-
this.texts[last] += more;
|
|
96
|
-
this.bytes[last] = len;
|
|
97
|
-
}
|
|
98
|
-
openPass(pass) {
|
|
99
|
-
const rule = this.spec.rules.get(pass.name);
|
|
100
|
-
if (undefined === rule) {
|
|
101
|
-
this.spell(pass);
|
|
102
|
-
return 'continue';
|
|
103
|
-
}
|
|
104
|
-
const key = named(rule.key, pass);
|
|
105
|
-
let then;
|
|
106
|
-
let begins = false;
|
|
107
|
-
if (undefined !== rule.container) {
|
|
108
|
-
if (!this.carry) {
|
|
109
|
-
begins = true;
|
|
110
|
-
then = 'object' === rule.container ? shared_1.Ev.objectStart : shared_1.Ev.arrayStart;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else if (undefined !== rule.scalar && 'value' !== rule.scalar) {
|
|
114
|
-
const token = pass.tokens[rule.scalar.token];
|
|
115
|
-
if (undefined !== token)
|
|
116
|
-
then = scalar(token.val);
|
|
117
|
-
}
|
|
118
|
-
this.spell(pass);
|
|
119
|
-
const member = named(rule.member, pass);
|
|
120
|
-
if (undefined !== rule.container) {
|
|
121
|
-
if (begins)
|
|
122
|
-
this.open++;
|
|
123
|
-
else
|
|
124
|
-
this.carry = false;
|
|
125
|
-
}
|
|
126
|
-
if (true === rule.text) {
|
|
127
|
-
this.texts.push('');
|
|
128
|
-
this.bytes.push(0);
|
|
129
|
-
}
|
|
130
|
-
for (const ev of [
|
|
131
|
-
undefined === key ? undefined : shared_1.Ev.key(key),
|
|
132
|
-
then,
|
|
133
|
-
undefined === member ? undefined : shared_1.Ev.key(member),
|
|
134
|
-
]) {
|
|
135
|
-
if (undefined !== ev && 'stop' === this.down.event(ev))
|
|
136
|
-
return 'stop';
|
|
137
|
-
}
|
|
138
|
-
return 'continue';
|
|
139
|
-
}
|
|
140
|
-
closePass(pass) {
|
|
141
|
-
const rule = this.spec.rules.get(pass.name);
|
|
142
|
-
if (undefined === rule) {
|
|
143
|
-
this.spell(pass);
|
|
144
|
-
return 'continue';
|
|
145
|
-
}
|
|
146
|
-
// A `:text` rule's text closes first, and joins the one around it
|
|
147
|
-
// before this pass's own tokens do; it is yielded before anything
|
|
148
|
-
// else, once the rest of the pass is known not to fail.
|
|
149
|
-
let text;
|
|
150
|
-
if (true === rule.text) {
|
|
151
|
-
text = this.texts.pop();
|
|
152
|
-
if (undefined === text)
|
|
153
|
-
throw typeError('top: the vector is empty; there is no last item');
|
|
154
|
-
const n = this.bytes.pop();
|
|
155
|
-
if (0 < this.texts.length)
|
|
156
|
-
this.write(text, n);
|
|
157
|
-
}
|
|
158
|
-
this.spell(pass);
|
|
159
|
-
let then;
|
|
160
|
-
if (undefined === rule.container) {
|
|
161
|
-
if ('value' === rule.scalar && undefined !== pass.value)
|
|
162
|
-
then = scalar(pass.value);
|
|
163
|
-
}
|
|
164
|
-
else if (undefined !== pass.alt && (0, shared_1.isTreeContainer)(this.spec, pass.alt.r)) {
|
|
165
|
-
this.carry = true;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
if (0 === this.open)
|
|
169
|
-
throw typeError('pop: the vector is empty; there is no last item to remove');
|
|
170
|
-
this.open--;
|
|
171
|
-
this.carry = false;
|
|
172
|
-
then = 'object' === rule.container ? shared_1.Ev.objectEnd : shared_1.Ev.arrayEnd;
|
|
173
|
-
}
|
|
174
|
-
if (undefined !== text && 'stop' === this.down.event(shared_1.Ev.string(text)))
|
|
175
|
-
return 'stop';
|
|
176
|
-
return undefined === then ? 'continue' : this.down.event(then);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
exports.TransduceTree = TransduceTree;
|
|
180
|
-
// The member name a field of a rule's entry names for a pass: the string,
|
|
181
|
-
// or the `:val` of the pass's token at that index, nothing when the pass
|
|
182
|
-
// consumed no such token; the library's `key` refuses a name that is not a
|
|
183
|
-
// string.
|
|
184
|
-
function named(field, pass) {
|
|
185
|
-
if (undefined === field)
|
|
186
|
-
return undefined;
|
|
187
|
-
if ('name' in field)
|
|
188
|
-
return field.name;
|
|
189
|
-
const token = pass.tokens[field.token];
|
|
190
|
-
if (undefined === token)
|
|
191
|
-
return undefined;
|
|
192
|
-
if ('string' !== token.val.type) {
|
|
193
|
-
throw typeError(`key: the name must be a string, not ${kind(token.val)}`);
|
|
194
|
-
}
|
|
195
|
-
return token.val.value;
|
|
196
|
-
}
|
|
197
|
-
// A value as the library's `scalar` takes it, or its refusal.
|
|
198
|
-
function scalar(value) {
|
|
199
|
-
switch (value.type) {
|
|
200
|
-
case 'null':
|
|
201
|
-
return shared_1.Ev.null;
|
|
202
|
-
case 'bool':
|
|
203
|
-
return shared_1.Ev.bool(value.value);
|
|
204
|
-
case 'number':
|
|
205
|
-
return shared_1.Ev.number(value.value, value.lexeme);
|
|
206
|
-
case 'string':
|
|
207
|
-
return shared_1.Ev.string(value.value);
|
|
208
|
-
default:
|
|
209
|
-
throw typeError(`scalar: the value must be null, a boolean, a number or a string, not ${kind(value)}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// What a value is, in the runtime's words.
|
|
213
|
-
function kind(value) {
|
|
214
|
-
switch (value.type) {
|
|
215
|
-
case 'null':
|
|
216
|
-
return 'null';
|
|
217
|
-
case 'bool':
|
|
218
|
-
return 'a boolean';
|
|
219
|
-
case 'number':
|
|
220
|
-
return 'a number';
|
|
221
|
-
case 'string':
|
|
222
|
-
return 'a string';
|
|
223
|
-
case 'array':
|
|
224
|
-
return 'a vector';
|
|
225
|
-
case 'object':
|
|
226
|
-
return 'a record';
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
// The runtime's type error: `DSL_TYPE_ERROR`, the `type_mismatch` word
|
|
230
|
-
// first.
|
|
231
|
-
function typeError(message) {
|
|
232
|
-
return new shared_1.Fail('DSL_TYPE_ERROR', `type_mismatch: ${message}`);
|
|
233
|
-
}
|
|
234
|
-
//# sourceMappingURL=transduce-tree.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transduce-tree.js","sourceRoot":"","sources":["../src/transduce-tree.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;AAE5C,yEAAyE;AACzE,0EAA0E;AAC1E,iEAAiE;AACjE,EAAE;AACF,wEAAwE;AACxE,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,yEAAyE;AACzE,kEAAkE;AAClE,oEAAoE;AACpE,0EAA0E;AAC1E,yEAAyE;AACzE,yEAAyE;AACzE,wEAAwE;AACxE,uEAAuE;AACvE,oEAAoE;AACpE,sEAAsE;AACtE,mCAAmC;AACnC,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,0EAA0E;AAC1E,6DAA6D;AAC7D,qEAAqE;AACrE,uEAAuE;AACvE,oBAAoB;AACpB,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,uEAAuE;AACvE,qEAAqE;AACrE,2EAA2E;AAC3E,UAAU;AAEV,mDAAqG;AAGrG,+DAA+D;AAC/D;IAUE,YACW,IAAc,EACd,IAAU;QADV,SAAI,GAAJ,IAAI,CAAU;QACd,SAAI,GAAJ,IAAI,CAAM;QAXrB,mBAAmB;QACnB,SAAI,GAAG,CAAC,CAAA;QACR,4DAA4D;QAC5D,UAAK,GAAG,KAAK,CAAA;QACb,wEAAwE;QACxE,yDAAyD;QAChD,UAAK,GAAa,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AAO,WAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC7B,KAAK,QAAQ;YACX,OAAO,WAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAC7C,KAAK,QAAQ;YACX,OAAO,WAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC/B;YACE,MAAM,SAAS,CAAC,wEAAwE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC1G,CAAC;AACH,CAAC;AAED,2CAA2C;AAC3C,SAAS,IAAI,CAAC,KAAY;IACxB,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,MAAM;YACT,OAAO,MAAM,CAAA;QACf,KAAK,MAAM;YACT,OAAO,WAAW,CAAA;QACpB,KAAK,QAAQ;YACX,OAAO,UAAU,CAAA;QACnB,KAAK,QAAQ;YACX,OAAO,UAAU,CAAA;QACnB,KAAK,OAAO;YACV,OAAO,UAAU,CAAA;QACnB,KAAK,QAAQ;YACX,OAAO,UAAU,CAAA;IACrB,CAAC;AACH,CAAC;AAED,uEAAuE;AACvE,SAAS;AACT,SAAS,SAAS,CAAC,OAAe;IAChC,OAAO,IAAI,aAAI,CAAC,gBAAgB,EAAE,kBAAkB,OAAO,EAAE,CAAC,CAAA;AAChE,CAAC"}
|
package/src/transduce-tree.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 tabnas, MIT License */
|
|
2
|
-
|
|
3
|
-
// `TransduceTree`: alchemy's `transduce-tree` run natively, the parser's
|
|
4
|
-
// rule passes (`ParserEvents/1`) in and a tree's `JsonEvents/1` out, as a
|
|
5
|
-
// `TreeSpec` keyed by rule name says (rs/src/transduce_tree.rs).
|
|
6
|
-
//
|
|
7
|
-
// The library's text (`stdlib/transduce.alc`) is the specification, and
|
|
8
|
-
// alchemy's `TreeSpec` documents what a native must do: each pass is looked
|
|
9
|
-
// up by its rule's name, one lookup per pass whatever the spec's size; an
|
|
10
|
-
// open pass announces its key, then begins its container or yields its
|
|
11
|
-
// scalar from one of its tokens, then announces its member; a close pass
|
|
12
|
-
// yields its text, when its rule is a `:text` rule, then ends its
|
|
13
|
-
// container, or yields its own value; and a container whose rule is
|
|
14
|
-
// replaced by a rule the spec names a container is one container, so that
|
|
15
|
-
// close ends nothing and the replacing open begins nothing. The state is
|
|
16
|
-
// the count of open containers, whether a close handed its container on,
|
|
17
|
-
// and the text each open `:text` rule has gathered, to which every pass
|
|
18
|
-
// writes its tokens' source text, so the native retains the document's
|
|
19
|
-
// nesting and an open rule's text, and nothing else of its width or
|
|
20
|
-
// length, as the library's step does. alchemy-cli's differential test
|
|
21
|
-
// holds the two to the same bytes.
|
|
22
|
-
//
|
|
23
|
-
// A text is held to the spec's `maxTextBytes` as it grows, at the joins
|
|
24
|
-
// the library's `string-join` makes and in their order: a pass's tokens
|
|
25
|
-
// together, then the innermost text with them, and a closed text with the
|
|
26
|
-
// text around it, each refused past the bound with alchemy's
|
|
27
|
-
// `treeTextRefusal`. The routers say this native reads `:member` and
|
|
28
|
-
// `:text` (routers.ts), which is what lets the lowering hand it a spec
|
|
29
|
-
// that uses either.
|
|
30
|
-
//
|
|
31
|
-
// A pass's events are worked out before the first of them is written, as
|
|
32
|
-
// the library's step returns them together: a pass that fails writes none.
|
|
33
|
-
// The failures are the library's, with its codes and texts, and in its
|
|
34
|
-
// order: an open pass's key, then what it begins or yields, then its
|
|
35
|
-
// tokens' text, then its member; a close pass's text, then what it ends or
|
|
36
|
-
// yields.
|
|
37
|
-
|
|
38
|
-
import { Datum, Ev, Fail, isTreeContainer, treeTextRefusal, utf8Bytes } from '@tabnas/alchemy/shared'
|
|
39
|
-
import type { Flow, JsonEvent, ParserEvent, ParserSink, RulePass, Sink, TreeKey, TreeSpec } from '@tabnas/alchemy/shared'
|
|
40
|
-
|
|
41
|
-
// The library's `transduce-tree`, natively, writing to `down`.
|
|
42
|
-
export class TransduceTree implements ParserSink {
|
|
43
|
-
// Containers open.
|
|
44
|
-
open = 0
|
|
45
|
-
// A close handed its container on to the rule replacing it.
|
|
46
|
-
carry = false
|
|
47
|
-
// The text each open `:text` rule has gathered, the innermost last, and
|
|
48
|
-
// its length in UTF-8 bytes, which the bound is held to.
|
|
49
|
-
readonly texts: string[] = []
|
|
50
|
-
readonly bytes: number[] = []
|
|
51
|
-
|
|
52
|
-
constructor(
|
|
53
|
-
readonly spec: TreeSpec,
|
|
54
|
-
readonly down: Sink,
|
|
55
|
-
) {}
|
|
56
|
-
|
|
57
|
-
event(ev: ParserEvent): Flow {
|
|
58
|
-
switch (ev.type) {
|
|
59
|
-
case 'open':
|
|
60
|
-
return this.openPass(ev.pass)
|
|
61
|
-
case 'close':
|
|
62
|
-
return this.closePass(ev.pass)
|
|
63
|
-
case 'end':
|
|
64
|
-
if (0 < this.open) {
|
|
65
|
-
throw new Fail('PROTOCOL_ORDER_ERROR', "the rule passes ended inside a container, which a tree's never do")
|
|
66
|
-
}
|
|
67
|
-
return this.down.event(Ev.end)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// The most bytes a text may hold.
|
|
72
|
-
private get max(): number {
|
|
73
|
-
return this.spec.maxTextBytes ?? Infinity
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// The pass's tokens written to the innermost open text, if one is and the
|
|
77
|
-
// pass consumed any, as the library's `transduce-spell` writes them: the
|
|
78
|
-
// tokens' text joined, then written to the innermost, each join held to
|
|
79
|
-
// the bound.
|
|
80
|
-
private spell(pass: RulePass): void {
|
|
81
|
-
if (0 === this.texts.length || 0 === pass.tokens.length) return
|
|
82
|
-
let more = ''
|
|
83
|
-
let n = 0
|
|
84
|
-
for (const token of pass.tokens) {
|
|
85
|
-
more += token.src
|
|
86
|
-
n += utf8Bytes(token.src)
|
|
87
|
-
}
|
|
88
|
-
if (n > this.max) throw treeTextRefusal(n, this.max)
|
|
89
|
-
this.write(more, n)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// `more`, of `n` bytes, written at the end of the innermost open text, as
|
|
93
|
-
// the library's `transduce-write` joins the two, held to the bound.
|
|
94
|
-
private write(more: string, n: number): void {
|
|
95
|
-
const last = this.texts.length - 1
|
|
96
|
-
const len = this.bytes[last] + n
|
|
97
|
-
if (len > this.max) throw treeTextRefusal(len, this.max)
|
|
98
|
-
this.texts[last] += more
|
|
99
|
-
this.bytes[last] = len
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private openPass(pass: RulePass): Flow {
|
|
103
|
-
const rule = this.spec.rules.get(pass.name)
|
|
104
|
-
if (undefined === rule) {
|
|
105
|
-
this.spell(pass)
|
|
106
|
-
return 'continue'
|
|
107
|
-
}
|
|
108
|
-
const key = named(rule.key, pass)
|
|
109
|
-
let then: JsonEvent | undefined
|
|
110
|
-
let begins = false
|
|
111
|
-
if (undefined !== rule.container) {
|
|
112
|
-
if (!this.carry) {
|
|
113
|
-
begins = true
|
|
114
|
-
then = 'object' === rule.container ? Ev.objectStart : Ev.arrayStart
|
|
115
|
-
}
|
|
116
|
-
} else if (undefined !== rule.scalar && 'value' !== rule.scalar) {
|
|
117
|
-
const token = pass.tokens[rule.scalar.token]
|
|
118
|
-
if (undefined !== token) then = scalar(token.val)
|
|
119
|
-
}
|
|
120
|
-
this.spell(pass)
|
|
121
|
-
const member = named(rule.member, pass)
|
|
122
|
-
if (undefined !== rule.container) {
|
|
123
|
-
if (begins) this.open++
|
|
124
|
-
else this.carry = false
|
|
125
|
-
}
|
|
126
|
-
if (true === rule.text) {
|
|
127
|
-
this.texts.push('')
|
|
128
|
-
this.bytes.push(0)
|
|
129
|
-
}
|
|
130
|
-
for (const ev of [
|
|
131
|
-
undefined === key ? undefined : Ev.key(key),
|
|
132
|
-
then,
|
|
133
|
-
undefined === member ? undefined : Ev.key(member),
|
|
134
|
-
]) {
|
|
135
|
-
if (undefined !== ev && 'stop' === this.down.event(ev)) return 'stop'
|
|
136
|
-
}
|
|
137
|
-
return 'continue'
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private closePass(pass: RulePass): Flow {
|
|
141
|
-
const rule = this.spec.rules.get(pass.name)
|
|
142
|
-
if (undefined === rule) {
|
|
143
|
-
this.spell(pass)
|
|
144
|
-
return 'continue'
|
|
145
|
-
}
|
|
146
|
-
// A `:text` rule's text closes first, and joins the one around it
|
|
147
|
-
// before this pass's own tokens do; it is yielded before anything
|
|
148
|
-
// else, once the rest of the pass is known not to fail.
|
|
149
|
-
let text: string | undefined
|
|
150
|
-
if (true === rule.text) {
|
|
151
|
-
text = this.texts.pop()
|
|
152
|
-
if (undefined === text) throw typeError('top: the vector is empty; there is no last item')
|
|
153
|
-
const n = this.bytes.pop() as number
|
|
154
|
-
if (0 < this.texts.length) this.write(text, n)
|
|
155
|
-
}
|
|
156
|
-
this.spell(pass)
|
|
157
|
-
let then: JsonEvent | undefined
|
|
158
|
-
if (undefined === rule.container) {
|
|
159
|
-
if ('value' === rule.scalar && undefined !== pass.value) then = scalar(pass.value)
|
|
160
|
-
} else if (undefined !== pass.alt && isTreeContainer(this.spec, pass.alt.r)) {
|
|
161
|
-
this.carry = true
|
|
162
|
-
} else {
|
|
163
|
-
if (0 === this.open) throw typeError('pop: the vector is empty; there is no last item to remove')
|
|
164
|
-
this.open--
|
|
165
|
-
this.carry = false
|
|
166
|
-
then = 'object' === rule.container ? Ev.objectEnd : Ev.arrayEnd
|
|
167
|
-
}
|
|
168
|
-
if (undefined !== text && 'stop' === this.down.event(Ev.string(text))) return 'stop'
|
|
169
|
-
return undefined === then ? 'continue' : this.down.event(then)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// The member name a field of a rule's entry names for a pass: the string,
|
|
174
|
-
// or the `:val` of the pass's token at that index, nothing when the pass
|
|
175
|
-
// consumed no such token; the library's `key` refuses a name that is not a
|
|
176
|
-
// string.
|
|
177
|
-
function named(field: TreeKey | undefined, pass: RulePass): string | undefined {
|
|
178
|
-
if (undefined === field) return undefined
|
|
179
|
-
if ('name' in field) return field.name
|
|
180
|
-
const token = pass.tokens[field.token]
|
|
181
|
-
if (undefined === token) return undefined
|
|
182
|
-
if ('string' !== token.val.type) {
|
|
183
|
-
throw typeError(`key: the name must be a string, not ${kind(token.val)}`)
|
|
184
|
-
}
|
|
185
|
-
return token.val.value
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// A value as the library's `scalar` takes it, or its refusal.
|
|
189
|
-
function scalar(value: Datum): JsonEvent {
|
|
190
|
-
switch (value.type) {
|
|
191
|
-
case 'null':
|
|
192
|
-
return Ev.null
|
|
193
|
-
case 'bool':
|
|
194
|
-
return Ev.bool(value.value)
|
|
195
|
-
case 'number':
|
|
196
|
-
return Ev.number(value.value, value.lexeme)
|
|
197
|
-
case 'string':
|
|
198
|
-
return Ev.string(value.value)
|
|
199
|
-
default:
|
|
200
|
-
throw typeError(`scalar: the value must be null, a boolean, a number or a string, not ${kind(value)}`)
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// What a value is, in the runtime's words.
|
|
205
|
-
function kind(value: Datum): string {
|
|
206
|
-
switch (value.type) {
|
|
207
|
-
case 'null':
|
|
208
|
-
return 'null'
|
|
209
|
-
case 'bool':
|
|
210
|
-
return 'a boolean'
|
|
211
|
-
case 'number':
|
|
212
|
-
return 'a number'
|
|
213
|
-
case 'string':
|
|
214
|
-
return 'a string'
|
|
215
|
-
case 'array':
|
|
216
|
-
return 'a vector'
|
|
217
|
-
case 'object':
|
|
218
|
-
return 'a record'
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// The runtime's type error: `DSL_TYPE_ERROR`, the `type_mismatch` word
|
|
223
|
-
// first.
|
|
224
|
-
function typeError(message: string): Fail {
|
|
225
|
-
return new Fail('DSL_TYPE_ERROR', `type_mismatch: ${message}`)
|
|
226
|
-
}
|