@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
@@ -12,6 +12,23 @@ import { processor } from "./remark.js";
12
12
  const COMMENT_RE = /^<!--([\s\S]*?)-->$/;
13
13
  /** Matches a `markspec:` directive line within a comment body. */
14
14
  const DIRECTIVE_RE = /^markspec:(\S+)\s?(.*)?$/;
15
+ /**
16
+ * A whole-line markspec directive comment: `<!-- markspec:<rest> -->`
17
+ * occupying the line on its own (optional surrounding whitespace, and
18
+ * optional whitespace after `<!--`). This is the single definition the
19
+ * validator's body carve-out (spec §2.4.1) and the parser's trailer
20
+ * heuristics both consult, so they can never disagree on what a directive
21
+ * comment is (#687).
22
+ */
23
+ const DIRECTIVE_COMMENT_LINE_RE = /^\s*<!--\s*markspec:[\s\S]*?-->\s*$/;
24
+ /**
25
+ * Return `true` when `line` is a standalone `<!-- markspec:* -->` directive
26
+ * comment. Accepts the line trimmed or with surrounding whitespace, and both
27
+ * the spaced (`<!-- markspec:`) and no-space (`<!--markspec:`) forms.
28
+ */
29
+ export function isMarkspecDirectiveComment(line) {
30
+ return DIRECTIVE_COMMENT_LINE_RE.test(line);
31
+ }
15
32
  /**
16
33
  * Detect MarkSpec directives in a Markdown string.
17
34
  *
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAa,UAAU,EAAE,KAAK,EAAc,MAAM,iBAAiB,CAAC;AAkBhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAwB7C,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAsDD,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,mBAAmB,CA8CrB"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAa,UAAU,EAAE,KAAK,EAAc,MAAM,iBAAiB,CAAC;AAmBhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAwB7C,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAsDD,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,mBAAmB,CA8CrB"}
@@ -7,6 +7,7 @@
7
7
  import { CORE_RELATIONS, IDENTITY_KEY, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, shapeFromIdValue, UNIVERSAL_ATTRIBUTE_KEYS, } from "../model/mod.js";
8
8
  import { ATTR_LINE_RE, collateAttributes, parseAttributes, splitBodyAndAttributes, } from "./attributes.js";
9
9
  import { extractBodyTokens } from "./body_tokens.js";
10
+ import { isMarkspecDirectiveComment } from "./directives.js";
10
11
  import { processor } from "./remark.js";
11
12
  import { buildBodyAstWithTree } from "../ast/build.js";
12
13
  import { translateEntryLocations } from "./translate.js";
@@ -335,6 +336,14 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
335
336
  const trimmed = bodyLines[i].trim();
336
337
  if (!trimmed)
337
338
  continue; // skip trailing blanks
339
+ // A `<!-- markspec:* -->` directive comment is legitimate body
340
+ // content (spec §2.4.1), not a trailer line — skip it so its
341
+ // `<!--markspec` colon-prefix is never mistaken for a malformed
342
+ // trailer key. `continue` (not `break`) keeps scanning earlier lines,
343
+ // so a genuine leaked-trailer typo sitting above a directive comment
344
+ // still fires MSL-P022 (#687, preserves #697).
345
+ if (isMarkspecDirectiveComment(trimmed))
346
+ continue;
338
347
  const colonMatch = COLON_SPLIT_RE.exec(trimmed);
339
348
  if (!colonMatch)
340
349
  break; // stop at non-colon line
@@ -2,33 +2,23 @@
2
2
  * @module typl/bullet
3
3
  *
4
4
  * Bullet-glossary surface adapter — recognises CommonMark bullet list
5
- * items whose first paragraph matches typl syntax (`$X : ...` binding
6
- * or `type X = ...` typedef). Mixed lists are supported: items that
7
- * match are treated as typl declarations; non-matching bullets are
8
- * left alone.
9
- *
10
- * Each matching item produces one TyplBulletExtraction; the parser
11
- * integration calls parseTyplBlock on each `source` independently.
12
- * Per-item position-bridging uses the item's range and formula
13
- * documented in bridgeTyplDiagnostic.
5
+ * items whose first paragraph is a typl declaration (`$X : …` binding or
6
+ * `type X = …` typedef). A thin wrapper over the shared
7
+ * declaration-surface machinery (core/decl): it supplies typl's text
8
+ * recognizer and re-exports the common declaration node as
9
+ * {@linkcode TyplBulletExtraction}. Mixed lists are supported — matching
10
+ * items are extracted, non-matching bullets are left alone.
14
11
  *
15
12
  * See ADR-019.
16
13
  */
