@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.
Files changed (331) hide show
  1. package/esm/ast/build.d.ts +70 -0
  2. package/esm/ast/build.d.ts.map +1 -0
  3. package/esm/ast/build.js +605 -0
  4. package/esm/ast/equivalence.d.ts +18 -0
  5. package/esm/ast/equivalence.d.ts.map +1 -0
  6. package/esm/ast/equivalence.js +56 -0
  7. package/esm/ast/nodes.d.ts +221 -0
  8. package/esm/ast/nodes.d.ts.map +1 -0
  9. package/esm/ast/nodes.js +12 -0
  10. package/esm/ast/normalize.d.ts +67 -0
  11. package/esm/ast/normalize.d.ts.map +1 -0
  12. package/esm/ast/normalize.js +255 -0
  13. package/esm/ast/render.d.ts +34 -0
  14. package/esm/ast/render.d.ts.map +1 -0
  15. package/esm/ast/render.js +215 -0
  16. package/esm/compiler/inverses.d.ts +2 -8
  17. package/esm/compiler/inverses.d.ts.map +1 -1
  18. package/esm/compiler/inverses.js +50 -14
  19. package/esm/compiler/manifest.d.ts +59 -0
  20. package/esm/compiler/manifest.d.ts.map +1 -0
  21. package/esm/compiler/manifest.js +48 -0
  22. package/esm/compiler/mod.d.ts +9 -1
  23. package/esm/compiler/mod.d.ts.map +1 -1
  24. package/esm/compiler/mod.js +21 -2
  25. package/esm/compiler/ndjson_writer.d.ts +50 -0
  26. package/esm/compiler/ndjson_writer.d.ts.map +1 -0
  27. package/esm/compiler/ndjson_writer.js +73 -0
  28. package/esm/compiler/schema.d.ts +18 -1
  29. package/esm/compiler/schema.d.ts.map +1 -1
  30. package/esm/compiler/schema.js +18 -9
  31. package/esm/config/mod.d.ts.map +1 -1
  32. package/esm/config/mod.js +54 -0
  33. package/esm/formatter/mod.d.ts +56 -6
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +372 -41
  36. package/esm/formatter/synth_ulid.d.ts +21 -0
  37. package/esm/formatter/synth_ulid.d.ts.map +1 -0
  38. package/esm/formatter/synth_ulid.js +64 -0
  39. package/esm/lint/mod.d.ts +10 -0
  40. package/esm/lint/mod.d.ts.map +1 -0
  41. package/esm/lint/mod.js +7 -0
  42. package/esm/lint/rules/lexicon.d.ts +24 -0
  43. package/esm/lint/rules/lexicon.d.ts.map +1 -0
  44. package/esm/lint/rules/lexicon.js +236 -0
  45. package/esm/lint/rules/struct.d.ts +17 -0
  46. package/esm/lint/rules/struct.d.ts.map +1 -0
  47. package/esm/lint/rules/struct.js +55 -0
  48. package/esm/lint/rules/suppression.d.ts +19 -0
  49. package/esm/lint/rules/suppression.d.ts.map +1 -0
  50. package/esm/lint/rules/suppression.js +75 -0
  51. package/esm/lint/runner.d.ts +39 -0
  52. package/esm/lint/runner.d.ts.map +1 -0
  53. package/esm/lint/runner.js +112 -0
  54. package/esm/lint/types.d.ts +19 -0
  55. package/esm/lint/types.d.ts.map +1 -0
  56. package/esm/lint/types.js +9 -0
  57. package/esm/mod.d.ts +21 -8
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +16 -5
  60. package/esm/model/attributes.d.ts.map +1 -1
  61. package/esm/model/attributes.js +163 -2
  62. package/esm/model/discriminating_attr.d.ts +33 -0
  63. package/esm/model/discriminating_attr.d.ts.map +1 -0
  64. package/esm/model/discriminating_attr.js +74 -0
  65. package/esm/model/mod.d.ts +100 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +58 -2
  68. package/esm/model/palette.d.ts +18 -0
  69. package/esm/model/palette.d.ts.map +1 -0
  70. package/esm/model/palette.js +23 -0
  71. package/esm/model/profile.d.ts +33 -27
  72. package/esm/model/profile.d.ts.map +1 -1
  73. package/esm/model/source_introspection.d.ts +26 -0
  74. package/esm/model/source_introspection.d.ts.map +1 -0
  75. package/esm/model/source_introspection.js +77 -0
  76. package/esm/model/type_hierarchy.d.ts +51 -0
  77. package/esm/model/type_hierarchy.d.ts.map +1 -0
  78. package/esm/model/type_hierarchy.js +126 -0
  79. package/esm/model/uri_scheme_map.d.ts +21 -0
  80. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  81. package/esm/model/uri_scheme_map.js +66 -0
  82. package/esm/parser/attributes.d.ts.map +1 -1
  83. package/esm/parser/attributes.js +9 -6
  84. package/esm/parser/entity_refs.d.ts +53 -0
  85. package/esm/parser/entity_refs.d.ts.map +1 -0
  86. package/esm/parser/entity_refs.js +151 -0
  87. package/esm/parser/glossary.d.ts +43 -0
  88. package/esm/parser/glossary.d.ts.map +1 -0
  89. package/esm/parser/glossary.js +217 -0
  90. package/esm/parser/markdown.d.ts +10 -3
  91. package/esm/parser/markdown.d.ts.map +1 -1
  92. package/esm/parser/markdown.js +241 -11
  93. package/esm/parser/mod.d.ts +1 -0
  94. package/esm/parser/mod.d.ts.map +1 -1
  95. package/esm/parser/mod.js +4 -3
  96. package/esm/parser/source.d.ts +20 -0
  97. package/esm/parser/source.d.ts.map +1 -1
  98. package/esm/parser/source.js +4 -4
  99. package/esm/profile/chain.js +3 -13
  100. package/esm/profile/colors.d.ts +26 -0
  101. package/esm/profile/colors.d.ts.map +1 -0
  102. package/esm/profile/colors.js +46 -0
  103. package/esm/profile/introspect.d.ts +135 -0
  104. package/esm/profile/introspect.d.ts.map +1 -0
  105. package/esm/profile/introspect.js +378 -0
  106. package/esm/profile/load.d.ts.map +1 -1
  107. package/esm/profile/load.js +67 -0
  108. package/esm/profile/manifest.d.ts.map +1 -1
  109. package/esm/profile/manifest.js +278 -104
  110. package/esm/profile/merge.js +139 -39
  111. package/esm/profile/mod.d.ts +3 -4
  112. package/esm/profile/mod.d.ts.map +1 -1
  113. package/esm/profile/mod.js +6 -2
  114. package/esm/reporter/mod.js +4 -4
  115. package/esm/util/fence.d.ts +30 -0
  116. package/esm/util/fence.d.ts.map +1 -0
  117. package/esm/util/fence.js +40 -0
  118. package/esm/validator/attributes.d.ts +3 -3
  119. package/esm/validator/attributes.d.ts.map +1 -1
  120. package/esm/validator/attributes.js +1 -18
  121. package/esm/validator/body_blocks.d.ts +38 -0
  122. package/esm/validator/body_blocks.d.ts.map +1 -0
  123. package/esm/validator/body_blocks.js +218 -0
  124. package/esm/validator/caption_convention.d.ts +29 -0
  125. package/esm/validator/caption_convention.d.ts.map +1 -0
  126. package/esm/validator/caption_convention.js +58 -0
  127. package/esm/validator/captions.d.ts +22 -0
  128. package/esm/validator/captions.d.ts.map +1 -0
  129. package/esm/validator/captions.js +137 -0
  130. package/esm/validator/component_schemes.d.ts +73 -0
  131. package/esm/validator/component_schemes.d.ts.map +1 -0
  132. package/esm/validator/component_schemes.js +375 -0
  133. package/esm/validator/feature_ac.d.ts +28 -0
  134. package/esm/validator/feature_ac.d.ts.map +1 -0
  135. package/esm/validator/feature_ac.js +102 -0
  136. package/esm/validator/listing.d.ts +42 -0
  137. package/esm/validator/listing.d.ts.map +1 -0
  138. package/esm/validator/listing.js +295 -0
  139. package/esm/validator/mod.d.ts +2 -0
  140. package/esm/validator/mod.d.ts.map +1 -1
  141. package/esm/validator/mod.js +253 -12
  142. package/esm/validator/modal_keywords.d.ts +23 -0
  143. package/esm/validator/modal_keywords.d.ts.map +1 -0
  144. package/esm/validator/modal_keywords.js +137 -0
  145. package/esm/validator/per_type_attrs.d.ts +29 -0
  146. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  147. package/esm/validator/per_type_attrs.js +75 -0
  148. package/esm/validator/pipeline.d.ts +7 -2
  149. package/esm/validator/pipeline.d.ts.map +1 -1
  150. package/esm/validator/pipeline.js +40 -7
  151. package/esm/validator/trace_types.d.ts +26 -0
  152. package/esm/validator/trace_types.d.ts.map +1 -0
  153. package/esm/validator/trace_types.js +232 -0
  154. package/esm/validator/traceability.d.ts +3 -4
  155. package/esm/validator/traceability.d.ts.map +1 -1
  156. package/esm/validator/traceability.js +5 -10
  157. package/esm/validator/type_resolution.d.ts +67 -0
  158. package/esm/validator/type_resolution.d.ts.map +1 -0
  159. package/esm/validator/type_resolution.js +140 -0
  160. package/esm/validator/types.d.ts +45 -0
  161. package/esm/validator/types.d.ts.map +1 -1
  162. package/esm/validator/types.js +128 -16
  163. package/esm/validator/value_types.d.ts +8 -0
  164. package/esm/validator/value_types.d.ts.map +1 -1
  165. package/esm/validator/value_types.js +8 -1
  166. package/package.json +1 -1
  167. package/script/ast/build.d.ts +70 -0
  168. package/script/ast/build.d.ts.map +1 -0
  169. package/script/ast/build.js +610 -0
  170. package/script/ast/equivalence.d.ts +18 -0
  171. package/script/ast/equivalence.d.ts.map +1 -0
  172. package/script/ast/equivalence.js +59 -0
  173. package/script/ast/nodes.d.ts +221 -0
  174. package/script/ast/nodes.d.ts.map +1 -0
  175. package/script/ast/nodes.js +13 -0
  176. package/script/ast/normalize.d.ts +67 -0
  177. package/script/ast/normalize.d.ts.map +1 -0
  178. package/script/ast/normalize.js +258 -0
  179. package/script/ast/render.d.ts +34 -0
  180. package/script/ast/render.d.ts.map +1 -0
  181. package/script/ast/render.js +218 -0
  182. package/script/compiler/inverses.d.ts +2 -8
  183. package/script/compiler/inverses.d.ts.map +1 -1
  184. package/script/compiler/inverses.js +50 -14
  185. package/script/compiler/manifest.d.ts +59 -0
  186. package/script/compiler/manifest.d.ts.map +1 -0
  187. package/script/compiler/manifest.js +51 -0
  188. package/script/compiler/mod.d.ts +9 -1
  189. package/script/compiler/mod.d.ts.map +1 -1
  190. package/script/compiler/mod.js +21 -2
  191. package/script/compiler/ndjson_writer.d.ts +50 -0
  192. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  193. package/script/compiler/ndjson_writer.js +78 -0
  194. package/script/compiler/schema.d.ts +18 -1
  195. package/script/compiler/schema.d.ts.map +1 -1
  196. package/script/compiler/schema.js +18 -8
  197. package/script/config/mod.d.ts.map +1 -1
  198. package/script/config/mod.js +54 -0
  199. package/script/formatter/mod.d.ts +56 -6
  200. package/script/formatter/mod.d.ts.map +1 -1
  201. package/script/formatter/mod.js +375 -41
  202. package/script/formatter/synth_ulid.d.ts +21 -0
  203. package/script/formatter/synth_ulid.d.ts.map +1 -0
  204. package/script/formatter/synth_ulid.js +67 -0
  205. package/script/lint/mod.d.ts +10 -0
  206. package/script/lint/mod.d.ts.map +1 -0
  207. package/script/lint/mod.js +12 -0
  208. package/script/lint/rules/lexicon.d.ts +24 -0
  209. package/script/lint/rules/lexicon.d.ts.map +1 -0
  210. package/script/lint/rules/lexicon.js +240 -0
  211. package/script/lint/rules/struct.d.ts +17 -0
  212. package/script/lint/rules/struct.d.ts.map +1 -0
  213. package/script/lint/rules/struct.js +59 -0
  214. package/script/lint/rules/suppression.d.ts +19 -0
  215. package/script/lint/rules/suppression.d.ts.map +1 -0
  216. package/script/lint/rules/suppression.js +80 -0
  217. package/script/lint/runner.d.ts +39 -0
  218. package/script/lint/runner.d.ts.map +1 -0
  219. package/script/lint/runner.js +116 -0
  220. package/script/lint/types.d.ts +19 -0
  221. package/script/lint/types.d.ts.map +1 -0
  222. package/script/lint/types.js +10 -0
  223. package/script/mod.d.ts +21 -8
  224. package/script/mod.d.ts.map +1 -1
  225. package/script/mod.js +58 -32
  226. package/script/model/attributes.d.ts.map +1 -1
  227. package/script/model/attributes.js +163 -2
  228. package/script/model/discriminating_attr.d.ts +33 -0
  229. package/script/model/discriminating_attr.d.ts.map +1 -0
  230. package/script/model/discriminating_attr.js +77 -0
  231. package/script/model/mod.d.ts +100 -3
  232. package/script/model/mod.d.ts.map +1 -1
  233. package/script/model/mod.js +67 -3
  234. package/script/model/palette.d.ts +18 -0
  235. package/script/model/palette.d.ts.map +1 -0
  236. package/script/model/palette.js +26 -0
  237. package/script/model/profile.d.ts +33 -27
  238. package/script/model/profile.d.ts.map +1 -1
  239. package/script/model/source_introspection.d.ts +26 -0
  240. package/script/model/source_introspection.d.ts.map +1 -0
  241. package/script/model/source_introspection.js +80 -0
  242. package/script/model/type_hierarchy.d.ts +51 -0
  243. package/script/model/type_hierarchy.d.ts.map +1 -0
  244. package/script/model/type_hierarchy.js +130 -0
  245. package/script/model/uri_scheme_map.d.ts +21 -0
  246. package/script/model/uri_scheme_map.d.ts.map +1 -0
  247. package/script/model/uri_scheme_map.js +69 -0
  248. package/script/parser/attributes.d.ts.map +1 -1
  249. package/script/parser/attributes.js +9 -6
  250. package/script/parser/entity_refs.d.ts +53 -0
  251. package/script/parser/entity_refs.d.ts.map +1 -0
  252. package/script/parser/entity_refs.js +155 -0
  253. package/script/parser/glossary.d.ts +43 -0
  254. package/script/parser/glossary.d.ts.map +1 -0
  255. package/script/parser/glossary.js +221 -0
  256. package/script/parser/markdown.d.ts +10 -3
  257. package/script/parser/markdown.d.ts.map +1 -1
  258. package/script/parser/markdown.js +240 -10
  259. package/script/parser/mod.d.ts +1 -0
  260. package/script/parser/mod.d.ts.map +1 -1
  261. package/script/parser/mod.js +8 -4
  262. package/script/parser/source.d.ts +20 -0
  263. package/script/parser/source.d.ts.map +1 -1
  264. package/script/parser/source.js +4 -1
  265. package/script/profile/chain.js +3 -13
  266. package/script/profile/colors.d.ts +26 -0
  267. package/script/profile/colors.d.ts.map +1 -0
  268. package/script/profile/colors.js +49 -0
  269. package/script/profile/introspect.d.ts +135 -0
  270. package/script/profile/introspect.d.ts.map +1 -0
  271. package/script/profile/introspect.js +381 -0
  272. package/script/profile/load.d.ts.map +1 -1
  273. package/script/profile/load.js +67 -0
  274. package/script/profile/manifest.d.ts.map +1 -1
  275. package/script/profile/manifest.js +280 -106
  276. package/script/profile/merge.js +139 -39
  277. package/script/profile/mod.d.ts +3 -4
  278. package/script/profile/mod.d.ts.map +1 -1
  279. package/script/profile/mod.js +9 -6
  280. package/script/reporter/mod.js +4 -4
  281. package/script/util/fence.d.ts +30 -0
  282. package/script/util/fence.d.ts.map +1 -0
  283. package/script/util/fence.js +44 -0
  284. package/script/validator/attributes.d.ts +3 -3
  285. package/script/validator/attributes.d.ts.map +1 -1
  286. package/script/validator/attributes.js +1 -18
  287. package/script/validator/body_blocks.d.ts +38 -0
  288. package/script/validator/body_blocks.d.ts.map +1 -0
  289. package/script/validator/body_blocks.js +221 -0
  290. package/script/validator/caption_convention.d.ts +29 -0
  291. package/script/validator/caption_convention.d.ts.map +1 -0
  292. package/script/validator/caption_convention.js +61 -0
  293. package/script/validator/captions.d.ts +22 -0
  294. package/script/validator/captions.d.ts.map +1 -0
  295. package/script/validator/captions.js +140 -0
  296. package/script/validator/component_schemes.d.ts +73 -0
  297. package/script/validator/component_schemes.d.ts.map +1 -0
  298. package/script/validator/component_schemes.js +384 -0
  299. package/script/validator/feature_ac.d.ts +28 -0
  300. package/script/validator/feature_ac.d.ts.map +1 -0
  301. package/script/validator/feature_ac.js +105 -0
  302. package/script/validator/listing.d.ts +42 -0
  303. package/script/validator/listing.d.ts.map +1 -0
  304. package/script/validator/listing.js +298 -0
  305. package/script/validator/mod.d.ts +2 -0
  306. package/script/validator/mod.d.ts.map +1 -1
  307. package/script/validator/mod.js +256 -14
  308. package/script/validator/modal_keywords.d.ts +23 -0
  309. package/script/validator/modal_keywords.d.ts.map +1 -0
  310. package/script/validator/modal_keywords.js +140 -0
  311. package/script/validator/per_type_attrs.d.ts +29 -0
  312. package/script/validator/per_type_attrs.d.ts.map +1 -0
  313. package/script/validator/per_type_attrs.js +78 -0
  314. package/script/validator/pipeline.d.ts +7 -2
  315. package/script/validator/pipeline.d.ts.map +1 -1
  316. package/script/validator/pipeline.js +39 -6
  317. package/script/validator/trace_types.d.ts +26 -0
  318. package/script/validator/trace_types.d.ts.map +1 -0
  319. package/script/validator/trace_types.js +235 -0
  320. package/script/validator/traceability.d.ts +3 -4
  321. package/script/validator/traceability.d.ts.map +1 -1
  322. package/script/validator/traceability.js +5 -10
  323. package/script/validator/type_resolution.d.ts +67 -0
  324. package/script/validator/type_resolution.d.ts.map +1 -0
  325. package/script/validator/type_resolution.js +146 -0
  326. package/script/validator/types.d.ts +45 -0
  327. package/script/validator/types.d.ts.map +1 -1
  328. package/script/validator/types.js +131 -16
  329. package/script/validator/value_types.d.ts +8 -0
  330. package/script/validator/value_types.d.ts.map +1 -1
  331. package/script/validator/value_types.js +10 -2
@@ -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,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
+ }
@@ -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 Array of parsed entries
36
+ * @returns Parsed entries and any parse-level diagnostics
30
37
  */
31
- export declare function parseMarkdown(markdown: string, options?: ParseMarkdownOptions): Entry[];
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;AASpE,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;AA4BD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,KAAK,EAAE,CAoCT"}
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"}