@driftsys/markspec 0.2.0 → 0.3.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/README.md +32 -8
- package/esm/compiler/inverses.d.ts +22 -0
- package/esm/compiler/inverses.d.ts.map +1 -0
- package/esm/compiler/inverses.js +147 -0
- package/esm/compiler/link_target.d.ts +19 -0
- package/esm/compiler/link_target.d.ts.map +1 -0
- package/esm/compiler/link_target.js +66 -0
- package/esm/compiler/mod.d.ts +7 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +61 -14
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +20 -1
- package/esm/config/markspec.d.ts +51 -0
- package/esm/config/markspec.d.ts.map +1 -0
- package/esm/config/markspec.js +216 -0
- package/esm/config/mod.d.ts +4 -0
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +27 -16
- package/esm/formatter/mod.d.ts +12 -2
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +130 -22
- package/esm/mod.d.ts +10 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +5 -2
- package/esm/model/attributes.d.ts +47 -0
- package/esm/model/attributes.d.ts.map +1 -0
- package/esm/model/attributes.js +97 -0
- package/esm/model/mod.d.ts +255 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +27 -1
- package/esm/model/profile.d.ts +189 -0
- package/esm/model/profile.d.ts.map +1 -0
- package/esm/model/profile.js +31 -0
- package/esm/parser/attributes.d.ts +13 -1
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +47 -0
- package/esm/parser/frontmatter.d.ts +53 -0
- package/esm/parser/frontmatter.d.ts.map +1 -0
- package/esm/parser/frontmatter.js +185 -0
- package/esm/parser/grammars.js +11 -2
- package/esm/parser/markdown.d.ts +11 -4
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +85 -38
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +39 -9
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +20 -13
- package/esm/profile/cache.d.ts +29 -0
- package/esm/profile/cache.d.ts.map +1 -0
- package/esm/profile/cache.js +45 -0
- package/esm/profile/chain.d.ts +42 -0
- package/esm/profile/chain.d.ts.map +1 -0
- package/esm/profile/chain.js +193 -0
- package/esm/profile/git-cache.d.ts +73 -0
- package/esm/profile/git-cache.d.ts.map +1 -0
- package/esm/profile/git-cache.js +96 -0
- package/esm/profile/load.d.ts +28 -0
- package/esm/profile/load.d.ts.map +1 -0
- package/esm/profile/load.js +50 -0
- package/esm/profile/manifest.d.ts +21 -0
- package/esm/profile/manifest.d.ts.map +1 -0
- package/esm/profile/manifest.js +830 -0
- package/esm/profile/merge.d.ts +26 -0
- package/esm/profile/merge.d.ts.map +1 -0
- package/esm/profile/merge.js +518 -0
- package/esm/profile/mod.d.ts +23 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +14 -0
- package/esm/profile/npm.d.ts +51 -0
- package/esm/profile/npm.d.ts.map +1 -0
- package/esm/profile/npm.js +186 -0
- package/esm/profile/resolver.d.ts +60 -0
- package/esm/profile/resolver.d.ts.map +1 -0
- package/esm/profile/resolver.js +132 -0
- package/esm/reporter/mod.js +14 -27
- package/esm/validator/attributes.d.ts +43 -0
- package/esm/validator/attributes.d.ts.map +1 -0
- package/esm/validator/attributes.js +169 -0
- package/esm/validator/mod.d.ts +27 -6
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +132 -124
- package/esm/validator/normalize.d.ts +21 -0
- package/esm/validator/normalize.d.ts.map +1 -0
- package/esm/validator/normalize.js +58 -0
- package/esm/validator/pattern.d.ts +23 -0
- package/esm/validator/pattern.d.ts.map +1 -0
- package/esm/validator/pattern.js +44 -0
- package/esm/validator/pipeline.d.ts +30 -0
- package/esm/validator/pipeline.d.ts.map +1 -0
- package/esm/validator/pipeline.js +115 -0
- package/esm/validator/traceability.d.ts +48 -0
- package/esm/validator/traceability.d.ts.map +1 -0
- package/esm/validator/traceability.js +141 -0
- package/esm/validator/types.d.ts +48 -0
- package/esm/validator/types.d.ts.map +1 -0
- package/esm/validator/types.js +140 -0
- package/esm/validator/value_types.d.ts +20 -0
- package/esm/validator/value_types.d.ts.map +1 -0
- package/esm/validator/value_types.js +126 -0
- package/package.json +1 -1
- package/script/compiler/inverses.d.ts +22 -0
- package/script/compiler/inverses.d.ts.map +1 -0
- package/script/compiler/inverses.js +150 -0
- package/script/compiler/link_target.d.ts +19 -0
- package/script/compiler/link_target.d.ts.map +1 -0
- package/script/compiler/link_target.js +69 -0
- package/script/compiler/mod.d.ts +7 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +62 -14
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +20 -1
- package/script/config/markspec.d.ts +51 -0
- package/script/config/markspec.d.ts.map +1 -0
- package/script/config/markspec.js +222 -0
- package/script/config/mod.d.ts +4 -0
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +28 -16
- package/script/formatter/mod.d.ts +12 -2
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +131 -22
- package/script/mod.d.ts +10 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +48 -19
- package/script/model/attributes.d.ts +47 -0
- package/script/model/attributes.d.ts.map +1 -0
- package/script/model/attributes.js +101 -0
- package/script/model/mod.d.ts +255 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +34 -2
- package/script/model/profile.d.ts +189 -0
- package/script/model/profile.d.ts.map +1 -0
- package/script/model/profile.js +34 -0
- package/script/parser/attributes.d.ts +13 -1
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +48 -0
- package/script/parser/frontmatter.d.ts +53 -0
- package/script/parser/frontmatter.d.ts.map +1 -0
- package/script/parser/frontmatter.js +188 -0
- package/script/parser/grammars.js +11 -2
- package/script/parser/markdown.d.ts +11 -4
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +84 -37
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +41 -10
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +20 -13
- package/script/profile/cache.d.ts +29 -0
- package/script/profile/cache.d.ts.map +1 -0
- package/script/profile/cache.js +48 -0
- package/script/profile/chain.d.ts +42 -0
- package/script/profile/chain.d.ts.map +1 -0
- package/script/profile/chain.js +229 -0
- package/script/profile/git-cache.d.ts +73 -0
- package/script/profile/git-cache.d.ts.map +1 -0
- package/script/profile/git-cache.js +104 -0
- package/script/profile/load.d.ts +28 -0
- package/script/profile/load.d.ts.map +1 -0
- package/script/profile/load.js +53 -0
- package/script/profile/manifest.d.ts +21 -0
- package/script/profile/manifest.d.ts.map +1 -0
- package/script/profile/manifest.js +833 -0
- package/script/profile/merge.d.ts +26 -0
- package/script/profile/merge.d.ts.map +1 -0
- package/script/profile/merge.js +521 -0
- package/script/profile/mod.d.ts +23 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +31 -0
- package/script/profile/npm.d.ts +51 -0
- package/script/profile/npm.d.ts.map +1 -0
- package/script/profile/npm.js +191 -0
- package/script/profile/resolver.d.ts +60 -0
- package/script/profile/resolver.d.ts.map +1 -0
- package/script/profile/resolver.js +136 -0
- package/script/reporter/mod.js +14 -27
- package/script/validator/attributes.d.ts +43 -0
- package/script/validator/attributes.d.ts.map +1 -0
- package/script/validator/attributes.js +173 -0
- package/script/validator/mod.d.ts +27 -6
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +145 -123
- package/script/validator/normalize.d.ts +21 -0
- package/script/validator/normalize.d.ts.map +1 -0
- package/script/validator/normalize.js +61 -0
- package/script/validator/pattern.d.ts +23 -0
- package/script/validator/pattern.d.ts.map +1 -0
- package/script/validator/pattern.js +47 -0
- package/script/validator/pipeline.d.ts +30 -0
- package/script/validator/pipeline.d.ts.map +1 -0
- package/script/validator/pipeline.js +118 -0
- package/script/validator/traceability.d.ts +48 -0
- package/script/validator/traceability.d.ts.map +1 -0
- package/script/validator/traceability.js +146 -0
- package/script/validator/types.d.ts +48 -0
- package/script/validator/types.d.ts.map +1 -0
- package/script/validator/types.js +144 -0
- package/script/validator/value_types.d.ts +20 -0
- package/script/validator/value_types.d.ts.map +1 -0
- package/script/validator/value_types.js +129 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module model/profile
|
|
3
|
+
*
|
|
4
|
+
* Profile data model — TypeScript types that mirror ADR-008 §4 manifest
|
|
5
|
+
* schema. Used by the profile loader, merger, and validator.
|
|
6
|
+
*/
|
|
7
|
+
import type { EntryShape } from "./mod.js";
|
|
8
|
+
/** All 14 attribute value-type keywords recognized by the core. */
|
|
9
|
+
export declare const VALUE_TYPES: readonly ["id", "id-list", "uri", "url", "path", "path-or-id", "enum", "tag-list", "text", "citation", "external-id", "integer", "date", "boolean"];
|
|
10
|
+
export type ValueType = typeof VALUE_TYPES[number];
|
|
11
|
+
/** Types whose default cardinality is a list (`0..N`). */
|
|
12
|
+
export declare const LIST_VALUE_TYPES: ReadonlySet<ValueType>;
|
|
13
|
+
/** Count bounds `lower..upper` where upper = Infinity represents `N`. */
|
|
14
|
+
export interface Cardinality {
|
|
15
|
+
readonly lower: number;
|
|
16
|
+
readonly upper: number;
|
|
17
|
+
}
|
|
18
|
+
/** Inverse declaration for link attributes (`id` / `id-list`). */
|
|
19
|
+
export interface InverseDecl {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly category: string;
|
|
22
|
+
}
|
|
23
|
+
/** A single attribute declaration within a profile scope. */
|
|
24
|
+
export interface AttrDecl {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly type: ValueType;
|
|
27
|
+
readonly required: boolean;
|
|
28
|
+
readonly cardinality: Cardinality;
|
|
29
|
+
readonly values?: readonly string[];
|
|
30
|
+
readonly inverse?: InverseDecl;
|
|
31
|
+
}
|
|
32
|
+
/** Target matcher: either a type name or a shape matcher object. */
|
|
33
|
+
export type TargetMatcher = string | {
|
|
34
|
+
readonly shape: "identified" | "referenced";
|
|
35
|
+
};
|
|
36
|
+
/** Traceability rule declared on a shape or type scope. */
|
|
37
|
+
export interface TraceRule {
|
|
38
|
+
readonly target: readonly TargetMatcher[];
|
|
39
|
+
readonly cardinality?: Cardinality;
|
|
40
|
+
readonly required: boolean;
|
|
41
|
+
}
|
|
42
|
+
export type EnforcementMode = "off" | "warn" | "error";
|
|
43
|
+
export interface TypeDef {
|
|
44
|
+
readonly name: string;
|
|
45
|
+
readonly shape: EntryShape;
|
|
46
|
+
readonly displayIdPattern?: string;
|
|
47
|
+
readonly displayIdPatternEnforcement: EnforcementMode;
|
|
48
|
+
readonly required: readonly string[];
|
|
49
|
+
readonly attributes: readonly AttrDecl[];
|
|
50
|
+
readonly traceability: ReadonlyMap<string, TraceRule>;
|
|
51
|
+
/** Optional semantic color-role name (key into `ProfileManifest.colors`). */
|
|
52
|
+
readonly color?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface DocTypeDef {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly contains: readonly string[];
|
|
57
|
+
readonly description?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Specifier scheme identifying where a profile lives. */
|
|
60
|
+
export type ProfileSpecifier = {
|
|
61
|
+
readonly kind: "local";
|
|
62
|
+
readonly path: string;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "git";
|
|
65
|
+
readonly repo: string;
|
|
66
|
+
readonly subpath?: string;
|
|
67
|
+
readonly tag: string;
|
|
68
|
+
} | {
|
|
69
|
+
readonly kind: "npm";
|
|
70
|
+
readonly scope?: string;
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly range: string;
|
|
73
|
+
};
|
|
74
|
+
/** Parsed `markspec.yaml` content — the manifest authored in a profile. */
|
|
75
|
+
export interface ProfileManifest {
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly version: string;
|
|
78
|
+
readonly description?: string;
|
|
79
|
+
readonly license?: string;
|
|
80
|
+
readonly extends?: ProfileSpecifier;
|
|
81
|
+
readonly universalRequired: readonly string[];
|
|
82
|
+
readonly universalAttributes: readonly AttrDecl[];
|
|
83
|
+
readonly labels: readonly string[];
|
|
84
|
+
/**
|
|
85
|
+
* Semantic color-role bindings authored on this manifest.
|
|
86
|
+
* Maps a profile-author-chosen name (e.g. "primary") to a palette hue
|
|
87
|
+
* name (one of "blue", "cyan", "teal", "orange", "red", "purple", "grey").
|
|
88
|
+
* Empty when the manifest does not declare `profile.colors:`.
|
|
89
|
+
*/
|
|
90
|
+
readonly colors: ReadonlyMap<string, string>;
|
|
91
|
+
readonly identified: {
|
|
92
|
+
readonly required: readonly string[];
|
|
93
|
+
readonly attributes: readonly AttrDecl[];
|
|
94
|
+
readonly traceability: ReadonlyMap<string, TraceRule>;
|
|
95
|
+
};
|
|
96
|
+
readonly referenced: {
|
|
97
|
+
readonly required: readonly string[];
|
|
98
|
+
readonly attributes: readonly AttrDecl[];
|
|
99
|
+
};
|
|
100
|
+
readonly types: ReadonlyMap<string, TypeDef>;
|
|
101
|
+
readonly documents: {
|
|
102
|
+
readonly types: readonly DocTypeDef[];
|
|
103
|
+
readonly frontMatter: readonly AttrDecl[];
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A profile after it has been resolved and parsed. One tier of a
|
|
108
|
+
* {@linkcode ProfileChain}.
|
|
109
|
+
*
|
|
110
|
+
* `sourcePath` is the absolute path of the `markspec.yaml` the manifest was
|
|
111
|
+
* parsed from. `baseDir` is the directory containing that file — used as the
|
|
112
|
+
* context for resolving this profile's `extends:` (in Phase 3+).
|
|
113
|
+
*/
|
|
114
|
+
export interface LoadedProfile {
|
|
115
|
+
readonly id: string;
|
|
116
|
+
readonly version: string;
|
|
117
|
+
readonly specifier: ProfileSpecifier;
|
|
118
|
+
readonly manifest: ProfileManifest;
|
|
119
|
+
readonly sourcePath: string;
|
|
120
|
+
readonly baseDir: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The resolved profile chain for a project. A Phase 2 chain always contains
|
|
124
|
+
* exactly one tier (no `extends:` walking). Phase 3 introduces multi-tier
|
|
125
|
+
* chains ordered root-parent → leaf-child.
|
|
126
|
+
*/
|
|
127
|
+
export interface ProfileChain {
|
|
128
|
+
readonly tiers: readonly LoadedProfile[];
|
|
129
|
+
readonly effective: EffectiveProfile;
|
|
130
|
+
}
|
|
131
|
+
/** Identifier of the profile (tier) that contributed a value — `manifest.id`. */
|
|
132
|
+
export type ProfileId = string;
|
|
133
|
+
/** A single value annotated with the profile it originated from. */
|
|
134
|
+
export interface ProvenancedValue<T> {
|
|
135
|
+
readonly value: T;
|
|
136
|
+
readonly origin: ProfileId;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A map-valued entry: the current effective value, the tier that set it, and
|
|
140
|
+
* the ordered list of parent tiers whose values this entry narrowed or
|
|
141
|
+
* replaced. Used for fields where children can override parents (attributes,
|
|
142
|
+
* traceability rules, type definitions).
|
|
143
|
+
*/
|
|
144
|
+
export interface ProvenancedMapEntry<V> {
|
|
145
|
+
readonly value: V;
|
|
146
|
+
readonly origin: ProfileId;
|
|
147
|
+
readonly overrides?: readonly ProfileId[];
|
|
148
|
+
}
|
|
149
|
+
/** Map with per-entry provenance. Keys are always strings (attr/type/link names). */
|
|
150
|
+
export type ProvenancedMap<V> = ReadonlyMap<string, ProvenancedMapEntry<V>>;
|
|
151
|
+
/** Shape-scope rules after merging (identified or referenced). */
|
|
152
|
+
export interface EffectiveShapeScope {
|
|
153
|
+
readonly required: ProvenancedValue<readonly string[]>;
|
|
154
|
+
readonly attributes: ProvenancedMap<AttrDecl>;
|
|
155
|
+
/** Referenced scope's traceability is always empty (referenced entries don't originate links). */
|
|
156
|
+
readonly traceability: ProvenancedMap<TraceRule>;
|
|
157
|
+
}
|
|
158
|
+
/** Type-scope rules after merging. */
|
|
159
|
+
export interface EffectiveTypeDef {
|
|
160
|
+
readonly name: string;
|
|
161
|
+
/** Shape is frozen at the type's declaration — never changes across the chain. */
|
|
162
|
+
readonly shape: EntryShape;
|
|
163
|
+
readonly displayIdPattern: ProvenancedValue<string | undefined>;
|
|
164
|
+
readonly displayIdPatternEnforcement: ProvenancedValue<EnforcementMode>;
|
|
165
|
+
/** Resolved semantic color-role name, or `undefined` when unset. */
|
|
166
|
+
readonly color: ProvenancedValue<string | undefined>;
|
|
167
|
+
readonly required: ProvenancedValue<readonly string[]>;
|
|
168
|
+
readonly attributes: ProvenancedMap<AttrDecl>;
|
|
169
|
+
readonly traceability: ProvenancedMap<TraceRule>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The merged, validator-ready view of a profile chain. Every field carries
|
|
173
|
+
* per-rule provenance so a diagnostic can blame the right tier.
|
|
174
|
+
*/
|
|
175
|
+
export interface EffectiveProfile {
|
|
176
|
+
readonly required: ProvenancedValue<readonly string[]>;
|
|
177
|
+
readonly attributes: ProvenancedMap<AttrDecl>;
|
|
178
|
+
readonly labels: ProvenancedValue<readonly string[]>;
|
|
179
|
+
/** Semantic color-role bindings merged across the chain. */
|
|
180
|
+
readonly colors: ProvenancedMap<string>;
|
|
181
|
+
readonly identified: EffectiveShapeScope;
|
|
182
|
+
readonly referenced: EffectiveShapeScope;
|
|
183
|
+
readonly types: ProvenancedMap<EffectiveTypeDef>;
|
|
184
|
+
readonly documents: {
|
|
185
|
+
readonly types: ProvenancedMap<DocTypeDef>;
|
|
186
|
+
readonly frontMatter: ProvenancedMap<AttrDecl>;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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CAAC;KAChD,CAAC;CACH"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module model/profile
|
|
3
|
+
*
|
|
4
|
+
* Profile data model — TypeScript types that mirror ADR-008 §4 manifest
|
|
5
|
+
* schema. Used by the profile loader, merger, and validator.
|
|
6
|
+
*/
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Value types (ADR-002 Annex C)
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
/** All 14 attribute value-type keywords recognized by the core. */
|
|
11
|
+
export const VALUE_TYPES = [
|
|
12
|
+
"id",
|
|
13
|
+
"id-list",
|
|
14
|
+
"uri",
|
|
15
|
+
"url",
|
|
16
|
+
"path",
|
|
17
|
+
"path-or-id",
|
|
18
|
+
"enum",
|
|
19
|
+
"tag-list",
|
|
20
|
+
"text",
|
|
21
|
+
"citation",
|
|
22
|
+
"external-id",
|
|
23
|
+
"integer",
|
|
24
|
+
"date",
|
|
25
|
+
"boolean",
|
|
26
|
+
];
|
|
27
|
+
/** Types whose default cardinality is a list (`0..N`). */
|
|
28
|
+
export const LIST_VALUE_TYPES = new Set([
|
|
29
|
+
"id-list",
|
|
30
|
+
"tag-list",
|
|
31
|
+
]);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Handles trailing backslash separators and distinguishes
|
|
6
6
|
* trailing attribute blocks from body prose.
|
|
7
7
|
*/
|
|
8
|
-
import type { Attribute } from "../model/mod.js";
|
|
8
|
+
import type { Attribute, TypedAttributes } from "../model/mod.js";
|
|
9
9
|
/**
|
|
10
10
|
* Parse an array of attribute lines into Attribute objects.
|
|
11
11
|
*
|
|
@@ -22,6 +22,18 @@ export declare function parseAttributes(lines: readonly string[]): Attribute[];
|
|
|
22
22
|
* Used to detect attribute blocks at the end of entry bodies.
|
|
23
23
|
*/
|
|
24
24
|
export declare const ATTR_LINE_RE: RegExp;
|
|
25
|
+
/**
|
|
26
|
+
* Collate a flat list of parsed attributes into a typed, keyed map per
|
|
27
|
+
* ADR-002 §2.6.
|
|
28
|
+
*
|
|
29
|
+
* - Repeatable types (`id-list` / `tag-list` / `external-id`): multi-line
|
|
30
|
+
* entries merge; CSV values on a single line split on `,`.
|
|
31
|
+
* - `citation`: multi-line only (locators may contain commas).
|
|
32
|
+
* - Single-valued types: all occurrences are preserved in-order; the
|
|
33
|
+
* validator decides what to do about duplicates.
|
|
34
|
+
* - Unknown keys: preserved as-is, one entry per occurrence.
|
|
35
|
+
*/
|
|
36
|
+
export declare function collateAttributes(attributes: readonly Attribute[]): TypedAttributes;
|
|
25
37
|
/**
|
|
26
38
|
* Split raw entry content into body text and attribute lines.
|
|
27
39
|
*
|
|
@@ -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,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;AAUlE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,CAiBrE;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,QAA6B,CAAC;AAYvD;;;;;;;;;;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"}
|
package/esm/parser/attributes.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Handles trailing backslash separators and distinguishes
|
|
6
6
|
* trailing attribute blocks from body prose.
|
|
7
7
|
*/
|
|
8
|
+
import { attributeSpec } from "../model/attributes.js";
|
|
8
9
|
/**
|
|
9
10
|
* Pattern matching a `Key: Value` attribute line.
|
|
10
11
|
* Key must start with an uppercase letter, may contain lowercase letters and hyphens.
|
|
@@ -42,6 +43,52 @@ export function parseAttributes(lines) {
|
|
|
42
43
|
* Used to detect attribute blocks at the end of entry bodies.
|
|
43
44
|
*/
|
|
44
45
|
export const ATTR_LINE_RE = /^[A-Z][A-Za-z-]*: .+\\?$/;
|
|
46
|
+
/**
|
|
47
|
+
* Types whose values may be CSV-split on input per ADR-002 §2.6.
|
|
48
|
+
* `citation` is deliberately excluded because locators may contain commas.
|
|
49
|
+
*/
|
|
50
|
+
const CSV_SPLITTABLE_TYPES = new Set([
|
|
51
|
+
"id-list",
|
|
52
|
+
"tag-list",
|
|
53
|
+
"external-id",
|
|
54
|
+
]);
|
|
55
|
+
/**
|
|
56
|
+
* Collate a flat list of parsed attributes into a typed, keyed map per
|
|
57
|
+
* ADR-002 §2.6.
|
|
58
|
+
*
|
|
59
|
+
* - Repeatable types (`id-list` / `tag-list` / `external-id`): multi-line
|
|
60
|
+
* entries merge; CSV values on a single line split on `,`.
|
|
61
|
+
* - `citation`: multi-line only (locators may contain commas).
|
|
62
|
+
* - Single-valued types: all occurrences are preserved in-order; the
|
|
63
|
+
* validator decides what to do about duplicates.
|
|
64
|
+
* - Unknown keys: preserved as-is, one entry per occurrence.
|
|
65
|
+
*/
|
|
66
|
+
export function collateAttributes(attributes) {
|
|
67
|
+
const map = new Map();
|
|
68
|
+
for (const attr of attributes) {
|
|
69
|
+
const spec = attributeSpec(attr.key);
|
|
70
|
+
const type = spec?.type;
|
|
71
|
+
let values;
|
|
72
|
+
if (type && CSV_SPLITTABLE_TYPES.has(type) && attr.value.includes(",")) {
|
|
73
|
+
values = attr.value
|
|
74
|
+
.split(",")
|
|
75
|
+
.map((s) => s.trim())
|
|
76
|
+
.filter((s) => s.length > 0);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
values = [attr.value];
|
|
80
|
+
}
|
|
81
|
+
const existing = map.get(attr.key);
|
|
82
|
+
if (existing) {
|
|
83
|
+
existing.push(...values);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
map.set(attr.key, values);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Freeze value arrays to match the readonly contract.
|
|
90
|
+
return new Map(Array.from(map, ([key, values]) => [key, Object.freeze([...values])]));
|
|
91
|
+
}
|
|
45
92
|
/**
|
|
46
93
|
* Split raw entry content into body text and attribute lines.
|
|
47
94
|
*
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/frontmatter
|
|
3
|
+
*
|
|
4
|
+
* YAML front-matter parser per ADR-007.
|
|
5
|
+
*
|
|
6
|
+
* Extracts a `---`-delimited YAML block at the top of a Markdown file,
|
|
7
|
+
* classifies keys into core / `metadata` / allowlisted ecosystem, and rejects
|
|
8
|
+
* forbidden keys (MSL-D001). Returns a {@linkcode DocumentAttributes} record
|
|
9
|
+
* and the markdown content with the front matter stripped.
|
|
10
|
+
*
|
|
11
|
+
* Full validation of core-key value types is deferred to the validator
|
|
12
|
+
* (Phase 3); this module handles extraction and key-category classification.
|
|
13
|
+
*/
|
|
14
|
+
import type { Diagnostic, DocumentAttributes } from "../model/mod.js";
|
|
15
|
+
/** Options for {@linkcode extractFrontMatter}. */
|
|
16
|
+
export interface ExtractFrontMatterOptions {
|
|
17
|
+
/** File path used in diagnostic source locations. */
|
|
18
|
+
readonly file?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Profile-declared keys. Accepted alongside core keys, passed through on
|
|
21
|
+
* {@linkcode FrontMatterResult.attributes.extra}.
|
|
22
|
+
*/
|
|
23
|
+
readonly profileKeys?: readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* Allowlisted ecosystem keys from `.markspec.yaml`
|
|
26
|
+
* (`frontMatter.allowedKeys`). Accepted and passed through on
|
|
27
|
+
* {@linkcode FrontMatterResult.attributes.extra}.
|
|
28
|
+
*/
|
|
29
|
+
readonly allowedKeys?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/** Result of front-matter extraction. */
|
|
32
|
+
export interface FrontMatterResult {
|
|
33
|
+
/** Parsed document attributes. Empty when no front matter is present. */
|
|
34
|
+
readonly attributes: DocumentAttributes;
|
|
35
|
+
/** Diagnostics (forbidden keys, unknown keys, YAML errors). */
|
|
36
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
37
|
+
/** Markdown content with front matter stripped. */
|
|
38
|
+
readonly markdown: string;
|
|
39
|
+
/** Whether front matter was present. */
|
|
40
|
+
readonly hadFrontMatter: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extract YAML front matter from a Markdown source, validate its keys, and
|
|
44
|
+
* return structured attributes plus the stripped markdown.
|
|
45
|
+
*
|
|
46
|
+
* No front matter → {@linkcode FrontMatterResult.hadFrontMatter} is `false`
|
|
47
|
+
* and attributes are empty.
|
|
48
|
+
*
|
|
49
|
+
* @param markdown - Full source text, including any leading front matter.
|
|
50
|
+
* @param options - Key allowlists and file path for diagnostics.
|
|
51
|
+
*/
|
|
52
|
+
export declare function extractFrontMatter(markdown: string, options?: ExtractFrontMatterOptions): FrontMatterResult;
|
|
53
|
+
//# sourceMappingURL=frontmatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/parser/frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAyCtE,kDAAkD;AAClD,MAAM,WAAW,yBAAyB;IACxC,qDAAqD;IACrD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED,yCAAyC;AACzC,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wCAAwC;IACxC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,yBAAyB,GAClC,iBAAiB,CA8InB"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/frontmatter
|
|
3
|
+
*
|
|
4
|
+
* YAML front-matter parser per ADR-007.
|
|
5
|
+
*
|
|
6
|
+
* Extracts a `---`-delimited YAML block at the top of a Markdown file,
|
|
7
|
+
* classifies keys into core / `metadata` / allowlisted ecosystem, and rejects
|
|
8
|
+
* forbidden keys (MSL-D001). Returns a {@linkcode DocumentAttributes} record
|
|
9
|
+
* and the markdown content with the front matter stripped.
|
|
10
|
+
*
|
|
11
|
+
* Full validation of core-key value types is deferred to the validator
|
|
12
|
+
* (Phase 3); this module handles extraction and key-category classification.
|
|
13
|
+
*/
|
|
14
|
+
import { parse as parseYaml } from "@std/yaml";
|
|
15
|
+
/**
|
|
16
|
+
* YAML front-matter delimiter — `---` at start of file, closing `---`, then
|
|
17
|
+
* any number of trailing newlines so the stripped markdown begins cleanly.
|
|
18
|
+
* Empty YAML body (`---\n---\n`) is accepted.
|
|
19
|
+
*/
|
|
20
|
+
const FRONT_MATTER_RE = /^---\r?\n([\s\S]*?)(?:\r?\n)?---\r?\n?(?:\r?\n)*/;
|
|
21
|
+
/**
|
|
22
|
+
* Core document-level attribute keys per ADR-007. Kebab-case by convention.
|
|
23
|
+
*/
|
|
24
|
+
const CORE_KEYS = new Set([
|
|
25
|
+
"document-id",
|
|
26
|
+
"document-type",
|
|
27
|
+
"labels",
|
|
28
|
+
"deprecated",
|
|
29
|
+
"external-id",
|
|
30
|
+
"supersedes",
|
|
31
|
+
"references",
|
|
32
|
+
"metadata",
|
|
33
|
+
]);
|
|
34
|
+
/**
|
|
35
|
+
* Keys forbidden in front matter per ADR-007 — already expressed natively in
|
|
36
|
+
* Markdown (H1, body, images) or in git history (authors, dates).
|
|
37
|
+
*/
|
|
38
|
+
const FORBIDDEN_KEYS = new Set([
|
|
39
|
+
"title",
|
|
40
|
+
"description",
|
|
41
|
+
"toc",
|
|
42
|
+
"authors",
|
|
43
|
+
"author",
|
|
44
|
+
"date",
|
|
45
|
+
"created",
|
|
46
|
+
"modified",
|
|
47
|
+
"cover",
|
|
48
|
+
"images",
|
|
49
|
+
"sections",
|
|
50
|
+
]);
|
|
51
|
+
/**
|
|
52
|
+
* Extract YAML front matter from a Markdown source, validate its keys, and
|
|
53
|
+
* return structured attributes plus the stripped markdown.
|
|
54
|
+
*
|
|
55
|
+
* No front matter → {@linkcode FrontMatterResult.hadFrontMatter} is `false`
|
|
56
|
+
* and attributes are empty.
|
|
57
|
+
*
|
|
58
|
+
* @param markdown - Full source text, including any leading front matter.
|
|
59
|
+
* @param options - Key allowlists and file path for diagnostics.
|
|
60
|
+
*/
|
|
61
|
+
export function extractFrontMatter(markdown, options) {
|
|
62
|
+
const file = options?.file ?? "<unknown>";
|
|
63
|
+
const match = FRONT_MATTER_RE.exec(markdown);
|
|
64
|
+
if (!match) {
|
|
65
|
+
return {
|
|
66
|
+
attributes: {},
|
|
67
|
+
diagnostics: [],
|
|
68
|
+
markdown,
|
|
69
|
+
hadFrontMatter: false,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const yamlBody = match[1];
|
|
73
|
+
const remaining = markdown.slice(match[0].length);
|
|
74
|
+
const diagnostics = [];
|
|
75
|
+
let raw;
|
|
76
|
+
try {
|
|
77
|
+
raw = parseYaml(yamlBody);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
diagnostics.push({
|
|
81
|
+
code: "MSL-D001",
|
|
82
|
+
severity: "error",
|
|
83
|
+
message: `front matter: invalid YAML — ${err instanceof Error ? err.message : String(err)}`,
|
|
84
|
+
location: { file, line: 1, column: 1 },
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
attributes: {},
|
|
88
|
+
diagnostics,
|
|
89
|
+
markdown: remaining,
|
|
90
|
+
hadFrontMatter: true,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (raw == null) {
|
|
94
|
+
return {
|
|
95
|
+
attributes: {},
|
|
96
|
+
diagnostics,
|
|
97
|
+
markdown: remaining,
|
|
98
|
+
hadFrontMatter: true,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
102
|
+
diagnostics.push({
|
|
103
|
+
code: "MSL-D001",
|
|
104
|
+
severity: "error",
|
|
105
|
+
message: "front matter must be a YAML mapping",
|
|
106
|
+
location: { file, line: 1, column: 1 },
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
attributes: {},
|
|
110
|
+
diagnostics,
|
|
111
|
+
markdown: remaining,
|
|
112
|
+
hadFrontMatter: true,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const entries = raw;
|
|
116
|
+
const profileKeys = new Set(options?.profileKeys ?? []);
|
|
117
|
+
const allowedKeys = new Set(options?.allowedKeys ?? []);
|
|
118
|
+
const core = {};
|
|
119
|
+
const extra = {};
|
|
120
|
+
let metadata;
|
|
121
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
122
|
+
if (FORBIDDEN_KEYS.has(key)) {
|
|
123
|
+
diagnostics.push({
|
|
124
|
+
code: "MSL-D001",
|
|
125
|
+
severity: "error",
|
|
126
|
+
message: `front matter key '${key}' is forbidden — express it in Markdown or git history instead`,
|
|
127
|
+
location: { file, line: 1, column: 1 },
|
|
128
|
+
});
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (key === "metadata") {
|
|
132
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
133
|
+
diagnostics.push({
|
|
134
|
+
code: "MSL-D001",
|
|
135
|
+
severity: "error",
|
|
136
|
+
message: "front matter 'metadata' must be a mapping",
|
|
137
|
+
location: { file, line: 1, column: 1 },
|
|
138
|
+
});
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
metadata = value;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
// Transitional: status: was removed in favor of Labels: DRAFT / deprecated:
|
|
145
|
+
if (key === "status") {
|
|
146
|
+
diagnostics.push({
|
|
147
|
+
code: "MSL-D002",
|
|
148
|
+
severity: "warning",
|
|
149
|
+
message: `front-matter key 'status' is no longer recognized; ` +
|
|
150
|
+
`use 'Labels: DRAFT' for draft state or 'deprecated: "<reason>"' for retirement`,
|
|
151
|
+
location: { file, line: 1, column: 1 },
|
|
152
|
+
});
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (CORE_KEYS.has(key)) {
|
|
156
|
+
core[key] = value;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (profileKeys.has(key) || allowedKeys.has(key)) {
|
|
160
|
+
extra[key] = value;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
diagnostics.push({
|
|
164
|
+
code: "MSL-D001",
|
|
165
|
+
severity: "error",
|
|
166
|
+
message: `unknown front matter key '${key}' — must be core, profile-declared, 'metadata', or allowlisted in .markspec.yaml`,
|
|
167
|
+
location: { file, line: 1, column: 1 },
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const attributes = {};
|
|
171
|
+
const mutable = attributes;
|
|
172
|
+
for (const [key, value] of Object.entries(core)) {
|
|
173
|
+
mutable[key] = value;
|
|
174
|
+
}
|
|
175
|
+
if (metadata !== undefined)
|
|
176
|
+
mutable.metadata = metadata;
|
|
177
|
+
if (Object.keys(extra).length > 0)
|
|
178
|
+
mutable.extra = extra;
|
|
179
|
+
return {
|
|
180
|
+
attributes,
|
|
181
|
+
diagnostics,
|
|
182
|
+
markdown: remaining,
|
|
183
|
+
hadFrontMatter: true,
|
|
184
|
+
};
|
|
185
|
+
}
|
package/esm/parser/grammars.js
CHANGED
|
@@ -56,6 +56,15 @@ async function doLoad(grammarName) {
|
|
|
56
56
|
await Parser.init();
|
|
57
57
|
initialized = true;
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
// The compiled binary embeds grammars as .wasm.bin to bypass Deno's
|
|
60
|
+
// WASM-import resolver (see scripts/compile_binary.ts). Prefer the
|
|
61
|
+
// mirror when present; fall back to .wasm in dev mode.
|
|
62
|
+
const binPath = join(GRAMMARS_DIR, `${grammarName}.wasm.bin`);
|
|
63
|
+
try {
|
|
64
|
+
await Deno.stat(binPath);
|
|
65
|
+
return Parser.Language.load(binPath);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return Parser.Language.load(join(GRAMMARS_DIR, `${grammarName}.wasm`));
|
|
69
|
+
}
|
|
61
70
|
}
|
package/esm/parser/markdown.d.ts
CHANGED
|
@@ -2,20 +2,27 @@
|
|
|
2
2
|
* @module parser/markdown
|
|
3
3
|
*
|
|
4
4
|
* CommonMark + MarkSpec extension parser. Walks the mdast AST to detect
|
|
5
|
-
* `- [
|
|
5
|
+
* `- [DISPLAY_ID] Title` entry blocks and extract structured attributes.
|
|
6
6
|
*/
|
|
7
7
|
import type { Entry } from "../model/mod.js";
|
|
8
8
|
/** Options for {@linkcode parseMarkdown}. */
|
|
9
9
|
export interface ParseMarkdownOptions {
|
|
10
10
|
/** File path used in source locations. */
|
|
11
11
|
readonly file?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Is this a references document? If undefined, auto-detect from file path.
|
|
14
|
+
* When true, `[slug]` items without an `Id:` attribute are still admitted
|
|
15
|
+
* as referenced-entry candidates (the validator flags the missing `Id:`).
|
|
16
|
+
*/
|
|
17
|
+
readonly isReferencesDoc?: boolean;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* Parse a Markdown string and return all MarkSpec entries found.
|
|
15
21
|
*
|
|
16
|
-
* Walks the mdast AST to detect `- [DISPLAY_ID] Title` list items
|
|
17
|
-
*
|
|
18
|
-
*
|
|
22
|
+
* Walks the mdast AST to detect `- [DISPLAY_ID] Title` list items with
|
|
23
|
+
* indented body content. Extracts display ID, title, body, and trailing
|
|
24
|
+
* attribute blocks. Entry shape (identified or referenced) is decided by
|
|
25
|
+
* the `Id:` attribute's value format.
|
|
19
26
|
*
|
|
20
27
|
* @param markdown - Markdown source text
|
|
21
28
|
* @param options - Parse options (file path for source locations)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAa,KAAK,EAAc,MAAM,iBAAiB,CAAC;AASpE,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;CACpC;AA4BD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,KAAK,EAAE,CAoCT"}
|