@driftsys/markspec 0.10.2 → 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 (67) hide show
  1. package/esm/decl/mod.d.ts +18 -0
  2. package/esm/decl/mod.d.ts.map +1 -0
  3. package/esm/decl/mod.js +14 -0
  4. package/esm/decl/resolve.d.ts +104 -0
  5. package/esm/decl/resolve.d.ts.map +1 -0
  6. package/esm/decl/resolve.js +66 -0
  7. package/esm/decl/surfaces.d.ts +96 -0
  8. package/esm/decl/surfaces.d.ts.map +1 -0
  9. package/esm/decl/surfaces.js +122 -0
  10. package/esm/decl/table.d.ts +50 -0
  11. package/esm/decl/table.d.ts.map +1 -0
  12. package/esm/decl/table.js +124 -0
  13. package/esm/mod.d.ts +1 -1
  14. package/esm/mod.js +1 -1
  15. package/esm/parser/directives.d.ts +6 -0
  16. package/esm/parser/directives.d.ts.map +1 -1
  17. package/esm/parser/directives.js +17 -0
  18. package/esm/parser/markdown.d.ts.map +1 -1
  19. package/esm/parser/markdown.js +9 -0
  20. package/esm/typl/bullet.d.ts +13 -23
  21. package/esm/typl/bullet.d.ts.map +1 -1
  22. package/esm/typl/bullet.js +6 -40
  23. package/esm/typl/fence.d.ts +12 -21
  24. package/esm/typl/fence.d.ts.map +1 -1
  25. package/esm/typl/fence.js +5 -20
  26. package/esm/typl/inline.d.ts +15 -24
  27. package/esm/typl/inline.d.ts.map +1 -1
  28. package/esm/typl/inline.js +6 -44
  29. package/esm/typl/recognize.d.ts +14 -0
  30. package/esm/typl/recognize.d.ts.map +1 -0
  31. package/esm/typl/recognize.js +19 -0
  32. package/esm/validator/body_blocks.d.ts.map +1 -1
  33. package/esm/validator/body_blocks.js +3 -9
  34. package/package.json +1 -1
  35. package/script/decl/mod.d.ts +18 -0
  36. package/script/decl/mod.d.ts.map +1 -0
  37. package/script/decl/mod.js +24 -0
  38. package/script/decl/resolve.d.ts +104 -0
  39. package/script/decl/resolve.d.ts.map +1 -0
  40. package/script/decl/resolve.js +70 -0
  41. package/script/decl/surfaces.d.ts +96 -0
  42. package/script/decl/surfaces.d.ts.map +1 -0
  43. package/script/decl/surfaces.js +128 -0
  44. package/script/decl/table.d.ts +50 -0
  45. package/script/decl/table.d.ts.map +1 -0
  46. package/script/decl/table.js +127 -0
  47. package/script/mod.d.ts +1 -1
  48. package/script/mod.js +1 -1
  49. package/script/parser/directives.d.ts +6 -0
  50. package/script/parser/directives.d.ts.map +1 -1
  51. package/script/parser/directives.js +18 -0
  52. package/script/parser/markdown.d.ts.map +1 -1
  53. package/script/parser/markdown.js +9 -0
  54. package/script/typl/bullet.d.ts +13 -23
  55. package/script/typl/bullet.d.ts.map +1 -1
  56. package/script/typl/bullet.js +6 -40
  57. package/script/typl/fence.d.ts +12 -21
  58. package/script/typl/fence.d.ts.map +1 -1
  59. package/script/typl/fence.js +5 -20
  60. package/script/typl/inline.d.ts +15 -24
  61. package/script/typl/inline.d.ts.map +1 -1
  62. package/script/typl/inline.js +6 -44
  63. package/script/typl/recognize.d.ts +14 -0
  64. package/script/typl/recognize.d.ts.map +1 -0
  65. package/script/typl/recognize.js +22 -0
  66. package/script/validator/body_blocks.d.ts.map +1 -1
  67. package/script/validator/body_blocks.js +3 -9
