@driftsys/markspec 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/ast/build.d.ts +70 -0
- package/esm/ast/build.d.ts.map +1 -0
- package/esm/ast/build.js +605 -0
- package/esm/ast/equivalence.d.ts +18 -0
- package/esm/ast/equivalence.d.ts.map +1 -0
- package/esm/ast/equivalence.js +56 -0
- package/esm/ast/nodes.d.ts +221 -0
- package/esm/ast/nodes.d.ts.map +1 -0
- package/esm/ast/nodes.js +12 -0
- package/esm/ast/normalize.d.ts +67 -0
- package/esm/ast/normalize.d.ts.map +1 -0
- package/esm/ast/normalize.js +255 -0
- package/esm/ast/render.d.ts +34 -0
- package/esm/ast/render.d.ts.map +1 -0
- package/esm/ast/render.js +215 -0
- package/esm/compiler/inverses.d.ts +2 -8
- package/esm/compiler/inverses.d.ts.map +1 -1
- package/esm/compiler/inverses.js +50 -14
- package/esm/compiler/manifest.d.ts +59 -0
- package/esm/compiler/manifest.d.ts.map +1 -0
- package/esm/compiler/manifest.js +48 -0
- package/esm/compiler/mod.d.ts +9 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +21 -2
- package/esm/compiler/ndjson_writer.d.ts +50 -0
- package/esm/compiler/ndjson_writer.d.ts.map +1 -0
- package/esm/compiler/ndjson_writer.js +73 -0
- package/esm/compiler/schema.d.ts +18 -1
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +18 -9
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +54 -0
- package/esm/formatter/mod.d.ts +49 -4
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +362 -33
- package/esm/formatter/synth_ulid.d.ts +21 -0
- package/esm/formatter/synth_ulid.d.ts.map +1 -0
- package/esm/formatter/synth_ulid.js +64 -0
- package/esm/lint/mod.d.ts +10 -0
- package/esm/lint/mod.d.ts.map +1 -0
- package/esm/lint/mod.js +7 -0
- package/esm/lint/rules/lexicon.d.ts +24 -0
- package/esm/lint/rules/lexicon.d.ts.map +1 -0
- package/esm/lint/rules/lexicon.js +236 -0
- package/esm/lint/rules/struct.d.ts +17 -0
- package/esm/lint/rules/struct.d.ts.map +1 -0
- package/esm/lint/rules/struct.js +55 -0
- package/esm/lint/rules/suppression.d.ts +19 -0
- package/esm/lint/rules/suppression.d.ts.map +1 -0
- package/esm/lint/rules/suppression.js +75 -0
- package/esm/lint/runner.d.ts +39 -0
- package/esm/lint/runner.d.ts.map +1 -0
- package/esm/lint/runner.js +112 -0
- package/esm/lint/types.d.ts +19 -0
- package/esm/lint/types.d.ts.map +1 -0
- package/esm/lint/types.js +9 -0
- package/esm/mod.d.ts +19 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +14 -3
- package/esm/model/attributes.d.ts.map +1 -1
- package/esm/model/attributes.js +163 -2
- package/esm/model/discriminating_attr.d.ts +33 -0
- package/esm/model/discriminating_attr.d.ts.map +1 -0
- package/esm/model/discriminating_attr.js +74 -0
- package/esm/model/mod.d.ts +98 -3
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +57 -2
- package/esm/model/profile.d.ts +33 -27
- package/esm/model/profile.d.ts.map +1 -1
- package/esm/model/source_introspection.d.ts +26 -0
- package/esm/model/source_introspection.d.ts.map +1 -0
- package/esm/model/source_introspection.js +77 -0
- package/esm/model/type_hierarchy.d.ts +51 -0
- package/esm/model/type_hierarchy.d.ts.map +1 -0
- package/esm/model/type_hierarchy.js +126 -0
- package/esm/model/uri_scheme_map.d.ts +21 -0
- package/esm/model/uri_scheme_map.d.ts.map +1 -0
- package/esm/model/uri_scheme_map.js +66 -0
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +9 -6
- package/esm/parser/entity_refs.d.ts +53 -0
- package/esm/parser/entity_refs.d.ts.map +1 -0
- package/esm/parser/entity_refs.js +151 -0
- package/esm/parser/glossary.d.ts +43 -0
- package/esm/parser/glossary.d.ts.map +1 -0
- package/esm/parser/glossary.js +217 -0
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +223 -7
- package/esm/parser/mod.d.ts +1 -0
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +1 -0
- package/esm/parser/source.d.ts +20 -0
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +3 -3
- package/esm/profile/chain.js +3 -13
- package/esm/profile/colors.js +1 -1
- package/esm/profile/introspect.d.ts +135 -0
- package/esm/profile/introspect.d.ts.map +1 -0
- package/esm/profile/introspect.js +378 -0
- package/esm/profile/load.d.ts.map +1 -1
- package/esm/profile/load.js +67 -0
- package/esm/profile/manifest.d.ts.map +1 -1
- package/esm/profile/manifest.js +277 -88
- package/esm/profile/merge.js +139 -39
- package/esm/profile/mod.d.ts +2 -4
- package/esm/profile/mod.d.ts.map +1 -1
- package/esm/profile/mod.js +5 -2
- package/esm/reporter/mod.js +4 -4
- package/esm/util/fence.d.ts +30 -0
- package/esm/util/fence.d.ts.map +1 -0
- package/esm/util/fence.js +40 -0
- package/esm/validator/attributes.d.ts +3 -3
- package/esm/validator/attributes.d.ts.map +1 -1
- package/esm/validator/attributes.js +1 -18
- package/esm/validator/body_blocks.d.ts +38 -0
- package/esm/validator/body_blocks.d.ts.map +1 -0
- package/esm/validator/body_blocks.js +218 -0
- package/esm/validator/caption_convention.d.ts +29 -0
- package/esm/validator/caption_convention.d.ts.map +1 -0
- package/esm/validator/caption_convention.js +58 -0
- package/esm/validator/captions.d.ts +22 -0
- package/esm/validator/captions.d.ts.map +1 -0
- package/esm/validator/captions.js +137 -0
- package/esm/validator/component_schemes.d.ts +73 -0
- package/esm/validator/component_schemes.d.ts.map +1 -0
- package/esm/validator/component_schemes.js +375 -0
- package/esm/validator/feature_ac.d.ts +28 -0
- package/esm/validator/feature_ac.d.ts.map +1 -0
- package/esm/validator/feature_ac.js +102 -0
- package/esm/validator/listing.d.ts +42 -0
- package/esm/validator/listing.d.ts.map +1 -0
- package/esm/validator/listing.js +295 -0
- package/esm/validator/mod.d.ts +2 -0
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +253 -12
- package/esm/validator/modal_keywords.d.ts +23 -0
- package/esm/validator/modal_keywords.d.ts.map +1 -0
- package/esm/validator/modal_keywords.js +137 -0
- package/esm/validator/per_type_attrs.d.ts +29 -0
- package/esm/validator/per_type_attrs.d.ts.map +1 -0
- package/esm/validator/per_type_attrs.js +75 -0
- package/esm/validator/pipeline.d.ts +7 -2
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +40 -7
- package/esm/validator/trace_types.d.ts +26 -0
- package/esm/validator/trace_types.d.ts.map +1 -0
- package/esm/validator/trace_types.js +232 -0
- package/esm/validator/traceability.d.ts +3 -4
- package/esm/validator/traceability.d.ts.map +1 -1
- package/esm/validator/traceability.js +5 -10
- package/esm/validator/type_resolution.d.ts +67 -0
- package/esm/validator/type_resolution.d.ts.map +1 -0
- package/esm/validator/type_resolution.js +140 -0
- package/esm/validator/types.d.ts +45 -0
- package/esm/validator/types.d.ts.map +1 -1
- package/esm/validator/types.js +128 -16
- package/esm/validator/value_types.d.ts +8 -0
- package/esm/validator/value_types.d.ts.map +1 -1
- package/esm/validator/value_types.js +8 -1
- package/package.json +1 -1
- package/script/ast/build.d.ts +70 -0
- package/script/ast/build.d.ts.map +1 -0
- package/script/ast/build.js +610 -0
- package/script/ast/equivalence.d.ts +18 -0
- package/script/ast/equivalence.d.ts.map +1 -0
- package/script/ast/equivalence.js +59 -0
- package/script/ast/nodes.d.ts +221 -0
- package/script/ast/nodes.d.ts.map +1 -0
- package/script/ast/nodes.js +13 -0
- package/script/ast/normalize.d.ts +67 -0
- package/script/ast/normalize.d.ts.map +1 -0
- package/script/ast/normalize.js +258 -0
- package/script/ast/render.d.ts +34 -0
- package/script/ast/render.d.ts.map +1 -0
- package/script/ast/render.js +218 -0
- package/script/compiler/inverses.d.ts +2 -8
- package/script/compiler/inverses.d.ts.map +1 -1
- package/script/compiler/inverses.js +50 -14
- package/script/compiler/manifest.d.ts +59 -0
- package/script/compiler/manifest.d.ts.map +1 -0
- package/script/compiler/manifest.js +51 -0
- package/script/compiler/mod.d.ts +9 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +21 -2
- package/script/compiler/ndjson_writer.d.ts +50 -0
- package/script/compiler/ndjson_writer.d.ts.map +1 -0
- package/script/compiler/ndjson_writer.js +78 -0
- package/script/compiler/schema.d.ts +18 -1
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +18 -8
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +54 -0
- package/script/formatter/mod.d.ts +49 -4
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +365 -33
- package/script/formatter/synth_ulid.d.ts +21 -0
- package/script/formatter/synth_ulid.d.ts.map +1 -0
- package/script/formatter/synth_ulid.js +67 -0
- package/script/lint/mod.d.ts +10 -0
- package/script/lint/mod.d.ts.map +1 -0
- package/script/lint/mod.js +12 -0
- package/script/lint/rules/lexicon.d.ts +24 -0
- package/script/lint/rules/lexicon.d.ts.map +1 -0
- package/script/lint/rules/lexicon.js +240 -0
- package/script/lint/rules/struct.d.ts +17 -0
- package/script/lint/rules/struct.d.ts.map +1 -0
- package/script/lint/rules/struct.js +59 -0
- package/script/lint/rules/suppression.d.ts +19 -0
- package/script/lint/rules/suppression.d.ts.map +1 -0
- package/script/lint/rules/suppression.js +80 -0
- package/script/lint/runner.d.ts +39 -0
- package/script/lint/runner.d.ts.map +1 -0
- package/script/lint/runner.js +116 -0
- package/script/lint/types.d.ts +19 -0
- package/script/lint/types.d.ts.map +1 -0
- package/script/lint/types.js +10 -0
- package/script/mod.d.ts +19 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +56 -32
- package/script/model/attributes.d.ts.map +1 -1
- package/script/model/attributes.js +163 -2
- package/script/model/discriminating_attr.d.ts +33 -0
- package/script/model/discriminating_attr.d.ts.map +1 -0
- package/script/model/discriminating_attr.js +77 -0
- package/script/model/mod.d.ts +98 -3
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +64 -3
- package/script/model/profile.d.ts +33 -27
- package/script/model/profile.d.ts.map +1 -1
- package/script/model/source_introspection.d.ts +26 -0
- package/script/model/source_introspection.d.ts.map +1 -0
- package/script/model/source_introspection.js +80 -0
- package/script/model/type_hierarchy.d.ts +51 -0
- package/script/model/type_hierarchy.d.ts.map +1 -0
- package/script/model/type_hierarchy.js +130 -0
- package/script/model/uri_scheme_map.d.ts +21 -0
- package/script/model/uri_scheme_map.d.ts.map +1 -0
- package/script/model/uri_scheme_map.js +69 -0
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +9 -6
- package/script/parser/entity_refs.d.ts +53 -0
- package/script/parser/entity_refs.d.ts.map +1 -0
- package/script/parser/entity_refs.js +155 -0
- package/script/parser/glossary.d.ts +43 -0
- package/script/parser/glossary.d.ts.map +1 -0
- package/script/parser/glossary.js +221 -0
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +222 -6
- package/script/parser/mod.d.ts +1 -0
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +5 -1
- package/script/parser/source.d.ts +20 -0
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +3 -0
- package/script/profile/chain.js +3 -13
- package/script/profile/colors.js +1 -1
- package/script/profile/introspect.d.ts +135 -0
- package/script/profile/introspect.d.ts.map +1 -0
- package/script/profile/introspect.js +381 -0
- package/script/profile/load.d.ts.map +1 -1
- package/script/profile/load.js +67 -0
- package/script/profile/manifest.d.ts.map +1 -1
- package/script/profile/manifest.js +276 -87
- package/script/profile/merge.js +139 -39
- package/script/profile/mod.d.ts +2 -4
- package/script/profile/mod.d.ts.map +1 -1
- package/script/profile/mod.js +7 -6
- package/script/reporter/mod.js +4 -4
- package/script/util/fence.d.ts +30 -0
- package/script/util/fence.d.ts.map +1 -0
- package/script/util/fence.js +44 -0
- package/script/validator/attributes.d.ts +3 -3
- package/script/validator/attributes.d.ts.map +1 -1
- package/script/validator/attributes.js +1 -18
- package/script/validator/body_blocks.d.ts +38 -0
- package/script/validator/body_blocks.d.ts.map +1 -0
- package/script/validator/body_blocks.js +221 -0
- package/script/validator/caption_convention.d.ts +29 -0
- package/script/validator/caption_convention.d.ts.map +1 -0
- package/script/validator/caption_convention.js +61 -0
- package/script/validator/captions.d.ts +22 -0
- package/script/validator/captions.d.ts.map +1 -0
- package/script/validator/captions.js +140 -0
- package/script/validator/component_schemes.d.ts +73 -0
- package/script/validator/component_schemes.d.ts.map +1 -0
- package/script/validator/component_schemes.js +384 -0
- package/script/validator/feature_ac.d.ts +28 -0
- package/script/validator/feature_ac.d.ts.map +1 -0
- package/script/validator/feature_ac.js +105 -0
- package/script/validator/listing.d.ts +42 -0
- package/script/validator/listing.d.ts.map +1 -0
- package/script/validator/listing.js +298 -0
- package/script/validator/mod.d.ts +2 -0
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +256 -14
- package/script/validator/modal_keywords.d.ts +23 -0
- package/script/validator/modal_keywords.d.ts.map +1 -0
- package/script/validator/modal_keywords.js +140 -0
- package/script/validator/per_type_attrs.d.ts +29 -0
- package/script/validator/per_type_attrs.d.ts.map +1 -0
- package/script/validator/per_type_attrs.js +78 -0
- package/script/validator/pipeline.d.ts +7 -2
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +39 -6
- package/script/validator/trace_types.d.ts +26 -0
- package/script/validator/trace_types.d.ts.map +1 -0
- package/script/validator/trace_types.js +235 -0
- package/script/validator/traceability.d.ts +3 -4
- package/script/validator/traceability.d.ts.map +1 -1
- package/script/validator/traceability.js +5 -10
- package/script/validator/type_resolution.d.ts +67 -0
- package/script/validator/type_resolution.d.ts.map +1 -0
- package/script/validator/type_resolution.js +146 -0
- package/script/validator/types.d.ts +45 -0
- package/script/validator/types.d.ts.map +1 -1
- package/script/validator/types.js +131 -16
- package/script/validator/value_types.d.ts +8 -0
- package/script/validator/value_types.d.ts.map +1 -1
- package/script/validator/value_types.js +10 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/entity_refs
|
|
3
|
+
*
|
|
4
|
+
* Inline `$Identifier` entity-reference extraction (spec §2.5.2).
|
|
5
|
+
* Scans entry body prose for `$Identifier` tokens and classifies each by
|
|
6
|
+
* its case convention (type / instance / constant). Code and feature fence
|
|
7
|
+
* boundaries are derived from the body AST to exclude verbatim content
|
|
8
|
+
* without re-implementing fence detection on the raw string. Math-fence
|
|
9
|
+
* handling retains the `$$`-toggle approach on the raw body string for
|
|
10
|
+
* inline math contexts the AST cannot distinguish.
|
|
11
|
+
*/
|
|
12
|
+
import { buildBodyAst } from "../ast/build.js";
|
|
13
|
+
/**
|
|
14
|
+
* Lexical pattern for an inline entity reference. The leading `$` is the
|
|
15
|
+
* sigil; identifier characters follow. The pattern intentionally rejects
|
|
16
|
+
* the math-fence `$$…$$` form: a `$$` is consumed as two starts but the
|
|
17
|
+
* caller (see {@linkcode extractEntityRefs}) discards any match preceded
|
|
18
|
+
* by another `$`.
|
|
19
|
+
*/
|
|
20
|
+
const ENTITY_REF_RE = /\$([A-Za-z][A-Za-z0-9_]*)/g;
|
|
21
|
+
/**
|
|
22
|
+
* Decide the case convention of an entity-reference identifier per spec
|
|
23
|
+
* §2.5.2:
|
|
24
|
+
*
|
|
25
|
+
* - `constant` — all-uppercase letters/digits/underscores, contains at
|
|
26
|
+
* least one underscore or digit, ends with `[A-Z0-9]`. Distinguishes
|
|
27
|
+
* `$DEBOUNCE_WINDOW` from a single-segment PascalCase like `$ASIL`.
|
|
28
|
+
* - `type` — starts with an uppercase letter (PascalCase / single
|
|
29
|
+
* uppercase segment).
|
|
30
|
+
* - `instance` — starts with a lowercase letter (camelCase).
|
|
31
|
+
*/
|
|
32
|
+
export function classifyConvention(ident) {
|
|
33
|
+
if (/^[A-Z][A-Z0-9_]*[A-Z0-9]$/.test(ident) && /[_0-9]/.test(ident)) {
|
|
34
|
+
return "constant";
|
|
35
|
+
}
|
|
36
|
+
if (/^[A-Z]/.test(ident))
|
|
37
|
+
return "type";
|
|
38
|
+
return "instance";
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Code/feature-block line-range collection from bodyAst
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
/**
|
|
44
|
+
* Collect the set of 1-based body-relative line numbers that belong to
|
|
45
|
+
* code or feature fenced blocks. These lines are unconditionally excluded
|
|
46
|
+
* from entity-reference scanning.
|
|
47
|
+
*
|
|
48
|
+
* Math blocks (`MathNode`) are NOT included here — their interior lines
|
|
49
|
+
* are excluded via the `$$`-toggle logic in {@linkcode extractEntityRefs}
|
|
50
|
+
* (which handles both block-level and the inline `$$…$$` known-limitation
|
|
51
|
+
* case that the AST cannot distinguish).
|
|
52
|
+
*
|
|
53
|
+
* Recurses into list items via the list branch to find nested verbatim blocks.
|
|
54
|
+
*/
|
|
55
|
+
function collectCodeFeatureLines(blocks) {
|
|
56
|
+
const excluded = new Set();
|
|
57
|
+
for (const block of blocks) {
|
|
58
|
+
if (block.kind === "code" || block.kind === "feature") {
|
|
59
|
+
for (let ln = block.range.start.line; ln <= block.range.end.line; ln++) {
|
|
60
|
+
excluded.add(ln);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (block.kind === "list") {
|
|
64
|
+
for (const item of block.items) {
|
|
65
|
+
for (const sub of item.blocks) {
|
|
66
|
+
for (const ln of collectCodeFeatureLines([sub])) {
|
|
67
|
+
excluded.add(ln);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return excluded;
|
|
74
|
+
}
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Public API
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
/**
|
|
79
|
+
* Extract `$Identifier` entity references from a body string.
|
|
80
|
+
*
|
|
81
|
+
* Skips fenced code blocks (between paired ` ``` ` or `~~~` markers) per
|
|
82
|
+
* spec §2.5.2 (markers are recognised in prose only, not in verbatim
|
|
83
|
+
* content). Code and Feature fence boundaries are derived from the body AST
|
|
84
|
+
* rather than regex-scanning the raw body string. Math content is skipped
|
|
85
|
+
* two ways: an inline `$$…$$` fence by discarding any `$ident` match
|
|
86
|
+
* preceded by another `$`; a multi-line display-math block (a line that is
|
|
87
|
+
* exactly `$$`, its interior lines, and the closing `$$`) by tracking the
|
|
88
|
+
* delimiter across lines — this retains the original `$$`-toggle approach
|
|
89
|
+
* because the markdown AST does not distinguish inline `$$` fences from
|
|
90
|
+
* plain text when no surrounding blank lines are present.
|
|
91
|
+
*
|
|
92
|
+
* The reported {@linkcode SourceLocation} uses 1-based line numbers
|
|
93
|
+
* relative to the body string; callers add the entry's body offset to
|
|
94
|
+
* obtain file-relative positions.
|
|
95
|
+
*
|
|
96
|
+
* @param body Entry body prose (post-`splitBodyAndAttributes`).
|
|
97
|
+
* @param baseLocation Source location of the body's first line, used as
|
|
98
|
+
* the `file` field on every emitted {@linkcode EntityRef} and as the
|
|
99
|
+
* starting line.
|
|
100
|
+
* @param blocks Optional pre-built body AST. When provided, the AST is used
|
|
101
|
+
* directly to identify code/feature block line ranges, avoiding a redundant
|
|
102
|
+
* `buildBodyAst` call. When omitted, the AST is built internally.
|
|
103
|
+
*/
|
|
104
|
+
export function extractEntityRefs(body, baseLocation, blocks) {
|
|
105
|
+
if (!body.trim())
|
|
106
|
+
return [];
|
|
107
|
+
// Use the caller-supplied body AST when available; otherwise build it
|
|
108
|
+
// internally to identify code/feature block line ranges.
|
|
109
|
+
const resolvedBlocks = blocks ?? buildBodyAst(body);
|
|
110
|
+
const codeFeatureLines = collectCodeFeatureLines(resolvedBlocks);
|
|
111
|
+
const refs = [];
|
|
112
|
+
// A line whose only content is `$$` opens (or closes) a display-math
|
|
113
|
+
// block; its interior lines are verbatim math, not prose. Inline
|
|
114
|
+
// `$$…$$` on a single line is *not* a fence (trimmed ≠ `$$`) and is
|
|
115
|
+
// still handled by the per-match "preceded by another $" guard below.
|
|
116
|
+
let inMathFence = false;
|
|
117
|
+
const lines = body.split("\n");
|
|
118
|
+
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
119
|
+
const line = lines[lineIdx];
|
|
120
|
+
// Body lines are 1-based; codeFeatureLines stores 1-based line numbers.
|
|
121
|
+
const bodyLine = lineIdx + 1;
|
|
122
|
+
if (codeFeatureLines.has(bodyLine))
|
|
123
|
+
continue;
|
|
124
|
+
if (line.trim() === "$$") {
|
|
125
|
+
inMathFence = !inMathFence;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (inMathFence)
|
|
129
|
+
continue;
|
|
130
|
+
ENTITY_REF_RE.lastIndex = 0;
|
|
131
|
+
let match;
|
|
132
|
+
while ((match = ENTITY_REF_RE.exec(line)) !== null) {
|
|
133
|
+
// Discard the second half of a `$$…$$` math fence.
|
|
134
|
+
if (match.index > 0 && line[match.index - 1] === "$")
|
|
135
|
+
continue;
|
|
136
|
+
// Discard if the `$` is itself preceded by `\` (escaped).
|
|
137
|
+
if (match.index > 0 && line[match.index - 1] === "\\")
|
|
138
|
+
continue;
|
|
139
|
+
refs.push({
|
|
140
|
+
ident: match[0],
|
|
141
|
+
convention: classifyConvention(match[1]),
|
|
142
|
+
location: {
|
|
143
|
+
file: baseLocation.file,
|
|
144
|
+
line: baseLocation.line + lineIdx,
|
|
145
|
+
column: match.index + 1,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return refs;
|
|
151
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/glossary
|
|
3
|
+
*
|
|
4
|
+
* Validates the glossary heading-shape grammar (spec §4.2).
|
|
5
|
+
*
|
|
6
|
+
* A `markspec:glossary` document uses H1/H2/H3 headings instead of entry
|
|
7
|
+
* blocks. This module walks the mdast AST to validate the four structural
|
|
8
|
+
* rules (R4-a through R4-e) and emits MSL-L020–L024 diagnostics.
|
|
9
|
+
*/
|
|
10
|
+
import type { Diagnostic } from "../model/mod.js";
|
|
11
|
+
/** Options for {@linkcode validateGlossaryStructure}. */
|
|
12
|
+
export interface GlossaryValidationOptions {
|
|
13
|
+
/** File path used in source locations. */
|
|
14
|
+
readonly file?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Result of glossary structure validation. */
|
|
17
|
+
export interface GlossaryValidationResult {
|
|
18
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
19
|
+
/** Number of H3 terms found (used by caller to detect empty glossary). */
|
|
20
|
+
readonly termCount: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Derive the canonical slug from an H3 term text per spec §4.2 R4-c:
|
|
24
|
+
* lowercase → trim → collapse whitespace runs to "-" →
|
|
25
|
+
* drop chars outside [a-z0-9._/-]
|
|
26
|
+
*/
|
|
27
|
+
export declare function deriveTermSlug(text: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Walk a glossary document's mdast AST and validate the H1/H2/H3
|
|
30
|
+
* heading-shape grammar (spec §4.2).
|
|
31
|
+
*
|
|
32
|
+
* Emits:
|
|
33
|
+
* - MSL-L020: zero or ≥2 H1 headings (error)
|
|
34
|
+
* - MSL-L021: H3 with no preceding H2 in the file (error)
|
|
35
|
+
* - MSL-L022: duplicate term slug within the same H2 group (error)
|
|
36
|
+
* - MSL-L023: H3 with no definition blocks before the next H3/H2/EOF (warning)
|
|
37
|
+
* - MSL-L024: heading deeper than H3 (H4+) inside glossary (error)
|
|
38
|
+
*
|
|
39
|
+
* Note: MSL-L025 (link refs interleaved between terms) is out of scope
|
|
40
|
+
* for this implementation.
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateGlossaryStructure(markdown: string, options?: GlossaryValidationOptions): GlossaryValidationResult;
|
|
43
|
+
//# sourceMappingURL=glossary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glossary.d.ts","sourceRoot":"","sources":["../../src/parser/glossary.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,iBAAiB,CAAC;AAGlE,yDAAyD;AACzD,MAAM,WAAW,yBAAyB;IACxC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,+CAA+C;AAC/C,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMnD;AAkBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,yBAAyB,GAClC,wBAAwB,CAoN1B"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/glossary
|
|
3
|
+
*
|
|
4
|
+
* Validates the glossary heading-shape grammar (spec §4.2).
|
|
5
|
+
*
|
|
6
|
+
* A `markspec:glossary` document uses H1/H2/H3 headings instead of entry
|
|
7
|
+
* blocks. This module walks the mdast AST to validate the four structural
|
|
8
|
+
* rules (R4-a through R4-e) and emits MSL-L020–L024 diagnostics.
|
|
9
|
+
*/
|
|
10
|
+
import { processor } from "./remark.js";
|
|
11
|
+
/**
|
|
12
|
+
* Derive the canonical slug from an H3 term text per spec §4.2 R4-c:
|
|
13
|
+
* lowercase → trim → collapse whitespace runs to "-" →
|
|
14
|
+
* drop chars outside [a-z0-9._/-]
|
|
15
|
+
*/
|
|
16
|
+
export function deriveTermSlug(text) {
|
|
17
|
+
return text
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.trim()
|
|
20
|
+
.replace(/\s+/g, "-")
|
|
21
|
+
.replace(/[^a-z0-9._/-]/g, "");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Extract the plain-text content from a heading node by walking its
|
|
25
|
+
* inline children and concatenating Text node values.
|
|
26
|
+
*/
|
|
27
|
+
function headingText(node) {
|
|
28
|
+
let text = "";
|
|
29
|
+
for (const child of node.children) {
|
|
30
|
+
if (child.type === "text") {
|
|
31
|
+
text += child.value;
|
|
32
|
+
}
|
|
33
|
+
else if (child.type === "inlineCode") {
|
|
34
|
+
text += child.value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Walk a glossary document's mdast AST and validate the H1/H2/H3
|
|
41
|
+
* heading-shape grammar (spec §4.2).
|
|
42
|
+
*
|
|
43
|
+
* Emits:
|
|
44
|
+
* - MSL-L020: zero or ≥2 H1 headings (error)
|
|
45
|
+
* - MSL-L021: H3 with no preceding H2 in the file (error)
|
|
46
|
+
* - MSL-L022: duplicate term slug within the same H2 group (error)
|
|
47
|
+
* - MSL-L023: H3 with no definition blocks before the next H3/H2/EOF (warning)
|
|
48
|
+
* - MSL-L024: heading deeper than H3 (H4+) inside glossary (error)
|
|
49
|
+
*
|
|
50
|
+
* Note: MSL-L025 (link refs interleaved between terms) is out of scope
|
|
51
|
+
* for this implementation.
|
|
52
|
+
*/
|
|
53
|
+
export function validateGlossaryStructure(markdown, options) {
|
|
54
|
+
const file = options?.file ?? "<unknown>";
|
|
55
|
+
const tree = processor.parse(markdown);
|
|
56
|
+
const diagnostics = [];
|
|
57
|
+
const nodes = [];
|
|
58
|
+
for (const node of tree.children) {
|
|
59
|
+
if (node.type === "heading") {
|
|
60
|
+
const h = node;
|
|
61
|
+
nodes.push({
|
|
62
|
+
depth: h.depth,
|
|
63
|
+
text: headingText(h),
|
|
64
|
+
line: h.position?.start.line ?? 1,
|
|
65
|
+
column: h.position?.start.column ?? 1,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// -----------------------------------------------------------------------
|
|
70
|
+
// R4-a: exactly one H1.
|
|
71
|
+
// -----------------------------------------------------------------------
|
|
72
|
+
const h1Nodes = nodes.filter((n) => n.depth === 1);
|
|
73
|
+
if (h1Nodes.length !== 1) {
|
|
74
|
+
const loc = h1Nodes.length > 0
|
|
75
|
+
? { file, line: h1Nodes[0].line, column: h1Nodes[0].column }
|
|
76
|
+
: { file, line: 1, column: 1 };
|
|
77
|
+
diagnostics.push({
|
|
78
|
+
code: "MSL-L020",
|
|
79
|
+
severity: "error",
|
|
80
|
+
message: h1Nodes.length === 0
|
|
81
|
+
? `${file}: glossary must have exactly one H1 title (found 0) (spec §4.2 R4-a)`
|
|
82
|
+
: `${file}: glossary must have exactly one H1 title (found ${h1Nodes.length}) (spec §4.2 R4-a)`,
|
|
83
|
+
location: loc,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// -----------------------------------------------------------------------
|
|
87
|
+
// R4-e: no headings deeper than H3.
|
|
88
|
+
// -----------------------------------------------------------------------
|
|
89
|
+
for (const n of nodes) {
|
|
90
|
+
if (n.depth >= 4) {
|
|
91
|
+
diagnostics.push({
|
|
92
|
+
code: "MSL-L024",
|
|
93
|
+
severity: "error",
|
|
94
|
+
message: `${file}:${n.line}: H${n.depth} heading '${n.text}' — ` +
|
|
95
|
+
`glossary shape is exactly three levels (H1/H2/H3); ` +
|
|
96
|
+
`headings deeper than H3 are not allowed (spec §4.2 R4-e)`,
|
|
97
|
+
location: { file, line: n.line, column: n.column },
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const events = [];
|
|
102
|
+
for (const node of tree.children) {
|
|
103
|
+
if (node.type === "heading") {
|
|
104
|
+
const h = node;
|
|
105
|
+
events.push({
|
|
106
|
+
kind: "heading",
|
|
107
|
+
depth: h.depth,
|
|
108
|
+
text: headingText(h),
|
|
109
|
+
line: h.position?.start.line ?? 1,
|
|
110
|
+
col: h.position?.start.column ?? 1,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (node.type !== "definition" && node.type !== "html") {
|
|
114
|
+
// Any non-heading, non-link-ref, non-HTML block is definition content.
|
|
115
|
+
events.push({ kind: "block" });
|
|
116
|
+
}
|
|
117
|
+
// "definition" nodes are link-reference definitions → not definition content
|
|
118
|
+
// "html" nodes are directive comments → not definition content
|
|
119
|
+
}
|
|
120
|
+
let hasH2 = false;
|
|
121
|
+
let currentGroupSlugs = new Set();
|
|
122
|
+
let termCount = 0;
|
|
123
|
+
// For L023: track the last H3 and whether it received definition blocks.
|
|
124
|
+
let lastH3 = null;
|
|
125
|
+
let lastH3HasContent = false;
|
|
126
|
+
for (const event of events) {
|
|
127
|
+
if (event.kind === "block") {
|
|
128
|
+
if (lastH3 !== null) {
|
|
129
|
+
lastH3HasContent = true;
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
// heading event
|
|
134
|
+
const { depth, text, line, col } = event;
|
|
135
|
+
if (depth === 2) {
|
|
136
|
+
// Flush L023 check for the previous H3 before starting a new group.
|
|
137
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
138
|
+
diagnostics.push({
|
|
139
|
+
code: "MSL-L023",
|
|
140
|
+
severity: "warning",
|
|
141
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
142
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
143
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
hasH2 = true;
|
|
147
|
+
currentGroupSlugs = new Set();
|
|
148
|
+
lastH3 = null;
|
|
149
|
+
lastH3HasContent = false;
|
|
150
|
+
}
|
|
151
|
+
else if (depth === 3) {
|
|
152
|
+
// Flush L023 check for the previous H3.
|
|
153
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
154
|
+
diagnostics.push({
|
|
155
|
+
code: "MSL-L023",
|
|
156
|
+
severity: "warning",
|
|
157
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
158
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
159
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
// R4-b: H3 requires a preceding H2.
|
|
163
|
+
if (!hasH2) {
|
|
164
|
+
diagnostics.push({
|
|
165
|
+
code: "MSL-L021",
|
|
166
|
+
severity: "error",
|
|
167
|
+
message: `${file}:${line}: term '${text}' has no preceding H2 ` +
|
|
168
|
+
`letter-group heading (spec §4.2 R4-b)`,
|
|
169
|
+
location: { file, line, column: col },
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// R4-c: duplicate slug within the same H2 group.
|
|
173
|
+
const slug = deriveTermSlug(text);
|
|
174
|
+
if (slug.length > 0 && currentGroupSlugs.has(slug)) {
|
|
175
|
+
diagnostics.push({
|
|
176
|
+
code: "MSL-L022",
|
|
177
|
+
severity: "error",
|
|
178
|
+
message: `${file}:${line}: duplicate term slug '${slug}' ` +
|
|
179
|
+
`(derived from '${text}') within the same H2 group (spec §4.2 R4-c)`,
|
|
180
|
+
location: { file, line, column: col },
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else if (slug.length > 0) {
|
|
184
|
+
currentGroupSlugs.add(slug);
|
|
185
|
+
}
|
|
186
|
+
termCount++;
|
|
187
|
+
lastH3 = { text, line, col };
|
|
188
|
+
lastH3HasContent = false;
|
|
189
|
+
}
|
|
190
|
+
else if (depth === 1) {
|
|
191
|
+
// Additional H1s: only emit L020 once (from the count check above).
|
|
192
|
+
// Flush L023 on the last H3 if needed.
|
|
193
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
194
|
+
diagnostics.push({
|
|
195
|
+
code: "MSL-L023",
|
|
196
|
+
severity: "warning",
|
|
197
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
198
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
199
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
200
|
+
});
|
|
201
|
+
lastH3 = null;
|
|
202
|
+
lastH3HasContent = false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Flush L023 for the final H3 in the document.
|
|
207
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
208
|
+
diagnostics.push({
|
|
209
|
+
code: "MSL-L023",
|
|
210
|
+
severity: "warning",
|
|
211
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
212
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
213
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return { diagnostics, termCount };
|
|
217
|
+
}
|
|
@@ -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;
|
|
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;AAYhF,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;CACpC;AAkCD,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,CAsCrB"}
|