@driftsys/markspec 0.3.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 +56 -6
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +372 -41
- 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 +21 -8
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +16 -5
- 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 +100 -3
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +58 -2
- package/esm/model/palette.d.ts +18 -0
- package/esm/model/palette.d.ts.map +1 -0
- package/esm/model/palette.js +23 -0
- 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 +10 -3
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +241 -11
- package/esm/parser/mod.d.ts +1 -0
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +4 -3
- package/esm/parser/source.d.ts +20 -0
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +4 -4
- package/esm/profile/chain.js +3 -13
- package/esm/profile/colors.d.ts +26 -0
- package/esm/profile/colors.d.ts.map +1 -0
- package/esm/profile/colors.js +46 -0
- 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 +278 -104
- package/esm/profile/merge.js +139 -39
- package/esm/profile/mod.d.ts +3 -4
- package/esm/profile/mod.d.ts.map +1 -1
- package/esm/profile/mod.js +6 -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 +56 -6
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +375 -41
- 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 +21 -8
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +58 -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 +100 -3
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +67 -3
- package/script/model/palette.d.ts +18 -0
- package/script/model/palette.d.ts.map +1 -0
- package/script/model/palette.js +26 -0
- 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 +10 -3
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +240 -10
- package/script/parser/mod.d.ts +1 -0
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +8 -4
- package/script/parser/source.d.ts +20 -0
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +4 -1
- package/script/profile/chain.js +3 -13
- package/script/profile/colors.d.ts +26 -0
- package/script/profile/colors.d.ts.map +1 -0
- package/script/profile/colors.js +49 -0
- 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 +280 -106
- package/script/profile/merge.js +139 -39
- package/script/profile/mod.d.ts +3 -4
- package/script/profile/mod.d.ts.map +1 -1
- package/script/profile/mod.js +9 -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,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module model/uri_scheme_map
|
|
3
|
+
*
|
|
4
|
+
* Reference-shape URI → core type inference per ADR-003 §Part 6.
|
|
5
|
+
* Used by spec §1.3.1 step 5 of the type-resolution chain: a Reference
|
|
6
|
+
* entry whose `Id:` is a recognised URI scheme can infer its core type
|
|
7
|
+
* without an explicit `Type:` attribute.
|
|
8
|
+
*
|
|
9
|
+
* The map is intentionally conservative: only patterns the spec lists
|
|
10
|
+
* normatively are encoded. Profile extensions to the scheme map land
|
|
11
|
+
* in the profile layer.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Infer a core type name from a Reference-shape `Id:` value (a URI).
|
|
15
|
+
* Returns `undefined` when no rule matches — the caller should leave
|
|
16
|
+
* the entry type unresolved rather than guess.
|
|
17
|
+
*
|
|
18
|
+
* @param idValue The raw `Id:` value (a scheme-qualified URI).
|
|
19
|
+
*/
|
|
20
|
+
export declare function inferTypeFromUriScheme(idValue: string): string | undefined;
|
|
21
|
+
//# sourceMappingURL=uri_scheme_map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri_scheme_map.d.ts","sourceRoot":"","sources":["../../src/model/uri_scheme_map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA6DH;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1E"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module model/uri_scheme_map
|
|
4
|
+
*
|
|
5
|
+
* Reference-shape URI → core type inference per ADR-003 §Part 6.
|
|
6
|
+
* Used by spec §1.3.1 step 5 of the type-resolution chain: a Reference
|
|
7
|
+
* entry whose `Id:` is a recognised URI scheme can infer its core type
|
|
8
|
+
* without an explicit `Type:` attribute.
|
|
9
|
+
*
|
|
10
|
+
* The map is intentionally conservative: only patterns the spec lists
|
|
11
|
+
* normatively are encoded. Profile extensions to the scheme map land
|
|
12
|
+
* in the profile layer.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.inferTypeFromUriScheme = inferTypeFromUriScheme;
|
|
16
|
+
const URI_SCHEME_RULES = [
|
|
17
|
+
// Package URLs (purl) — Software components
|
|
18
|
+
{ pattern: /^pkg:cargo\//, type: "SoftwareComponent" },
|
|
19
|
+
{ pattern: /^pkg:npm\//, type: "SoftwareComponent" },
|
|
20
|
+
{ pattern: /^pkg:maven\//, type: "SoftwareComponent" },
|
|
21
|
+
{ pattern: /^pkg:pypi\//, type: "SoftwareComponent" },
|
|
22
|
+
{ pattern: /^pkg:go\//, type: "SoftwareComponent" },
|
|
23
|
+
{ pattern: /^pkg:nuget\//, type: "SoftwareComponent" },
|
|
24
|
+
{ pattern: /^pkg:deno\//, type: "SoftwareComponent" },
|
|
25
|
+
{ pattern: /^pkg:swift\//, type: "SoftwareComponent" },
|
|
26
|
+
{ pattern: /^pkg:firmware\//, type: "SoftwareComponent" },
|
|
27
|
+
// Package URLs — Hardware components
|
|
28
|
+
{ pattern: /^pkg:hw\//, type: "HardwareComponent" },
|
|
29
|
+
{ pattern: /^pkg:device\//, type: "HardwareComponent" },
|
|
30
|
+
// Standards / regulations / RFCs / papers
|
|
31
|
+
{ pattern: /^urn:iso:std:iso:/, type: "Requirement" },
|
|
32
|
+
{ pattern: /^urn:iso:std:iec:/, type: "Requirement" },
|
|
33
|
+
{ pattern: /^urn:iso:std:iso:iec:ieee:/, type: "Requirement" },
|
|
34
|
+
{ pattern: /^urn:ietf:rfc:/, type: "Requirement" },
|
|
35
|
+
{ pattern: /^urn:nist:/, type: "Requirement" },
|
|
36
|
+
{ pattern: /^urn:unece:/, type: "Requirement" },
|
|
37
|
+
{ pattern: /^doi:/, type: "Requirement" },
|
|
38
|
+
// External tracker schemes — Requirement (proxy item in external system)
|
|
39
|
+
{ pattern: /^codebeamer:/, type: "Requirement" },
|
|
40
|
+
{ pattern: /^doors:/, type: "Requirement" },
|
|
41
|
+
{ pattern: /^polarion:/, type: "Requirement" },
|
|
42
|
+
// Interface description schemes
|
|
43
|
+
{ pattern: /^urn:openapi:/, type: "Contract" },
|
|
44
|
+
{ pattern: /^urn:asyncapi:/, type: "Contract" },
|
|
45
|
+
{ pattern: /^urn:protobuf:/, type: "Contract" },
|
|
46
|
+
{ pattern: /^urn:wsdl:/, type: "Contract" },
|
|
47
|
+
{ pattern: /^urn:autosar:port:/, type: "Contract" },
|
|
48
|
+
// Hardware interfaces (bus networks)
|
|
49
|
+
{ pattern: /^urn:can-bus:/, type: "HardwareInterface" },
|
|
50
|
+
// Glossary terms
|
|
51
|
+
{ pattern: /^urn:refhub:term:/, type: "Definition" },
|
|
52
|
+
{ pattern: /^urn:driftsys:refhub:term:/, type: "Definition" },
|
|
53
|
+
// PLM
|
|
54
|
+
{ pattern: /^plm:/, type: "HardwareComponent" },
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* Infer a core type name from a Reference-shape `Id:` value (a URI).
|
|
58
|
+
* Returns `undefined` when no rule matches — the caller should leave
|
|
59
|
+
* the entry type unresolved rather than guess.
|
|
60
|
+
*
|
|
61
|
+
* @param idValue The raw `Id:` value (a scheme-qualified URI).
|
|
62
|
+
*/
|
|
63
|
+
function inferTypeFromUriScheme(idValue) {
|
|
64
|
+
for (const rule of URI_SCHEME_RULES) {
|
|
65
|
+
if (rule.pattern.test(idValue))
|
|
66
|
+
return rule.type;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/parser/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/parser/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAalE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,CAgBrE;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,QAA6B,CAAC;AAYvD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,eAAe,CA6BjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,GACd,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CA+BpB"}
|
|
@@ -15,9 +15,12 @@ const attributes_js_1 = require("../model/attributes.js");
|
|
|
15
15
|
/**
|
|
16
16
|
* Pattern matching a `Key: Value` attribute line.
|
|
17
17
|
* Key must start with an uppercase letter, may contain lowercase letters and hyphens.
|
|
18
|
-
* Value is everything after
|
|
18
|
+
* Value is everything after `:` (with optional space), with optional trailing
|
|
19
|
+
* backslash stripped. The value group is optional so that `Key:` and `Key: \`
|
|
20
|
+
* are recognized (and subsequently skipped as empty-value lines) rather than
|
|
21
|
+
* silently ignored.
|
|
19
22
|
*/
|
|
20
|
-
const ATTRIBUTE_RE = /^([A-Z][A-Za-z-]*)
|
|
23
|
+
const ATTRIBUTE_RE = /^([A-Z][A-Za-z-]*):\s*(.*?)\\?$/;
|
|
21
24
|
/**
|
|
22
25
|
* Parse an array of attribute lines into Attribute objects.
|
|
23
26
|
*
|
|
@@ -36,10 +39,10 @@ function parseAttributes(lines) {
|
|
|
36
39
|
continue;
|
|
37
40
|
const match = ATTRIBUTE_RE.exec(trimmed);
|
|
38
41
|
if (match) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
value:
|
|
42
|
-
});
|
|
42
|
+
const value = (match[2] ?? "").trim();
|
|
43
|
+
if (!value)
|
|
44
|
+
continue; // skip empty-value lines — `Key:` or `Key: \`
|
|
45
|
+
attributes.push({ key: match[1], value });
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
return attributes;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 type { EntityRef, EntityRefConvention, SourceLocation } from "../model/mod.js";
|
|
13
|
+
import type { BodyBlock } from "../ast/nodes.js";
|
|
14
|
+
/**
|
|
15
|
+
* Decide the case convention of an entity-reference identifier per spec
|
|
16
|
+
* §2.5.2:
|
|
17
|
+
*
|
|
18
|
+
* - `constant` — all-uppercase letters/digits/underscores, contains at
|
|
19
|
+
* least one underscore or digit, ends with `[A-Z0-9]`. Distinguishes
|
|
20
|
+
* `$DEBOUNCE_WINDOW` from a single-segment PascalCase like `$ASIL`.
|
|
21
|
+
* - `type` — starts with an uppercase letter (PascalCase / single
|
|
22
|
+
* uppercase segment).
|
|
23
|
+
* - `instance` — starts with a lowercase letter (camelCase).
|
|
24
|
+
*/
|
|
25
|
+
export declare function classifyConvention(ident: string): EntityRefConvention;
|
|
26
|
+
/**
|
|
27
|
+
* Extract `$Identifier` entity references from a body string.
|
|
28
|
+
*
|
|
29
|
+
* Skips fenced code blocks (between paired ` ``` ` or `~~~` markers) per
|
|
30
|
+
* spec §2.5.2 (markers are recognised in prose only, not in verbatim
|
|
31
|
+
* content). Code and Feature fence boundaries are derived from the body AST
|
|
32
|
+
* rather than regex-scanning the raw body string. Math content is skipped
|
|
33
|
+
* two ways: an inline `$$…$$` fence by discarding any `$ident` match
|
|
34
|
+
* preceded by another `$`; a multi-line display-math block (a line that is
|
|
35
|
+
* exactly `$$`, its interior lines, and the closing `$$`) by tracking the
|
|
36
|
+
* delimiter across lines — this retains the original `$$`-toggle approach
|
|
37
|
+
* because the markdown AST does not distinguish inline `$$` fences from
|
|
38
|
+
* plain text when no surrounding blank lines are present.
|
|
39
|
+
*
|
|
40
|
+
* The reported {@linkcode SourceLocation} uses 1-based line numbers
|
|
41
|
+
* relative to the body string; callers add the entry's body offset to
|
|
42
|
+
* obtain file-relative positions.
|
|
43
|
+
*
|
|
44
|
+
* @param body Entry body prose (post-`splitBodyAndAttributes`).
|
|
45
|
+
* @param baseLocation Source location of the body's first line, used as
|
|
46
|
+
* the `file` field on every emitted {@linkcode EntityRef} and as the
|
|
47
|
+
* starting line.
|
|
48
|
+
* @param blocks Optional pre-built body AST. When provided, the AST is used
|
|
49
|
+
* directly to identify code/feature block line ranges, avoiding a redundant
|
|
50
|
+
* `buildBodyAst` call. When omitted, the AST is built internally.
|
|
51
|
+
*/
|
|
52
|
+
export declare function extractEntityRefs(body: string, baseLocation: SourceLocation, blocks?: readonly BodyBlock[]): EntityRef[];
|
|
53
|
+
//# sourceMappingURL=entity_refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity_refs.d.ts","sourceRoot":"","sources":["../../src/parser/entity_refs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,mBAAmB,EACnB,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAWjD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAMrE;AA0CD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,cAAc,EAC5B,MAAM,CAAC,EAAE,SAAS,SAAS,EAAE,GAC5B,SAAS,EAAE,CAiDb"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module parser/entity_refs
|
|
4
|
+
*
|
|
5
|
+
* Inline `$Identifier` entity-reference extraction (spec §2.5.2).
|
|
6
|
+
* Scans entry body prose for `$Identifier` tokens and classifies each by
|
|
7
|
+
* its case convention (type / instance / constant). Code and feature fence
|
|
8
|
+
* boundaries are derived from the body AST to exclude verbatim content
|
|
9
|
+
* without re-implementing fence detection on the raw string. Math-fence
|
|
10
|
+
* handling retains the `$$`-toggle approach on the raw body string for
|
|
11
|
+
* inline math contexts the AST cannot distinguish.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.classifyConvention = classifyConvention;
|
|
15
|
+
exports.extractEntityRefs = extractEntityRefs;
|
|
16
|
+
const build_js_1 = require("../ast/build.js");
|
|
17
|
+
/**
|
|
18
|
+
* Lexical pattern for an inline entity reference. The leading `$` is the
|
|
19
|
+
* sigil; identifier characters follow. The pattern intentionally rejects
|
|
20
|
+
* the math-fence `$$…$$` form: a `$$` is consumed as two starts but the
|
|
21
|
+
* caller (see {@linkcode extractEntityRefs}) discards any match preceded
|
|
22
|
+
* by another `$`.
|
|
23
|
+
*/
|
|
24
|
+
const ENTITY_REF_RE = /\$([A-Za-z][A-Za-z0-9_]*)/g;
|
|
25
|
+
/**
|
|
26
|
+
* Decide the case convention of an entity-reference identifier per spec
|
|
27
|
+
* §2.5.2:
|
|
28
|
+
*
|
|
29
|
+
* - `constant` — all-uppercase letters/digits/underscores, contains at
|
|
30
|
+
* least one underscore or digit, ends with `[A-Z0-9]`. Distinguishes
|
|
31
|
+
* `$DEBOUNCE_WINDOW` from a single-segment PascalCase like `$ASIL`.
|
|
32
|
+
* - `type` — starts with an uppercase letter (PascalCase / single
|
|
33
|
+
* uppercase segment).
|
|
34
|
+
* - `instance` — starts with a lowercase letter (camelCase).
|
|
35
|
+
*/
|
|
36
|
+
function classifyConvention(ident) {
|
|
37
|
+
if (/^[A-Z][A-Z0-9_]*[A-Z0-9]$/.test(ident) && /[_0-9]/.test(ident)) {
|
|
38
|
+
return "constant";
|
|
39
|
+
}
|
|
40
|
+
if (/^[A-Z]/.test(ident))
|
|
41
|
+
return "type";
|
|
42
|
+
return "instance";
|
|
43
|
+
}
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Code/feature-block line-range collection from bodyAst
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
/**
|
|
48
|
+
* Collect the set of 1-based body-relative line numbers that belong to
|
|
49
|
+
* code or feature fenced blocks. These lines are unconditionally excluded
|
|
50
|
+
* from entity-reference scanning.
|
|
51
|
+
*
|
|
52
|
+
* Math blocks (`MathNode`) are NOT included here — their interior lines
|
|
53
|
+
* are excluded via the `$$`-toggle logic in {@linkcode extractEntityRefs}
|
|
54
|
+
* (which handles both block-level and the inline `$$…$$` known-limitation
|
|
55
|
+
* case that the AST cannot distinguish).
|
|
56
|
+
*
|
|
57
|
+
* Recurses into list items via the list branch to find nested verbatim blocks.
|
|
58
|
+
*/
|
|
59
|
+
function collectCodeFeatureLines(blocks) {
|
|
60
|
+
const excluded = new Set();
|
|
61
|
+
for (const block of blocks) {
|
|
62
|
+
if (block.kind === "code" || block.kind === "feature") {
|
|
63
|
+
for (let ln = block.range.start.line; ln <= block.range.end.line; ln++) {
|
|
64
|
+
excluded.add(ln);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (block.kind === "list") {
|
|
68
|
+
for (const item of block.items) {
|
|
69
|
+
for (const sub of item.blocks) {
|
|
70
|
+
for (const ln of collectCodeFeatureLines([sub])) {
|
|
71
|
+
excluded.add(ln);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return excluded;
|
|
78
|
+
}
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Public API
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
/**
|
|
83
|
+
* Extract `$Identifier` entity references from a body string.
|
|
84
|
+
*
|
|
85
|
+
* Skips fenced code blocks (between paired ` ``` ` or `~~~` markers) per
|
|
86
|
+
* spec §2.5.2 (markers are recognised in prose only, not in verbatim
|
|
87
|
+
* content). Code and Feature fence boundaries are derived from the body AST
|
|
88
|
+
* rather than regex-scanning the raw body string. Math content is skipped
|
|
89
|
+
* two ways: an inline `$$…$$` fence by discarding any `$ident` match
|
|
90
|
+
* preceded by another `$`; a multi-line display-math block (a line that is
|
|
91
|
+
* exactly `$$`, its interior lines, and the closing `$$`) by tracking the
|
|
92
|
+
* delimiter across lines — this retains the original `$$`-toggle approach
|
|
93
|
+
* because the markdown AST does not distinguish inline `$$` fences from
|
|
94
|
+
* plain text when no surrounding blank lines are present.
|
|
95
|
+
*
|
|
96
|
+
* The reported {@linkcode SourceLocation} uses 1-based line numbers
|
|
97
|
+
* relative to the body string; callers add the entry's body offset to
|
|
98
|
+
* obtain file-relative positions.
|
|
99
|
+
*
|
|
100
|
+
* @param body Entry body prose (post-`splitBodyAndAttributes`).
|
|
101
|
+
* @param baseLocation Source location of the body's first line, used as
|
|
102
|
+
* the `file` field on every emitted {@linkcode EntityRef} and as the
|
|
103
|
+
* starting line.
|
|
104
|
+
* @param blocks Optional pre-built body AST. When provided, the AST is used
|
|
105
|
+
* directly to identify code/feature block line ranges, avoiding a redundant
|
|
106
|
+
* `buildBodyAst` call. When omitted, the AST is built internally.
|
|
107
|
+
*/
|
|
108
|
+
function extractEntityRefs(body, baseLocation, blocks) {
|
|
109
|
+
if (!body.trim())
|
|
110
|
+
return [];
|
|
111
|
+
// Use the caller-supplied body AST when available; otherwise build it
|
|
112
|
+
// internally to identify code/feature block line ranges.
|
|
113
|
+
const resolvedBlocks = blocks ?? (0, build_js_1.buildBodyAst)(body);
|
|
114
|
+
const codeFeatureLines = collectCodeFeatureLines(resolvedBlocks);
|
|
115
|
+
const refs = [];
|
|
116
|
+
// A line whose only content is `$$` opens (or closes) a display-math
|
|
117
|
+
// block; its interior lines are verbatim math, not prose. Inline
|
|
118
|
+
// `$$…$$` on a single line is *not* a fence (trimmed ≠ `$$`) and is
|
|
119
|
+
// still handled by the per-match "preceded by another $" guard below.
|
|
120
|
+
let inMathFence = false;
|
|
121
|
+
const lines = body.split("\n");
|
|
122
|
+
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
123
|
+
const line = lines[lineIdx];
|
|
124
|
+
// Body lines are 1-based; codeFeatureLines stores 1-based line numbers.
|
|
125
|
+
const bodyLine = lineIdx + 1;
|
|
126
|
+
if (codeFeatureLines.has(bodyLine))
|
|
127
|
+
continue;
|
|
128
|
+
if (line.trim() === "$$") {
|
|
129
|
+
inMathFence = !inMathFence;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (inMathFence)
|
|
133
|
+
continue;
|
|
134
|
+
ENTITY_REF_RE.lastIndex = 0;
|
|
135
|
+
let match;
|
|
136
|
+
while ((match = ENTITY_REF_RE.exec(line)) !== null) {
|
|
137
|
+
// Discard the second half of a `$$…$$` math fence.
|
|
138
|
+
if (match.index > 0 && line[match.index - 1] === "$")
|
|
139
|
+
continue;
|
|
140
|
+
// Discard if the `$` is itself preceded by `\` (escaped).
|
|
141
|
+
if (match.index > 0 && line[match.index - 1] === "\\")
|
|
142
|
+
continue;
|
|
143
|
+
refs.push({
|
|
144
|
+
ident: match[0],
|
|
145
|
+
convention: classifyConvention(match[1]),
|
|
146
|
+
location: {
|
|
147
|
+
file: baseLocation.file,
|
|
148
|
+
line: baseLocation.line + lineIdx,
|
|
149
|
+
column: match.index + 1,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return refs;
|
|
155
|
+
}
|
|
@@ -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,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module parser/glossary
|
|
4
|
+
*
|
|
5
|
+
* Validates the glossary heading-shape grammar (spec §4.2).
|
|
6
|
+
*
|
|
7
|
+
* A `markspec:glossary` document uses H1/H2/H3 headings instead of entry
|
|
8
|
+
* blocks. This module walks the mdast AST to validate the four structural
|
|
9
|
+
* rules (R4-a through R4-e) and emits MSL-L020–L024 diagnostics.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.deriveTermSlug = deriveTermSlug;
|
|
13
|
+
exports.validateGlossaryStructure = validateGlossaryStructure;
|
|
14
|
+
const remark_js_1 = require("./remark.js");
|
|
15
|
+
/**
|
|
16
|
+
* Derive the canonical slug from an H3 term text per spec §4.2 R4-c:
|
|
17
|
+
* lowercase → trim → collapse whitespace runs to "-" →
|
|
18
|
+
* drop chars outside [a-z0-9._/-]
|
|
19
|
+
*/
|
|
20
|
+
function deriveTermSlug(text) {
|
|
21
|
+
return text
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.trim()
|
|
24
|
+
.replace(/\s+/g, "-")
|
|
25
|
+
.replace(/[^a-z0-9._/-]/g, "");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract the plain-text content from a heading node by walking its
|
|
29
|
+
* inline children and concatenating Text node values.
|
|
30
|
+
*/
|
|
31
|
+
function headingText(node) {
|
|
32
|
+
let text = "";
|
|
33
|
+
for (const child of node.children) {
|
|
34
|
+
if (child.type === "text") {
|
|
35
|
+
text += child.value;
|
|
36
|
+
}
|
|
37
|
+
else if (child.type === "inlineCode") {
|
|
38
|
+
text += child.value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return text;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Walk a glossary document's mdast AST and validate the H1/H2/H3
|
|
45
|
+
* heading-shape grammar (spec §4.2).
|
|
46
|
+
*
|
|
47
|
+
* Emits:
|
|
48
|
+
* - MSL-L020: zero or ≥2 H1 headings (error)
|
|
49
|
+
* - MSL-L021: H3 with no preceding H2 in the file (error)
|
|
50
|
+
* - MSL-L022: duplicate term slug within the same H2 group (error)
|
|
51
|
+
* - MSL-L023: H3 with no definition blocks before the next H3/H2/EOF (warning)
|
|
52
|
+
* - MSL-L024: heading deeper than H3 (H4+) inside glossary (error)
|
|
53
|
+
*
|
|
54
|
+
* Note: MSL-L025 (link refs interleaved between terms) is out of scope
|
|
55
|
+
* for this implementation.
|
|
56
|
+
*/
|
|
57
|
+
function validateGlossaryStructure(markdown, options) {
|
|
58
|
+
const file = options?.file ?? "<unknown>";
|
|
59
|
+
const tree = remark_js_1.processor.parse(markdown);
|
|
60
|
+
const diagnostics = [];
|
|
61
|
+
const nodes = [];
|
|
62
|
+
for (const node of tree.children) {
|
|
63
|
+
if (node.type === "heading") {
|
|
64
|
+
const h = node;
|
|
65
|
+
nodes.push({
|
|
66
|
+
depth: h.depth,
|
|
67
|
+
text: headingText(h),
|
|
68
|
+
line: h.position?.start.line ?? 1,
|
|
69
|
+
column: h.position?.start.column ?? 1,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// -----------------------------------------------------------------------
|
|
74
|
+
// R4-a: exactly one H1.
|
|
75
|
+
// -----------------------------------------------------------------------
|
|
76
|
+
const h1Nodes = nodes.filter((n) => n.depth === 1);
|
|
77
|
+
if (h1Nodes.length !== 1) {
|
|
78
|
+
const loc = h1Nodes.length > 0
|
|
79
|
+
? { file, line: h1Nodes[0].line, column: h1Nodes[0].column }
|
|
80
|
+
: { file, line: 1, column: 1 };
|
|
81
|
+
diagnostics.push({
|
|
82
|
+
code: "MSL-L020",
|
|
83
|
+
severity: "error",
|
|
84
|
+
message: h1Nodes.length === 0
|
|
85
|
+
? `${file}: glossary must have exactly one H1 title (found 0) (spec §4.2 R4-a)`
|
|
86
|
+
: `${file}: glossary must have exactly one H1 title (found ${h1Nodes.length}) (spec §4.2 R4-a)`,
|
|
87
|
+
location: loc,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// -----------------------------------------------------------------------
|
|
91
|
+
// R4-e: no headings deeper than H3.
|
|
92
|
+
// -----------------------------------------------------------------------
|
|
93
|
+
for (const n of nodes) {
|
|
94
|
+
if (n.depth >= 4) {
|
|
95
|
+
diagnostics.push({
|
|
96
|
+
code: "MSL-L024",
|
|
97
|
+
severity: "error",
|
|
98
|
+
message: `${file}:${n.line}: H${n.depth} heading '${n.text}' — ` +
|
|
99
|
+
`glossary shape is exactly three levels (H1/H2/H3); ` +
|
|
100
|
+
`headings deeper than H3 are not allowed (spec §4.2 R4-e)`,
|
|
101
|
+
location: { file, line: n.line, column: n.column },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const events = [];
|
|
106
|
+
for (const node of tree.children) {
|
|
107
|
+
if (node.type === "heading") {
|
|
108
|
+
const h = node;
|
|
109
|
+
events.push({
|
|
110
|
+
kind: "heading",
|
|
111
|
+
depth: h.depth,
|
|
112
|
+
text: headingText(h),
|
|
113
|
+
line: h.position?.start.line ?? 1,
|
|
114
|
+
col: h.position?.start.column ?? 1,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else if (node.type !== "definition" && node.type !== "html") {
|
|
118
|
+
// Any non-heading, non-link-ref, non-HTML block is definition content.
|
|
119
|
+
events.push({ kind: "block" });
|
|
120
|
+
}
|
|
121
|
+
// "definition" nodes are link-reference definitions → not definition content
|
|
122
|
+
// "html" nodes are directive comments → not definition content
|
|
123
|
+
}
|
|
124
|
+
let hasH2 = false;
|
|
125
|
+
let currentGroupSlugs = new Set();
|
|
126
|
+
let termCount = 0;
|
|
127
|
+
// For L023: track the last H3 and whether it received definition blocks.
|
|
128
|
+
let lastH3 = null;
|
|
129
|
+
let lastH3HasContent = false;
|
|
130
|
+
for (const event of events) {
|
|
131
|
+
if (event.kind === "block") {
|
|
132
|
+
if (lastH3 !== null) {
|
|
133
|
+
lastH3HasContent = true;
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
// heading event
|
|
138
|
+
const { depth, text, line, col } = event;
|
|
139
|
+
if (depth === 2) {
|
|
140
|
+
// Flush L023 check for the previous H3 before starting a new group.
|
|
141
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
142
|
+
diagnostics.push({
|
|
143
|
+
code: "MSL-L023",
|
|
144
|
+
severity: "warning",
|
|
145
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
146
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
147
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
hasH2 = true;
|
|
151
|
+
currentGroupSlugs = new Set();
|
|
152
|
+
lastH3 = null;
|
|
153
|
+
lastH3HasContent = false;
|
|
154
|
+
}
|
|
155
|
+
else if (depth === 3) {
|
|
156
|
+
// Flush L023 check for the previous H3.
|
|
157
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
158
|
+
diagnostics.push({
|
|
159
|
+
code: "MSL-L023",
|
|
160
|
+
severity: "warning",
|
|
161
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
162
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
163
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
// R4-b: H3 requires a preceding H2.
|
|
167
|
+
if (!hasH2) {
|
|
168
|
+
diagnostics.push({
|
|
169
|
+
code: "MSL-L021",
|
|
170
|
+
severity: "error",
|
|
171
|
+
message: `${file}:${line}: term '${text}' has no preceding H2 ` +
|
|
172
|
+
`letter-group heading (spec §4.2 R4-b)`,
|
|
173
|
+
location: { file, line, column: col },
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
// R4-c: duplicate slug within the same H2 group.
|
|
177
|
+
const slug = deriveTermSlug(text);
|
|
178
|
+
if (slug.length > 0 && currentGroupSlugs.has(slug)) {
|
|
179
|
+
diagnostics.push({
|
|
180
|
+
code: "MSL-L022",
|
|
181
|
+
severity: "error",
|
|
182
|
+
message: `${file}:${line}: duplicate term slug '${slug}' ` +
|
|
183
|
+
`(derived from '${text}') within the same H2 group (spec §4.2 R4-c)`,
|
|
184
|
+
location: { file, line, column: col },
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else if (slug.length > 0) {
|
|
188
|
+
currentGroupSlugs.add(slug);
|
|
189
|
+
}
|
|
190
|
+
termCount++;
|
|
191
|
+
lastH3 = { text, line, col };
|
|
192
|
+
lastH3HasContent = false;
|
|
193
|
+
}
|
|
194
|
+
else if (depth === 1) {
|
|
195
|
+
// Additional H1s: only emit L020 once (from the count check above).
|
|
196
|
+
// Flush L023 on the last H3 if needed.
|
|
197
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
198
|
+
diagnostics.push({
|
|
199
|
+
code: "MSL-L023",
|
|
200
|
+
severity: "warning",
|
|
201
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
202
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
203
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
204
|
+
});
|
|
205
|
+
lastH3 = null;
|
|
206
|
+
lastH3HasContent = false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Flush L023 for the final H3 in the document.
|
|
211
|
+
if (lastH3 !== null && !lastH3HasContent) {
|
|
212
|
+
diagnostics.push({
|
|
213
|
+
code: "MSL-L023",
|
|
214
|
+
severity: "warning",
|
|
215
|
+
message: `${file}:${lastH3.line}: term '${lastH3.text}' has an ` +
|
|
216
|
+
`empty definition (spec §4.2 R4-d)`,
|
|
217
|
+
location: { file, line: lastH3.line, column: lastH3.col },
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return { diagnostics, termCount };
|
|
221
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* CommonMark + MarkSpec extension parser. Walks the mdast AST to detect
|
|
5
5
|
* `- [DISPLAY_ID] Title` entry blocks and extract structured attributes.
|
|
6
6
|
*/
|
|
7
|
-
import type { Entry } from "../model/mod.js";
|
|
7
|
+
import type { Diagnostic, Entry } from "../model/mod.js";
|
|
8
8
|
/** Options for {@linkcode parseMarkdown}. */
|
|
9
9
|
export interface ParseMarkdownOptions {
|
|
10
10
|
/** File path used in source locations. */
|
|
@@ -16,6 +16,13 @@ export interface ParseMarkdownOptions {
|
|
|
16
16
|
*/
|
|
17
17
|
readonly isReferencesDoc?: boolean;
|
|
18
18
|
}
|
|
19
|
+
/** Result returned by {@linkcode parseMarkdown}. */
|
|
20
|
+
export interface ParseMarkdownResult {
|
|
21
|
+
/** Parsed entries found in the Markdown source. */
|
|
22
|
+
readonly entries: Entry[];
|
|
23
|
+
/** Parse-level diagnostics (e.g., deprecation warnings). */
|
|
24
|
+
readonly diagnostics: Diagnostic[];
|
|
25
|
+
}
|
|
19
26
|
/**
|
|
20
27
|
* Parse a Markdown string and return all MarkSpec entries found.
|
|
21
28
|
*
|
|
@@ -26,7 +33,7 @@ export interface ParseMarkdownOptions {
|
|
|
26
33
|
*
|
|
27
34
|
* @param markdown - Markdown source text
|
|
28
35
|
* @param options - Parse options (file path for source locations)
|
|
29
|
-
* @returns
|
|
36
|
+
* @returns Parsed entries and any parse-level diagnostics
|
|
30
37
|
*/
|
|
31
|
-
export declare function parseMarkdown(markdown: string, options?: ParseMarkdownOptions):
|
|
38
|
+
export declare function parseMarkdown(markdown: string, options?: ParseMarkdownOptions): ParseMarkdownResult;
|
|
32
39
|
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAa,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"}
|