@@ -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"}
@@ -0,0 +1,124 @@
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
+ /** GFM layout offset: a data row at `rows[i]` sits `i` lines past the
23
+ * header (line 0) and delimiter (line 1) rows in the table's raw source. */
24
+ const HEADER_AND_DELIMITER_LINES = 2;
25
+ /**
26
+ * Walk a body AST and return a declaration for every table data row the
27
+ * `rowToSource` recognizer accepts, in source order. Recurses into
28
+ * container nodes (ListNode via ListItemNode.blocks) so tables nested
29
+ * inside list items are found. Rows the recognizer skips (`undefined`)
30
+ * contribute nothing — the malformed-row case.
31
+ */
32
+ export function extractTableDeclarations(blocks, rowToSource) {
33
+ const results = [];
34
+ walk(blocks, rowToSource, results);
35
+ return results;
36
+ }
37
+ function walk(blocks, rowToSource, out) {
38
+ for (let i = 0; i < blocks.length; i++) {
39
+ const block = blocks[i];
40
+ if (block.kind === "table") {
41
+ const captionText = adjacentTableCaption(blocks, i);
42
+ const rawLines = block.raw.split("\n");
43
+ for (let r = 0; r < block.rows.length; r++) {
44
+ const cells = block.rows[r].map((cell) => cell.text);
45
+ const source = rowToSource(cells);
46
+ if (source === undefined)
47
+ continue;
48
+ out.push({
49
+ source,
50
+ range: rowRange(block, rawLines, r),
51
+ ...(captionText !== undefined ? { captionText } : {}),
52
+ });
53
+ }
54
+ }
55
+ else if (block.kind === "list") {
56
+ for (const item of block.items)
57
+ walk(item.blocks, rowToSource, out);
58
+ }
59
+ }
60
+ }
61
+ /**
62
+ * Return the text of the `Table:` caption that captions the table at
63
+ * `blocks[index]`, or `undefined` when there is none.
64
+ *
65
+ * Pairing is by local adjacency, re-deriving the above/below rule from the
66
+ * neighbours rather than trusting `CaptionNode.position`: the builder assigns
67
+ * `position` only for top-level blocks (`assignCaptionPositions` in
68
+ * core/ast/build.ts), so a caption inside a list item keeps the default
69
+ * `"below"` and cannot be trusted. A `Table:` caption immediately before the
70
+ * table captions it (the table is the caption's next captionable block); one
71
+ * immediately after captions it only when no captionable block follows the
72
+ * caption — otherwise that caption belongs to the following block.
73
+ */
74
+ function adjacentTableCaption(blocks, index) {
75
+ const prev = blocks[index - 1];
76
+ if (isTableCaption(prev))
77
+ return prev.text;
78
+ const next = blocks[index + 1];
79
+ if (isTableCaption(next) && !isCaptionable(blocks[index + 2])) {
80
+ return next.text;
81
+ }
82
+ return undefined;
83
+ }
84
+ function isTableCaption(block) {
85
+ return block?.kind === "caption" && block.keyword === "Table";
86
+ }
87
+ /**
88
+ * Block kinds a caption can caption (mirrors the captionable set in
89
+ * `assignCaptionPositions`, core/ast/build.ts). Used to decide whether a
90
+ * caption that follows a table belongs to that table or to a later
91
+ * captionable block.
92
+ */
93
+ function isCaptionable(block) {
94
+ if (block === undefined)
95
+ return false;
96
+ switch (block.kind) {
97
+ case "figure":
98
+ case "table":
99
+ case "code":
100
+ case "feature":
101
+ case "math":
102
+ case "list":
103
+ return true;
104
+ default:
105
+ return false;
106
+ }
107
+ }
108
+ /**
109
+ * The line-precise range of data row `rowIndex`. The table's `range.start`
110
+ * is the header line; the data row sits `HEADER_AND_DELIMITER_LINES +
111
+ * rowIndex` lines below it, at the table's start column. `raw` is de-indented
112
+ * by `verbatimSlice`, so adding the de-indented row length to the table's
113
+ * column yields the true source span — correct for both top-level (column 1)
114
+ * and list-nested (indented) tables.
115
+ */
116
+ function rowRange(table, rawLines, rowIndex) {
117
+ const line = table.range.start.line + HEADER_AND_DELIMITER_LINES + rowIndex;
118
+ const column = table.range.start.column;
119
+ const rawLine = rawLines[HEADER_AND_DELIMITER_LINES + rowIndex] ?? "";
120
+ return {
121
+ start: { line, column },
122
+ end: { line, column: column + rawLine.length },
123
+ };
124
+ }
package/esm/mod.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * from core/mod.ts, never from internal paths.
9
9
  */
