@driftsys/markspec 0.12.1 → 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 (279) 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/criteria/scenarios.d.ts +55 -0
  15. package/esm/criteria/scenarios.d.ts.map +1 -0
  16. package/esm/criteria/scenarios.js +133 -0
  17. package/esm/discovery/mod.d.ts +20 -1
  18. package/esm/discovery/mod.d.ts.map +1 -1
  19. package/esm/discovery/mod.js +105 -17
  20. package/esm/formatter/entry_body.d.ts +8 -5
  21. package/esm/formatter/entry_body.d.ts.map +1 -1
  22. package/esm/formatter/entry_body.js +12 -8
  23. package/esm/formatter/feature_file.d.ts +40 -0
  24. package/esm/formatter/feature_file.d.ts.map +1 -0
  25. package/esm/formatter/feature_file.js +88 -0
  26. package/esm/formatter/mod.d.ts +21 -2
  27. package/esm/formatter/mod.d.ts.map +1 -1
  28. package/esm/formatter/mod.js +64 -22
  29. package/esm/gates/mod.d.ts +2 -2
  30. package/esm/gates/mod.d.ts.map +1 -1
  31. package/esm/gates/mod.js +17 -2
  32. package/esm/gherkin/load.d.ts +35 -0
  33. package/esm/gherkin/load.d.ts.map +1 -0
  34. package/esm/gherkin/load.js +39 -0
  35. package/esm/gherkin/parse.d.ts +11 -0
  36. package/esm/gherkin/parse.d.ts.map +1 -0
  37. package/esm/gherkin/parse.js +311 -0
  38. package/esm/gherkin/position.d.ts +23 -0
  39. package/esm/gherkin/position.d.ts.map +1 -0
  40. package/esm/gherkin/position.js +21 -0
  41. package/esm/gherkin/procedure.d.ts +76 -0
  42. package/esm/gherkin/procedure.d.ts.map +1 -0
  43. package/esm/gherkin/procedure.js +164 -0
  44. package/esm/gherkin/project.d.ts +35 -0
  45. package/esm/gherkin/project.d.ts.map +1 -0
  46. package/esm/gherkin/project.js +64 -0
  47. package/esm/gherkin/role.d.ts +23 -0
  48. package/esm/gherkin/role.d.ts.map +1 -0
  49. package/esm/gherkin/role.js +28 -0
  50. package/esm/gherkin/types.d.ts +118 -0
  51. package/esm/gherkin/types.d.ts.map +1 -0
  52. package/esm/gherkin/types.js +12 -0
  53. package/esm/lock/acquire_compile.d.ts +12 -4
  54. package/esm/lock/acquire_compile.d.ts.map +1 -1
  55. package/esm/lock/acquire_compile.js +15 -5
  56. package/esm/lock/canonical_edges.d.ts +6 -2
  57. package/esm/lock/canonical_edges.d.ts.map +1 -1
  58. package/esm/lock/canonical_edges.js +10 -3
  59. package/esm/lock/model.d.ts +5 -0
  60. package/esm/lock/model.d.ts.map +1 -1
  61. package/esm/lock/parser.d.ts.map +1 -1
  62. package/esm/lock/parser.js +2 -0
  63. package/esm/lock/resolve.d.ts +6 -2
  64. package/esm/lock/resolve.d.ts.map +1 -1
  65. package/esm/lock/resolve.js +36 -4
  66. package/esm/lock/serializer.d.ts.map +1 -1
  67. package/esm/lock/serializer.js +7 -1
  68. package/esm/mod.d.ts +23 -6
  69. package/esm/mod.d.ts.map +1 -1
  70. package/esm/mod.js +18 -5
  71. package/esm/model/mod.d.ts +42 -1
  72. package/esm/model/mod.d.ts.map +1 -1
  73. package/esm/model/mod.js +1 -1
  74. package/esm/model/relations.d.ts +9 -0
  75. package/esm/model/relations.d.ts.map +1 -1
  76. package/esm/model/relations.js +16 -1
  77. package/esm/parser/attributes.d.ts +82 -3
  78. package/esm/parser/attributes.d.ts.map +1 -1
  79. package/esm/parser/attributes.js +199 -32
  80. package/esm/parser/body_tokens.d.ts +1 -1
  81. package/esm/parser/body_tokens.d.ts.map +1 -1
  82. package/esm/parser/body_tokens.js +49 -35
  83. package/esm/parser/feature_file.d.ts +116 -0
  84. package/esm/parser/feature_file.d.ts.map +1 -0
  85. package/esm/parser/feature_file.js +540 -0
  86. package/esm/parser/markdown.d.ts +7 -0
  87. package/esm/parser/markdown.d.ts.map +1 -1
  88. package/esm/parser/markdown.js +129 -40
  89. package/esm/parser/mod.d.ts +18 -0
  90. package/esm/parser/mod.d.ts.map +1 -1
  91. package/esm/parser/mod.js +51 -0
  92. package/esm/parser/translate.d.ts.map +1 -1
  93. package/esm/parser/translate.js +5 -0
  94. package/esm/refs/mod.d.ts +2 -1
  95. package/esm/refs/mod.d.ts.map +1 -1
  96. package/esm/refs/mod.js +12 -4
  97. package/esm/refs/split.d.ts +58 -0
  98. package/esm/refs/split.d.ts.map +1 -0
  99. package/esm/refs/split.js +137 -0
  100. package/esm/reporter/mod.d.ts +7 -0
  101. package/esm/reporter/mod.d.ts.map +1 -1
  102. package/esm/reporter/mod.js +113 -3
  103. package/esm/validator/attributes.d.ts.map +1 -1
  104. package/esm/validator/attributes.js +4 -1
  105. package/esm/validator/block_role.d.ts +40 -0
  106. package/esm/validator/block_role.d.ts.map +1 -0
  107. package/esm/validator/block_role.js +109 -0
  108. package/esm/validator/feature_ac.d.ts.map +1 -1
  109. package/esm/validator/feature_ac.js +6 -1
  110. package/esm/validator/feature_parse.d.ts +35 -0
  111. package/esm/validator/feature_parse.d.ts.map +1 -0
  112. package/esm/validator/feature_parse.js +69 -0
  113. package/esm/validator/locators.d.ts +36 -0
  114. package/esm/validator/locators.d.ts.map +1 -0
  115. package/esm/validator/locators.js +184 -0
  116. package/esm/validator/mod.d.ts +10 -1
  117. package/esm/validator/mod.d.ts.map +1 -1
  118. package/esm/validator/mod.js +38 -14
  119. package/esm/validator/normalize.d.ts.map +1 -1
  120. package/esm/validator/normalize.js +8 -3
  121. package/esm/validator/per_type_attrs.d.ts +3 -3
  122. package/esm/validator/per_type_attrs.js +3 -3
  123. package/esm/validator/pipeline.d.ts +4 -12
  124. package/esm/validator/pipeline.d.ts.map +1 -1
  125. package/esm/validator/pipeline.js +24 -5
  126. package/esm/validator/procedure.d.ts +22 -0
  127. package/esm/validator/procedure.d.ts.map +1 -0
  128. package/esm/validator/procedure.js +58 -0
  129. package/esm/validator/trace_types.d.ts.map +1 -1
  130. package/esm/validator/trace_types.js +4 -3
  131. package/esm/validator/traceability.d.ts.map +1 -1
  132. package/esm/validator/traceability.js +4 -1
  133. package/esm/validator/type_resolution.d.ts +5 -3
  134. package/esm/validator/type_resolution.d.ts.map +1 -1
  135. package/esm/validator/type_resolution.js +14 -2
  136. package/esm/validator/types.d.ts +11 -0
  137. package/esm/validator/types.d.ts.map +1 -1
  138. package/esm/validator/types.js +26 -4
  139. package/esm/validator/uxil_family.d.ts +1 -1
  140. package/package.json +3 -1
  141. package/script/ast/build.d.ts.map +1 -1
  142. package/script/ast/build.js +19 -5
  143. package/script/ast/equivalence.js +14 -2
  144. package/script/ast/nodes.d.ts +15 -3
  145. package/script/ast/nodes.d.ts.map +1 -1
  146. package/script/compiler/inverses.d.ts.map +1 -1
  147. package/script/compiler/inverses.js +18 -3
  148. package/script/compiler/mod.d.ts +34 -1
  149. package/script/compiler/mod.d.ts.map +1 -1
  150. package/script/compiler/mod.js +110 -46
  151. package/script/compiler/schema.d.ts +3 -2
  152. package/script/compiler/schema.d.ts.map +1 -1
  153. package/script/compiler/schema.js +6 -3
  154. package/script/criteria/scenarios.d.ts +55 -0
  155. package/script/criteria/scenarios.d.ts.map +1 -0
  156. package/script/criteria/scenarios.js +139 -0
  157. package/script/discovery/mod.d.ts +20 -1
  158. package/script/discovery/mod.d.ts.map +1 -1
  159. package/script/discovery/mod.js +106 -17
  160. package/script/formatter/entry_body.d.ts +8 -5
  161. package/script/formatter/entry_body.d.ts.map +1 -1
  162. package/script/formatter/entry_body.js +12 -8
  163. package/script/formatter/feature_file.d.ts +40 -0
  164. package/script/formatter/feature_file.d.ts.map +1 -0
  165. package/script/formatter/feature_file.js +92 -0
  166. package/script/formatter/mod.d.ts +21 -2
  167. package/script/formatter/mod.d.ts.map +1 -1
  168. package/script/formatter/mod.js +63 -21
  169. package/script/gates/mod.d.ts +2 -2
  170. package/script/gates/mod.d.ts.map +1 -1
  171. package/script/gates/mod.js +17 -2
  172. package/script/gherkin/load.d.ts +35 -0
  173. package/script/gherkin/load.d.ts.map +1 -0
  174. package/script/gherkin/load.js +76 -0
  175. package/script/gherkin/parse.d.ts +11 -0
  176. package/script/gherkin/parse.d.ts.map +1 -0
  177. package/script/gherkin/parse.js +314 -0
  178. package/script/gherkin/position.d.ts +23 -0
  179. package/script/gherkin/position.d.ts.map +1 -0
  180. package/script/gherkin/position.js +24 -0
  181. package/script/gherkin/procedure.d.ts +76 -0
  182. package/script/gherkin/procedure.d.ts.map +1 -0
  183. package/script/gherkin/procedure.js +169 -0
  184. package/script/gherkin/project.d.ts +35 -0
  185. package/script/gherkin/project.d.ts.map +1 -0
  186. package/script/gherkin/project.js +67 -0
  187. package/script/gherkin/role.d.ts +23 -0
  188. package/script/gherkin/role.d.ts.map +1 -0
  189. package/script/gherkin/role.js +31 -0
  190. package/script/gherkin/types.d.ts +118 -0
  191. package/script/gherkin/types.d.ts.map +1 -0
  192. package/script/gherkin/types.js +13 -0
  193. package/script/lock/acquire_compile.d.ts +12 -4
  194. package/script/lock/acquire_compile.d.ts.map +1 -1
  195. package/script/lock/acquire_compile.js +15 -5
  196. package/script/lock/canonical_edges.d.ts +6 -2
  197. package/script/lock/canonical_edges.d.ts.map +1 -1
  198. package/script/lock/canonical_edges.js +10 -3
  199. package/script/lock/model.d.ts +5 -0
  200. package/script/lock/model.d.ts.map +1 -1
  201. package/script/lock/parser.d.ts.map +1 -1
  202. package/script/lock/parser.js +2 -0
  203. package/script/lock/resolve.d.ts +6 -2
  204. package/script/lock/resolve.d.ts.map +1 -1
  205. package/script/lock/resolve.js +36 -4
  206. package/script/lock/serializer.d.ts.map +1 -1
  207. package/script/lock/serializer.js +7 -1
  208. package/script/mod.d.ts +23 -6
  209. package/script/mod.d.ts.map +1 -1
  210. package/script/mod.js +45 -6
  211. package/script/model/mod.d.ts +42 -1
  212. package/script/model/mod.d.ts.map +1 -1
  213. package/script/model/mod.js +2 -1
  214. package/script/model/relations.d.ts +9 -0
  215. package/script/model/relations.d.ts.map +1 -1
  216. package/script/model/relations.js +17 -1
  217. package/script/parser/attributes.d.ts +82 -3
  218. package/script/parser/attributes.d.ts.map +1 -1
  219. package/script/parser/attributes.js +205 -33
  220. package/script/parser/body_tokens.d.ts +1 -1
  221. package/script/parser/body_tokens.d.ts.map +1 -1
  222. package/script/parser/body_tokens.js +49 -35
  223. package/script/parser/feature_file.d.ts +116 -0
  224. package/script/parser/feature_file.d.ts.map +1 -0
  225. package/script/parser/feature_file.js +548 -0
  226. package/script/parser/markdown.d.ts +7 -0
  227. package/script/parser/markdown.d.ts.map +1 -1
  228. package/script/parser/markdown.js +128 -39
  229. package/script/parser/mod.d.ts +18 -0
  230. package/script/parser/mod.d.ts.map +1 -1
  231. package/script/parser/mod.js +52 -1
  232. package/script/parser/translate.d.ts.map +1 -1
  233. package/script/parser/translate.js +5 -0
  234. package/script/refs/mod.d.ts +2 -1
  235. package/script/refs/mod.d.ts.map +1 -1
  236. package/script/refs/mod.js +12 -4
  237. package/script/refs/split.d.ts +58 -0
  238. package/script/refs/split.d.ts.map +1 -0
  239. package/script/refs/split.js +145 -0
  240. package/script/reporter/mod.d.ts +7 -0
  241. package/script/reporter/mod.d.ts.map +1 -1
  242. package/script/reporter/mod.js +113 -3
  243. package/script/validator/attributes.d.ts.map +1 -1
  244. package/script/validator/attributes.js +4 -1
  245. package/script/validator/block_role.d.ts +40 -0
  246. package/script/validator/block_role.d.ts.map +1 -0
  247. package/script/validator/block_role.js +112 -0
  248. package/script/validator/feature_ac.d.ts.map +1 -1
  249. package/script/validator/feature_ac.js +6 -1
  250. package/script/validator/feature_parse.d.ts +35 -0
  251. package/script/validator/feature_parse.d.ts.map +1 -0
  252. package/script/validator/feature_parse.js +73 -0
  253. package/script/validator/locators.d.ts +36 -0
  254. package/script/validator/locators.d.ts.map +1 -0
  255. package/script/validator/locators.js +188 -0
  256. package/script/validator/mod.d.ts +10 -1
  257. package/script/validator/mod.d.ts.map +1 -1
  258. package/script/validator/mod.js +38 -14
  259. package/script/validator/normalize.d.ts.map +1 -1
  260. package/script/validator/normalize.js +8 -3
  261. package/script/validator/per_type_attrs.d.ts +3 -3
  262. package/script/validator/per_type_attrs.js +3 -3
  263. package/script/validator/pipeline.d.ts +4 -12
  264. package/script/validator/pipeline.d.ts.map +1 -1
  265. package/script/validator/pipeline.js +23 -5
  266. package/script/validator/procedure.d.ts +22 -0
  267. package/script/validator/procedure.d.ts.map +1 -0
  268. package/script/validator/procedure.js +61 -0
  269. package/script/validator/trace_types.d.ts.map +1 -1
  270. package/script/validator/trace_types.js +4 -3
  271. package/script/validator/traceability.d.ts.map +1 -1
  272. package/script/validator/traceability.js +4 -1
  273. package/script/validator/type_resolution.d.ts +5 -3
  274. package/script/validator/type_resolution.d.ts.map +1 -1
  275. package/script/validator/type_resolution.js +14 -2
  276. package/script/validator/types.d.ts +11 -0
  277. package/script/validator/types.d.ts.map +1 -1
  278. package/script/validator/types.js +27 -4
  279. package/script/validator/uxil_family.d.ts +1 -1
