@driftsys/markspec 0.10.1 → 0.10.3

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.
Files changed (135) hide show
  1. package/esm/collect/mod.d.ts +34 -0
  2. package/esm/collect/mod.d.ts.map +1 -0
  3. package/esm/collect/mod.js +37 -0
  4. package/esm/decl/mod.d.ts +18 -0
  5. package/esm/decl/mod.d.ts.map +1 -0
  6. package/esm/decl/mod.js +14 -0
  7. package/esm/decl/resolve.d.ts +104 -0
  8. package/esm/decl/resolve.d.ts.map +1 -0
  9. package/esm/decl/resolve.js +66 -0
  10. package/esm/decl/surfaces.d.ts +96 -0
  11. package/esm/decl/surfaces.d.ts.map +1 -0
  12. package/esm/decl/surfaces.js +122 -0
  13. package/esm/decl/table.d.ts +50 -0
  14. package/esm/decl/table.d.ts.map +1 -0
  15. package/esm/decl/table.js +124 -0
  16. package/esm/formatter/mod.d.ts.map +1 -1
  17. package/esm/formatter/mod.js +29 -1
  18. package/esm/gates/mod.d.ts +82 -0
  19. package/esm/gates/mod.d.ts.map +1 -0
  20. package/esm/gates/mod.js +139 -0
  21. package/esm/lint/runner.d.ts +26 -3
  22. package/esm/lint/runner.d.ts.map +1 -1
  23. package/esm/lint/runner.js +39 -9
  24. package/esm/lock/edge_drift.d.ts +31 -0
  25. package/esm/lock/edge_drift.d.ts.map +1 -0
  26. package/esm/lock/edge_drift.js +29 -0
  27. package/esm/lock/mod.d.ts +2 -0
  28. package/esm/lock/mod.d.ts.map +1 -1
  29. package/esm/lock/mod.js +1 -0
  30. package/esm/mod.d.ts +11 -6
  31. package/esm/mod.d.ts.map +1 -1
  32. package/esm/mod.js +10 -4
  33. package/esm/model/mod.d.ts +8 -0
  34. package/esm/model/mod.d.ts.map +1 -1
  35. package/esm/model/mod.js +10 -0
  36. package/esm/model/profile.d.ts +8 -0
  37. package/esm/model/profile.d.ts.map +1 -1
  38. package/esm/parser/directives.d.ts +6 -0
  39. package/esm/parser/directives.d.ts.map +1 -1
  40. package/esm/parser/directives.js +17 -0
  41. package/esm/parser/markdown.d.ts.map +1 -1
  42. package/esm/parser/markdown.js +47 -11
  43. package/esm/profile/delivered.d.ts +22 -1
  44. package/esm/profile/delivered.d.ts.map +1 -1
  45. package/esm/profile/delivered.js +44 -1
  46. package/esm/profile/merge.js +1 -0
  47. package/esm/reporter/mod.d.ts.map +1 -1
  48. package/esm/reporter/mod.js +2 -3
  49. package/esm/typl/bullet.d.ts +13 -23
  50. package/esm/typl/bullet.d.ts.map +1 -1
  51. package/esm/typl/bullet.js +6 -40
  52. package/esm/typl/fence.d.ts +12 -21
  53. package/esm/typl/fence.d.ts.map +1 -1
  54. package/esm/typl/fence.js +5 -20
  55. package/esm/typl/inline.d.ts +15 -24
  56. package/esm/typl/inline.d.ts.map +1 -1
  57. package/esm/typl/inline.js +6 -44
  58. package/esm/typl/recognize.d.ts +14 -0
  59. package/esm/typl/recognize.d.ts.map +1 -0
  60. package/esm/typl/recognize.js +19 -0
  61. package/esm/util/fence.d.ts +8 -0
  62. package/esm/util/fence.d.ts.map +1 -1
  63. package/esm/util/fence.js +22 -0
  64. package/esm/validator/body_blocks.d.ts.map +1 -1
  65. package/esm/validator/body_blocks.js +3 -9
  66. package/esm/validator/corpus.d.ts.map +1 -1
  67. package/esm/validator/corpus.js +14 -12
  68. package/package.json +1 -1
  69. package/script/collect/mod.d.ts +34 -0
  70. package/script/collect/mod.d.ts.map +1 -0
  71. package/script/collect/mod.js +40 -0
  72. package/script/decl/mod.d.ts +18 -0
  73. package/script/decl/mod.d.ts.map +1 -0
  74. package/script/decl/mod.js +24 -0
  75. package/script/decl/resolve.d.ts +104 -0
  76. package/script/decl/resolve.d.ts.map +1 -0
  77. package/script/decl/resolve.js +70 -0
  78. package/script/decl/surfaces.d.ts +96 -0
  79. package/script/decl/surfaces.d.ts.map +1 -0
  80. package/script/decl/surfaces.js +128 -0
  81. package/script/decl/table.d.ts +50 -0
  82. package/script/decl/table.d.ts.map +1 -0
  83. package/script/decl/table.js +127 -0
  84. package/script/formatter/mod.d.ts.map +1 -1
  85. package/script/formatter/mod.js +29 -1
  86. package/script/gates/mod.d.ts +82 -0
  87. package/script/gates/mod.d.ts.map +1 -0
  88. package/script/gates/mod.js +144 -0
  89. package/script/lint/runner.d.ts +26 -3
  90. package/script/lint/runner.d.ts.map +1 -1
  91. package/script/lint/runner.js +39 -9
  92. package/script/lock/edge_drift.d.ts +31 -0
  93. package/script/lock/edge_drift.d.ts.map +1 -0
  94. package/script/lock/edge_drift.js +32 -0
  95. package/script/lock/mod.d.ts +2 -0
  96. package/script/lock/mod.d.ts.map +1 -1
  97. package/script/lock/mod.js +3 -1
  98. package/script/mod.d.ts +11 -6
  99. package/script/mod.d.ts.map +1 -1
  100. package/script/mod.js +45 -29
  101. package/script/model/mod.d.ts +8 -0
  102. package/script/model/mod.d.ts.map +1 -1
  103. package/script/model/mod.js +11 -0
  104. package/script/model/profile.d.ts +8 -0
  105. package/script/model/profile.d.ts.map +1 -1
  106. package/script/parser/directives.d.ts +6 -0
  107. package/script/parser/directives.d.ts.map +1 -1
  108. package/script/parser/directives.js +18 -0
  109. package/script/parser/markdown.d.ts.map +1 -1
  110. package/script/parser/markdown.js +47 -11
  111. package/script/profile/delivered.d.ts +22 -1
  112. package/script/profile/delivered.d.ts.map +1 -1
  113. package/script/profile/delivered.js +45 -1
  114. package/script/profile/merge.js +1 -0
  115. package/script/reporter/mod.d.ts.map +1 -1
  116. package/script/reporter/mod.js +2 -3
  117. package/script/typl/bullet.d.ts +13 -23
  118. package/script/typl/bullet.d.ts.map +1 -1
  119. package/script/typl/bullet.js +6 -40
  120. package/script/typl/fence.d.ts +12 -21
  121. package/script/typl/fence.d.ts.map +1 -1
  122. package/script/typl/fence.js +5 -20
  123. package/script/typl/inline.d.ts +15 -24
  124. package/script/typl/inline.d.ts.map +1 -1
  125. package/script/typl/inline.js +6 -44
  126. package/script/typl/recognize.d.ts +14 -0
  127. package/script/typl/recognize.d.ts.map +1 -0
  128. package/script/typl/recognize.js +22 -0
  129. package/script/util/fence.d.ts +8 -0
  130. package/script/util/fence.d.ts.map +1 -1
  131. package/script/util/fence.js +23 -0
  132. package/script/validator/body_blocks.d.ts.map +1 -1
  133. package/script/validator/body_blocks.js +3 -9
  134. package/script/validator/corpus.d.ts.map +1 -1
  135. package/script/validator/corpus.js +14 -12
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @module core/collect
3
+ *
4
+ * Project-entry collection: discover every MarkSpec-relevant file under a
5
+ * root and parse it into a flat `Entry[]`. The single source of truth for
6
+ * "the set of entries whose trace edges the lockfile pins" — shared by
7
+ * `markspec lock` (the pinner) and its checkers (`compile`, `fmt`, `doctor`)
8
+ * so they cannot disagree on which files count. Previously each of those
9
+ * commands hand-rolled the same discover→parse loop (a `cli/commands/lock.ts`
10
+ * private helper the others reached into), which had to stay byte-identical
11
+ * by hand or the lockfile edge-hash comparison would drift spuriously.
12
+ */
13
+ import type { Entry } from "../model/mod.js";
14
+ import { type DiscoveryIO } from "../discovery/mod.js";
15
+ /** Options for {@linkcode collectProjectEntries}. */
16
+ export interface CollectOptions {
17
+ /** Gitignore-syntax patterns (e.g. `project.yaml` `exclude:`), anchored at
18
+ * `root`. Applied after `.gitignore` rules. Defaults to none. */
19
+ readonly exclude?: readonly string[];
20
+ }
21
+ /**
22
+ * Walk `root` via {@linkcode discoverFiles} — relying on its default
23
+ * extension set (`RELEVANT_EXTENSIONS`), the parity point every caller
24
+ * depends on — and parse each discovered file, returning the flattened
25
+ * entry list. Unreadable files are skipped. Parse diagnostics are not
26
+ * surfaced here: this collector exists to give the lockfile pinner and its
27
+ * checkers one definition of the file set; callers that need diagnostics
28
+ * re-parse.
29
+ *
30
+ * @param io Injected filesystem surface (keeps `core/` Node-compatible; CLI
31
+ * entry points pass a Deno-backed implementation).
32
+ */
33
+ export declare function collectProjectEntries(root: string, io: DiscoveryIO, opts?: CollectOptions): Promise<Entry[]>;
34
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/collect/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtE,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC7B;qEACiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,WAAW,EACf,IAAI,GAAE,cAAmB,GACxB,OAAO,CAAC,KAAK,EAAE,CAAC,CASlB"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @module core/collect
3
+ *
4
+ * Project-entry collection: discover every MarkSpec-relevant file under a
5
+ * root and parse it into a flat `Entry[]`. The single source of truth for
6
+ * "the set of entries whose trace edges the lockfile pins" — shared by
7
+ * `markspec lock` (the pinner) and its checkers (`compile`, `fmt`, `doctor`)
8
+ * so they cannot disagree on which files count. Previously each of those
9
+ * commands hand-rolled the same discover→parse loop (a `cli/commands/lock.ts`
10
+ * private helper the others reached into), which had to stay byte-identical
11
+ * by hand or the lockfile edge-hash comparison would drift spuriously.
12
+ */
13
+ import { discoverFiles } from "../discovery/mod.js";
14
+ import { parseFile } from "../parser/mod.js";
15
+ /**
16
+ * Walk `root` via {@linkcode discoverFiles} — relying on its default
17
+ * extension set (`RELEVANT_EXTENSIONS`), the parity point every caller
18
+ * depends on — and parse each discovered file, returning the flattened
19
+ * entry list. Unreadable files are skipped. Parse diagnostics are not
20
+ * surfaced here: this collector exists to give the lockfile pinner and its
21
+ * checkers one definition of the file set; callers that need diagnostics
22
+ * re-parse.
23
+ *
24
+ * @param io Injected filesystem surface (keeps `core/` Node-compatible; CLI
25
+ * entry points pass a Deno-backed implementation).
26
+ */
27
+ export async function collectProjectEntries(root, io, opts = {}) {
28
+ const out = [];
29
+ for await (const file of discoverFiles(root, io, { exclude: opts.exclude })) {
30
+ const content = await io.readFile(file);
31
+ if (content === undefined)
32
+ continue;
33
+ const result = await parseFile(content, { file });
34
+ out.push(...result.entries);
35
+ }
36
+ return out;
37
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module core/decl
3
+ *
4
+ * Shared declaration-surface machinery (uxil epic #717 §A). DSL-agnostic
5
+ * walkers that extract declaration sites from an entry body's four
6
+ * embedding surfaces — fenced code blocks, bullet paragraphs, inline code
7
+ * spans, and table rows — parameterized by a recognizer, plus the
8
+ * entry-local base-resolution engine (S4) that resolves relative refs
9
+ * against the base an enclosing declaration establishes. typl consumes
10
+ * these today; uxil (§B) rides on the same substrate.
11
+ */
12
+ export type { BlockDeclaration, FenceRecognizer, InlineDeclaration, TextRecognizer, } from "./surfaces.js";
13
+ export { extractBulletDeclarations, extractFenceDeclarations, extractInlineDeclarations, stripCodeSpanDelimiters, } from "./surfaces.js";
14
+ export type { RowRecognizer, TableRowDeclaration } from "./table.js";
15
+ export { extractTableDeclarations } from "./table.js";
16
+ export type { BaseScope, RefOps, RefResolution, RootCheck } from "./resolve.js";
17
+ export { checkSingleRoot, resolveRef } from "./resolve.js";
18
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/decl/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module core/decl
3
+ *
4
+ * Shared declaration-surface machinery (uxil epic #717 §A). DSL-agnostic
5
+ * walkers that extract declaration sites from an entry body's four
6
+ * embedding surfaces — fenced code blocks, bullet paragraphs, inline code
7
+ * spans, and table rows — parameterized by a recognizer, plus the
8
+ * entry-local base-resolution engine (S4) that resolves relative refs
9
+ * against the base an enclosing declaration establishes. typl consumes
10
+ * these today; uxil (§B) rides on the same substrate.
11
+ */
12
+ export { extractBulletDeclarations, extractFenceDeclarations, extractInlineDeclarations, stripCodeSpanDelimiters, } from "./surfaces.js";
13
+ export { extractTableDeclarations } from "./table.js";
14
+ export { checkSingleRoot, resolveRef } from "./resolve.js";
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @module core/decl/resolve
3
+ *
4
+ * Entry-local base-resolution engine (uxil epic #717 §A). The DSL-agnostic
5
+ * *normative rule set* for resolving a relative reference against the base
6
+ * an enclosing declaration established. typl's published tier and uxil both
7
+ * consume it; the engine knows nothing about either vocabulary.
8
+ *
9
+ * The six rules from #722, and where each lives:
10
+ *
11
+ * 1. Only *declarations* create bases; *citations* never do. — The caller
12
+ * sets {@linkcode BaseScope.base} only for declaration scopes; a scope
13
+ * built from a citation leaves it `undefined`.
14
+ * 2. Bases are entry-local (no document-ambient scope). — The engine only
15
+ * ever walks the `parent` chain it is given; there is no global lookup.
16
+ * 3. Innermost base wins. — {@linkcode resolveRef} returns on the first
17
+ * ancestor (nearest first) that carries a base.
18
+ * 4. Scope is structural, never sequential. — The engine follows `parent`
19
+ * links only; siblings are unreachable, so reordering declarations can
20
+ * never rebind a ref.
21
+ * 5. Exactly one root declaration per declaring entry. —
22
+ * {@linkcode checkSingleRoot}.
23
+ * 6. Declarations/citations sit in code spans. — A surface concern
24
+ * (core/decl/surfaces + the DSL recognizer); the engine sees only the
25
+ * already-extracted ref token.
26
+ *
27
+ * The caller builds the {@linkcode BaseScope} chain from the entry's
28
+ * structural nesting (list membership, table membership) — that mapping is
29
+ * DSL- and surface-specific and lands with the table surface (S3) and the
30
+ * DSL consumers (S5/S7).
31
+ */
32
+ /**
33
+ * A structural scope in an entry's declaration tree. {@linkcode resolveRef}
34
+ * walks `parent` links from innermost to outermost.
35
+ *
36
+ * `base` is the base a *declaration* established at this scope, or
37
+ * `undefined` when this scope establishes none (a citation scope, or a
38
+ * structural container that declares nothing). Because the engine reaches
39
+ * enclosing scopes only through `parent`, siblings are invisible to one
40
+ * another and ordering within a level is irrelevant — the scope is purely
41
+ * structural (rule 4).
42
+ */
43
+ export interface BaseScope {
44
+ /** The base declared at this scope, if any. */
45
+ readonly base?: string;
46
+ /** The enclosing scope, or `undefined` at the entry root. */
47
+ readonly parent?: BaseScope;
48
+ }
49
+ /**
50
+ * The DSL-specific reference operations the engine is parameterized by.
51
+ * Keeping these injected is what makes the engine vocabulary-agnostic: typl
52
+ * dotted paths and uxil `ux:` URIs supply their own notions of "absolute"
53
+ * and of how a base combines with a relative ref.
54
+ */
55
+ export interface RefOps {
56
+ /** True when `ref` is already absolute and needs no base. */
57
+ readonly isAbsolute: (ref: string) => boolean;
58
+ /** Combine an enclosing `base` with a relative `ref` into a full ref. */
59
+ readonly join: (base: string, ref: string) => string;
60
+ }
61
+ /**
62
+ * Outcome of {@linkcode resolveRef}. `no-base-in-scope` is returned for a
63
+ * relative ref that finds no base in any ancestor; the DSL host maps that
64
+ * reason to its own diagnostic code (typl TYPL-0xx, uxil UXIL-0xx).
65
+ */
66
+ export type RefResolution = {
67
+ readonly ok: true;
68
+ readonly ref: string;
69
+ } | {
70
+ readonly ok: false;
71
+ readonly reason: "no-base-in-scope";
72
+ };
73
+ /**
74
+ * Resolve `ref` at `scope`. An absolute ref passes through unchanged. A
75
+ * relative ref is joined with the base of the nearest enclosing scope that
76
+ * carries one (innermost wins, rule 3); a single join with that base only —
77
+ * bases are not accumulated up the chain, because each scope's `base` is
78
+ * already its fully-qualified prefix. A relative ref with no base in any
79
+ * ancestor yields `{ ok: false, reason: "no-base-in-scope" }`.
80
+ *
81
+ * `scope` may be `undefined` (a ref at the very top with no enclosing
82
+ * declaration); a relative ref there is likewise `no-base-in-scope`.
83
+ */
84
+ export declare function resolveRef(ref: string, scope: BaseScope | undefined, ops: RefOps): RefResolution;
85
+ /**
86
+ * Outcome of {@linkcode checkSingleRoot}. On failure, `roots` carries the
87
+ * offending set so the DSL host can locate each one for its diagnostic.
88
+ */
89
+ export type RootCheck<T> = {
90
+ readonly ok: true;
91
+ readonly root: T;
92
+ } | {
93
+ readonly ok: false;
94
+ readonly reason: "no-root" | "multiple-roots";
95
+ readonly roots: readonly T[];
96
+ };
97
+ /**
98
+ * Enforce the one-root invariant (rule 5): a declaring entry must have
99
+ * exactly one root declaration. Returns the sole root on success, or a
100
+ * `no-root` / `multiple-roots` failure carrying the offending set. Generic
101
+ * over the DSL's root-declaration type — the engine only counts.
102
+ */
103
+ export declare function checkSingleRoot<T>(roots: readonly T[]): RootCheck<T>;
104
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/decl/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACrB,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAC9C,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACtD;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,GAAG,EAAE,MAAM,GACV,aAAa,CAMf;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACvC;IACA,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAAC;IAC9C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;CAC9B,CAAC;AAEJ;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAOpE"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @module core/decl/resolve
3
+ *
4
+ * Entry-local base-resolution engine (uxil epic #717 §A). The DSL-agnostic
5
+ * *normative rule set* for resolving a relative reference against the base
6
+ * an enclosing declaration established. typl's published tier and uxil both
7
+ * consume it; the engine knows nothing about either vocabulary.
8
+ *
9
+ * The six rules from #722, and where each lives:
10
+ *
11
+ * 1. Only *declarations* create bases; *citations* never do. — The caller
12
+ * sets {@linkcode BaseScope.base} only for declaration scopes; a scope
13
+ * built from a citation leaves it `undefined`.
14
+ * 2. Bases are entry-local (no document-ambient scope). — The engine only
15
+ * ever walks the `parent` chain it is given; there is no global lookup.
16
+ * 3. Innermost base wins. — {@linkcode resolveRef} returns on the first
17
+ * ancestor (nearest first) that carries a base.
18
+ * 4. Scope is structural, never sequential. — The engine follows `parent`
19
+ * links only; siblings are unreachable, so reordering declarations can
20
+ * never rebind a ref.
21
+ * 5. Exactly one root declaration per declaring entry. —
22
+ * {@linkcode checkSingleRoot}.
23
+ * 6. Declarations/citations sit in code spans. — A surface concern
24
+ * (core/decl/surfaces + the DSL recognizer); the engine sees only the
25
+ * already-extracted ref token.
26
+ *
27
+ * The caller builds the {@linkcode BaseScope} chain from the entry's
28
+ * structural nesting (list membership, table membership) — that mapping is
29
+ * DSL- and surface-specific and lands with the table surface (S3) and the
30
+ * DSL consumers (S5/S7).
31
+ */
32
+ /**
33
+ * Resolve `ref` at `scope`. An absolute ref passes through unchanged. A
34
+ * relative ref is joined with the base of the nearest enclosing scope that
35
+ * carries one (innermost wins, rule 3); a single join with that base only —
36
+ * bases are not accumulated up the chain, because each scope's `base` is
37
+ * already its fully-qualified prefix. A relative ref with no base in any
38
+ * ancestor yields `{ ok: false, reason: "no-base-in-scope" }`.
39
+ *
40
+ * `scope` may be `undefined` (a ref at the very top with no enclosing
41
+ * declaration); a relative ref there is likewise `no-base-in-scope`.
42
+ */
43
+ export function resolveRef(ref, scope, ops) {
44
+ if (ops.isAbsolute(ref))
45
+ return { ok: true, ref };
46
+ for (let s = scope; s !== undefined; s = s.parent) {
47
+ if (s.base !== undefined)
48
+ return { ok: true, ref: ops.join(s.base, ref) };
49
+ }
50
+ return { ok: false, reason: "no-base-in-scope" };
51
+ }
52
+ /**
53
+ * Enforce the one-root invariant (rule 5): a declaring entry must have
54
+ * exactly one root declaration. Returns the sole root on success, or a
55
+ * `no-root` / `multiple-roots` failure carrying the offending set. Generic
56
+ * over the DSL's root-declaration type — the engine only counts.
57
+ */
58
+ export function checkSingleRoot(roots) {
59
+ if (roots.length === 1)
60
+ return { ok: true, root: roots[0] };
61
+ return {
62
+ ok: false,
63
+ reason: roots.length === 0 ? "no-root" : "multiple-roots",
64
+ roots,
65
+ };
66
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @module core/decl/surfaces
3
+ *
4
+ * DSL-agnostic declaration-surface machinery. Walks a MarkSpec entry body
5
+ * and extracts every *declaration site* on each of the three embedding
6
+ * surfaces, returning a common declaration node:
7
+ *
8
+ * - **fence** — a fenced code block whose info-string a DSL claims
9
+ * (e.g. ```typl). {@linkcode extractFenceDeclarations}
10
+ * - **bullet** — a list item whose first paragraph is a declaration.
11
+ * {@linkcode extractBulletDeclarations}
12
+ * - **inline** — a CommonMark code span whose text is a declaration.
13
+ * {@linkcode extractInlineDeclarations}
14
+ *
15
+ * Each walker is parameterized by a *recognizer* — the only DSL-specific
16
+ * input — and knows nothing about typl, uxil, or any concrete vocabulary.
17
+ * A DSL host (typl today; uxil and the table surface later) supplies the
18
+ * recognizer and consumes the returned {@linkcode BlockDeclaration} /
19
+ * {@linkcode InlineDeclaration} nodes.
20
+ *
21
+ * Extracted from the typl surface adapters (ADR-019) so §A of the uxil
22
+ * epic (#717) can share one substrate. typl's fence / bullet / inline
23
+ * modules are thin adapters over these functions and their observable
24
+ * output is unchanged.
25
+ */
26
+ import type { BodyBlock, SourceRange } from "../ast/nodes.js";
27
+ import type { BodyToken, SourceLocation } from "../model/mod.js";
28
+ /**
29
+ * A declaration found on a block surface (fenced code block or bullet
30
+ * paragraph). Carries the raw DSL `source` and the node's body-relative
31
+ * {@linkcode SourceRange} — the anchor a DSL host uses to bridge parse
32
+ * diagnostics back to file positions.
33
+ */
34
+ export interface BlockDeclaration {
35
+ /** Raw DSL source: the fence body, or the bullet's paragraph text. */
36
+ readonly source: string;
37
+ /** Source range of the fence, or of the bullet's first paragraph. */
38
+ readonly range: SourceRange;
39
+ }
40
+ /**
41
+ * A declaration found in an inline code span. Carries the raw DSL
42
+ * `source` (backtick delimiters stripped) and the span's file-relative
43
+ * {@linkcode SourceLocation} (the position `Entry.bodyTokens` records).
44
+ */
45
+ export interface InlineDeclaration {
46
+ /** Raw DSL source: the code span's inner text, backticks stripped. */
47
+ readonly source: string;
48
+ /** File-relative location of the code span. */
49
+ readonly location: SourceLocation;
50
+ }
51
+ /** Recognizer for the fence surface: does this info-string host the DSL? */
52
+ export type FenceRecognizer = (lang: string | undefined) => boolean;
53
+ /** Recognizer for the bullet / inline surfaces: is this text a declaration? */
54
+ export type TextRecognizer = (text: string) => boolean;
55
+ /**
56
+ * Walk a body AST and return every fenced code block whose info-string
57
+ * satisfies `matchLang`. Recurses into container nodes (ListNode via
58
+ * ListItemNode.blocks) so fences nested inside list items are found.
59
+ *
60
+ * BlockquoteNode and NoteNode carry only InlineContent (not nested
61
+ * BodyBlock[]), so they are not recursed into. Returns declarations in
62
+ * source order (depth-first traversal).
63
+ */
64
+ export declare function extractFenceDeclarations(blocks: readonly BodyBlock[], matchLang: FenceRecognizer): readonly BlockDeclaration[];
65
+ /**
66
+ * Walk a body AST and return every bullet-list item whose first paragraph
67
+ * satisfies `matchText`. Recurses through ListNode → ListItemNode.blocks
68
+ * for nested lists. Mixed lists are supported: items whose first paragraph
69
+ * matches are extracted; non-matching bullets are left alone.
70
+ *
71
+ * Returns declarations in source order (depth-first).
72
+ */
73
+ export declare function extractBulletDeclarations(blocks: readonly BodyBlock[], matchText: TextRecognizer): readonly BlockDeclaration[];
74
+ /**
75
+ * Strip the surrounding backtick delimiter(s) from an inline-code token's
76
+ * `text` field. `body_tokens.ts` stores inline-code text as `` `value` ``
77
+ * (with backtick delimiters); a DSL recognizer and parser need the inner
78
+ * value only.
79
+ *
80
+ * Handles both single-backtick (`` `…` ``) and double-backtick (` ``…`` `)
81
+ * delimiters. Returns the original string unchanged when it does not start
82
+ * and end with a matching backtick fence.
83
+ */
84
+ export declare function stripCodeSpanDelimiters(text: string): string;
85
+ /**
86
+ * Filter `bodyTokens` to inline-code spans whose contents (backticks
87
+ * stripped) satisfy `matchText`. Returns declarations in source order
88
+ * (the bodyTokens contract guarantees source order).
89
+ *
90
+ * `inline-code` tokens store their `text` field with surrounding backtick
91
+ * delimiters (e.g. `` `$X : signal` ``). This function strips those
92
+ * delimiters via {@linkcode stripCodeSpanDelimiters} before recognizing
93
+ * and before setting `source`, so the DSL parser receives the raw source.
94
+ */
95
+ export declare function extractInlineDeclarations(bodyTokens: readonly BodyToken[], matchText: TextRecognizer): readonly InlineDeclaration[];
96
+ //# sourceMappingURL=surfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surfaces.d.ts","sourceRoot":"","sources":["../../src/decl/surfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CACnC;AAED,4EAA4E;AAC5E,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;AAEpE,+EAA+E;AAC/E,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,SAAS,EAAE,eAAe,GACzB,SAAS,gBAAgB,EAAE,CAY7B;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,SAAS,EAAE,cAAc,GACxB,SAAS,gBAAgB,EAAE,CAwB7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,SAAS,SAAS,EAAE,EAChC,SAAS,EAAE,cAAc,GACxB,SAAS,iBAAiB,EAAE,CAS9B"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @module core/decl/surfaces
3
+ *
4
+ * DSL-agnostic declaration-surface machinery. Walks a MarkSpec entry body
5
+ * and extracts every *declaration site* on each of the three embedding
6
+ * surfaces, returning a common declaration node:
7
+ *
8
+ * - **fence** — a fenced code block whose info-string a DSL claims
9
+ * (e.g. ```typl). {@linkcode extractFenceDeclarations}
10
+ * - **bullet** — a list item whose first paragraph is a declaration.
11
+ * {@linkcode extractBulletDeclarations}
12
+ * - **inline** — a CommonMark code span whose text is a declaration.
13
+ * {@linkcode extractInlineDeclarations}
14
+ *
15
+ * Each walker is parameterized by a *recognizer* — the only DSL-specific
16
+ * input — and knows nothing about typl, uxil, or any concrete vocabulary.
17
+ * A DSL host (typl today; uxil and the table surface later) supplies the
18
+ * recognizer and consumes the returned {@linkcode BlockDeclaration} /
19
+ * {@linkcode InlineDeclaration} nodes.
20
+ *
21
+ * Extracted from the typl surface adapters (ADR-019) so §A of the uxil
22
+ * epic (#717) can share one substrate. typl's fence / bullet / inline
23
+ * modules are thin adapters over these functions and their observable
24
+ * output is unchanged.
25
+ */
26
+ /**
27
+ * Walk a body AST and return every fenced code block whose info-string
28
+ * satisfies `matchLang`. Recurses into container nodes (ListNode via
29
+ * ListItemNode.blocks) so fences nested inside list items are found.
30
+ *
31
+ * BlockquoteNode and NoteNode carry only InlineContent (not nested
32
+ * BodyBlock[]), so they are not recursed into. Returns declarations in
33
+ * source order (depth-first traversal).
34
+ */
35
+ export function extractFenceDeclarations(blocks, matchLang) {
36
+ const results = [];
37
+ for (const block of blocks) {
38
+ if (block.kind === "code" && matchLang(block.lang)) {
39
+ results.push({ source: block.text, range: block.range });
40
+ }
41
+ else if (block.kind === "list") {
42
+ for (const item of block.items) {
43
+ results.push(...extractFenceDeclarations(item.blocks, matchLang));
44
+ }
45
+ }
46
+ }
47
+ return results;
48
+ }
49
+ /**
50
+ * Walk a body AST and return every bullet-list item whose first paragraph
51
+ * satisfies `matchText`. Recurses through ListNode → ListItemNode.blocks
52
+ * for nested lists. Mixed lists are supported: items whose first paragraph
53
+ * matches are extracted; non-matching bullets are left alone.
54
+ *
55
+ * Returns declarations in source order (depth-first).
56
+ */
57
+ export function extractBulletDeclarations(blocks, matchText) {
58
+ const results = [];
59
+ for (const block of blocks) {
60
+ if (block.kind === "list") {
61
+ for (const item of block.items) {
62
+ if (item.blocks.length === 0)
63
+ continue;
64
+ const first = item.blocks[0];
65
+ if (first.kind === "paragraph") {
66
+ if (matchText(first.content.text)) {
67
+ results.push({ source: first.content.text, range: first.range });
68
+ }
69
+ }
70
+ // Recurse into nested blocks (the item may itself contain a list).
71
+ if (item.blocks.length > 1) {
72
+ results.push(...extractBulletDeclarations(item.blocks.slice(1), matchText));
73
+ }
74
+ else if (first.kind === "list") {
75
+ results.push(...extractBulletDeclarations([first], matchText));
76
+ }
77
+ }
78
+ }
79
+ }
80
+ return results;
81
+ }
82
+ /**
83
+ * Strip the surrounding backtick delimiter(s) from an inline-code token's
84
+ * `text` field. `body_tokens.ts` stores inline-code text as `` `value` ``
85
+ * (with backtick delimiters); a DSL recognizer and parser need the inner
86
+ * value only.
87
+ *
88
+ * Handles both single-backtick (`` `…` ``) and double-backtick (` ``…`` `)
89
+ * delimiters. Returns the original string unchanged when it does not start
90
+ * and end with a matching backtick fence.
91
+ */
92
+ export function stripCodeSpanDelimiters(text) {
93
+ if (text.startsWith("``") && text.endsWith("``") && text.length > 4) {
94
+ return text.slice(2, -2);
95
+ }
96
+ if (text.startsWith("`") && text.endsWith("`") && text.length > 2) {
97
+ return text.slice(1, -1);
98
+ }
99
+ return text;
100
+ }
101
+ /**
102
+ * Filter `bodyTokens` to inline-code spans whose contents (backticks
103
+ * stripped) satisfy `matchText`. Returns declarations in source order
104
+ * (the bodyTokens contract guarantees source order).
105
+ *
106
+ * `inline-code` tokens store their `text` field with surrounding backtick
107
+ * delimiters (e.g. `` `$X : signal` ``). This function strips those
108
+ * delimiters via {@linkcode stripCodeSpanDelimiters} before recognizing
109
+ * and before setting `source`, so the DSL parser receives the raw source.
110
+ */
111
+ export function extractInlineDeclarations(bodyTokens, matchText) {
112
+ const results = [];
113
+ for (const token of bodyTokens) {
114
+ if (token.kind !== "inline-code")
115
+ continue;
116
+ const inner = stripCodeSpanDelimiters(token.text);
117
+ if (!matchText(inner))
118
+ continue;
119
+ results.push({ source: inner, location: token.location });
120
+ }
121
+ return results;
122
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @module core/decl/table
3
+ *
4
+ * Table declaration surface (uxil epic #717 §A / S3). A fourth embedding
5
+ * surface on the shared declaration machinery (alongside fence, bullet, and
6
+ * inline): each **data row** of a GFM table is one declaration, and the
7
+ * table's `Table:` caption may carry a base that the entry-local resolver
8
+ * (S4) consumes.
9
+ *
10
+ * DSL-agnostic, like its siblings: the caller supplies a `rowToSource`
11
+ * recognizer that maps a row's cell texts to a declaration source (or
12
+ * `undefined` to skip a non-declaration / malformed row), and parses the
13
+ * actual base ref out of the surfaced {@linkcode TableRowDeclaration.captionText}
14
+ * itself — the caption's ref grammar is DSL-specific.
15
+ *
16
+ * Row positions: a {@linkcode TableNode} carries one range for the whole
17
+ * table and its verbatim `raw` source, but rows have no individual range
18
+ * (cells are stored as text only). Per-row ranges are therefore derived
19
+ * from the table's start line plus the row's index, past the GFM header and
20
+ * delimiter lines.
21
+ */
22
+ import type { BodyBlock } from "../ast/nodes.js";
23
+ import type { BlockDeclaration } from "./surfaces.js";
24
+ /**
25
+ * A declaration found on one data row of a table. Extends the shared
26
+ * {@linkcode BlockDeclaration} (`source` = the row reduced to a declaration
27
+ * by the DSL's recognizer; `range` = the row's line-precise span) with
28
+ * `captionText`: the enclosing table's `Table:` caption text, when the table
29
+ * has an adjacent one — the DSL parses a base ref out of it and hands that
30
+ * to the resolver (S4).
31
+ */
32
+ export interface TableRowDeclaration extends BlockDeclaration {
33
+ /** The enclosing table's `Table:` caption text, if any. */
34
+ readonly captionText?: string;
35
+ }
36
+ /**
37
+ * Maps a data row's cell texts to a declaration source, or returns
38
+ * `undefined` to skip the row (not a declaration, or malformed). The only
39
+ * DSL-specific input to {@linkcode extractTableDeclarations}.
40
+ */
41
+ export type RowRecognizer = (cells: readonly string[]) => string | undefined;
42
+ /**
43
+ * Walk a body AST and return a declaration for every table data row the
44
+ * `rowToSource` recognizer accepts, in source order. Recurses into
45
+ * container nodes (ListNode via ListItemNode.blocks) so tables nested
46
+ * inside list items are found. Rows the recognizer skips (`undefined`)
47
+ * contribute nothing — the malformed-row case.
48
+ */
49
+ export declare function extractTableDeclarations(blocks: readonly BodyBlock[], rowToSource: RowRecognizer): readonly TableRowDeclaration[];
50
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/decl/table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;AAM7E;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,WAAW,EAAE,aAAa,GACzB,SAAS,mBAAmB,EAAE,CAIhC"}