17
- import type { BodyBlock, SourceRange } from "../ast/nodes.js";
18
- /** A single typl bullet item found inside a body. */
19
- export interface TyplBulletExtraction {
20
- /** The typl source from one matching bullet item (paragraph text). */
21
- readonly source: string;
22
- /** Source range of the bullet's first paragraph. */
23
- readonly range: SourceRange;
24
- }
14
+ import type { BodyBlock } from "../ast/nodes.js";
15
+ import { type BlockDeclaration } from "../decl/mod.js";
16
+ /** A single typl bullet item found inside a body: `{ source, range }`. */
17
+ export type TyplBulletExtraction = BlockDeclaration;
25
18
  /**
26
- * Walk a body AST and return every bullet-list item whose first
27
- * paragraph matches typl syntax. Recurses through ListNode →
28
- * ListItemNode.blocks for nested lists (typl bullets inside a nested
29
- * list are picked up).
30
- *
31
- * Returns matches in source order (depth-first).
19
+ * Walk a body AST and return every bullet-list item whose first paragraph
20
+ * is a typl declaration, in source order (depth-first, recursing into
21
+ * nested lists). Delegates traversal to {@linkcode extractBulletDeclarations}.
32
22
  */
33
23
  export declare function extractTyplBullets(blocks: readonly BodyBlock[]): readonly TyplBulletExtraction[];
34
24
  //# sourceMappingURL=bullet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bullet.d.ts","sourceRoot":"","sources":["../../src/typl/bullet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,SAAS,EAAiB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE7E,qDAAqD;AACrD,MAAM,WAAW,oBAAoB;IACnC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAYD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,SAAS,oBAAoB,EAAE,CA0BjC"}