10
10
  import "./_dnt.polyfills.js";
11
- export declare const VERSION = "0.10.2";
11
+ export declare const VERSION = "0.10.3";
12
12
  export declare const CORE_SCHEMA_VERSION = 1;
13
13
  export { ConfigError, CORE_DISCIPLINE_REGISTRY, CORE_KINDS, CORE_RELATIONS, DEFAULT_PROJECT_CONFIG, descendantsOf, formatEntryOrigin, KNOWN_LINK_KINDS, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, makeUlid, MIXED_DISCIPLINE, PALETTE_HUES, REFHUB_URL, } from "./model/mod.js";
14
14
  export type { Attribute, BodyToken, BodyTokenKind, Caption, CaptionConventions, CaptionPosition, ConfigFieldError, DeliveredDocument, Diagnostic, Directive, Discipline, DisciplineRegistry, DisplayId, EarsTrigger, EffectiveProfile, EffectiveTypeDef, EntityRefConvention, Entry, EntryOrigin, EntryShape, EntrySource, ExtractorRule, InlineRef, KindDecl, LabelConcern, LabelConcernKind, LabelValue, Link, LinkKind, LoadedProfile, ModalCase, PaletteHue, ProfileChain, ProfileConvention, ProjectConfig, ProvenancedMap, ProvenancedMapEntry, ProvenancedValue, RelationDef, Severity, SourceLocation, Ulid, } from "./model/mod.js";
package/esm/mod.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * from core/mod.ts, never from internal paths.
9
9
  */
10
10
  import "./_dnt.polyfills.js";
11
- export const VERSION = "0.10.2";
11
+ export const VERSION = "0.10.3";
12
12
  export const CORE_SCHEMA_VERSION = 1;
13
13
  // Model types
14
14
  export { ConfigError, CORE_DISCIPLINE_REGISTRY, CORE_KINDS, CORE_RELATIONS, DEFAULT_PROJECT_CONFIG, descendantsOf, formatEntryOrigin, KNOWN_LINK_KINDS, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, makeUlid, MIXED_DISCIPLINE, PALETTE_HUES, REFHUB_URL, } from "./model/mod.js";
@@ -13,6 +13,12 @@ export interface DetectDirectivesOptions {
13
13
  /** File path used in source locations. */
14
14
  readonly file?: string;
15
15
  }
16
+ /**
17
+ * Return `true` when `line` is a standalone `<!-- markspec:* -->` directive
18
+ * comment. Accepts the line trimmed or with surrounding whitespace, and both
19
+ * the spaced (`<!-- markspec:`) and no-space (`<!--markspec:`) forms.
20
+ */
21
+ export declare function isMarkspecDirectiveComment(line: string): boolean;
16
22
  /**
17
23
  * Detect MarkSpec directives in a Markdown string.
18
24
  *
@@ -1 +1 @@
1
- {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../../src/parser/directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAGjE,gDAAgD;AAChD,MAAM,WAAW,uBAAuB;IACtC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAQD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,uBAAuB,GAChC,SAAS,EAAE,CAqEb"}
1
+ {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../../src/parser/directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAGjE,gDAAgD;AAChD,MAAM,WAAW,uBAAuB;IACtC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAkBD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,uBAAuB,GAChC,SAAS,EAAE,CAqEb"}