@driftsys/markspec 0.12.0 → 0.13.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 (317) hide show
  1. package/esm/ast/build.d.ts.map +1 -1
  2. package/esm/ast/build.js +19 -5
  3. package/esm/ast/equivalence.js +14 -2
  4. package/esm/ast/nodes.d.ts +15 -3
  5. package/esm/ast/nodes.d.ts.map +1 -1
  6. package/esm/compiler/inverses.d.ts.map +1 -1
  7. package/esm/compiler/inverses.js +18 -3
  8. package/esm/compiler/mod.d.ts +34 -1
  9. package/esm/compiler/mod.d.ts.map +1 -1
  10. package/esm/compiler/mod.js +112 -48
  11. package/esm/compiler/schema.d.ts +3 -2
  12. package/esm/compiler/schema.d.ts.map +1 -1
  13. package/esm/compiler/schema.js +6 -3
  14. package/esm/config/markspec.d.ts +2 -2
  15. package/esm/config/mod.d.ts.map +1 -1
  16. package/esm/config/mod.js +47 -5
  17. package/esm/criteria/scenarios.d.ts +55 -0
  18. package/esm/criteria/scenarios.d.ts.map +1 -0
  19. package/esm/criteria/scenarios.js +133 -0
  20. package/esm/discovery/mod.d.ts +20 -1
  21. package/esm/discovery/mod.d.ts.map +1 -1
  22. package/esm/discovery/mod.js +105 -17
  23. package/esm/discovery/projects.d.ts +6 -4
  24. package/esm/discovery/projects.d.ts.map +1 -1
  25. package/esm/discovery/projects.js +27 -17
  26. package/esm/formatter/entry_body.d.ts +13 -12
  27. package/esm/formatter/entry_body.d.ts.map +1 -1
  28. package/esm/formatter/entry_body.js +25 -17
  29. package/esm/formatter/feature_file.d.ts +40 -0
  30. package/esm/formatter/feature_file.d.ts.map +1 -0
  31. package/esm/formatter/feature_file.js +88 -0
  32. package/esm/formatter/md_equiv.d.ts +6 -5
  33. package/esm/formatter/md_equiv.d.ts.map +1 -1
  34. package/esm/formatter/md_equiv.js +6 -5
  35. package/esm/formatter/mod.d.ts +25 -3
  36. package/esm/formatter/mod.d.ts.map +1 -1
  37. package/esm/formatter/mod.js +267 -27
  38. package/esm/formatter/tab_markers.d.ts +15 -0
  39. package/esm/formatter/tab_markers.d.ts.map +1 -0
  40. package/esm/formatter/tab_markers.js +133 -0
  41. package/esm/gates/mod.d.ts +2 -2
  42. package/esm/gates/mod.d.ts.map +1 -1
  43. package/esm/gates/mod.js +18 -3
  44. package/esm/gherkin/load.d.ts +35 -0
  45. package/esm/gherkin/load.d.ts.map +1 -0
  46. package/esm/gherkin/load.js +39 -0
  47. package/esm/gherkin/parse.d.ts +11 -0
  48. package/esm/gherkin/parse.d.ts.map +1 -0
  49. package/esm/gherkin/parse.js +311 -0
  50. package/esm/gherkin/position.d.ts +23 -0
  51. package/esm/gherkin/position.d.ts.map +1 -0
  52. package/esm/gherkin/position.js +21 -0
  53. package/esm/gherkin/procedure.d.ts +76 -0
  54. package/esm/gherkin/procedure.d.ts.map +1 -0
  55. package/esm/gherkin/procedure.js +164 -0
  56. package/esm/gherkin/project.d.ts +35 -0
  57. package/esm/gherkin/project.d.ts.map +1 -0
  58. package/esm/gherkin/project.js +64 -0
  59. package/esm/gherkin/role.d.ts +23 -0
  60. package/esm/gherkin/role.d.ts.map +1 -0
  61. package/esm/gherkin/role.js +28 -0
  62. package/esm/gherkin/types.d.ts +118 -0
  63. package/esm/gherkin/types.d.ts.map +1 -0
  64. package/esm/gherkin/types.js +12 -0
  65. package/esm/lock/acquire_compile.d.ts +12 -4
  66. package/esm/lock/acquire_compile.d.ts.map +1 -1
  67. package/esm/lock/acquire_compile.js +15 -5
  68. package/esm/lock/canonical_edges.d.ts +6 -2
  69. package/esm/lock/canonical_edges.d.ts.map +1 -1
  70. package/esm/lock/canonical_edges.js +10 -3
  71. package/esm/lock/model.d.ts +5 -0
  72. package/esm/lock/model.d.ts.map +1 -1
  73. package/esm/lock/parser.d.ts.map +1 -1
  74. package/esm/lock/parser.js +2 -0
  75. package/esm/lock/resolve.d.ts +6 -2
  76. package/esm/lock/resolve.d.ts.map +1 -1
  77. package/esm/lock/resolve.js +36 -4
  78. package/esm/lock/serializer.d.ts.map +1 -1
  79. package/esm/lock/serializer.js +7 -1
  80. package/esm/lock/upstream_deps.js +1 -1
  81. package/esm/mod.d.ts +24 -6
  82. package/esm/mod.d.ts.map +1 -1
  83. package/esm/mod.js +19 -5
  84. package/esm/model/mod.d.ts +43 -2
  85. package/esm/model/mod.d.ts.map +1 -1
  86. package/esm/model/mod.js +1 -1
  87. package/esm/model/relations.d.ts +9 -0
  88. package/esm/model/relations.d.ts.map +1 -1
  89. package/esm/model/relations.js +16 -1
  90. package/esm/parser/attributes.d.ts +82 -3
  91. package/esm/parser/attributes.d.ts.map +1 -1
  92. package/esm/parser/attributes.js +199 -32
  93. package/esm/parser/body_tokens.d.ts +1 -1
  94. package/esm/parser/body_tokens.d.ts.map +1 -1
  95. package/esm/parser/body_tokens.js +49 -35
  96. package/esm/parser/feature_file.d.ts +116 -0
  97. package/esm/parser/feature_file.d.ts.map +1 -0
  98. package/esm/parser/feature_file.js +540 -0
  99. package/esm/parser/markdown.d.ts +7 -0
  100. package/esm/parser/markdown.d.ts.map +1 -1
  101. package/esm/parser/markdown.js +129 -40
  102. package/esm/parser/mod.d.ts +18 -0
  103. package/esm/parser/mod.d.ts.map +1 -1
  104. package/esm/parser/mod.js +51 -0
  105. package/esm/parser/translate.d.ts.map +1 -1
  106. package/esm/parser/translate.js +5 -0
  107. package/esm/refs/mod.d.ts +8 -3
  108. package/esm/refs/mod.d.ts.map +1 -1
  109. package/esm/refs/mod.js +20 -7
  110. package/esm/refs/split.d.ts +58 -0
  111. package/esm/refs/split.d.ts.map +1 -0
  112. package/esm/refs/split.js +137 -0
  113. package/esm/reporter/mod.d.ts +7 -0
  114. package/esm/reporter/mod.d.ts.map +1 -1
  115. package/esm/reporter/mod.js +113 -3
  116. package/esm/sync/mapping.d.ts +4 -3
  117. package/esm/sync/mapping.d.ts.map +1 -1
  118. package/esm/sync/mapping.js +52 -9
  119. package/esm/util/display_id.d.ts +20 -0
  120. package/esm/util/display_id.d.ts.map +1 -0
  121. package/esm/util/display_id.js +19 -0
  122. package/esm/validator/attributes.d.ts.map +1 -1
  123. package/esm/validator/attributes.js +4 -1
  124. package/esm/validator/block_role.d.ts +40 -0
  125. package/esm/validator/block_role.d.ts.map +1 -0
  126. package/esm/validator/block_role.js +109 -0
  127. package/esm/validator/feature_ac.d.ts.map +1 -1
  128. package/esm/validator/feature_ac.js +6 -1
  129. package/esm/validator/feature_parse.d.ts +35 -0
  130. package/esm/validator/feature_parse.d.ts.map +1 -0
  131. package/esm/validator/feature_parse.js +69 -0
  132. package/esm/validator/locators.d.ts +36 -0
  133. package/esm/validator/locators.d.ts.map +1 -0
  134. package/esm/validator/locators.js +184 -0
  135. package/esm/validator/mod.d.ts +10 -1
  136. package/esm/validator/mod.d.ts.map +1 -1
  137. package/esm/validator/mod.js +38 -14
  138. package/esm/validator/normalize.d.ts.map +1 -1
  139. package/esm/validator/normalize.js +8 -3
  140. package/esm/validator/per_type_attrs.d.ts +3 -3
  141. package/esm/validator/per_type_attrs.js +3 -3
  142. package/esm/validator/pipeline.d.ts +10 -16
  143. package/esm/validator/pipeline.d.ts.map +1 -1
  144. package/esm/validator/pipeline.js +37 -16
  145. package/esm/validator/procedure.d.ts +22 -0
  146. package/esm/validator/procedure.d.ts.map +1 -0
  147. package/esm/validator/procedure.js +58 -0
  148. package/esm/validator/trace_types.d.ts.map +1 -1
  149. package/esm/validator/trace_types.js +4 -3
  150. package/esm/validator/traceability.d.ts.map +1 -1
  151. package/esm/validator/traceability.js +4 -1
  152. package/esm/validator/type_resolution.d.ts +5 -3
  153. package/esm/validator/type_resolution.d.ts.map +1 -1
  154. package/esm/validator/type_resolution.js +14 -2
  155. package/esm/validator/types.d.ts +11 -0
  156. package/esm/validator/types.d.ts.map +1 -1
  157. package/esm/validator/types.js +26 -4
  158. package/esm/validator/uxil_family.d.ts +1 -1
  159. package/package.json +3 -1
  160. package/script/ast/build.d.ts.map +1 -1
  161. package/script/ast/build.js +19 -5
  162. package/script/ast/equivalence.js +14 -2
  163. package/script/ast/nodes.d.ts +15 -3
  164. package/script/ast/nodes.d.ts.map +1 -1
  165. package/script/compiler/inverses.d.ts.map +1 -1
  166. package/script/compiler/inverses.js +18 -3
  167. package/script/compiler/mod.d.ts +34 -1
  168. package/script/compiler/mod.d.ts.map +1 -1
  169. package/script/compiler/mod.js +110 -46
  170. package/script/compiler/schema.d.ts +3 -2
  171. package/script/compiler/schema.d.ts.map +1 -1
  172. package/script/compiler/schema.js +6 -3
  173. package/script/config/markspec.d.ts +2 -2
  174. package/script/config/mod.d.ts.map +1 -1
  175. package/script/config/mod.js +47 -5
  176. package/script/criteria/scenarios.d.ts +55 -0
  177. package/script/criteria/scenarios.d.ts.map +1 -0
  178. package/script/criteria/scenarios.js +139 -0
  179. package/script/discovery/mod.d.ts +20 -1
  180. package/script/discovery/mod.d.ts.map +1 -1
  181. package/script/discovery/mod.js +106 -17
  182. package/script/discovery/projects.d.ts +6 -4
  183. package/script/discovery/projects.d.ts.map +1 -1
  184. package/script/discovery/projects.js +27 -17
  185. package/script/formatter/entry_body.d.ts +13 -12
  186. package/script/formatter/entry_body.d.ts.map +1 -1
  187. package/script/formatter/entry_body.js +25 -17
  188. package/script/formatter/feature_file.d.ts +40 -0
  189. package/script/formatter/feature_file.d.ts.map +1 -0
  190. package/script/formatter/feature_file.js +92 -0
  191. package/script/formatter/md_equiv.d.ts +6 -5
  192. package/script/formatter/md_equiv.d.ts.map +1 -1
  193. package/script/formatter/md_equiv.js +6 -5
  194. package/script/formatter/mod.d.ts +25 -3
  195. package/script/formatter/mod.d.ts.map +1 -1
  196. package/script/formatter/mod.js +266 -26
  197. package/script/formatter/tab_markers.d.ts +15 -0
  198. package/script/formatter/tab_markers.d.ts.map +1 -0
  199. package/script/formatter/tab_markers.js +141 -0
  200. package/script/gates/mod.d.ts +2 -2
  201. package/script/gates/mod.d.ts.map +1 -1
  202. package/script/gates/mod.js +18 -3
  203. package/script/gherkin/load.d.ts +35 -0
  204. package/script/gherkin/load.d.ts.map +1 -0
  205. package/script/gherkin/load.js +76 -0
  206. package/script/gherkin/parse.d.ts +11 -0
  207. package/script/gherkin/parse.d.ts.map +1 -0
  208. package/script/gherkin/parse.js +314 -0
  209. package/script/gherkin/position.d.ts +23 -0
  210. package/script/gherkin/position.d.ts.map +1 -0
  211. package/script/gherkin/position.js +24 -0
  212. package/script/gherkin/procedure.d.ts +76 -0
  213. package/script/gherkin/procedure.d.ts.map +1 -0
  214. package/script/gherkin/procedure.js +169 -0
  215. package/script/gherkin/project.d.ts +35 -0
  216. package/script/gherkin/project.d.ts.map +1 -0
  217. package/script/gherkin/project.js +67 -0
  218. package/script/gherkin/role.d.ts +23 -0
  219. package/script/gherkin/role.d.ts.map +1 -0
  220. package/script/gherkin/role.js +31 -0
  221. package/script/gherkin/types.d.ts +118 -0
  222. package/script/gherkin/types.d.ts.map +1 -0
  223. package/script/gherkin/types.js +13 -0
  224. package/script/lock/acquire_compile.d.ts +12 -4
  225. package/script/lock/acquire_compile.d.ts.map +1 -1
  226. package/script/lock/acquire_compile.js +15 -5
  227. package/script/lock/canonical_edges.d.ts +6 -2
  228. package/script/lock/canonical_edges.d.ts.map +1 -1
  229. package/script/lock/canonical_edges.js +10 -3
  230. package/script/lock/model.d.ts +5 -0
  231. package/script/lock/model.d.ts.map +1 -1
  232. package/script/lock/parser.d.ts.map +1 -1
  233. package/script/lock/parser.js +2 -0
  234. package/script/lock/resolve.d.ts +6 -2
  235. package/script/lock/resolve.d.ts.map +1 -1
  236. package/script/lock/resolve.js +36 -4
  237. package/script/lock/serializer.d.ts.map +1 -1
  238. package/script/lock/serializer.js +7 -1
  239. package/script/lock/upstream_deps.js +1 -1
  240. package/script/mod.d.ts +24 -6
  241. package/script/mod.d.ts.map +1 -1
  242. package/script/mod.js +48 -6
  243. package/script/model/mod.d.ts +43 -2
  244. package/script/model/mod.d.ts.map +1 -1
  245. package/script/model/mod.js +2 -1
  246. package/script/model/relations.d.ts +9 -0
  247. package/script/model/relations.d.ts.map +1 -1
  248. package/script/model/relations.js +17 -1
  249. package/script/parser/attributes.d.ts +82 -3
  250. package/script/parser/attributes.d.ts.map +1 -1
  251. package/script/parser/attributes.js +205 -33
  252. package/script/parser/body_tokens.d.ts +1 -1
  253. package/script/parser/body_tokens.d.ts.map +1 -1
  254. package/script/parser/body_tokens.js +49 -35
  255. package/script/parser/feature_file.d.ts +116 -0
  256. package/script/parser/feature_file.d.ts.map +1 -0
  257. package/script/parser/feature_file.js +548 -0
  258. package/script/parser/markdown.d.ts +7 -0
  259. package/script/parser/markdown.d.ts.map +1 -1
  260. package/script/parser/markdown.js +128 -39
  261. package/script/parser/mod.d.ts +18 -0
  262. package/script/parser/mod.d.ts.map +1 -1
  263. package/script/parser/mod.js +52 -1
  264. package/script/parser/translate.d.ts.map +1 -1
  265. package/script/parser/translate.js +5 -0
  266. package/script/refs/mod.d.ts +8 -3
  267. package/script/refs/mod.d.ts.map +1 -1
  268. package/script/refs/mod.js +20 -7
  269. package/script/refs/split.d.ts +58 -0
  270. package/script/refs/split.d.ts.map +1 -0
  271. package/script/refs/split.js +145 -0
  272. package/script/reporter/mod.d.ts +7 -0
  273. package/script/reporter/mod.d.ts.map +1 -1
  274. package/script/reporter/mod.js +113 -3
  275. package/script/sync/mapping.d.ts +4 -3
  276. package/script/sync/mapping.d.ts.map +1 -1
  277. package/script/sync/mapping.js +52 -9
  278. package/script/util/display_id.d.ts +20 -0
  279. package/script/util/display_id.d.ts.map +1 -0
  280. package/script/util/display_id.js +22 -0
  281. package/script/validator/attributes.d.ts.map +1 -1
  282. package/script/validator/attributes.js +4 -1
  283. package/script/validator/block_role.d.ts +40 -0
  284. package/script/validator/block_role.d.ts.map +1 -0
  285. package/script/validator/block_role.js +112 -0
  286. package/script/validator/feature_ac.d.ts.map +1 -1
  287. package/script/validator/feature_ac.js +6 -1
  288. package/script/validator/feature_parse.d.ts +35 -0
  289. package/script/validator/feature_parse.d.ts.map +1 -0
  290. package/script/validator/feature_parse.js +73 -0
  291. package/script/validator/locators.d.ts +36 -0
  292. package/script/validator/locators.d.ts.map +1 -0
  293. package/script/validator/locators.js +188 -0
  294. package/script/validator/mod.d.ts +10 -1
  295. package/script/validator/mod.d.ts.map +1 -1
  296. package/script/validator/mod.js +38 -14
  297. package/script/validator/normalize.d.ts.map +1 -1
  298. package/script/validator/normalize.js +8 -3
  299. package/script/validator/per_type_attrs.d.ts +3 -3
  300. package/script/validator/per_type_attrs.js +3 -3
  301. package/script/validator/pipeline.d.ts +10 -16
  302. package/script/validator/pipeline.d.ts.map +1 -1
  303. package/script/validator/pipeline.js +36 -16
  304. package/script/validator/procedure.d.ts +22 -0
  305. package/script/validator/procedure.d.ts.map +1 -0
  306. package/script/validator/procedure.js +61 -0
  307. package/script/validator/trace_types.d.ts.map +1 -1
  308. package/script/validator/trace_types.js +4 -3
  309. package/script/validator/traceability.d.ts.map +1 -1
  310. package/script/validator/traceability.js +4 -1
  311. package/script/validator/type_resolution.d.ts +5 -3
  312. package/script/validator/type_resolution.d.ts.map +1 -1
  313. package/script/validator/type_resolution.js +14 -2
  314. package/script/validator/types.d.ts +11 -0
  315. package/script/validator/types.d.ts.map +1 -1
  316. package/script/validator/types.js +27 -4
  317. package/script/validator/uxil_family.d.ts +1 -1