@@ -17,14 +17,21 @@ export const CORE_RELATIONS = [
17
17
  linkKind: "satisfies",
18
18
  targetTypes: ["Specification"],
19
19
  lockEdge: true,
20
+ locator: "criterion",
20
21
  },
21
22
  {
22
23
  attr: "Derived-from",
23
24
  linkKind: "derived-from",
24
25
  targetTypes: ["Specification"],
25
26
  lockEdge: true,
27
+ locator: "free",
28
+ },
29
+ {
30
+ attr: "References",
31
+ linkKind: "references",
32
+ lockEdge: true,
33
+ locator: "free",
26
34
  },
27
- { attr: "References", linkKind: "references", lockEdge: true },
28
35
  {
29
36
  attr: "Allocated-to",
30
37
  linkKind: "allocated-to",
@@ -41,6 +48,7 @@ export const CORE_RELATIONS = [
41
48
  attr: "Verifies",
42
49
  linkKind: "verifies",
43
50
  targetTypes: ["Requirement", "Contract"],
51
+ locator: "criterion",
44
52
  },
45
53
  {
46
54
  attr: "Tests",
@@ -77,6 +85,13 @@ export const CORE_RELATIONS = [
77
85
  { attr: "Mitigated-by", targetTypes: ["Specification"] },
78
86
  { attr: "Affects", targetTypes: ["Component", "Unit", "Contract"] },
79
87
  ];
88
+ /** The locator mode of the relation with trailer key `attr`, or `undefined`
89
+ * when the relation does not accept a locator (or is not a core relation).
90
+ * The facet is core-only: a profile-declared relation has no locator mode
91
+ * in this slice, so this function returns `undefined` for it. */
92
+ export function relationLocatorMode(attr) {
93
+ return CORE_RELATIONS.find((r) => r.attr === attr)?.locator;
94
+ }
80
95
  /**
81
96
  * Lock-edge keys that are NOT forward relations. The lockfile tracks the
82
97
  * verification edge by its inverse name `Verified-by` (not `Verifies`), so it is
@@ -6,6 +6,38 @@
6
6
  * trailing attribute blocks from body prose.
7
7
  */
8
8
  import type { Attribute, TypedAttributes } from "../model/mod.js";
9
+ /**
10
+ * Canonical set of trailer attribute keys the core recognizes: the union of
11
+ * every authored universal attribute, every core trace relation, and the
12
+ * extra inverse lock key (`Verified-by`). Universal keys with
13
+ * `origin: "generated"` (`Contains`, `Caused`, ...) are left out: the compiler
14
+ * computes them and authors never write them (#706).
15
+ *
16
+ * Two uses:
17
+ *
18
+ * - Trailer detection: an unindented final paragraph without an `Id:` line
19
+ * is a trailer only when every key is in this set
20
+ * ({@linkcode findTrailerStart}, #916).
21
+ * - The MSL-P022 typo check: a malformed key that is a typo of a key in
22
+ * this set still raises MSL-P022 (#697).
23
+ *
24
+ * MSL-P020 on body prose uses only `Id` and the trace-relation keys of this
25
+ * set; any other `Word:` lead-in (`Rationale:`, `Note:`) is prose (#654,
26
+ * #916).
27
+ */
28
+ export declare const RECOGNIZED_TRAILER_KEYS: ReadonlySet<string>;
29
+ /**
30
+ * Parse one attribute line: the line is trimmed, one trailing continuation
31
+ * backslash is dropped, and the value is trimmed. The value is empty for
32
+ * `Key:` and `Key: \`. Returns `undefined` when the line is not a
33
+ * `Key:` line. {@linkcode parseAttributes} reads lines through this
34
+ * function, and so do the Markdown A011, A012 and A013 quick fixes of the
35
+ * LSP, so they agree with the parser.
36
+ */
37
+ export declare function parseAttributeLine(line: string): {
38
+ key: string;
39
+ value: string;
40
+ } | undefined;
9
41
  /**
10
42
  * Parse an array of attribute lines into Attribute objects.
11
43
  *
@@ -34,12 +66,59 @@ export declare const ATTR_LINE_RE: RegExp;
34
66
  * - Unknown keys: preserved as-is, one entry per occurrence.
35
67
  */
36
68
  export declare function collateAttributes(attributes: readonly Attribute[]): TypedAttributes;
69
+ /**
70
+ * Width of the leading whitespace of `line` in columns, with a tab moving
71
+ * to the next multiple of 4. CommonMark uses the same tab stop, so a line
72
+ * that mixes spaces and tabs is measured as the code-block rule sees it.
73
+ */
74
+ export declare function leadingColumns(line: string): number;
75
+ /** `true` when `line` is indented by 4 or more columns (code-block indent). */
76
+ export declare function isIndented(line: string): boolean;
77
+ /**
78
+ * Find the index of the first line of the trailer block in `lines`, or
79
+ * `lines.length` when there is none. `lines` holds entry content with the
80
+ * list-item indent removed. The parser and `markspec fmt` both call this
81
+ * function, so they always agree on which lines are attributes.
82
+ *
83
+ * Every trailer line is a `Key: Value` line or a continuation line: a
84
+ * whitespace-led line below a line that ends with `\` or `,`. The attribute
85
+ * parser reads one attribute per line and cannot read a continuation line,
86
+ * so the parser reports it as MSL-P021 and `markspec fmt` leaves such a
87
+ * trailer unchanged. Keeping it in the trailer means no layout makes the
88
+ * entry lose its `Id:` or an attribute. A line of any other shape ends the
89
+ * trailer.
90
+ *
91
+ * Three shapes are trailers:
92
+ *
93
+ * - The indented run (canonical): the trailing `Key: Value` lines that are
94
+ * each indented by 4 or more columns. This is accepted with or without a
95
+ * blank line above it, as before #916.
96
+ * - The trailer paragraph: the trailing `Key: Value` lines, indented or not,
97
+ * that start the content or follow an empty line, when they hold an `Id:`
98
+ * line or use only keys in {@linkcode RECOGNIZED_TRAILER_KEYS} (#916, rule
99
+ * of #914).
100
+ * - The Id run under prose: trailing `Key: Value` lines directly under a
101
+ * prose line, with no blank line between, that hold an `Id:` line on any
102
+ * of their lines, indented or not.
103
+ * The `Id:` line shows that the author meant a trailer; reading it as
104
+ * prose would make `markspec fmt` stamp a new Id.
105
+ * {@linkcode isTrailerUnderProse} reports this shape.
106
+ *
107
+ * Any other trailing `Key: value` line is body prose.
108
+ */
109
+ export declare function findTrailerStart(lines: readonly string[]): number;
110
+ /**
111
+ * `true` when the trailer of `lines` is an Id run directly under prose
112
+ * (no blank line before it, no indentation). The parser reports it as
113
+ * MSL-P020 (warning); `markspec fmt` moves it to the canonical layout.
114
+ */
115
+ export declare function isTrailerUnderProse(lines: readonly string[]): boolean;
37
116
  /**
38
117
  * Split raw entry content into body text and attribute lines.
39
118
  *
40
- * Attributes are `Key: Value` lines at the **end** of the entry content,
41
- * forming a contiguous block. A `Key: Value` line in the middle of body
42
- * prose is NOT treated as an attribute — only the trailing block counts.
119
+ * The trailer block is located by {@linkcode findTrailerStart}. A
120
+ * `Key: Value` line anywhere else, including a trailing one that does not
121
+ * meet that rule, stays body text.
43
122
  *
44
123
  * @param content - Raw text content of an entry (after title line, indentation stripped)
45
124
  * @returns Tuple of [body, attributeLines]
@@ -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;AAalE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,CAgBrE;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,QAA6B,CAAC;AAEvD;;;;;;;;;;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"}
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;AAMlE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAMtD,CAAC;AAYH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,GACX;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAI5C;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,CAWrE;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,QAA6B,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,eAAe,CA8BjB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQnD;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAErE;AAwFD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,GACd,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAcpB"}
@@ -6,6 +6,33 @@
6
6
  * trailing attribute blocks from body prose.
7
7
  */
8
8
  import { attributeSpec, CSV_SPLITTABLE_TYPES } from "../model/attributes.js";
9
+ import { splitTraceValues } from "../refs/split.js";
10
+ import { UNIVERSAL_ATTRIBUTE_KEYS } from "../model/attributes.js";
11
+ import { CORE_RELATIONS, LOCK_EXTRA_INVERSE_KEYS } from "../model/relations.js";
12
+ /**
13
+ * Canonical set of trailer attribute keys the core recognizes: the union of
14
+ * every authored universal attribute, every core trace relation, and the
15
+ * extra inverse lock key (`Verified-by`). Universal keys with
16
+ * `origin: "generated"` (`Contains`, `Caused`, ...) are left out: the compiler
17
+ * computes them and authors never write them (#706).
18
+ *
19
+ * Two uses:
20
+ *
21
+ * - Trailer detection: an unindented final paragraph without an `Id:` line
22
+ * is a trailer only when every key is in this set
23
+ * ({@linkcode findTrailerStart}, #916).
24
+ * - The MSL-P022 typo check: a malformed key that is a typo of a key in
25
+ * this set still raises MSL-P022 (#697).
26
+ *
27
+ * MSL-P020 on body prose uses only `Id` and the trace-relation keys of this
28
+ * set; any other `Word:` lead-in (`Rationale:`, `Note:`) is prose (#654,
29
+ * #916).
30
+ */
31
+ export const RECOGNIZED_TRAILER_KEYS = new Set([
32
+ ...UNIVERSAL_ATTRIBUTE_KEYS.filter((key) => attributeSpec(key)?.origin !== "generated"),
33
+ ...CORE_RELATIONS.map((r) => r.attr),
34
+ ...LOCK_EXTRA_INVERSE_KEYS,
35
+ ]);
9
36
  /**
10
37
  * Pattern matching a `Key: Value` attribute line.
11
38
  * Key must start with an uppercase letter, may contain lowercase letters and hyphens.
@@ -15,6 +42,20 @@ import { attributeSpec, CSV_SPLITTABLE_TYPES } from "../model/attributes.js";
15
42
  * silently ignored.
16
43
  */
17
44
  const ATTRIBUTE_RE = /^([A-Z][A-Za-z-]*):\s*(.*?)\\?$/;
45
+ /**
46
+ * Parse one attribute line: the line is trimmed, one trailing continuation
47
+ * backslash is dropped, and the value is trimmed. The value is empty for
48
+ * `Key:` and `Key: \`. Returns `undefined` when the line is not a
49
+ * `Key:` line. {@linkcode parseAttributes} reads lines through this
50
+ * function, and so do the Markdown A011, A012 and A013 quick fixes of the
51
+ * LSP, so they agree with the parser.
52
+ */
53
+ export function parseAttributeLine(line) {
54
+ const match = ATTRIBUTE_RE.exec(line.trim());
55
+ if (!match)
56
+ return undefined;
57
+ return { key: match[1], value: (match[2] ?? "").trim() };
58
+ }
18
59
  /**
19
60
  * Parse an array of attribute lines into Attribute objects.
20
61
  *
@@ -28,16 +69,12 @@ const ATTRIBUTE_RE = /^([A-Z][A-Za-z-]*):\s*(.*?)\\?$/;
28
69
  export function parseAttributes(lines) {
29
70
  const attributes = [];
30
71
  for (const line of lines) {
31
- const trimmed = line.trim();
32
- if (!trimmed)
72
+ const parsed = parseAttributeLine(line);
73
+ if (!parsed)
33
74
  continue;
34
- const match = ATTRIBUTE_RE.exec(trimmed);
35
- if (match) {
36
- const value = (match[2] ?? "").trim();
37
- if (!value)
38
- continue; // skip empty-value lines — `Key:` or `Key: \`
39
- attributes.push({ key: match[1], value });
40
- }
75
+ if (!parsed.value)
76
+ continue; // skip empty-value lines — `Key:` or `Key: \`
77
+ attributes.push(parsed);
41
78
  }
42
79
  return attributes;
43
80
  }
@@ -64,7 +101,8 @@ export function collateAttributes(attributes) {
64
101
  const type = spec?.type;
65
102
  let values;
66
103
  if (type && CSV_SPLITTABLE_TYPES.has(type) && attr.value.includes(",")) {
67
- values = attr.value
104
+ // An id-list value keeps commas inside a bracket locator (#915).
105
+ values = type === "id-list" ? splitTraceValues(attr.value) : attr.value
68
106
  .split(",")
69
107
  .map((s) => s.trim())
70
108
  .filter((s) => s.length > 0);
@@ -84,36 +122,165 @@ export function collateAttributes(attributes) {
84
122
  return new Map(Array.from(map, ([key, values]) => [key, Object.freeze([...values])]));
85
123
  }
86
124
  /**
87
- * Split raw entry content into body text and attribute lines.
125
+ * Width of the leading whitespace of `line` in columns, with a tab moving
126
+ * to the next multiple of 4. CommonMark uses the same tab stop, so a line
127
+ * that mixes spaces and tabs is measured as the code-block rule sees it.
128
+ */
129
+ export function leadingColumns(line) {
130
+ let column = 0;
131
+ for (const ch of line) {
132
+ if (ch === " ")
133
+ column++;
134
+ else if (ch === "\t")
135
+ column += 4 - (column % 4);
136
+ else
137
+ break;
138
+ }
139
+ return column;
140
+ }
141
+ /** `true` when `line` is indented by 4 or more columns (code-block indent). */
142
+ export function isIndented(line) {
143
+ return leadingColumns(line) >= 4;
144
+ }
145
+ /** The key of a `Key: Value` line, or `undefined` for any other line. */
146
+ function trailerKey(line) {
147
+ const trimmed = line.trim();
148
+ return ATTR_LINE_RE.test(trimmed)
149
+ ? /^([A-Z][A-Za-z-]*):/.exec(trimmed)?.[1]
150
+ : undefined;
151
+ }
152
+ /**
153
+ * Find the index of the first line of the trailer block in `lines`, or
154
+ * `lines.length` when there is none. `lines` holds entry content with the
155
+ * list-item indent removed. The parser and `markspec fmt` both call this
156
+ * function, so they always agree on which lines are attributes.
88
157
  *
89
- * Attributes are `Key: Value` lines at the **end** of the entry content,
90
- * forming a contiguous block. A `Key: Value` line in the middle of body
91
- * prose is NOT treated as an attribute — only the trailing block counts.
158
+ * Every trailer line is a `Key: Value` line or a continuation line: a
159
+ * whitespace-led line below a line that ends with `\` or `,`. The attribute
160
+ * parser reads one attribute per line and cannot read a continuation line,
161
+ * so the parser reports it as MSL-P021 and `markspec fmt` leaves such a
162
+ * trailer unchanged. Keeping it in the trailer means no layout makes the
163
+ * entry lose its `Id:` or an attribute. A line of any other shape ends the
164
+ * trailer.
92
165
  *
93
- * @param content - Raw text content of an entry (after title line, indentation stripped)
94
- * @returns Tuple of [body, attributeLines]
166
+ * Three shapes are trailers:
167
+ *
168
+ * - The indented run (canonical): the trailing `Key: Value` lines that are
169
+ * each indented by 4 or more columns. This is accepted with or without a
170
+ * blank line above it, as before #916.
171
+ * - The trailer paragraph: the trailing `Key: Value` lines, indented or not,
172
+ * that start the content or follow an empty line, when they hold an `Id:`
173
+ * line or use only keys in {@linkcode RECOGNIZED_TRAILER_KEYS} (#916, rule
174
+ * of #914).
175
+ * - The Id run under prose: trailing `Key: Value` lines directly under a
176
+ * prose line, with no blank line between, that hold an `Id:` line on any
177
+ * of their lines, indented or not.
178
+ * The `Id:` line shows that the author meant a trailer; reading it as
179
+ * prose would make `markspec fmt` stamp a new Id.
180
+ * {@linkcode isTrailerUnderProse} reports this shape.
181
+ *
182
+ * Any other trailing `Key: value` line is body prose.
95
183
  */
96
- export function splitBodyAndAttributes(content) {
97
- const lines = content.split("\n");
98
- // Walk backwards to find the contiguous trailing attribute block
99
- let attrStart = lines.length;
100
- for (let i = lines.length - 1; i >= 0; i--) {
101
- const trimmed = lines[i].trim();
102
- if (trimmed === "") {
103
- // Empty line: if we haven't started collecting attributes, skip.
104
- // If we have attributes below, this blank line is the boundary.
105
- if (attrStart < lines.length)
106
- break;
107
- continue;
184
+ export function findTrailerStart(lines) {
185
+ return locateTrailer(lines).start;
186
+ }
187
+ /**
188
+ * `true` when the trailer of `lines` is an Id run directly under prose
189
+ * (no blank line before it, no indentation). The parser reports it as
190
+ * MSL-P020 (warning); `markspec fmt` moves it to the canonical layout.
191
+ */
192
+ export function isTrailerUnderProse(lines) {
193
+ return locateTrailer(lines).underProse;
194
+ }
195
+ function locateTrailer(lines) {
196
+ let end = lines.length;
197
+ while (end > 0 && lines[end - 1].trim() === "")
198
+ end--;
199
+ // The trailing run of `Key: Value` lines and continuation lines.
200
+ const continuation = [];
201
+ let blockStart = end;
202
+ while (blockStart > 0) {
203
+ const i = blockStart - 1;
204
+ if (trailerKey(lines[i]) !== undefined) {
205
+ continuation[i] = false;
108
206
  }
109
- if (ATTR_LINE_RE.test(trimmed)) {
110
- attrStart = i;
207
+ else if (isContinuation(lines, i)) {
208
+ continuation[i] = true;
111
209
  }
112
- else {
113
- // Non-attribute, non-empty line — stop scanning
210
+ else
114
211
  break;
212
+ blockStart--;
213
+ }
214
+ // The indented run: indented `Key: Value` lines and their continuations.
215
+ let indentedStart = end;
216
+ while (indentedStart > blockStart &&
217
+ (continuation[indentedStart - 1] || isIndented(lines[indentedStart - 1])))
218
+ indentedStart--;
219
+ while (indentedStart < end && continuation[indentedStart])
220
+ indentedStart++;
221
+ // Unindented `Key: Value` lines (and continuations) directly above it.
222
+ let runStart = indentedStart;
223
+ while (runStart > blockStart &&
224
+ (continuation[runStart - 1] || !isIndented(lines[runStart - 1])))
225
+ runStart--;
226
+ while (runStart < indentedStart && continuation[runStart])
227
+ runStart++;
228
+ const keysOf = (from, to) => lines.slice(from, to).map((l) => trailerKey(l)).filter((k) => k !== undefined);
229
+ if (runStart < indentedStart) {
230
+ const ownParagraph = runStart === 0 || lines[runStart - 1].trim() === "";
231
+ const keys = keysOf(runStart, end);
232
+ if (ownParagraph &&
233
+ (keys.includes("Id") ||
234
+ keys.every((k) => RECOGNIZED_TRAILER_KEYS.has(k)))) {
235
+ return { start: runStart, underProse: false };
236
+ }
237
+ if (!ownParagraph && keysOf(runStart, indentedStart).includes("Id")) {
238
+ return { start: runStart, underProse: true };
115
239
  }
116
240
  }
241
+ // Any other trailing run that holds an `Id:` line is the trailer too,
242
+ // whatever its indentation: reading it as body would make `markspec fmt`
243
+ // stamp a replacement Id.
244
+ let idRunStart = blockStart;
245
+ while (idRunStart < end && continuation[idRunStart])
246
+ idRunStart++;
247
+ if (idRunStart < (indentedStart < end ? indentedStart : end) &&
248
+ keysOf(idRunStart, end).includes("Id")) {
249
+ const ownParagraph = idRunStart === 0 ||
250
+ lines[idRunStart - 1].trim() === "";
251
+ return { start: idRunStart, underProse: !ownParagraph };
252
+ }
253
+ return {
254
+ start: indentedStart < end ? indentedStart : lines.length,
255
+ underProse: false,
256
+ };
257
+ }
258
+ /**
259
+ * `true` when `lines[i]` continues the value of the line above it: it
260
+ * starts with whitespace, and the line above ends with `\` or `,`. The
261
+ * attribute parser cannot read such a line, so the parser reports it as
262
+ * MSL-P021 and `markspec fmt` leaves the trailer as it is. Keeping it in
263
+ * the trailer keeps the trailer's `Id:` and attributes.
264
+ */
265
+ function isContinuation(lines, i) {
266
+ if (i === 0 || !/^\s/.test(lines[i]) || lines[i].trim() === "") {
267
+ return false;
268
+ }
269
+ return /[\\,]$/.test(lines[i - 1].trimEnd());
270
+ }
271
+ /**
272
+ * Split raw entry content into body text and attribute lines.
273
+ *
274
+ * The trailer block is located by {@linkcode findTrailerStart}. A
275
+ * `Key: Value` line anywhere else, including a trailing one that does not
276
+ * meet that rule, stays body text.
277
+ *
278
+ * @param content - Raw text content of an entry (after title line, indentation stripped)
279
+ * @returns Tuple of [body, attributeLines]
280
+ */
281
+ export function splitBodyAndAttributes(content) {
282
+ const lines = content.split("\n");
283
+ const attrStart = findTrailerStart(lines);
117
284
  const bodyLines = lines.slice(0, attrStart);
118
285
  const attrLines = lines.slice(attrStart);
119
286
  // Trim trailing empty lines from body
@@ -5,7 +5,7 @@
5
5
  * the six BodyTokenKind variants, skipping verbatim regions (code, math,
6
6
  * inline-code spans). Inside ` ```feature ` / ` ```gherkin ` fences the
7
7
  * modal/EARS/entity-ref scanners are suppressed and the gherkin
8
- * section/step scanners run instead.
8
+ * section/step tokens come from the normalized Gherkin AST instead.
9
9
  *
10
10
  * Single source of truth for inline-construct extraction. Replaces the
11
11
  * pre-ADR-016 marker mechanism (`InlineContent.markers`) and the
@@ -1 +1 @@
1
- {"version":3,"file":"body_tokens.d.ts","sourceRoot":"","sources":["../../src/parser/body_tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,SAAS,EAET,cAAc,EACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,cAAc,CAAC;AA+JtD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,YAAY,EAAE,cAAc,EAC5B,YAAY,SAAI,EAChB,SAAS,CAAC,EAAE,IAAI,GACf,SAAS,SAAS,EAAE,CAsEtB"}
1
+ {"version":3,"file":"body_tokens.d.ts","sourceRoot":"","sources":["../../src/parser/body_tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,SAAS,EAET,cAAc,EACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,cAAc,CAAC;AAyKtD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,YAAY,EAAE,cAAc,EAC5B,YAAY,SAAI,EAChB,SAAS,CAAC,EAAE,IAAI,GACf,SAAS,SAAS,EAAE,CAsEtB"}
@@ -5,7 +5,7 @@
5
5
  * the six BodyTokenKind variants, skipping verbatim regions (code, math,
6
6
  * inline-code spans). Inside ` ```feature ` / ` ```gherkin ` fences the
7
7
  * modal/EARS/entity-ref scanners are suppressed and the gherkin
8
- * section/step scanners run instead.
8
+ * section/step tokens come from the normalized Gherkin AST instead.
9
9
  *
10
10
  * Single source of truth for inline-construct extraction. Replaces the
11
11
  * pre-ADR-016 marker mechanism (`InlineContent.markers`) and the
@@ -39,10 +39,6 @@ const MODAL_RE = /\b(shall not|should not|must not|shall|should|may|must|will)\b
39
39
  const EARS_RE = /\b(When|While|If|Where|Then)\b/g;
40
40
  /** `$Identifier` entity reference (spec §2.5.2). */
41
41
  const ENTITY_REF_RE = /\$([A-Za-z][A-Za-z0-9_]*)/g;
42
- /** Gherkin section headers — class-like tokens. */
43
- const GHERKIN_SECTION_RE = /\b(Feature|Background|Rule|Scenario Outline|Scenario Template|Scenarios|Examples|Scenario)\b/g;
44
- /** Gherkin step keywords. */
45
- const GHERKIN_STEP_RE = /\b(Given|When|Then|And|But)\b/g;
46
42
  /**
47
43
  * Collect body-relative 1-based line numbers that fall inside verbatim
48
44
  * blocks: fenced code, fenced feature, math. Lines in this set are
@@ -70,43 +66,61 @@ function collectVerbatimLines(blocks) {
70
66
  return lines;
71
67
  }
72
68
  /**
73
- * Walk `bodyAst` for `feature` nodes. For each, scan its source text for
74
- * Gherkin section + step keywords. Positions are body-relative based on
75
- * the node's `range.start.line`.
69
+ * Walk `bodyAst` for `feature` nodes and emit one token per Gherkin
70
+ * structural keyword and per step keyword, taken from the normalized AST
71
+ * (ADR-016). Token text is the keyword as authored, so a block written in
72
+ * another language (`# language: fr`) yields `Scénario` and `Soit`. A
73
+ * keyword inside step text, a description, or a doc string is not a
74
+ * keyword in the AST and gives no token.
75
+ *
76
+ * Determinism rule: a node emits Gherkin tokens only when it carries a
77
+ * `feature` AST. A node with a `parseError`, or with neither field (the
78
+ * parser was not loaded when the node was built), emits none. Only the
79
+ * Gherkin tokens depend on the parser; modal, EARS, entity-ref and
80
+ * inline-code tokens never do. Gherkin tokens are read only by LSP
81
+ * semantic tokens, which receive entries from `parseFile`; that path loads
82
+ * the parser before it builds any entry that holds a gherkin or feature
83
+ * fence, unless the parser import failed; then no node has a `feature`
84
+ * and no Gherkin tokens are emitted.
85
+ *
86
+ * Positions are file-relative like the other tokens: the line is the
87
+ * node's body-relative start plus the AST line, and the column adds
88
+ * `columnOffset` (list-item indent or doc-comment prefix width).
89
+ * Background steps come from `FeatureAst.backgrounds`, so each is emitted
90
+ * once at its own position, also when the block has no scenario.
76
91
  */
77
92
  function emitGherkin(blocks, out, baseLocation, columnOffset) {
78
93
  for (const block of blocks) {
79
94
  if (block.kind === "feature") {
95
+ const feature = block.feature;
96
+ if (!feature)
97
+ continue;
80
98
  const startLine = block.range.start.line;
81
- const lines = block.source.split("\n");
82
- for (let li = 0; li < lines.length; li++) {
83
- const line = lines[li];
84
- // Body-relative line; feature fence's opening ``` line is at startLine,
85
- // content begins at startLine + 1.
86
- const lineNo = baseLocation.line + (startLine - 1) + (li + 1);
87
- let m;
88
- GHERKIN_SECTION_RE.lastIndex = 0;
89
- while ((m = GHERKIN_SECTION_RE.exec(line)) !== null) {
90
- out.push({
91
- kind: "gherkin-section",
92
- text: m[1],
93
- location: {
94
- file: baseLocation.file,
95
- line: lineNo,
96
- column: m.index + 1 + columnOffset,
97
- },
98
- });
99
- }
100
- GHERKIN_STEP_RE.lastIndex = 0;
101
- while ((m = GHERKIN_STEP_RE.exec(line)) !== null) {
99
+ const at = (range) => ({
100
+ file: baseLocation.file,
101
+ line: baseLocation.line + (startLine - 1) + range.start.line,
102
+ column: range.start.column + columnOffset,
103
+ });
104
+ for (const section of feature.sections) {
105
+ out.push({
106
+ kind: "gherkin-section",
107
+ text: section.keyword,
108
+ location: at(section.range),
109
+ });
110
+ }
111
+ for (const step of feature.backgrounds) {
112
+ out.push({
113
+ kind: "gherkin-step",
114
+ text: step.keyword,
115
+ location: at(step.range),
116
+ });
117
+ }
118
+ for (const scenario of feature.scenarios) {
119
+ for (const step of scenario.steps) {
102
120
  out.push({
103
121
  kind: "gherkin-step",
104
- text: m[1],
105
- location: {
106
- file: baseLocation.file,
107
- line: lineNo,
108
- column: m.index + 1 + columnOffset,
109
- },
122
+ text: step.keyword,
123
+ location: at(step.range),
110
124
  });
111
125
  }
112
126
  }