@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.
- 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/config/markspec.d.ts +2 -2
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +47 -5
- 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/discovery/projects.d.ts +6 -4
- package/esm/discovery/projects.d.ts.map +1 -1
- package/esm/discovery/projects.js +27 -17
- package/esm/formatter/entry_body.d.ts +13 -12
- package/esm/formatter/entry_body.d.ts.map +1 -1
- package/esm/formatter/entry_body.js +25 -17
- 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/md_equiv.d.ts +6 -5
- package/esm/formatter/md_equiv.d.ts.map +1 -1
- package/esm/formatter/md_equiv.js +6 -5
- package/esm/formatter/mod.d.ts +25 -3
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +267 -27
- package/esm/formatter/tab_markers.d.ts +15 -0
- package/esm/formatter/tab_markers.d.ts.map +1 -0
- package/esm/formatter/tab_markers.js +133 -0
- package/esm/gates/mod.d.ts +2 -2
- package/esm/gates/mod.d.ts.map +1 -1
- package/esm/gates/mod.js +18 -3
- 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/lock/upstream_deps.js +1 -1
- package/esm/mod.d.ts +24 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +19 -5
- package/esm/model/mod.d.ts +43 -2
- 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 +8 -3
- package/esm/refs/mod.d.ts.map +1 -1
- package/esm/refs/mod.js +20 -7
- 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/sync/mapping.d.ts +4 -3
- package/esm/sync/mapping.d.ts.map +1 -1
- package/esm/sync/mapping.js +52 -9
- package/esm/util/display_id.d.ts +20 -0
- package/esm/util/display_id.d.ts.map +1 -0
- package/esm/util/display_id.js +19 -0
- 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 +10 -16
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +37 -16
- 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/config/markspec.d.ts +2 -2
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +47 -5
- 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/discovery/projects.d.ts +6 -4
- package/script/discovery/projects.d.ts.map +1 -1
- package/script/discovery/projects.js +27 -17
- package/script/formatter/entry_body.d.ts +13 -12
- package/script/formatter/entry_body.d.ts.map +1 -1
- package/script/formatter/entry_body.js +25 -17
- 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/md_equiv.d.ts +6 -5
- package/script/formatter/md_equiv.d.ts.map +1 -1
- package/script/formatter/md_equiv.js +6 -5
- package/script/formatter/mod.d.ts +25 -3
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +266 -26
- package/script/formatter/tab_markers.d.ts +15 -0
- package/script/formatter/tab_markers.d.ts.map +1 -0
- package/script/formatter/tab_markers.js +141 -0
- package/script/gates/mod.d.ts +2 -2
- package/script/gates/mod.d.ts.map +1 -1
- package/script/gates/mod.js +18 -3
- 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/lock/upstream_deps.js +1 -1
- package/script/mod.d.ts +24 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +48 -6
- package/script/model/mod.d.ts +43 -2
- 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 +8 -3
- package/script/refs/mod.d.ts.map +1 -1
- package/script/refs/mod.js +20 -7
- 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/sync/mapping.d.ts +4 -3
- package/script/sync/mapping.d.ts.map +1 -1
- package/script/sync/mapping.js +52 -9
- package/script/util/display_id.d.ts +20 -0
- package/script/util/display_id.d.ts.map +1 -0
- package/script/util/display_id.js +22 -0
- 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 +10 -16
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +36 -16
- 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
|
@@ -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"}
|
package/esm/parser/attributes.js
CHANGED
|
@@ -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
|
|
32
|
-
if (!
|
|
72
|
+
const parsed = parseAttributeLine(line);
|
|
73
|
+
if (!parsed)
|
|
33
74
|
continue;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
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
|
-
*
|
|
94
|
-
*
|
|
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
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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 (
|
|
110
|
-
|
|
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
|
|
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"}
|
|
@@ -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
|
|
@@ -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
|
|
74
|
-
*
|
|
75
|
-
* the
|
|
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
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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:
|
|
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
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/parser/feature_file
|
|
3
|
+
*
|
|
4
|
+
* Reads `.feature` files as MarkSpec sources. A header is a run of comment
|
|
5
|
+
* lines that starts with `# [ID] Title` and sits directly above a Gherkin
|
|
6
|
+
* node, optionally with tag lines in between.
|
|
7
|
+
*/
|
|
8
|
+
import type { GherkinDocument } from "@cucumber/messages";
|
|
9
|
+
import type { Diagnostic, Entry } from "../model/mod.js";
|
|
10
|
+
import type { GherkinApi } from "../gherkin/load.js";
|
|
11
|
+
/** The kind of Gherkin node a header sits above. */
|
|
12
|
+
export type FeatureNodeKind = "feature" | "rule" | "background" | "scenario" | "examples" | "step";
|
|
13
|
+
/** One header comment block of a `.feature` file. */
|
|
14
|
+
export interface FeatureHeader {
|
|
15
|
+
/**
|
|
16
|
+
* The kind of node the header sits above, or `undefined` when it is not
|
|
17
|
+
* directly above a node (an orphan header).
|
|
18
|
+
*/
|
|
19
|
+
readonly kind: FeatureNodeKind | undefined;
|
|
20
|
+
/** 1-based file line of the first comment line. */
|
|
21
|
+
readonly startLine: number;
|
|
22
|
+
/** 1-based file line of the last comment line. */
|
|
23
|
+
readonly endLine: number;
|
|
24
|
+
/** 1-based column of the `#` on the first comment line. */
|
|
25
|
+
readonly column: number;
|
|
26
|
+
/** Comment lines without the `#`: the first line also loses every space
|
|
27
|
+
* after it, each later line at most one space. */
|
|
28
|
+
readonly lines: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* For each line, the number of characters from the line start up to and
|
|
31
|
+
* including the removed `#` and spaces. File column = width + offset + 1.
|
|
32
|
+
*/
|
|
33
|
+
readonly prefixWidths: readonly number[];
|
|
34
|
+
}
|
|
35
|
+
/** A header-start comment text: `[ID] ` after the `#`. */
|
|
36
|
+
export declare const FEATURE_HEADER_START_RE: RegExp;
|
|
37
|
+
/**
|
|
38
|
+
* Exclusive end index of the header comment run that starts at `titleIdx`.
|
|
39
|
+
*
|
|
40
|
+
* The run is the consecutive comment lines (`^\s*#`) from `titleIdx` down.
|
|
41
|
+
* It stops before a non-comment line, before the next header start (comment
|
|
42
|
+
* text starting with `[ID] `), and before a `# language:` line.
|
|
43
|
+
*
|
|
44
|
+
* @param lines - The file lines, without line endings.
|
|
45
|
+
* @param titleIdx - Zero-based index of the header's first line.
|
|
46
|
+
*/
|
|
47
|
+
export declare function featureHeaderRunEnd(lines: readonly string[], titleIdx: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* Find the header comment blocks of a parsed `.feature` file.
|
|
50
|
+
*
|
|
51
|
+
* A comment line whose text starts with `[ID] ` starts a new header, so
|
|
52
|
+
* stacked headers are separate. The result is keyed by the file line of the
|
|
53
|
+
* node keyword that a header sits above. A header that is not directly above
|
|
54
|
+
* a node (only tag lines and plain comments may stand between; a blank line,
|
|
55
|
+
* another header or any other line breaks the link) has `kind: undefined`
|
|
56
|
+
* and is keyed by its own first line, so a caller can report it. The two
|
|
57
|
+
* kinds of key never collide, because a node line is not a comment line.
|
|
58
|
+
*
|
|
59
|
+
* @param document - The parsed Gherkin document of `text`.
|
|
60
|
+
* @param text - The file text. Line endings may be LF or CRLF.
|
|
61
|
+
*/
|
|
62
|
+
export declare function findHeaders(document: GherkinDocument, text: string): Map<number, FeatureHeader>;
|
|
63
|
+
/**
|
|
64
|
+
* Turn one header into an entry whose positions are file-relative.
|
|
65
|
+
*
|
|
66
|
+
* The header lines are wrapped as a Markdown list item and parsed like a
|
|
67
|
+
* source doc comment. A trailer in git style (no indent) is canonical in a
|
|
68
|
+
* `.feature` header, so the Markdown-only MSL-P023 warning is dropped. An
|
|
69
|
+
* empty body is not an error here: the node description can supply it.
|
|
70
|
+
* A header that is only a title still gives an entry, with an empty body
|
|
71
|
+
* (`allowTitleOnly`).
|
|
72
|
+
* The result has no entry when the header text does not form one.
|
|
73
|
+
*
|
|
74
|
+
* @param header - A header found by {@linkcode findHeaders}.
|
|
75
|
+
* @param file - File path used in locations.
|
|
76
|
+
*/
|
|
77
|
+
export declare function headerEntry(header: FeatureHeader, file: string): {
|
|
78
|
+
entry?: Entry;
|
|
79
|
+
diagnostics: Diagnostic[];
|
|
80
|
+
};
|
|
81
|
+
/** `true` when the text has a `# [ID]` header line (an entry candidate). */
|
|
82
|
+
export declare function hasFeatureHeaderLine(text: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Read the entries of a `.feature` file (epic #915 Case B).
|
|
85
|
+
*
|
|
86
|
+
* A `Feature`, `Rule` or `Scenario` with a `# [ID] Title` header comment is
|
|
87
|
+
* an entry. A scenario without a header belongs to the nearest enclosing
|
|
88
|
+
* headed `Rule`, else the headed `Feature`; with no headed ancestor it is not
|
|
89
|
+
* in the model. Each entry gets one `FeatureNode`: its `source` is the text
|
|
90
|
+
* of the owning node's span (first tag or keyword line to its last content
|
|
91
|
+
* line), its `feature` is the projected AST with ranges rebased to that
|
|
92
|
+
* span, and its `range` is set so `featureFileLine` returns file lines.
|
|
93
|
+
* The Gherkin description of the node is appended to the body after the
|
|
94
|
+
* header prose. Tags are not labels.
|
|
95
|
+
*
|
|
96
|
+
* Diagnostics: the header parse diagnostics; `MSL-P030` when an entry has
|
|
97
|
+
* neither header prose nor a description and no content (a Scenario entry
|
|
98
|
+
* whose scenario has no step, or a Feature or Rule entry that owns no
|
|
99
|
+
* scenario), at the `#` of the header line; `MSL-B069` (warning) for a header
|
|
100
|
+
* above a Background, Examples or step, or above no node. When the file does
|
|
101
|
+
* not parse, there are no entries and one `MSL-B062` warning at the parser
|
|
102
|
+
* position, but only when the file has a header line, so a plain Cucumber
|
|
103
|
+
* file never gets a new diagnostic.
|
|
104
|
+
*
|
|
105
|
+
* @param text - The file text (LF or CRLF).
|
|
106
|
+
* @param options.file - File path used in locations.
|
|
107
|
+
* @param options.api - The loaded Gherkin parser.
|
|
108
|
+
*/
|
|
109
|
+
export declare function parseFeatureFile(text: string, options: {
|
|
110
|
+
readonly file: string;
|
|
111
|
+
readonly api: GherkinApi;
|
|
112
|
+
}): {
|
|
113
|
+
entries: Entry[];
|
|
114
|
+
diagnostics: Diagnostic[];
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=feature_file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature_file.d.ts","sourceRoot":"","sources":["../../src/parser/feature_file.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAEV,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAOrD,oDAAoD;AACpD,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,MAAM,GACN,YAAY,GACZ,UAAU,GACV,UAAU,GACV,MAAM,CAAC;AAEX,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC;IAC3C,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;sDACkD;IAClD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAcD,0DAA0D;AAC1D,eAAO,MAAM,uBAAuB,EAAE,MAErC,CAAC;AAGF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,GACf,MAAM,CAWR;AAoCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,MAAM,GACX,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAgF5B;AAUD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CAe9C;AAWD,4EAA4E;AAC5E,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAiBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAA;CAAE,GAC3D;IAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CAkPjD"}
|