1
+ {"version":3,"file":"bullet.d.ts","sourceRoot":"","sources":["../../src/typl/bullet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,gBAAgB,CAAC;AAGxB,0EAA0E;AAC1E,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,SAAS,oBAAoB,EAAE,CAEjC"}
@@ -1,44 +1,10 @@
1
- /** Matches a typl binding bullet (paragraph text). */
2
- const BULLET_BINDING_RE = /^\$[A-Za-z_][A-Za-z0-9_]*\s*:/;
3
- /** Matches a typl typedef bullet (paragraph text). */
4
- const BULLET_TYPEDEF_RE = /^type\s+[A-Za-z_][A-Za-z0-9_]*\s*=/;
5
- function isTyplBulletText(text) {
6
- return BULLET_BINDING_RE.test(text) || BULLET_TYPEDEF_RE.test(text);
7
- }
1
+ import { extractBulletDeclarations, } from "../decl/mod.js";
2
+ import { isTyplDeclarationText } from "./recognize.js";
8
3
  /**
9
- * Walk a body AST and return every bullet-list item whose first
10
- * paragraph matches typl syntax. Recurses through ListNode →
11
- * ListItemNode.blocks for nested lists (typl bullets inside a nested
12
- * list are picked up).
13
- *
14
- * Returns matches in source order (depth-first).
4
+ * Walk a body AST and return every bullet-list item whose first paragraph
5
+ * is a typl declaration, in source order (depth-first, recursing into
6
+ * nested lists). Delegates traversal to {@linkcode extractBulletDeclarations}.
15
7
  */
16
8
  export function extractTyplBullets(blocks) {
17
- const results = [];
18
- for (const block of blocks) {
19
- if (block.kind === "list") {
20
- for (const item of block.items) {
21
- if (item.blocks.length === 0)
22
- continue;
23
- const first = item.blocks[0];
24
- if (first.kind === "paragraph") {
25
- const para = first;
26
- if (isTyplBulletText(para.content.text)) {
27
- results.push({
28
- source: para.content.text,
29
- range: para.range,
30
- });
31
- }
32
- }
33
- // Recurse into nested blocks (the item may itself contain a list)
34
- if (item.blocks.length > 1) {
35
- results.push(...extractTyplBullets(item.blocks.slice(1)));
36
- }
37
- else if (first.kind === "list") {
38
- results.push(...extractTyplBullets([first]));
39
- }
40
- }
41
- }
42
- }
43
- return results;
9
+ return extractBulletDeclarations(blocks, isTyplDeclarationText);
44
10
  }
@@ -2,30 +2,21 @@
2
2
  * @module typl/fence
3
3
  *
4
4
  * Fence surface adapter — extracts typl source from fenced code blocks
5
- * whose info-string is "typl". Operates on the canonical body AST
6
- * (BodyBlock[]) produced by core/ast/build.ts.
5
+ * whose info-string is "typl". A thin wrapper over the shared
6
+ * declaration-surface machinery (core/decl): it supplies typl's fence
7
+ * recognizer and re-exports the common declaration node as
8
+ * {@linkcode TyplFenceExtraction}.
7
9
  *
8
- * This module is parser-side only — it returns the raw typl source and
9
- * its source range. PR 3 will wire the extracted source through
10
- * parseTyplBlock and attach results to Entry.types.
10
+ * See ADR-019.
11
11
  */
12
- import type { BodyBlock, SourceRange } from "../ast/nodes.js";
13
- /** A single typl fence found inside a body. */
14
- export interface TyplFenceExtraction {
15
- /** The verbatim typl source from inside the fence (CodeNode.text). */
16
- readonly source: string;
17
- /** Source range of the whole fence (opening ``` through closing ```). */
18
- readonly range: SourceRange;
19
- }
12
+ import type { BodyBlock } from "../ast/nodes.js";
13
+ import { type BlockDeclaration } from "../decl/mod.js";
14
+ /** A single typl fence found inside a body: `{ source, range }`. */
15
+ export type TyplFenceExtraction = BlockDeclaration;
20
16
  /**
21
- * Walk a body AST and return every typl fence found. Recurses into
22
- * container nodes (ListNode via ListItemNode.blocks) so typl fences
23
- * nested inside list items are discovered.
24
- *
25
- * BlockquoteNode and NoteNode carry only InlineContent (not nested
26
- * BodyBlock[]), so they are not recursed into.
27
- *
28
- * Returns fences in source order (depth-first traversal).
17
+ * Walk a body AST and return every typl fence (```typl) found, in source
18
+ * order (depth-first, recursing into list items). Delegates traversal to
19
+ * {@linkcode extractFenceDeclarations}.
29
20
  */
30
21
  export declare function extractTyplFences(blocks: readonly BodyBlock[]): readonly TyplFenceExtraction[];
31
22
  //# sourceMappingURL=fence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/typl/fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,+CAA+C;AAC/C,MAAM,WAAW,mBAAmB;IAClC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,SAAS,mBAAmB,EAAE,CAYhC"}
1
+ {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/typl/fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,gBAAgB,CAAC;AAExB,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,SAAS,mBAAmB,EAAE,CAEhC"}
package/esm/typl/fence.js CHANGED
@@ -1,24 +1,9 @@
1
+ import { extractFenceDeclarations, } from "../decl/mod.js";
1
2
  /**
2
- * Walk a body AST and return every typl fence found. Recurses into
3
- * container nodes (ListNode via ListItemNode.blocks) so typl fences
4
- * nested inside list items are discovered.
5
- *
6
- * BlockquoteNode and NoteNode carry only InlineContent (not nested
7
- * BodyBlock[]), so they are not recursed into.
8
- *
9
- * Returns fences in source order (depth-first traversal).
3
+ * Walk a body AST and return every typl fence (```typl) found, in source
4
+ * order (depth-first, recursing into list items). Delegates traversal to
5
+ * {@linkcode extractFenceDeclarations}.
10
6
  */
11
7
  export function extractTyplFences(blocks) {
12
- const results = [];
13
- for (const block of blocks) {
14
- if (block.kind === "code" && block.lang === "typl") {
15
- results.push({ source: block.text, range: block.range });
16
- }
17
- else if (block.kind === "list") {
18
- for (const item of block.items) {
19
- results.push(...extractTyplFences(item.blocks));
20
- }
21
- }
22
- }
23
- return results;
8
+ return extractFenceDeclarations(blocks, (lang) => lang === "typl");
24
9
  }
@@ -1,34 +1,25 @@
1
1
  /**
2
2
  * @module typl/inline
3
3
  *
4
- * Inline backtick surface adapter — recognises typl declarations
5
- * wrapped in CommonMark code spans, e.g. `` `$X : signal float[0..300]` ``
6
- * scattered through entry prose.
7
- *
8
- * Filters Entry.bodyTokens (ADR-016) for `inline-code` tokens whose text
9
- * matches typl syntax. Each matching span produces one
10
- * TyplInlineExtraction; the parser integration calls parseTyplBlock on
11
- * each `source` independently.
4
+ * Inline backtick surface adapter — recognises typl declarations wrapped
5
+ * in CommonMark code spans, e.g. `` `$X : signal float[0..300]` ``
6
+ * scattered through entry prose. A thin wrapper over the shared
7
+ * declaration-surface machinery (core/decl): it supplies typl's text
8
+ * recognizer and re-exports the common declaration node as
9
+ * {@linkcode TyplInlineExtraction}. The shared machinery strips the
10
+ * backtick delimiters `Entry.bodyTokens` (ADR-016) records before
11
+ * recognizing, so `source` is the raw typl text.
12
12
  *
13
13
  * See ADR-019.
14
14
  */
15
- import type { BodyToken, SourceLocation } from "../model/mod.js";
16
- /** A single typl inline-code declaration found in an entry body. */
17
- export interface TyplInlineExtraction {
18
- /** The typl source from one matching code span (text between backticks). */
19
- readonly source: string;
20
- /** File-relative location of the code span. */
21
- readonly location: SourceLocation;
22
- }
15
+ import type { BodyToken } from "../model/mod.js";
16
+ import { type InlineDeclaration } from "../decl/mod.js";
17
+ /** A single typl inline-code declaration: `{ source, location }`. */
18
+ export type TyplInlineExtraction = InlineDeclaration;
23
19
  /**
24
- * Filter bodyTokens to inline-code spans whose contents match typl
25
- * syntax. Returns extractions in source order (the bodyTokens contract
26
- * guarantees source order).
27
- *
28
- * `inline-code` tokens in `bodyTokens` store their `text` field with
29
- * surrounding backtick delimiters (e.g., `` `$X : signal` ``). This
30
- * function strips those delimiters before pattern-matching and before
31
- * setting `source`, so `parseTyplBlock` receives the raw typl source.
20
+ * Filter `Entry.bodyTokens` to inline-code spans whose contents are typl
21
+ * declarations, in source order. Delegates to
22
+ * {@linkcode extractInlineDeclarations}.
32
23
  */
33
24
  export declare function extractTyplInlines(bodyTokens: readonly BodyToken[]): readonly TyplInlineExtraction[];
34
25
  //# sourceMappingURL=inline.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../../src/typl/inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjE,oEAAoE;AACpE,MAAM,WAAW,oBAAoB;IACnC,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CACnC;AAgCD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,SAAS,oBAAoB,EAAE,CASjC"}
1
+ {"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../../src/typl/inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AAGxB,qEAAqE;AACrE,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,SAAS,oBAAoB,EAAE,CAEjC"}
@@ -1,48 +1,10 @@
1
- /** Matches a typl binding span (code-span text). */
2
- const INLINE_BINDING_RE = /^\$[A-Za-z_][A-Za-z0-9_]*\s*:/;
3
- /** Matches a typl typedef span (code-span text). */
4
- const INLINE_TYPEDEF_RE = /^type\s+[A-Za-z_][A-Za-z0-9_]*\s*=/;
5
- function isTyplInlineText(text) {
6
- return INLINE_BINDING_RE.test(text) || INLINE_TYPEDEF_RE.test(text);
7
- }
8
- /**
9
- * Strip the surrounding backtick delimiter(s) from an inline-code token's
10
- * `text` field. `body_tokens.ts` stores inline-code text as `` `value` ``
11
- * (with backtick delimiters). The typl patterns and `parseTyplBlock` need
12
- * the inner value only.
13
- *
14
- * Handles both single-backtick (`` `…` ``) and double-backtick (` ``…`` `)
15
- * delimiters. Returns the original string unchanged when it does not start
16
- * and end with a matching backtick fence.
17
- */
18
- function stripBackticks(text) {
19
- if (text.startsWith("``") && text.endsWith("``") && text.length > 4) {
20
- return text.slice(2, -2);
21
- }
22
- if (text.startsWith("`") && text.endsWith("`") && text.length > 2) {
23
- return text.slice(1, -1);
24
- }
25
- return text;
26
- }
1
+ import { extractInlineDeclarations, } from "../decl/mod.js";
2
+ import { isTyplDeclarationText } from "./recognize.js";
27
3
  /**
28
- * Filter bodyTokens to inline-code spans whose contents match typl
29
- * syntax. Returns extractions in source order (the bodyTokens contract
30
- * guarantees source order).
31
- *
32
- * `inline-code` tokens in `bodyTokens` store their `text` field with
33
- * surrounding backtick delimiters (e.g., `` `$X : signal` ``). This
34
- * function strips those delimiters before pattern-matching and before
35
- * setting `source`, so `parseTyplBlock` receives the raw typl source.
4
+ * Filter `Entry.bodyTokens` to inline-code spans whose contents are typl
5
+ * declarations, in source order. Delegates to
6
+ * {@linkcode extractInlineDeclarations}.
36
7
  */
37
8
  export function extractTyplInlines(bodyTokens) {
38
- const results = [];
39
- for (const token of bodyTokens) {
40
- if (token.kind !== "inline-code")
41
- continue;
42
- const inner = stripBackticks(token.text);
43
- if (!isTyplInlineText(inner))
44
- continue;
45
- results.push({ source: inner, location: token.location });
46
- }
47
- return results;
9
+ return extractInlineDeclarations(bodyTokens, isTyplDeclarationText);
48
10
  }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module typl/recognize
3
+ *
4
+ * typl declaration recognizer — the DSL-specific predicate the shared
5
+ * declaration-surface machinery (core/decl) is parameterized by. A typl
6
+ * declaration is a binding (`$Name : …`) or a typedef (`type Name = …`).
7
+ * The bullet and inline surfaces share this text recognizer; the fence
8
+ * surface is recognized by its `typl` info-string (see fence.ts).
9
+ *
10
+ * See ADR-019.
11
+ */
12
+ /** True when `text` begins a typl binding or typedef declaration. */
13
+ export declare function isTyplDeclarationText(text: string): boolean;
14
+ //# sourceMappingURL=recognize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recognize.d.ts","sourceRoot":"","sources":["../../src/typl/recognize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module typl/recognize
3
+ *
4
+ * typl declaration recognizer — the DSL-specific predicate the shared
5
+ * declaration-surface machinery (core/decl) is parameterized by. A typl
6
+ * declaration is a binding (`$Name : …`) or a typedef (`type Name = …`).
7
+ * The bullet and inline surfaces share this text recognizer; the fence
8
+ * surface is recognized by its `typl` info-string (see fence.ts).
9
+ *
10
+ * See ADR-019.
11
+ */
12
+ /** Matches a typl binding: `$Name :`. */
13
+ const BINDING_RE = /^\$[A-Za-z_][A-Za-z0-9_]*\s*:/;
14
+ /** Matches a typl typedef: `type Name =`. */
15
+ const TYPEDEF_RE = /^type\s+[A-Za-z_][A-Za-z0-9_]*\s*=/;
16
+ /** True when `text` begins a typl binding or typedef declaration. */
17
+ export function isTyplDeclarationText(text) {
18
+ return BINDING_RE.test(text) || TYPEDEF_RE.test(text);
19
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"body_blocks.d.ts","sourceRoot":"","sources":["../../src/validator/body_blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAkMzD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,UAAU,EAAE,CAsBtE"}
1
+ {"version":3,"file":"body_blocks.d.ts","sourceRoot":"","sources":["../../src/validator/body_blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AA2LzD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,UAAU,EAAE,CAsBtE"}
@@ -27,6 +27,7 @@
27
27
  * Code, Feature, and Math blocks are automatically excluded because the
28
28
  * builder emits opaque nodes for verbatim content — no prose text to scan.
29
29
  */
30
+ import { isMarkspecDirectiveComment } from "../parser/directives.js";
30
31
  /**
31
32
  * HTML tag detection. Matches an opening, closing, or self-closing tag
32
33
  * (`<tag>`, `</tag>`, `<tag/>`). Doesn't match HTML comments — those
@@ -37,13 +38,6 @@
37
38
  const HTML_TAG_RE = /<\/?[A-Za-z][A-Za-z0-9]*(\s[^>]*)?\/?>/;
38
39
  /** Any HTML comment, `<!--…-->`. */
39
40
  const HTML_COMMENT_RE = /<!--[\s\S]*?-->/;
40
- /**
41
- * A whole-line markspec directive comment: `<!-- markspec:<rest> -->`
42
- * occupying the line on its own (optional leading/trailing
43
- * whitespace). The directive form is the one exception spec §2.4.1
44
- * carves out from the "no raw HTML" rule.
45
- */
46
- const MARKSPEC_DIRECTIVE_LINE_RE = /^\s*<!--\s*markspec:[\s\S]*?-->\s*$/;
47
41
  /**
48
42
  * Return `true` when `line` contains raw HTML the body model forbids:
49
43
  * any tag, or any comment that isn't a standalone markspec directive.
@@ -51,7 +45,7 @@ const MARKSPEC_DIRECTIVE_LINE_RE = /^\s*<!--\s*markspec:[\s\S]*?-->\s*$/;
51
45
  function hasForbiddenHtml(line) {
52
46
  if (HTML_TAG_RE.test(line))
53
47
  return true;
54
- if (HTML_COMMENT_RE.test(line) && !MARKSPEC_DIRECTIVE_LINE_RE.test(line)) {
48
+ if (HTML_COMMENT_RE.test(line) && !isMarkspecDirectiveComment(line)) {
55
49
  return true;
56
50
  }
57
51
  return false;
@@ -123,7 +117,7 @@ function violationsFromBlock(block) {
123
117
  else if (block.subkind === "html") {
124
118
  // Block-level HTML: check if it is a markspec directive (exempt)
125
119
  // or forbidden HTML. The `raw` field carries the verbatim source.
126
- if (!MARKSPEC_DIRECTIVE_LINE_RE.test(block.raw)) {
120
+ if (!isMarkspecDirectiveComment(block.raw)) {
127
121
  out.push({ diag: RAW_HTML_DIAG, bodyLine });
128
122
  }
129
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftsys/markspec",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "Markdown flavor and toolchain for traceable industrial documentation",
5
5
  "keywords": [
6
6
  "markdown",
@@ -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,24 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/decl
4
+ *
5
+ * Shared declaration-surface machinery (uxil epic #717 §A). DSL-agnostic
6
+ * walkers that extract declaration sites from an entry body's four
7
+ * embedding surfaces — fenced code blocks, bullet paragraphs, inline code
8
+ * spans, and table rows — parameterized by a recognizer, plus the
9
+ * entry-local base-resolution engine (S4) that resolves relative refs
10
+ * against the base an enclosing declaration establishes. typl consumes
11
+ * these today; uxil (§B) rides on the same substrate.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.resolveRef = exports.checkSingleRoot = exports.extractTableDeclarations = exports.stripCodeSpanDelimiters = exports.extractInlineDeclarations = exports.extractFenceDeclarations = exports.extractBulletDeclarations = void 0;
15
+ var surfaces_js_1 = require("./surfaces.js");
16
+ Object.defineProperty(exports, "extractBulletDeclarations", { enumerable: true, get: function () { return surfaces_js_1.extractBulletDeclarations; } });
17
+ Object.defineProperty(exports, "extractFenceDeclarations", { enumerable: true, get: function () { return surfaces_js_1.extractFenceDeclarations; } });
18
+ Object.defineProperty(exports, "extractInlineDeclarations", { enumerable: true, get: function () { return surfaces_js_1.extractInlineDeclarations; } });
19
+ Object.defineProperty(exports, "stripCodeSpanDelimiters", { enumerable: true, get: function () { return surfaces_js_1.stripCodeSpanDelimiters; } });
20
+ var table_js_1 = require("./table.js");
21
+ Object.defineProperty(exports, "extractTableDeclarations", { enumerable: true, get: function () { return table_js_1.extractTableDeclarations; } });
22
+ var resolve_js_1 = require("./resolve.js");
23
+ Object.defineProperty(exports, "checkSingleRoot", { enumerable: true, get: function () { return resolve_js_1.checkSingleRoot; } });
24
+ Object.defineProperty(exports, "resolveRef", { enumerable: true, get: function () { return resolve_js_1.resolveRef; } });
@@ -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"}