@@ -4,8 +4,8 @@
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 { attributeSpec, CORE_RELATIONS, IDENTITY_KEY, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, shapeFromIdValue, UNIVERSAL_ATTRIBUTE_KEYS, } from "../model/mod.js";
8
- import { ATTR_LINE_RE, collateAttributes, parseAttributes, splitBodyAndAttributes, } from "./attributes.js";
7
+ import { CORE_RELATIONS, IDENTITY_KEY, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, shapeFromIdValue, } from "../model/mod.js";
8
+ import { ATTR_LINE_RE, collateAttributes, findTrailerStart, isTrailerUnderProse, leadingColumns, parseAttributes, RECOGNIZED_TRAILER_KEYS, splitBodyAndAttributes, } from "./attributes.js";
9
9
  import { extractBodyTokens } from "./body_tokens.js";
10
10
  import { isMarkspecDirectiveComment } from "./directives.js";
11
11
  import { processor } from "./remark.js";
@@ -14,18 +14,8 @@ import { parseCodeRegions } from "./code_regions.js";
14
14
  import { normalizeLineEndings } from "../util/line_endings.js";
15
15
  import { translateEntryLocations } from "./translate.js";
16
16
  import { assembleTyplTypes } from "../typl/mod.js";
17
- /**
18
- * Canonical set of trailer attribute keys the core recognizes: the union of
19
- * every authored universal attribute, every core trace relation, and the
20
- * extra inverse lock key (`Verified-by`). Universal keys with
21
- * `origin: "generated"` (`Contains`, `Caused`, ...) are left out: the compiler
22
- * computes them and authors never write them (#706). MSL-P020 (misplaced
23
- * trailer) fires only when a body line's key is in this set; any other
24
- * capitalized `Word:` lead-in (`Note:`, `Example:`, `Assumption:`) is prose,
25
- * not a misplaced trailer (#654).
26
- */
27
- const RECOGNIZED_TRAILER_KEYS = new Set([
28
- ...UNIVERSAL_ATTRIBUTE_KEYS.filter((key) => attributeSpec(key)?.origin !== "generated"),
17
+ /** Keys of the core trace relations, for the MSL-P020 warning. */
18
+ const TRACE_RELATION_KEYS = new Set([
29
19
  ...CORE_RELATIONS.map((r) => r.attr),
30
20
  ...LOCK_EXTRA_INVERSE_KEYS,
31
21
  ]);
@@ -107,7 +97,7 @@ export function parseMarkdown(markdown, options) {
107
97
  if (list.ordered)
108
98
  continue;
109
99
  for (const item of list.children) {
110
- const entry = extractEntry(item, markdownLines, file, definitions, isReferencesDoc, diagnostics, !!options?.lineMap);
100
+ const entry = extractEntry(item, markdownLines, file, definitions, isReferencesDoc, diagnostics, !!options?.lineMap, options?.allowTitleOnly === true);
111
101
  if (entry)
112
102
  entries.push(entry);
113
103
  }
@@ -148,7 +138,7 @@ function detectReferencesDocument(_file, explicit) {
148
138
  * Returns undefined if the list item is not an entry block.
149
139
  * Diagnostics (e.g., deprecation warnings) are pushed into the accumulator.
150
140
  */
151
- function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, diagnostics, _hasLineMap = false) {
141
+ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, diagnostics, _hasLineMap = false, allowTitleOnly = false) {
152
142
  // Task list items (remark-gfm sets checked to true/false) are not entries.
153
143
  if (item.checked != null)
154
144
  return undefined;
@@ -256,19 +246,40 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
256
246
  }
257
247
  // Extract body content and attributes.
258
248
  const bodyContent = extractBodyContent(item, markdownLines);
259
- const [body, attrLines] = splitBodyAndAttributes(bodyContent);
249
+ const [rawBody, attrLines] = splitBodyAndAttributes(bodyContent);
250
+ const body = rawBody.trimStart();
260
251
  const attributes = parseAttributes(attrLines);
261
252
  const { blocks: bodyAst, tree: mdastTree } = buildBodyAstWithTree(body);
262
253
  const entryLine = item.position?.start.line ?? 1;
263
- // MSL-P020: trailers block is not the final indented code block.
264
- // Detect `Key: Value` lines in the body that likely should be trailers
265
- // but are not at the final position (body content follows them). Only lines
266
- // whose key is a recognized trailer attribute count — see
267
- // RECOGNIZED_TRAILER_KEYS — so ordinary prose (`Note:`, `Example:`) and
268
- // caption lead-ins (`Figure:`, `Table:`) are left as legitimate body content.
254
+ // MSL-P020: a body line that would carry identity or a trace link.
255
+ // Only `Id:` and the core trace relation keys count. Other recognized
256
+ // keys (`Rationale:`, `Labels:`, `Type:`) and any other capitalized
257
+ // lead-in (`Note:`, `Example:`) start ordinary body prose: such a line
258
+ // keeps its text in the body, and `markspec fmt` cannot change it, so
259
+ // an error there could never be cleared (#654, #916).
260
+ //
261
+ // - Error: an `Id:` or trace-relation line with other content after it
262
+ // (body content or the trailer block). The trailer is not at the final
263
+ // position, so the identity or the link is lost. A trailing run that
264
+ // holds an `Id:` line is always the trailer (findTrailerStart), so an
265
+ // `Id:` line never reaches the warning case below.
266
+ // - Warning: a trace-relation line in the trailing run of `Key: Value`
267
+ // lines of an entry with no trailer. The run was not accepted as the
268
+ // trailer (no blank line above it, or a key outside the core set), so
269
+ // the line is body text and does not create a trace link.
269
270
  if (body.length > 0) {
270
271
  const bodyLines = body.split("\n");
271
272
  const fencedLines = parseCodeRegions(normalizeLineEndings(body), mdastTree).fencedLines;
273
+ // Start of the trailing run of `Key: Value` lines (blank lines skipped
274
+ // at the end only).
275
+ let tailStart = bodyLines.length;
276
+ while (tailStart > 0 && bodyLines[tailStart - 1].trim() === "") {
277
+ tailStart--;
278
+ }
279
+ while (tailStart > 0 && !fencedLines.has(tailStart - 1) &&
280
+ ATTR_LINE_RE.test(bodyLines[tailStart - 1].trim()))
281
+ tailStart--;
282
+ let warned = false;
272
283
  for (let i = 0; i < bodyLines.length; i++) {
273
284
  // Reuse the LF-normalized body tree: examples cannot be misplaced trailers.
274
285
  if (fencedLines.has(i))
@@ -276,24 +287,49 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
276
287
  const trimmed = bodyLines[i].trim();
277
288
  if (!ATTR_LINE_RE.test(trimmed))
278
289
  continue;
279
- // Only a RECOGNIZED trailer key signals a genuinely misplaced trailer.
280
- // A body paragraph starting with any other capitalized word + colon
281
- // (`Note:`, `Example:`, `Assumption:`) is prose, not a trailer (#654).
282
- const keyMatch = trimmed.match(/^([A-Z][A-Za-z-]*):/);
283
- if (!keyMatch || !RECOGNIZED_TRAILER_KEYS.has(keyMatch[1]))
290
+ const key = trimmed.match(/^([A-Z][A-Za-z-]*):/)?.[1];
291
+ if (key === undefined)
284
292
  continue;
285
- // Found a misplaced trailer-like line in the body — non-final position
286
- diagnostics.push({
287
- code: "MSL-P020",
288
- severity: "error",
289
- message: `${displayId}: trailers block is not the final indented code ` +
290
- `block of the entry -- content appears after trailer-like ` +
291
- `lines (spec section 4.1)`,
292
- location: { file, line: entryLine, column: 1 },
293
- });
294
- break; // One diagnostic per entry is sufficient
293
+ if (key !== IDENTITY_KEY && !TRACE_RELATION_KEYS.has(key))
294
+ continue;
295
+ if (i < tailStart || attrLines.length > 0) {
296
+ diagnostics.push({
297
+ code: "MSL-P020",
298
+ severity: "error",
299
+ message: `${displayId}: trailers block is not the final indented code ` +
300
+ `block of the entry -- content appears after trailer-like ` +
301
+ `lines (spec section 4.1)`,
302
+ location: { file, line: entryLine, column: 1 },
303
+ });
304
+ break; // One diagnostic per entry is sufficient
305
+ }
306
+ if (!warned) {
307
+ warned = true;
308
+ diagnostics.push({
309
+ code: "MSL-P020",
310
+ severity: "warning",
311
+ message: `${displayId}: '${key}:' line is read as body ` +
312
+ `text, not as a trailer; to make it a trace link, put the ` +
313
+ `trailer in an indented block after a blank line ` +
314
+ `(spec section 4.1)`,
315
+ location: { file, line: entryLine, column: 1 },
316
+ });
317
+ }
295
318
  }
296
319
  }
320
+ // MSL-P020 (warning): the trailer is an `Id:` run directly under prose,
321
+ // with no blank line above it. It is still read as the trailer, so the entry keeps its
322
+ // identity, but it is not in the canonical layout (#916).
323
+ if (isTrailerUnderProse(bodyContent.split("\n"))) {
324
+ diagnostics.push({
325
+ code: "MSL-P020",
326
+ severity: "warning",
327
+ message: `${displayId}: trailers block is not separated from the ` +
328
+ `body by a blank line; run 'markspec fmt' to ` +
329
+ `move it to the canonical layout (spec section 4.1)`,
330
+ location: { file, line: entryLine, column: 1 },
331
+ });
332
+ }
297
333
  // MSL-P021 / MSL-P022: validate trailer lines for syntax correctness.
298
334
  // The trailer block is the final indented code block. Lines within it
299
335
  // should all match `Key: Value` syntax. We check both the parsed
@@ -313,8 +349,57 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
313
349
  const firstNonBlank = (markdownLines[line - 1] ?? "").search(/\S/);
314
350
  return { file, line, column: firstNonBlank >= 0 ? firstNonBlank + 1 : 1 };
315
351
  };
352
+ // MSL-P023: a trailer with a line indented less than 4 columns past the
353
+ // list-item content (git style) is accepted but not canonical in
354
+ // Markdown. Every trailer line is checked, tab-aware, so a block whose
355
+ // later lines are not indented is reported too: `markspec fmt` rewrites
356
+ // it. The warning points at the trailer's first line. The legacy
357
+ // trailing-backslash form has its own deprecation warning, so it is
358
+ // skipped. A run directly under prose is reported as MSL-P020 above, so
359
+ // at most one of the two warnings fires for a block.
360
+ const contentLines = bodyContent.split("\n");
361
+ if (attrLines.length > 0 &&
362
+ !attrLines.some((line) => line.trimEnd().endsWith("\\")) &&
363
+ !isTrailerUnderProse(contentLines)) {
364
+ const trailerIndex = findTrailerStart(contentLines);
365
+ const indent = itemContentIndent(item);
366
+ let notIndented = false;
367
+ let hasContinuation = false;
368
+ for (let i = trailerIndex; i < contentLines.length; i++) {
369
+ const rawLine = markdownLines[trailerLineLocation(i).line - 1] ?? "";
370
+ if (rawLine.trim() === "")
371
+ continue;
372
+ if (leadingColumns(rawLine) - indent < 4)
373
+ notIndented = true;
374
+ if (!ATTR_LINE_RE.test(rawLine.trim()))
375
+ hasContinuation = true;
376
+ }
377
+ if (notIndented) {
378
+ // fmt and the quick fix leave a trailer with a continuation line
379
+ // (MSL-P021) unchanged, so the hint to run fmt applies only without
380
+ // one.
381
+ const hint = hasContinuation
382
+ ? "fix the MSL-P021 continuation line by hand, then indent the trailer"
383
+ : "run `markspec fmt` to indent the trailer";
384
+ diagnostics.push({
385
+ code: "MSL-P023",
386
+ severity: "warning",
387
+ message: `${displayId}: a trailer line is not indented; ${hint} ` +
388
+ "(spec section 1.3)",
389
+ location: trailerLineLocation(trailerIndex),
390
+ });
391
+ }
392
+ }
316
393
  // `attrLines` is the contiguous, blank-free tail of `bodyContent`.
317
394
  const attrContentStart = bodyContent.split("\n").length - attrLines.length;
395
+ // File line of each parsed attribute. `parseAttributes` keeps one
396
+ // attribute per trailer line and skips blank and empty-valued lines.
397
+ const attributeLines = [];
398
+ for (const [attrIndex, rawLine] of attrLines.entries()) {
399
+ if (parseAttributes([rawLine]).length === 1) {
400
+ attributeLines.push(trailerLineLocation(attrContentStart + attrIndex).line);
401
+ }
402
+ }
318
403
  // Check lines that DID end up in attrLines but might have key issues
319
404
  for (const [attrIndex, rawLine] of attrLines.entries()) {
320
405
  const trailerLocation = trailerLineLocation(attrContentStart + attrIndex);
@@ -494,8 +579,9 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
494
579
  // Body requirement: identified entries require a body; referenced entries
495
580
  // may omit it. If there's only one child (the title paragraph), admit
496
581
  // only referenced entries.
497
- if (shape !== "Reference" && item.children.length < 2)
582
+ if (shape !== "Reference" && item.children.length < 2 && !allowTitleOnly) {
498
583
  return undefined;
584
+ }
499
585
  // Source location
500
586
  const line = item.position?.start.line ?? 1;
501
587
  const column = item.position?.start.column ?? 1;
@@ -540,6 +626,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
540
626
  location: entryLocation,
541
627
  bodyStartLine,
542
628
  ...(endLine !== undefined ? { endLine } : {}),
629
+ ...(attributeLines.length > 0 ? { attributeLines } : {}),
543
630
  source: { kind: "markdown" },
544
631
  properties: { file: { path: file, line, column } },
545
632
  bodyTokens,
@@ -585,5 +672,7 @@ function extractBodyContent(item, lines) {
585
672
  return line.slice(indent);
586
673
  return line;
587
674
  });
588
- return stripped.join("\n").trim();
675
+ // Keep the first line's own indent: it marks an indented trailer in a
676
+ // body-less entry, and `markspec fmt` sees the same text (#916).
677
+ return stripped.join("\n").trimEnd();
589
678
  }
@@ -10,6 +10,7 @@
10
10
  * - source: doc comment extraction from Rust, Kotlin, C, C++, Java
11
11
  */
12
12
  import type { Caption, Diagnostic, Document, Entry } from "../model/mod.js";
13
+ import { type GherkinApi } from "../gherkin/load.js";
13
14
  import { type DetectCaptionsOptions } from "./captions.js";
14
15
  export type { DetectCaptionsOptions } from "./captions.js";
15
16
  export { detectDirectives } from "./directives.js";
@@ -56,6 +57,21 @@ export interface ParseFileResult {
56
57
  */
57
58
  readonly diagnostics: readonly Diagnostic[];
58
59
  }
60
+ /**
61
+ * A fenced code block whose info string starts with the word `gherkin` or
62
+ * `feature`, followed by whitespace or the end of the line (so
63
+ * `gherkin-json` does not match). The fence has three or more backticks or
64
+ * tildes. Before the fence, the line may hold spaces, tabs, blockquote
65
+ * markers and doc-comment prefixes (`>`, `///`, `//!`, ` *`, `#`), and list
66
+ * markers (`-`, `*`, `+`, `1.`, `1)`) followed by a space or tab. The
67
+ * prefix holds no newline, so the match never spans lines, and each
68
+ * prefix character matches only one alternative, so the scan stays linear.
69
+ *
70
+ * @internal Exported for tests.
71
+ */
72
+ export declare const GHERKIN_FENCE_RE: RegExp;
73
+ /** Loads the Gherkin parser; replaced in tests. */
74
+ type GherkinLoader = () => Promise<GherkinApi>;
59
75
  /**
60
76
  * Parse a file and return entries, annotation links, and (for Markdown
61
77
  * files) a Document with front-matter attributes.
@@ -66,6 +82,8 @@ export interface ParseFileResult {
66
82
  */
67
83
  export declare function parseFile(content: string, options: {
68
84
  readonly file: string;
85
+ /** @internal Replaces the Gherkin parser loader in tests. */
86
+ readonly gherkinLoader?: GherkinLoader;
69
87
  }): Promise<ParseFileResult>;
70
88
  /**
71
89
  * Detect table and figure captions in a Markdown string.
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/parser/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAU5E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACV,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,E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M,oBAAoB,CAAC;AAE5E,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,YAAY,GACrB,KAAK,EAAE,CAOT;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAeD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,QACkE,CAAC;AAEhG,mDAAmD;AACnD,KAAK,aAAa,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;AAE/C;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IACP,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;CACxC,GACA,OAAO,CAAC,eAAe,CAAC,CAwF1B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,EAAE,CAEX"}
package/esm/parser/mod.js CHANGED
@@ -11,6 +11,8 @@
11
11
  */
12
12
  import { basename as pathBasename, extname } from "@std/path";
13
13
  import { normalizeLineEndings } from "../util/line_endings.js";
14
+ import { loadGherkin } from "../gherkin/load.js";
15
+ import { hasFeatureHeaderLine, parseFeatureFile } from "./feature_file.js";
14
16
  import { parseMarkdown } from "./markdown.js";
15
17
  import { isSupportedExtension, languageIdForExtension, loadGrammar, } from "./grammars.js";
16
18
  import { parseSource } from "./source.js";
@@ -52,6 +54,19 @@ function isReferencesDocument(file) {
52
54
  // same as POSIX.
53
55
  return /[\\/]references[\\/]/.test(file);
54
56
  }
57
+ /**
58
+ * A fenced code block whose info string starts with the word `gherkin` or
59
+ * `feature`, followed by whitespace or the end of the line (so
60
+ * `gherkin-json` does not match). The fence has three or more backticks or
61
+ * tildes. Before the fence, the line may hold spaces, tabs, blockquote
62
+ * markers and doc-comment prefixes (`>`, `///`, `//!`, ` *`, `#`), and list
63
+ * markers (`-`, `*`, `+`, `1.`, `1)`) followed by a space or tab. The
64
+ * prefix holds no newline, so the match never spans lines, and each
65
+ * prefix character matches only one alternative, so the scan stays linear.
66
+ *
67
+ * @internal Exported for tests.
68
+ */
69
+ export const GHERKIN_FENCE_RE = /^(?:[ \t/*#!>]|[-+][ \t]|\d{1,9}[.)][ \t])*(`{3,}|~{3,})[ \t]*(gherkin|feature)(?=[ \t]|$)/m;
55
70
  /**
56
71
  * Parse a file and return entries, annotation links, and (for Markdown
57
72
  * files) a Document with front-matter attributes.
@@ -62,7 +77,43 @@ function isReferencesDocument(file) {
62
77
  */
63
78
  export async function parseFile(content, options) {
64
79
  const ext = extname(options.file);
80
+ const lowerExt = ext.toLowerCase();
65
81
  const normalised = normalizeLineEndings(content);
82
+ // A `.feature` file always needs the parser (ADR-038): entries come from
83
+ // its `# [ID]` header comments. A load failure gives no entries and one
84
+ // MSL-B062 when the file has a header line, and never throws.
85
+ if (lowerExt === ".feature") {
86
+ let api;
87
+ try {
88
+ api = await (options.gherkinLoader ?? loadGherkin)();
89
+ }
90
+ catch (err) {
91
+ const diagnostics = hasFeatureHeaderLine(normalised)
92
+ ? [{
93
+ code: "MSL-B062",
94
+ severity: "warning",
95
+ message: `Gherkin file not parsed: the Gherkin parser failed to ` +
96
+ `load (${err instanceof Error ? err.message : String(err)})`,
97
+ location: { file: options.file, line: 1, column: 1 },
98
+ }]
99
+ : [];
100
+ return { entries: [], diagnostics };
101
+ }
102
+ return parseFeatureFile(normalised, { file: options.file, api });
103
+ }
104
+ // Load the Gherkin parser before the synchronous parse, and only when the
105
+ // text holds a gherkin or feature fence (the load is cached). A failed
106
+ // load is not fatal: parsing continues without the Gherkin AST, and the
107
+ // criteria come from the line scanner. The loader does not cache the
108
+ // failure, so a later file tries again.
109
+ if (GHERKIN_FENCE_RE.test(normalised)) {
110
+ try {
111
+ await (options.gherkinLoader ?? loadGherkin)();
112
+ }
113
+ catch {
114
+ // Continue without the parser (ADR-038 Decision 4).
115
+ }
116
+ }
66
117
  if (isSupportedExtension(ext)) {
67
118
  const language = await loadGrammar(ext);
68
119
  const languageId = languageIdForExtension(ext);
@@ -1 +1 @@
1
- {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/parser/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,iBAAiB,CAAC;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,OAAO,GACf,KAAK,EAAE,CAyDT"}
1
+ {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/parser/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,iBAAiB,CAAC;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,OAAO,GACf,KAAK,EAAE,CAgET"}
@@ -42,6 +42,11 @@ export function translateEntryLocations(entries, lineMap) {
42
42
  endLine: lineMap.translate(entry.endLine, 1)?.line ?? entry.endLine,
43
43
  }
44
44
  : {}),
45
+ ...(entry.attributeLines !== undefined
46
+ ? {
47
+ attributeLines: entry.attributeLines.map((line) => lineMap.translate(line, 1)?.line ?? line),
48
+ }
49
+ : {}),
45
50
  bodyAst: entry.bodyAst
46
51
  ? entry.bodyAst.map((block) => translateBlock(block, lineMap, fallbackPoint, warn))
47
52
  : entry.bodyAst,
package/esm/refs/mod.d.ts CHANGED
@@ -9,7 +9,8 @@
9
9
  *
10
10
  * Architecture: composed AROUND the pure `core/formatter` by the `markspec fmt`
11
11
  * CLI. It MUST NOT import `core/formatter`, and `core/formatter` MUST NOT import
12
- * it (WASM-migration purity guard, AGENTS.md).
12
+ * this module (WASM-migration purity guard, AGENTS.md). The formatter may
13
+ * import only the pure leaf `core/refs/split.ts` (ADR-026 D6).
13
14
  */
14
15
  import type { Entry } from "../model/mod.js";
15
16
  import type { LockEdge } from "../lock/mod.js";
@@ -34,9 +35,13 @@ export declare function buildRefIndex(entries: readonly Entry[]): RefIndex;
34
35
  * Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
35
36
  * `entries` MUST be the parse of `content` (used to map each trailer line to its
36
37
  * source entry's stable ULID). Returns the rewritten text and whether anything
37
- * changed. Lossless: only resolvable value tokens are replaced.
38
+ * changed. Lossless: only resolvable value tokens are replaced. Optional
39
+ * `preservedRanges` exclude 0-based, end-exclusive line spans from rewriting.
38
40
  */
39
- export declare function canonicalizeRefs(content: string, entries: readonly Entry[], index: RefIndex, ledger: readonly LockEdge[]): {
41
+ export declare function canonicalizeRefs(content: string, entries: readonly Entry[], index: RefIndex, ledger: readonly LockEdge[], preservedRanges?: readonly {
42
+ readonly start: number;
43
+ readonly end: number;
44
+ }[]): {
40
45
  output: string;
41
46
  changed: boolean;
42
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/refs/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBA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AAG,QAAQ,CAajE;AAmBD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,eAAe,GAAE,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACtE,GACH;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAwGtC"}
package/esm/refs/mod.js CHANGED
@@ -9,7 +9,8 @@
9
9
  *
10
10
  * Architecture: composed AROUND the pure `core/formatter` by the `markspec fmt`
11
11
  * CLI. It MUST NOT import `core/formatter`, and `core/formatter` MUST NOT import
12
- * it (WASM-migration purity guard, AGENTS.md).
12
+ * this module (WASM-migration purity guard, AGENTS.md). The formatter may
13
+ * import only the pure leaf `core/refs/split.ts` (ADR-026 D6).
13
14
  */
14
15
  import { CORE_RELATIONS, DISPLAY_ID_RE, LOCK_EXTRA_INVERSE_KEYS, ULID_RE, } from "../model/mod.js";
15
16
  import { fencedCodeLines } from "../util/fence.js";
@@ -49,15 +50,21 @@ const TRACE_TRAILER_RE = /^(\s{4,})([A-Z][A-Za-z-]*)(\s*:\s*)(.*)$/;
49
50
  * non-empty value-rest (no `Key:` — that sat on the first physical line).
50
51
  */
51
52
  const CONTINUATION_LINE_RE = /^(\s+)(\S.*)$/;
52
- /** Token splitter that preserves separators between value tokens. */
53
- const VALUE_TOKEN_RE = /[^\s,]+/g;
53
+ /**
54
+ * Token splitter that preserves separators between value tokens. The first
55
+ * alternative matches a closed scenario locator after whitespace
56
+ * (`STK_1 [AC one]`, #915, same grammar as `refs/split.ts`); a locator is
57
+ * kept verbatim, so only the target before it is rewritten.
58
+ */
59
+ const VALUE_TOKEN_RE = /(\s\[(?:\\[\s\S]|[^\]\\])+\])|[^\s,]+/g;
54
60
  /**
55
61
  * Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
56
62
  * `entries` MUST be the parse of `content` (used to map each trailer line to its
57
63
  * source entry's stable ULID). Returns the rewritten text and whether anything
58
- * changed. Lossless: only resolvable value tokens are replaced.
64
+ * changed. Lossless: only resolvable value tokens are replaced. Optional
65
+ * `preservedRanges` exclude 0-based, end-exclusive line spans from rewriting.
59
66
  */
60
- export function canonicalizeRefs(content, entries, index, ledger) {
67
+ export function canonicalizeRefs(content, entries, index, ledger, preservedRanges = []) {
61
68
  const ledgerByKey = new Map();
62
69
  for (const e of ledger) {
63
70
  if (e.targetUlid === undefined)
@@ -87,7 +94,11 @@ export function canonicalizeRefs(content, entries, index, ledger) {
87
94
  let changed = false;
88
95
  // Share CommonMark fence boundaries with other prose passes. Compute them
89
96
  // once so both the main loop and continuation loop remain linear (#705).
90
- const fencedLines = fencedCodeLines(content);
97
+ const fencedLines = new Set(fencedCodeLines(content));
98
+ for (const range of preservedRanges) {
99
+ for (let i = range.start; i < range.end; i++)
100
+ fencedLines.add(i);
101
+ }
91
102
  for (let i = 0; i < lines.length; i++) {
92
103
  if (fencedLines.has(i))
93
104
  continue;
@@ -153,7 +164,9 @@ export function canonicalizeRefs(content, entries, index, ledger) {
153
164
  function rewriteValuePreservingContinuation(value, sourceUlid, relation, index, ledgerByKey) {
154
165
  const hasBackslash = value.endsWith("\\");
155
166
  const core = hasBackslash ? value.slice(0, -1) : value;
156
- const rewritten = core.replace(VALUE_TOKEN_RE, (token) => rewriteToken(token, sourceUlid, relation, index, ledgerByKey));
167
+ const rewritten = core.replace(VALUE_TOKEN_RE, (token, locator) => locator !== undefined
168
+ ? token
169
+ : rewriteToken(token, sourceUlid, relation, index, ledgerByKey));
157
170
  return hasBackslash ? `${rewritten}\\` : rewritten;
158
171
  }
159
172
  function rewriteToken(token, sourceUlid, relation, index, ledgerByKey) {
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @module refs/split
3
+ *
4
+ * Bracket-aware splitting of trace attribute values. A value is
5
+ * `target [ 1*WSP "[" locator "]" ]`. A locator can contain commas, so a
6
+ * plain split on commas is wrong for it. The escapes `\]` and `\\` are
7
+ * valid inside a locator only; any other backslash sequence (such as `\x`)
8
+ * is kept as written. A locator must follow whitespace after the target,
9
+ * so `A[x]` has no locator. A value without a closed locator is read
10
+ * exactly as before scenario locators existed.
11
+ */
12
+ /** A parsed trace value. */
13
+ export interface ParsedTraceValue {
14
+ /** The referenced entry or reference identifier. */
15
+ readonly target: string;
16
+ /** The locator after {@linkcode normalizeLocator} and unescaping. */
17
+ readonly locator?: string;
18
+ /** The locator text exactly as authored between the brackets. */
19
+ readonly locatorRaw?: string;
20
+ }
21
+ /**
22
+ * Normalize locator text for comparison: Unicode NFC, trim, and collapse
23
+ * each whitespace run to one space.
24
+ */
25
+ export declare function normalizeLocator(text: string): string;
26
+ /**
27
+ * Split a trace attribute value into its parts. When at least one part has
28
+ * a closed bracket locator after whitespace, commas inside a locator do not
29
+ * split. Otherwise the value is split on every comma, exactly as before
30
+ * scenario locators existed, so an unterminated `[` does not change how a
31
+ * value is read. Parts are trimmed and empty parts are dropped.
32
+ */
33
+ export declare function splitTraceValues(value: string): string[];
34
+ /**
35
+ * Parse one value from {@linkcode splitTraceValues} into target and
36
+ * optional locator. A value without a closed locator after whitespace is
37
+ * kept whole as the target, as before scenario locators existed.
38
+ */
39
+ export declare function parseTraceValue(raw: string): ParsedTraceValue;
40
+ /**
41
+ * `true` when a trace value has a `[` after whitespace that no unescaped
42
+ * `]` closes. Such a value has no locator.
43
+ */
44
+ export declare function isUnterminatedLocator(raw: string): boolean;
45
+ /**
46
+ * The target of a trace value for existence and value-type checks: the
47
+ * target before a closed bracket locator, else the trimmed value as
48
+ * written.
49
+ */
50
+ export declare function traceTarget(raw: string): string;
51
+ /**
52
+ * The tokens of a trace value that can name another entry, for reference
53
+ * scans (find references, dependent counts). A closed locator is dropped,
54
+ * so an ID written inside a locator is not a reference. Any other part is
55
+ * split on whitespace and commas, as before scenario locators existed.
56
+ */
57
+ export declare function referenceTokens(value: string): string[];
58
+ //# sourceMappingURL=split.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split.d.ts","sourceRoot":"","sources":["../../src/refs/split.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4BAA4B;AAC5B,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAKxD;AAqCD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAU7D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAa1D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAWvD"}