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