@pubid/pubid 0.1.69 → 0.1.71
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 +123 -1
- package/dist/flavors/bsi/index.d.ts +3 -2
- package/dist/flavors/bsi/index.js +43 -42
- package/dist/flavors/bsi/worker.d.ts +3 -0
- package/dist/flavors/bsi/worker.js +18 -0
- package/dist/flavors/cen_cenelec/index.d.ts +3 -2
- package/dist/flavors/cen_cenelec/index.js +14 -8
- package/dist/flavors/cen_cenelec/worker.d.ts +3 -0
- package/dist/flavors/cen_cenelec/worker.js +17 -0
- package/dist/flavors/csa/index.d.ts +2 -1
- package/dist/flavors/csa/index.js +27 -28
- package/dist/flavors/csa/worker.d.ts +3 -0
- package/dist/flavors/csa/worker.js +17 -0
- package/dist/flavors/evs/index.d.ts +2 -1
- package/dist/flavors/evs/index.js +4 -4
- package/dist/flavors/evs/worker.d.ts +3 -0
- package/dist/flavors/evs/worker.js +18 -0
- package/dist/flavors/foreign-resolver.d.ts +6 -0
- package/dist/flavors/foreign-resolver.js +9 -0
- package/dist/flavors/gost/index.d.ts +2 -1
- package/dist/flavors/gost/index.js +19 -20
- package/dist/flavors/gost/worker.d.ts +3 -0
- package/dist/flavors/gost/worker.js +21 -0
- package/dist/flavors/ieee/artifact_tree.js +1 -1
- package/dist/flavors/ieee/implementation.d.ts +16 -0
- package/dist/flavors/ieee/implementation.js +2195 -0
- package/dist/flavors/ieee/index.js +18 -2181
- package/dist/flavors/ieee/worker.d.ts +7 -0
- package/dist/flavors/ieee/worker.js +31 -0
- package/dist/flavors/index.js +6 -6
- package/dist/flavors/nist/implementation.d.ts +5 -0
- package/dist/flavors/nist/implementation.js +1326 -0
- package/dist/flavors/nist/index.js +14 -1330
- package/dist/flavors/nist/worker.d.ts +3 -0
- package/dist/flavors/nist/worker.js +24 -0
- package/dist/flavors/oiml/implementation.d.ts +2 -1
- package/dist/flavors/oiml/implementation.js +2 -3
- package/dist/flavors/oiml/index.d.ts +2 -0
- package/dist/flavors/oiml/index.js +10 -0
- package/dist/flavors/oiml/worker.d.ts +2 -0
- package/dist/flavors/oiml/worker.js +14 -0
- package/dist/flavors/worker-registry.d.ts +13 -0
- package/dist/flavors/worker-registry.js +120 -0
- package/dist/parg/artifacts/ieee.d.ts +2 -0
- package/dist/parg/artifacts/ieee.js +5 -0
- package/dist/parg/artifacts/nist.d.ts +2 -0
- package/dist/parg/artifacts/nist.js +5 -0
- package/dist/parg/runtime.d.ts +1 -13
- package/dist/parg/runtime.js +4 -36
- package/dist/parg/shape.d.ts +13 -0
- package/dist/parg/shape.js +39 -0
- package/dist/parg/worker.d.ts +9 -0
- package/dist/parg/worker.js +32 -0
- package/dist/register-types.d.ts +7 -1
- package/dist/register-types.js +7 -1
- package/package.json +7 -2
|
@@ -0,0 +1,1326 @@
|
|
|
1
|
+
import { toBuilderTree } from "../../parg/shape.js";
|
|
2
|
+
import { preprocessNist } from "./preprocessor.js";
|
|
3
|
+
import { NIST_CLASSES, NistCode, NistEdition, NistPart, NistStage, NistSupplement, NistTranslation, NistUpdate, NistVersion, NistVolume, SP_SUBSERIES, seriesPolicy, } from "./model.js";
|
|
4
|
+
/**
|
|
5
|
+
* Port of lib/pubid/nist/{builder,caster,router,parser_output_normalizer,
|
|
6
|
+
* circular_supplement_builder}.rb — the parse-tree → identifier pipeline.
|
|
7
|
+
*/
|
|
8
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
9
|
+
const s = (v) => {
|
|
10
|
+
if (v === undefined || v === null)
|
|
11
|
+
return undefined;
|
|
12
|
+
const str = Array.isArray(v) ? v.join("") : String(v);
|
|
13
|
+
return str.length > 0 ? str : undefined;
|
|
14
|
+
};
|
|
15
|
+
function flatten(data) {
|
|
16
|
+
return Array.isArray(data) ? Object.assign({}, ...data) : data;
|
|
17
|
+
}
|
|
18
|
+
const TRANSLATION_MAP = {
|
|
19
|
+
es: "spa", sp: "spa", pt: "por", id: "ind",
|
|
20
|
+
chi: "zho", viet: "vie", port: "por", esp: "spa",
|
|
21
|
+
};
|
|
22
|
+
const MONTH_NUMBERS = {
|
|
23
|
+
Jan: 1, January: 1, Feb: 2, February: 2, Mar: 3, March: 3,
|
|
24
|
+
Apr: 4, April: 4, May: 5, Jun: 6, June: 6, Jul: 7, July: 7,
|
|
25
|
+
Aug: 8, August: 8, Sep: 9, Sept: 9, September: 9, Oct: 10, October: 10,
|
|
26
|
+
Nov: 11, November: 11, Dec: 12, December: 12,
|
|
27
|
+
};
|
|
28
|
+
const VALID_YEAR_RANGE_MIN = 1901;
|
|
29
|
+
const VALID_YEAR_RANGE_MAX = 2026;
|
|
30
|
+
const DASH_YEAR_AS_EDITION_SERIES = new Set(["HB", "CS", "FIPS"]);
|
|
31
|
+
// --- Parser output normalizer ---------------------------------------------------
|
|
32
|
+
function normalizeParsedHash(h) {
|
|
33
|
+
mergeEditionEIntoUpdate(h);
|
|
34
|
+
extractEmbeddedEditionWithYear(h);
|
|
35
|
+
extractEmbeddedEditionWithoutDashYear(h);
|
|
36
|
+
splitSecondNumberEditionYear(h);
|
|
37
|
+
splitFipsMonthYearAfterPart(h);
|
|
38
|
+
disambiguateIrCompoundVsEdition(h);
|
|
39
|
+
disambiguateDashYear(h);
|
|
40
|
+
}
|
|
41
|
+
function mergeEditionEIntoUpdate(h) {
|
|
42
|
+
const updatePrefix = h["update_prefix"];
|
|
43
|
+
const update = h["update"];
|
|
44
|
+
const editionE = h["edition_e"];
|
|
45
|
+
if (updatePrefix === undefined || update === undefined || !isObj(editionE))
|
|
46
|
+
return;
|
|
47
|
+
const editionId = editionE["edition_id"];
|
|
48
|
+
h["update"] = { ...(isObj(update) ? update : {}), update_year: editionId };
|
|
49
|
+
delete h["edition_e"];
|
|
50
|
+
}
|
|
51
|
+
function editionFromParts(type, id, additionalText) {
|
|
52
|
+
return { __edition: true, type, id, ...(additionalText !== undefined ? { additional_text: additionalText } : {}) };
|
|
53
|
+
}
|
|
54
|
+
function extractEmbeddedEditionWithYear(h) {
|
|
55
|
+
const first = s(h["first_number"]);
|
|
56
|
+
if (first !== undefined && /^[0-9]+[a-zA-Z]\d+$/.test(first) && h["edition_dash_year"] !== undefined) {
|
|
57
|
+
const m = /^(\d+)([a-zA-Z])(\d+)$/.exec(first);
|
|
58
|
+
if (m !== null) {
|
|
59
|
+
h["first_number"] = m[1];
|
|
60
|
+
h["edition_with_year"] = editionFromParts(m[2].toLowerCase(), m[3], s(isObj(h["edition_dash_year"]) ? h["edition_dash_year"]["dash_year"] : undefined));
|
|
61
|
+
delete h["edition_dash_year"];
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Same shape embedded in the SECOND number ("53e1988" of "260-53e1988").
|
|
66
|
+
const second = s(h["second_number"]);
|
|
67
|
+
if (second !== undefined && /^[0-9]+[a-zA-Z]\d+$/.test(second)) {
|
|
68
|
+
const m = /^(\d+)([a-zA-Z])(\d+)$/.exec(second);
|
|
69
|
+
if (m !== null) {
|
|
70
|
+
h["second_number"] = m[1];
|
|
71
|
+
h["edition_with_year"] = editionFromParts(m[2].toLowerCase(), m[3]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function extractEmbeddedEditionWithoutDashYear(h) {
|
|
76
|
+
if (h["second_number"] !== undefined)
|
|
77
|
+
return;
|
|
78
|
+
const first = s(h["first_number"]);
|
|
79
|
+
if (first === undefined || !/^[0-9]+[a-zA-Z]\d+$/.test(first))
|
|
80
|
+
return;
|
|
81
|
+
if (h["edition_dash_year"] !== undefined)
|
|
82
|
+
return;
|
|
83
|
+
const m = /^(\d+)([a-zA-Z])(\d+)$/.exec(first);
|
|
84
|
+
if (m === null)
|
|
85
|
+
return;
|
|
86
|
+
h["first_number"] = m[1];
|
|
87
|
+
h["edition_with_year"] = editionFromParts(m[2].toLowerCase(), m[3]);
|
|
88
|
+
}
|
|
89
|
+
function splitSecondNumberEditionYear(h) {
|
|
90
|
+
const combined = h["second_number_edition_year"];
|
|
91
|
+
if (!isObj(combined))
|
|
92
|
+
return;
|
|
93
|
+
h["second_number"] = combined["second_number"];
|
|
94
|
+
const dashYear = s(combined["dash_year"]);
|
|
95
|
+
const isHandbook = s(h["series"]) === "HB";
|
|
96
|
+
if (isHandbook && dashYear !== undefined && /^\d{4}$/.test(dashYear)) {
|
|
97
|
+
h["edition_from_year"] = editionFromParts("e", dashYear);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
h["edition_dash_year"] = { dash_year: dashYear };
|
|
101
|
+
}
|
|
102
|
+
delete h["second_number_edition_year"];
|
|
103
|
+
}
|
|
104
|
+
function splitFipsMonthYearAfterPart(h) {
|
|
105
|
+
const combined = h["fips_month_year_after_part"];
|
|
106
|
+
if (!isObj(combined))
|
|
107
|
+
return;
|
|
108
|
+
h["second_number"] = combined["second_number"];
|
|
109
|
+
const monthStr = s(combined["edition_month"]) ?? "";
|
|
110
|
+
const yearStr = s(combined["edition_year"]) ?? "";
|
|
111
|
+
const monthNum = MONTH_NUMBERS[monthStr];
|
|
112
|
+
const editionId = monthNum !== undefined ? `${yearStr}${String(monthNum).padStart(2, "0")}` : yearStr;
|
|
113
|
+
h["edition_from_year"] = editionFromParts("e", editionId);
|
|
114
|
+
delete h["fips_month_year_after_part"];
|
|
115
|
+
}
|
|
116
|
+
function disambiguateIrCompoundVsEdition(h) {
|
|
117
|
+
if (s(h["series"]) !== "IR")
|
|
118
|
+
return;
|
|
119
|
+
if (h["first_number"] === undefined || h["edition_dash_year"] === undefined)
|
|
120
|
+
return;
|
|
121
|
+
const firstNum = s(h["first_number"]) ?? "";
|
|
122
|
+
const dashYear = s(isObj(h["edition_dash_year"]) ? h["edition_dash_year"]["dash_year"] : undefined) ?? "";
|
|
123
|
+
if (!/^\d{2}$/.test(firstNum) || !/^\d{4}$/.test(dashYear))
|
|
124
|
+
return;
|
|
125
|
+
const isValidYear = Number(dashYear) >= VALID_YEAR_RANGE_MIN && Number(dashYear) <= VALID_YEAR_RANGE_MAX;
|
|
126
|
+
const hasEmbeddedEdition = h["edition_e"] !== undefined;
|
|
127
|
+
if (isValidYear && !hasEmbeddedEdition) {
|
|
128
|
+
h["edition"] = editionFromParts("e", dashYear);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
h["first_number"] = `${firstNum}-${dashYear}`;
|
|
132
|
+
}
|
|
133
|
+
delete h["edition_dash_year"];
|
|
134
|
+
}
|
|
135
|
+
function disambiguateDashYear(h) {
|
|
136
|
+
if (h["first_number"] === undefined || h["edition_dash_year"] === undefined)
|
|
137
|
+
return;
|
|
138
|
+
const first = s(h["first_number"]) ?? "";
|
|
139
|
+
if (/^[0-9]+[a-zA-Z]\d+$/.test(first))
|
|
140
|
+
return;
|
|
141
|
+
const dashYear = s(isObj(h["edition_dash_year"]) ? h["edition_dash_year"]["dash_year"] : undefined) ?? "";
|
|
142
|
+
const series = s(h["series"]) ?? "";
|
|
143
|
+
const dashYearNum = Number(dashYear);
|
|
144
|
+
const isValidYear = dashYearNum >= VALID_YEAR_RANGE_MIN && dashYearNum <= VALID_YEAR_RANGE_MAX;
|
|
145
|
+
if (series === "RPT") {
|
|
146
|
+
h["first_number"] = `${first}-${dashYear}`;
|
|
147
|
+
delete h["edition_dash_year"];
|
|
148
|
+
}
|
|
149
|
+
else if (series === "GCR") {
|
|
150
|
+
h["edition_from_year"] = editionFromParts("e", dashYear);
|
|
151
|
+
delete h["edition_dash_year"];
|
|
152
|
+
}
|
|
153
|
+
else if (series === "IR" && isValidYear) {
|
|
154
|
+
h["edition_from_year"] = editionFromParts("e", dashYear);
|
|
155
|
+
delete h["edition_dash_year"];
|
|
156
|
+
}
|
|
157
|
+
else if (DASH_YEAR_AS_EDITION_SERIES.has(series) && isValidYear) {
|
|
158
|
+
h["edition_from_year"] = editionFromParts("e", dashYear);
|
|
159
|
+
delete h["edition_dash_year"];
|
|
160
|
+
}
|
|
161
|
+
else if (dashYearNum < 1900) {
|
|
162
|
+
h["second_number"] = dashYear;
|
|
163
|
+
delete h["edition_dash_year"];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function classForKind(kind) {
|
|
167
|
+
return NIST_CLASSES.get(kind);
|
|
168
|
+
}
|
|
169
|
+
function locateIdentifierKlass(h) {
|
|
170
|
+
if (h["dated_date"] !== undefined && h["dated_seq"] !== undefined) {
|
|
171
|
+
return classForKind("dated-document");
|
|
172
|
+
}
|
|
173
|
+
let series = s(h["series"]);
|
|
174
|
+
// The default-series plain-number branch (pubid#711): the grammar's
|
|
175
|
+
// trailing alternatives accept a bare report number ("800-90B") and
|
|
176
|
+
// its publisher-led spelling ("NIST 800-90B") with NO series token.
|
|
177
|
+
// The SP series is the default: the docid-derived citation of
|
|
178
|
+
// NIST.SP.800-90B is exactly the bare docnumber "800-90B", and the
|
|
179
|
+
// Builder fills the same SP series the spelled form carries, so the
|
|
180
|
+
// two spellings are one identity to a lookup. No other branch can
|
|
181
|
+
// arrive here series-less (dated shapes returned above; every
|
|
182
|
+
// series-bearing branch captures :series).
|
|
183
|
+
if (series === undefined) {
|
|
184
|
+
return classForKind("special-publication");
|
|
185
|
+
}
|
|
186
|
+
if (series?.startsWith("NBS ") === true || series?.startsWith("NBS.") === true || series?.startsWith("NIST.") === true) {
|
|
187
|
+
const separator = series.startsWith("NBS ") ? "NBS " : series.startsWith("NBS.") ? "NBS." : "NIST.";
|
|
188
|
+
let simple = series.slice(separator.length);
|
|
189
|
+
if (simple === "LCIRC" || simple === "CIRC") {
|
|
190
|
+
return hasSupplement(h) ? classForKind("circular-supplement") : simple === "CIRC" ? classForKind("circular") : classForKind("letter-circular");
|
|
191
|
+
}
|
|
192
|
+
series = simple;
|
|
193
|
+
}
|
|
194
|
+
if (series === "CS") {
|
|
195
|
+
// The composite branch of the split first_number wrapper (the
|
|
196
|
+
// grammar's v#n# branch) arrives under first_number_composite.
|
|
197
|
+
const firstNum = h["first_number"] ?? h["first_number_composite"];
|
|
198
|
+
if (isObj(firstNum) && firstNum["volume_number"] !== undefined && firstNum["issue_number"] !== undefined) {
|
|
199
|
+
return classForKind("commercial-standards-monthly");
|
|
200
|
+
}
|
|
201
|
+
const firstNumStr = s(firstNum) ?? "";
|
|
202
|
+
if (/^e\d{3,}/.test(firstNumStr)) {
|
|
203
|
+
return classForKind("commercial-standard-emergency");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Series token → type via the typed-stage abbreviation table.
|
|
207
|
+
const kind = SERIES_TO_KIND[series ?? ""];
|
|
208
|
+
return kind !== undefined ? classForKind(kind) : classForKind("identifier");
|
|
209
|
+
}
|
|
210
|
+
const SERIES_TO_KIND = {
|
|
211
|
+
SP: "special-publication",
|
|
212
|
+
"NIST SP": "special-publication",
|
|
213
|
+
"NBS SP": "special-publication",
|
|
214
|
+
FIPS: "federal-information-processing-standards",
|
|
215
|
+
"NIST FIPS": "federal-information-processing-standards",
|
|
216
|
+
IR: "interagency-report",
|
|
217
|
+
"NIST IR": "interagency-report",
|
|
218
|
+
"NBS IR": "interagency-report",
|
|
219
|
+
HB: "handbook",
|
|
220
|
+
"NIST HB": "handbook",
|
|
221
|
+
"NBS HB": "handbook",
|
|
222
|
+
TN: "technical-note",
|
|
223
|
+
"NIST TN": "technical-note",
|
|
224
|
+
"NBS TN": "technical-note",
|
|
225
|
+
CIRC: "circular",
|
|
226
|
+
"NBS CIRC": "circular",
|
|
227
|
+
CRPL: "crpl-report",
|
|
228
|
+
"NBS CRPL": "crpl-report",
|
|
229
|
+
"CRPL-F-B": "crpl-report",
|
|
230
|
+
"CRPL-F-A": "crpl-report",
|
|
231
|
+
"NBS CRPL-F-B": "crpl-report",
|
|
232
|
+
"NBS CRPL-F-A": "crpl-report",
|
|
233
|
+
"NBS BRPD-CRPL-D": "crpl-report",
|
|
234
|
+
RPT: "report",
|
|
235
|
+
"NBS RPT": "report",
|
|
236
|
+
MONO: "monograph",
|
|
237
|
+
"NBS MONO": "monograph",
|
|
238
|
+
"NIST MONO": "monograph",
|
|
239
|
+
MP: "miscellaneous-publication",
|
|
240
|
+
"NBS MP": "miscellaneous-publication",
|
|
241
|
+
GCR: "grant-contractor-report",
|
|
242
|
+
"NIST GCR": "grant-contractor-report",
|
|
243
|
+
NCSTAR: "ncstar",
|
|
244
|
+
"NIST NCSTAR": "ncstar",
|
|
245
|
+
OWMWP: "owmwp",
|
|
246
|
+
"NIST OWMWP": "owmwp",
|
|
247
|
+
NSRDS: "nsrds",
|
|
248
|
+
"NBS NSRDS": "nsrds",
|
|
249
|
+
"NSRDS-NBS": "nsrds",
|
|
250
|
+
LCIRC: "letter-circular",
|
|
251
|
+
CS: "commercial-standard",
|
|
252
|
+
"NBS CS": "commercial-standard",
|
|
253
|
+
"NBS CS-E": "commercial-standard-emergency",
|
|
254
|
+
"CS-E": "commercial-standard-emergency",
|
|
255
|
+
CSM: "commercial-standards-monthly",
|
|
256
|
+
"NBS CSM": "commercial-standards-monthly",
|
|
257
|
+
"NIST PS": "identifier",
|
|
258
|
+
"NIST DCI": "identifier",
|
|
259
|
+
"NIST Other": "identifier",
|
|
260
|
+
"ITL Bulletin": "identifier",
|
|
261
|
+
"CSRC Building Block": "identifier",
|
|
262
|
+
"CSRC Use Case": "identifier",
|
|
263
|
+
"CSRC Book": "identifier",
|
|
264
|
+
};
|
|
265
|
+
function hasSupplement(h) {
|
|
266
|
+
return (h["supplement"] !== undefined ||
|
|
267
|
+
h["supplement_date_range"] !== undefined ||
|
|
268
|
+
h["supplement_date"] !== undefined ||
|
|
269
|
+
h["supplement_slash_year"] !== undefined ||
|
|
270
|
+
h["supplement_with_rev"] !== undefined);
|
|
271
|
+
}
|
|
272
|
+
function editionCast(type, id, additionalText, originalPrefix) {
|
|
273
|
+
const edition = new NistEdition({ type, id, ...(additionalText !== undefined ? { additional_text: additionalText } : {}), ...(originalPrefix !== undefined ? { original_prefix: originalPrefix } : {}) });
|
|
274
|
+
return { edition };
|
|
275
|
+
}
|
|
276
|
+
function cast(type, value, h, policy, series = "") {
|
|
277
|
+
switch (type) {
|
|
278
|
+
case "publisher":
|
|
279
|
+
return s(value);
|
|
280
|
+
case "dated_date": {
|
|
281
|
+
if (!isObj(value))
|
|
282
|
+
return undefined;
|
|
283
|
+
return { date_year: s(value["date_year"]), date_month: s(value["date_month"]), date_day: s(value["date_day"]) };
|
|
284
|
+
}
|
|
285
|
+
case "dated_seq":
|
|
286
|
+
return s(value) === undefined ? undefined : { dated_seq: s(value) };
|
|
287
|
+
case "year":
|
|
288
|
+
return s(value) === undefined ? undefined : Number(s(value));
|
|
289
|
+
case "series": {
|
|
290
|
+
const strValue = s(value);
|
|
291
|
+
if (strValue === undefined)
|
|
292
|
+
return undefined;
|
|
293
|
+
const m = /^(NBS|NIST) (.+)$/.exec(strValue);
|
|
294
|
+
if (m !== null) {
|
|
295
|
+
return { publisher: m[1], series: new NistCode({ value: m[2] }) };
|
|
296
|
+
}
|
|
297
|
+
return { series: new NistCode({ value: strValue }) };
|
|
298
|
+
}
|
|
299
|
+
case "volume_number": {
|
|
300
|
+
const v = s(value);
|
|
301
|
+
return v === undefined ? undefined : { volume: new NistVolume({ value: v }) };
|
|
302
|
+
}
|
|
303
|
+
case "issue_number": {
|
|
304
|
+
const v = s(value);
|
|
305
|
+
return v === undefined ? undefined : { part: new NistPart({ type: "n", value: v }) };
|
|
306
|
+
}
|
|
307
|
+
case "part_number":
|
|
308
|
+
return s(value);
|
|
309
|
+
case "n_letter_part": {
|
|
310
|
+
// Part type "n" with a letter value (pubid#555): the "1nA" /
|
|
311
|
+
// "1-1nA" annex tokens capture whole, the caster strips the n.
|
|
312
|
+
const v = s(value);
|
|
313
|
+
if (v === undefined)
|
|
314
|
+
return undefined;
|
|
315
|
+
return { part: new NistPart({ type: "n", value: v.replace(/^n/, "").toUpperCase() }) };
|
|
316
|
+
}
|
|
317
|
+
case "letter_number": {
|
|
318
|
+
if (!isObj(value))
|
|
319
|
+
return undefined;
|
|
320
|
+
const suffix = s(value["letter_suffix"]) ?? "";
|
|
321
|
+
const extra = s(value["letter_suffix_extra"]) ?? "";
|
|
322
|
+
const full = extra === "" ? suffix : `${suffix}${extra}`;
|
|
323
|
+
if (full === "")
|
|
324
|
+
return undefined;
|
|
325
|
+
// IR keeps R/Ur for the compound handler; NCSTAR/MONO keep any
|
|
326
|
+
// letter in the number (Ruby Series class dispatch).
|
|
327
|
+
if (series === "IR" && (full === "R" || full === "Ur"))
|
|
328
|
+
return { letter_number: { ...value, letter_suffix: full } };
|
|
329
|
+
if (series === "NCSTAR" || series === "MONO") {
|
|
330
|
+
return { letter_number: { ...value, letter_suffix: full } };
|
|
331
|
+
}
|
|
332
|
+
return { part: new NistPart({ type: "", value: full.toUpperCase() }) };
|
|
333
|
+
}
|
|
334
|
+
case "fips_part": {
|
|
335
|
+
const v = s(value);
|
|
336
|
+
return v === undefined ? undefined : { part: new NistPart({ type: "pt", value: v }) };
|
|
337
|
+
}
|
|
338
|
+
case "owmwp_date_number": {
|
|
339
|
+
if (value === undefined)
|
|
340
|
+
return undefined;
|
|
341
|
+
const v = isObj(value) ? value : {};
|
|
342
|
+
const owmwp = isObj(v["owmwp_date_number"]) ? v["owmwp_date_number"] : v;
|
|
343
|
+
const numberPart = `${s(owmwp["owmwp_month"])}-${s(owmwp["owmwp_day"])}`;
|
|
344
|
+
return { first_number: numberPart, edition: new NistEdition({ type: "e", id: s(owmwp["owmwp_year"]) }) };
|
|
345
|
+
}
|
|
346
|
+
// The polymorphic number wrappers split per branch in the grammar
|
|
347
|
+
// (asme's designator/designator_code pattern): first_number /
|
|
348
|
+
// second_number arrive over the bare branches, first_number_composite /
|
|
349
|
+
// second_number_composite (raw) over the branches carrying inner
|
|
350
|
+
// captures. The composite keys map onto the same dispatch.
|
|
351
|
+
case "first_number":
|
|
352
|
+
case "first_number_composite":
|
|
353
|
+
return castNumber("first_number", value, h, policy);
|
|
354
|
+
case "second_number":
|
|
355
|
+
case "second_number_composite":
|
|
356
|
+
return castNumber("second_number", value, h, policy);
|
|
357
|
+
case "crpl_range": {
|
|
358
|
+
const strValue = s(value);
|
|
359
|
+
if (strValue === undefined)
|
|
360
|
+
return undefined;
|
|
361
|
+
let m = /^(\d+)_(\d+-\d+)([A-Z])$/.exec(strValue);
|
|
362
|
+
if (m !== null) {
|
|
363
|
+
return {
|
|
364
|
+
second_number: m[1],
|
|
365
|
+
part: new NistPart({ type: "pt", value: m[2] }),
|
|
366
|
+
supplement: m[3],
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
m = /^(\d+)_(\d+-\d+)$/.exec(strValue);
|
|
370
|
+
if (m !== null) {
|
|
371
|
+
return { second_number: m[1], part: new NistPart({ type: "pt", value: m[2] }) };
|
|
372
|
+
}
|
|
373
|
+
return { second_number: strValue };
|
|
374
|
+
}
|
|
375
|
+
case "stage": {
|
|
376
|
+
if (!isObj(value))
|
|
377
|
+
return undefined;
|
|
378
|
+
const stageId = (s(value["stage_id"]) ?? "").toLowerCase();
|
|
379
|
+
const stageType = (s(value["stage_type"]) ?? "").toLowerCase();
|
|
380
|
+
if (stageId === "" || stageType === "")
|
|
381
|
+
return undefined;
|
|
382
|
+
return { stage: new NistStage({ id: stageId, type: stageType }) };
|
|
383
|
+
}
|
|
384
|
+
case "stage_id":
|
|
385
|
+
case "stage_type":
|
|
386
|
+
return undefined;
|
|
387
|
+
case "parsed_format": {
|
|
388
|
+
const v = s(value);
|
|
389
|
+
return v === "short" || v === undefined ? undefined : v;
|
|
390
|
+
}
|
|
391
|
+
case "translation": {
|
|
392
|
+
const v = s(value);
|
|
393
|
+
if (v === undefined)
|
|
394
|
+
return undefined;
|
|
395
|
+
const stripped = v.trim();
|
|
396
|
+
const code = TRANSLATION_MAP[stripped.toLowerCase()] ?? stripped.toLowerCase();
|
|
397
|
+
// The gem's Translation#to_s (short) renders the parenthesised
|
|
398
|
+
// suffix — the 1.x corpus shape ("(spa)", pubid#497); the wire
|
|
399
|
+
// serializes that form.
|
|
400
|
+
return { translation_component: new NistTranslation({ code }), translation: `(${code})` };
|
|
401
|
+
}
|
|
402
|
+
case "version": {
|
|
403
|
+
const v = s(value);
|
|
404
|
+
return v === undefined ? undefined : { version_component: new NistVersion({ value: v }) };
|
|
405
|
+
}
|
|
406
|
+
case "update": {
|
|
407
|
+
if (isObj(value)) {
|
|
408
|
+
// Ruby's prefix lookup reads the INNER hash where update_prefix
|
|
409
|
+
// never lands — the prefix is always the slash form.
|
|
410
|
+
const update = new NistUpdate({
|
|
411
|
+
number: s(value["update_number"]),
|
|
412
|
+
year: s(value["update_year"]),
|
|
413
|
+
month: s(value["update_month"]),
|
|
414
|
+
prefix: "slash",
|
|
415
|
+
});
|
|
416
|
+
return { update, update_component: update };
|
|
417
|
+
}
|
|
418
|
+
// Bare "-upd"/"/upd" with no details: Ruby's empty-string branch reads
|
|
419
|
+
// the OUTER hash prefix, so the dash/slash distinction survives here.
|
|
420
|
+
const barePrefix = (s(h["update_prefix"]) ?? "").includes("-") ? "dash" : "slash";
|
|
421
|
+
const update = new NistUpdate({ number: "1", prefix: barePrefix });
|
|
422
|
+
return { update, update_component: update };
|
|
423
|
+
}
|
|
424
|
+
case "update_prefix":
|
|
425
|
+
case "update_number":
|
|
426
|
+
case "update_year":
|
|
427
|
+
case "update_month":
|
|
428
|
+
return undefined;
|
|
429
|
+
case "volume": {
|
|
430
|
+
const v = s(value);
|
|
431
|
+
return v === undefined ? undefined : { volume: new NistVolume({ value: v }) };
|
|
432
|
+
}
|
|
433
|
+
case "section":
|
|
434
|
+
case "appendix":
|
|
435
|
+
case "errata":
|
|
436
|
+
case "index":
|
|
437
|
+
// The component's value is the long form either way (pubid#584):
|
|
438
|
+
// both spellings parse, the render prints the abbreviated indx.
|
|
439
|
+
if (s(value) === "indx")
|
|
440
|
+
return "index";
|
|
441
|
+
return s(value);
|
|
442
|
+
case "insert":
|
|
443
|
+
return s(value);
|
|
444
|
+
case "revision": {
|
|
445
|
+
if (isObj(value) && value["revision_prefix"] !== undefined) {
|
|
446
|
+
const prefix = s(value["revision_prefix"]) ?? "";
|
|
447
|
+
let id = (s(value["revision_id"]) ?? "").trim();
|
|
448
|
+
if (id === "" || id === "r" || id === "R")
|
|
449
|
+
id = "1";
|
|
450
|
+
else {
|
|
451
|
+
const m = /^(\d+[a-z]?)$/.exec(id);
|
|
452
|
+
if (m !== null)
|
|
453
|
+
id = m[1];
|
|
454
|
+
}
|
|
455
|
+
return editionCast("r", id, undefined, prefix);
|
|
456
|
+
}
|
|
457
|
+
const strValue = (s(value) ?? "").trim();
|
|
458
|
+
let revisionId;
|
|
459
|
+
if (strValue === "" || strValue === "r" || strValue === "R")
|
|
460
|
+
revisionId = "1";
|
|
461
|
+
else {
|
|
462
|
+
const m = /^[rR]?(\d+[a-z]?)$/.exec(strValue);
|
|
463
|
+
revisionId = m !== null ? m[1] : strValue;
|
|
464
|
+
}
|
|
465
|
+
return editionCast("r", revisionId);
|
|
466
|
+
}
|
|
467
|
+
case "revision_year": {
|
|
468
|
+
const yearValue = (s(value) ?? "").trim();
|
|
469
|
+
if (h["revision_month"] !== undefined)
|
|
470
|
+
return yearValue;
|
|
471
|
+
return editionCast("r", yearValue);
|
|
472
|
+
}
|
|
473
|
+
case "revision_month":
|
|
474
|
+
return s(value);
|
|
475
|
+
case "supplement_year":
|
|
476
|
+
return s(value) === undefined ? undefined : { supplement: s(value) };
|
|
477
|
+
case "supplement": {
|
|
478
|
+
if (value === undefined)
|
|
479
|
+
return undefined;
|
|
480
|
+
if (Array.isArray(value) && value.length === 0)
|
|
481
|
+
return { supplement: "" };
|
|
482
|
+
const strValue = (s(value) ?? "").trim();
|
|
483
|
+
return strValue === "" ? undefined : { supplement: strValue };
|
|
484
|
+
}
|
|
485
|
+
case "supplement_date_range": {
|
|
486
|
+
if (!isObj(value))
|
|
487
|
+
return undefined;
|
|
488
|
+
const ms = s(value["supp_month_start"]);
|
|
489
|
+
const ys = s(value["supp_year_start"]);
|
|
490
|
+
const me = s(value["supp_month_end"]);
|
|
491
|
+
const ye = s(value["supp_year_end"]);
|
|
492
|
+
return {
|
|
493
|
+
supplement_date_range_start: ms !== undefined && ys !== undefined ? `${ms}${ys}` : undefined,
|
|
494
|
+
supplement_date_range_end: me !== undefined && ye !== undefined ? `${me}${ye}` : undefined,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
case "supplement_date": {
|
|
498
|
+
if (!isObj(value))
|
|
499
|
+
return undefined;
|
|
500
|
+
const month = s(value["supp_month"]);
|
|
501
|
+
const year = s(value["supp_year"]);
|
|
502
|
+
return month !== undefined && year !== undefined ? { supplement: `${month}${year}` } : undefined;
|
|
503
|
+
}
|
|
504
|
+
case "supplement_slash_year": {
|
|
505
|
+
if (!isObj(value))
|
|
506
|
+
return undefined;
|
|
507
|
+
const number = s(value["supp_number"]);
|
|
508
|
+
const year = s(value["supp_year"]);
|
|
509
|
+
return number !== undefined && year !== undefined ? { supplement: `${number}/${year}` } : undefined;
|
|
510
|
+
}
|
|
511
|
+
case "supplement_with_rev":
|
|
512
|
+
return { supplement: "", supplement_has_revision: true };
|
|
513
|
+
case "supp_year":
|
|
514
|
+
return { supplement: s(value) ?? "" };
|
|
515
|
+
case "edition_e":
|
|
516
|
+
return isObj(value) ? editionCast("e", s(value["edition_id"])) : undefined;
|
|
517
|
+
case "edition_r":
|
|
518
|
+
case "edition_r_no_space":
|
|
519
|
+
case "edition_rev":
|
|
520
|
+
return isObj(value) ? editionCast("r", s(value["edition_id"])) : undefined;
|
|
521
|
+
case "edition_r_letter":
|
|
522
|
+
if (!isObj(value))
|
|
523
|
+
return undefined;
|
|
524
|
+
return editionCast("r", s(value["edition_id"]), (s(value["edition_letter"]) ?? "").toLowerCase());
|
|
525
|
+
case "edition_r_letter_only":
|
|
526
|
+
if (!isObj(value))
|
|
527
|
+
return undefined;
|
|
528
|
+
return editionCast("r", (s(value["edition_letter"]) ?? "").toLowerCase());
|
|
529
|
+
case "edition_historical":
|
|
530
|
+
return isObj(value) ? editionCast("-", s(value["edition_id"])) : undefined;
|
|
531
|
+
case "edition_r_with_space_letter":
|
|
532
|
+
case "edition_r_no_space_letter": {
|
|
533
|
+
if (!isObj(value))
|
|
534
|
+
return undefined;
|
|
535
|
+
const id = s(value["edition_id"]);
|
|
536
|
+
const editionLetter = (s(value["edition_letter"]) ?? "").toUpperCase();
|
|
537
|
+
const hasUpdate = h["update_prefix"] !== undefined || h["update"] !== undefined;
|
|
538
|
+
if (hasUpdate)
|
|
539
|
+
return editionCast("r", id, editionLetter);
|
|
540
|
+
return editionCast("r", id, editionLetter, " r");
|
|
541
|
+
}
|
|
542
|
+
case "edition_r_with_space": {
|
|
543
|
+
if (!isObj(value))
|
|
544
|
+
return undefined;
|
|
545
|
+
const id = s(value["edition_id"]);
|
|
546
|
+
const hasUpdate = h["update_prefix"] !== undefined || h["update"] !== undefined;
|
|
547
|
+
if (hasUpdate)
|
|
548
|
+
return editionCast("r", id);
|
|
549
|
+
return editionCast("r", id, undefined, " r");
|
|
550
|
+
}
|
|
551
|
+
case "edition_id":
|
|
552
|
+
case "edition_date":
|
|
553
|
+
case "legacy_edition":
|
|
554
|
+
case "edition_month":
|
|
555
|
+
return undefined;
|
|
556
|
+
case "edition_day":
|
|
557
|
+
return s(value);
|
|
558
|
+
case "edition_dash_year":
|
|
559
|
+
return undefined;
|
|
560
|
+
case "edition_year": {
|
|
561
|
+
const yearValue = s(value);
|
|
562
|
+
if (yearValue === undefined)
|
|
563
|
+
return undefined;
|
|
564
|
+
const monthStr = s(h["edition_month"]);
|
|
565
|
+
const policyHere = seriesPolicy(s(h["series"]));
|
|
566
|
+
if (monthStr !== undefined) {
|
|
567
|
+
const monthNum = MONTH_NUMBERS[monthStr];
|
|
568
|
+
if (monthNum !== undefined) {
|
|
569
|
+
if (!policyHere.modernEditionDate &&
|
|
570
|
+
/^[A-Z][a-z]+/.test(monthStr) &&
|
|
571
|
+
/^\d{4}$/.test(yearValue)) {
|
|
572
|
+
return {
|
|
573
|
+
edition: new NistEdition({ type: "-", id: "", additional_text: `${monthStr}${yearValue}` }),
|
|
574
|
+
edition_year: yearValue,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
let editionId = `${yearValue}${String(monthNum).padStart(2, "0")}`;
|
|
578
|
+
if (policyHere.modernEditionDate && h["edition_day"] !== undefined) {
|
|
579
|
+
const dayNum = Number(s(h["edition_day"]));
|
|
580
|
+
if (dayNum > 0 && dayNum <= 31)
|
|
581
|
+
editionId += `${String(dayNum).padStart(2, "0")}`;
|
|
582
|
+
}
|
|
583
|
+
return { edition: new NistEdition({ type: "e", id: editionId }), edition_year: yearValue };
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return { edition: new NistEdition({ type: "e", id: yearValue }), edition_year: yearValue };
|
|
587
|
+
}
|
|
588
|
+
case "edition_e_date":
|
|
589
|
+
return isObj(value) ? editionCast("e", s(value["edition_date"])) : undefined;
|
|
590
|
+
case "part": {
|
|
591
|
+
const strValue = (s(value) ?? "").trim();
|
|
592
|
+
if (strValue === "")
|
|
593
|
+
return undefined;
|
|
594
|
+
let m = /^(\d+)add(e\d+)$/.exec(strValue);
|
|
595
|
+
if (m !== null)
|
|
596
|
+
return { part: new NistPart({ type: "pt", value: m[1] }), addendum: "true" };
|
|
597
|
+
m = /^(\d+)add/.exec(strValue);
|
|
598
|
+
if (m !== null)
|
|
599
|
+
return { part: new NistPart({ type: "pt", value: m[1] }), addendum: "true" };
|
|
600
|
+
return { part: new NistPart({ type: "pt", value: strValue }) };
|
|
601
|
+
}
|
|
602
|
+
case "edition_letter":
|
|
603
|
+
return s(value);
|
|
604
|
+
case "public_draft":
|
|
605
|
+
return s(value);
|
|
606
|
+
case "draft": {
|
|
607
|
+
const strValue = (s(value) ?? "").trim();
|
|
608
|
+
if (strValue === "")
|
|
609
|
+
return undefined;
|
|
610
|
+
let m = /^\s*-draft\s+(\d+)$/.exec(strValue);
|
|
611
|
+
if (m !== null)
|
|
612
|
+
return { draft_number: m[1] };
|
|
613
|
+
m = /^\s*(\d+)pd$/.exec(strValue);
|
|
614
|
+
if (m !== null)
|
|
615
|
+
return { public_draft: m[1] };
|
|
616
|
+
return strValue;
|
|
617
|
+
}
|
|
618
|
+
case "addendum": {
|
|
619
|
+
if (isObj(value)) {
|
|
620
|
+
const addendumNum = (s(value["addendum_number"]) ?? "").trim();
|
|
621
|
+
return addendumNum !== "" ? { addendum_number: addendumNum } : { addendum: "true" };
|
|
622
|
+
}
|
|
623
|
+
const strValue = (s(value) ?? "").trim();
|
|
624
|
+
return strValue === "" ? { addendum: "true" } : { addendum_number: strValue };
|
|
625
|
+
}
|
|
626
|
+
case "addendum_number":
|
|
627
|
+
return s(value);
|
|
628
|
+
case "supplement_suffix":
|
|
629
|
+
return { supplement: s(value) ?? "" };
|
|
630
|
+
case "date": {
|
|
631
|
+
if (!isObj(value))
|
|
632
|
+
return undefined;
|
|
633
|
+
const month = s(value["date_month"]);
|
|
634
|
+
const year = s(value["date_year"]);
|
|
635
|
+
if (month !== undefined && year !== undefined && value["date_day"] === undefined && /^[A-Za-z]+$/.test(month)) {
|
|
636
|
+
return editionCast("-", undefined, `${month}${year}`);
|
|
637
|
+
}
|
|
638
|
+
return undefined;
|
|
639
|
+
}
|
|
640
|
+
default:
|
|
641
|
+
return isObj(value) ? value : undefined;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function castNumber(type, value, h, policy) {
|
|
645
|
+
if (value === undefined || (s(value) === undefined && !isObj(value)))
|
|
646
|
+
return undefined;
|
|
647
|
+
if (isObj(value)) {
|
|
648
|
+
if (value["owmwp_date_number"] !== undefined) {
|
|
649
|
+
const owmwp = value["owmwp_date_number"];
|
|
650
|
+
const numberPart = `${s(owmwp["owmwp_month"])}-${s(owmwp["owmwp_day"])}`;
|
|
651
|
+
return { [type]: numberPart, edition: new NistEdition({ type: "e", id: s(owmwp["owmwp_year"]) }) };
|
|
652
|
+
}
|
|
653
|
+
if (type === "second_number" && value["number_only"] !== undefined && value["edition_id"] !== undefined) {
|
|
654
|
+
return { second_number: value };
|
|
655
|
+
}
|
|
656
|
+
// The dotted revision spelling ("8278.r1"): fold to the edition,
|
|
657
|
+
// matching the glued "8278r1" canonical — the raw hash must not
|
|
658
|
+
// stringify into the number.
|
|
659
|
+
if (type === "second_number" && value["revision_simple"] !== undefined) {
|
|
660
|
+
const simple = value["revision_simple"];
|
|
661
|
+
const editionId = s(simple["edition_id"]) ?? "";
|
|
662
|
+
return {
|
|
663
|
+
edition: new NistEdition({ type: "r", id: editionId }),
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
if (type === "second_number" && value["revision_letter"] !== undefined) {
|
|
667
|
+
const revisionData = value["revision_letter"];
|
|
668
|
+
const numberOnly = s(revisionData["number_only"]) ?? "";
|
|
669
|
+
const letter = (s(revisionData["letter"]) ?? "").toUpperCase();
|
|
670
|
+
return { second_number: `${numberOnly}r${letter}` };
|
|
671
|
+
}
|
|
672
|
+
if (value["volume_number"] !== undefined && value["issue_number"] !== undefined) {
|
|
673
|
+
return {
|
|
674
|
+
volume: new NistVolume({ value: s(value["volume_number"]) }),
|
|
675
|
+
part: new NistPart({ type: "n", value: s(value["issue_number"]) }),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
if (type === "first_number" && value["number_with_rev_year"] !== undefined) {
|
|
679
|
+
const data = value["number_with_rev_year"];
|
|
680
|
+
return {
|
|
681
|
+
first_number: s(data["number"]),
|
|
682
|
+
edition: new NistEdition({ type: "rv", id: s(data["revision_year"]) }),
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
if (type === "first_number" && value["number_with_letter_revision"] !== undefined) {
|
|
686
|
+
const data = value["number_with_letter_revision"];
|
|
687
|
+
return {
|
|
688
|
+
first_number: s(data["number"]),
|
|
689
|
+
part: new NistPart({ type: "", value: (s(data["letter_suffix"]) ?? "").toUpperCase() }),
|
|
690
|
+
edition: new NistEdition({ type: "r", id: s(data["revision_id"]) }),
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
if (type === "first_number" && value["number"] !== undefined && value["language_code"] !== undefined) {
|
|
694
|
+
const languageCode = (s(value["language_code"]) ?? "").toLowerCase();
|
|
695
|
+
return {
|
|
696
|
+
first_number: s(value["number"]),
|
|
697
|
+
translation_component: new NistTranslation({ code: TRANSLATION_MAP[languageCode] ?? languageCode }),
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
if (type === "first_number" && value["number"] !== undefined && value["part_number"] !== undefined && value["edition_year"] !== undefined) {
|
|
701
|
+
return {
|
|
702
|
+
first_number: s(value["number"]),
|
|
703
|
+
part: new NistPart({ type: "pt", value: s(value["part_number"]) }),
|
|
704
|
+
edition: new NistEdition({ type: "e", id: s(value["edition_year"]) }),
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
if (type === "first_number" && value["number_with_volume"] !== undefined) {
|
|
708
|
+
const data = value["number_with_volume"];
|
|
709
|
+
if (data["volume_suffix"] !== undefined) {
|
|
710
|
+
return {
|
|
711
|
+
first_number: s(data["number"]),
|
|
712
|
+
volume: new NistVolume({ value: s(data["volume_suffix"]) }),
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
const strValue = s(value) ?? "";
|
|
718
|
+
if (type === "first_number") {
|
|
719
|
+
let m;
|
|
720
|
+
if (h["edition_year_separate"] !== undefined && /^(\d+)e(\d+)$/.test(strValue)) {
|
|
721
|
+
m = /^(\d+)e(\d+)$/.exec(strValue);
|
|
722
|
+
return {
|
|
723
|
+
first_number: m[1],
|
|
724
|
+
edition: new NistEdition({ type: "e", id: m[2], additional_text: s(h["edition_year_separate"]) }),
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
if (h["historical_month"] !== undefined && h["historical_year"] !== undefined) {
|
|
728
|
+
const monthPart = s(h["historical_month"]);
|
|
729
|
+
const yearPart = s(h["historical_year"]);
|
|
730
|
+
if (/^\d+$/.test(strValue)) {
|
|
731
|
+
return { first_number: strValue, edition: new NistEdition({ type: "-", additional_text: `${monthPart}${yearPart}` }) };
|
|
732
|
+
}
|
|
733
|
+
return { edition: new NistEdition({ type: "-", additional_text: `${monthPart}${yearPart}` }) };
|
|
734
|
+
}
|
|
735
|
+
if ((m = /^(\d+)supp?$/.exec(strValue)) !== null) {
|
|
736
|
+
if (h["supplement_year"] !== undefined) {
|
|
737
|
+
return { first_number: m[1], supplement: s(h["supplement_year"]) };
|
|
738
|
+
}
|
|
739
|
+
return { first_number: m[1], supplement: "" };
|
|
740
|
+
}
|
|
741
|
+
if ((m = /^(\d+)supprev$/.exec(strValue)) !== null) {
|
|
742
|
+
return { first_number: m[1], supplement: "", supplement_has_revision: true };
|
|
743
|
+
}
|
|
744
|
+
if ((m = /^(\d+)e(\d+)-(\d{4})$/.exec(strValue)) !== null) {
|
|
745
|
+
return { first_number: m[1], edition: new NistEdition({ type: "e", id: m[2], additional_text: m[3] }) };
|
|
746
|
+
}
|
|
747
|
+
if ((m = /^-([A-Za-z]{3,9})(\d{4})$/.exec(strValue)) !== null) {
|
|
748
|
+
return { edition: new NistEdition({ type: "-", additional_text: `${m[1]}${m[2]}` }) };
|
|
749
|
+
}
|
|
750
|
+
if (/^e(\d{3,})$/.test(strValue)) {
|
|
751
|
+
return { first_number: h["second_number"] !== undefined ? strValue : strValue.slice(1) };
|
|
752
|
+
}
|
|
753
|
+
if ((m = /^(\d+)e(\d+)$/.exec(strValue)) !== null && h["second_number"] === undefined && h["edition_dash_year"] === undefined) {
|
|
754
|
+
return { first_number: m[1], edition: new NistEdition({ type: "e", id: m[2] }) };
|
|
755
|
+
}
|
|
756
|
+
// "150-1Ae2009" / "53ar1": letter between the compound number and an
|
|
757
|
+
// edition/revision splits off as a Part component.
|
|
758
|
+
if ((m = /^(\d+-\d+)([A-Z])e(\d{4})$/.exec(strValue)) !== null) {
|
|
759
|
+
return {
|
|
760
|
+
first_number: m[1],
|
|
761
|
+
part: new NistPart({ type: "", value: m[2] }),
|
|
762
|
+
edition: new NistEdition({ type: "e", id: m[3] }),
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
if ((m = /^e(\d{1,2})$/.exec(strValue)) !== null) {
|
|
766
|
+
return { edition: new NistEdition({ type: "e", id: m[1] }) };
|
|
767
|
+
}
|
|
768
|
+
if ((m = /^(\d+)e(\d+)rev(\d{4})$/.exec(strValue)) !== null) {
|
|
769
|
+
return { first_number: m[1], edition: new NistEdition({ type: "e", id: m[2], additional_text: m[3] }) };
|
|
770
|
+
}
|
|
771
|
+
if ((m = /^(\d+)e(\d+)(rev.+)$/.exec(strValue)) !== null) {
|
|
772
|
+
return { first_number: m[1], edition: new NistEdition({ type: "e", id: m[2], additional_text: m[3].replace(/^rev/, "") }) };
|
|
773
|
+
}
|
|
774
|
+
if ((m = /^(\d+)supp([A-Za-z]{3,9})(\d{4})$/.exec(strValue)) !== null) {
|
|
775
|
+
return { first_number: m[1], supplement: `${m[2]}${m[3]}` };
|
|
776
|
+
}
|
|
777
|
+
if ((m = /^(\d+)supp(\d{4})$/.exec(strValue)) !== null) {
|
|
778
|
+
return { first_number: m[1], supplement: m[2] };
|
|
779
|
+
}
|
|
780
|
+
if ((m = /^(\d+)supp-(\d{4})$/.exec(strValue)) !== null) {
|
|
781
|
+
return { first_number: m[1], supplement: m[2] };
|
|
782
|
+
}
|
|
783
|
+
if ((m = /^(\d+)e(\d+)supp$/.exec(strValue)) !== null) {
|
|
784
|
+
return { first_number: m[1], edition: new NistEdition({ type: "e", id: m[2] }), supplement: "" };
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
else if (type === "second_number" && isObj(value) && value["first_number"] !== undefined) {
|
|
788
|
+
const v = value;
|
|
789
|
+
return {
|
|
790
|
+
first_number: s(v["first_number"]),
|
|
791
|
+
part: new NistPart({ value: s(v["part_value"]) ?? "" }),
|
|
792
|
+
edition: new NistEdition({ type: "r", id: s(v["revision_value"]) }),
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
let m;
|
|
796
|
+
if ((m = /^(.+?)pt(\d+)r(\d+[a-z]?)$/.exec(strValue)) !== null) {
|
|
797
|
+
return { [type]: m[1], part: new NistPart({ type: "pt", value: m[2] }), edition: new NistEdition({ type: "r", id: m[3] }) };
|
|
798
|
+
}
|
|
799
|
+
if ((m = /^(.+?)pt(\d+)$/.exec(strValue)) !== null) {
|
|
800
|
+
return { [type]: m[1], part: new NistPart({ type: "pt", value: m[2] }) };
|
|
801
|
+
}
|
|
802
|
+
if ((m = /^(\d+)v(\d+)$/.exec(strValue)) !== null) {
|
|
803
|
+
return { [type]: m[1], volume: m[2] };
|
|
804
|
+
}
|
|
805
|
+
if ((m = /^(.+?)(r\d+\/\d{4})$/i.exec(strValue)) !== null) {
|
|
806
|
+
const rm = /^r(\d+)\/(\d{4})$/.exec(m[2]);
|
|
807
|
+
if (rm !== null) {
|
|
808
|
+
return { [type]: m[1], edition: new NistEdition({ type: "r", id: rm[1], additional_text: rm[2] }) };
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if ((m = /^(.*\d)(r\d{4})$/i.exec(strValue)) !== null) {
|
|
812
|
+
return { [type]: m[1], edition: new NistEdition({ type: "r", id: m[2].slice(1) }) };
|
|
813
|
+
}
|
|
814
|
+
if ((m = /^(.+?)(r[A-Za-z]{3,9}\d{4})$/i.exec(strValue)) !== null) {
|
|
815
|
+
const rm = /^r([A-Za-z]{3,9})(\d{4})$/.exec(m[2]);
|
|
816
|
+
if (rm !== null) {
|
|
817
|
+
return { [type]: m[1], edition: new NistEdition({ type: "r", id: `${rm[1]}${rm[2]}` }) };
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
if ((m = /^(.*\d)(r\d+[a-z]?)$/i.exec(strValue)) !== null) {
|
|
821
|
+
return { [type]: m[1], edition: new NistEdition({ type: "r", id: m[2].slice(1) }) };
|
|
822
|
+
}
|
|
823
|
+
if ((m = /^(.+?)(?<![a-zA-Z])(r)$/i.exec(strValue)) !== null) {
|
|
824
|
+
return { [type]: m[1], edition: new NistEdition({ type: "r", id: "1" }) };
|
|
825
|
+
}
|
|
826
|
+
if ((m = /^(.+?)([A-Z])(r\d+[a-z]?)$/.exec(strValue)) !== null) {
|
|
827
|
+
return {
|
|
828
|
+
[type]: m[1],
|
|
829
|
+
part: new NistPart({ type: "", value: m[2] }),
|
|
830
|
+
edition: new NistEdition({ type: "r", id: m[3].slice(1) }),
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
if ((m = /^(.+?)([A-Z])$/.exec(strValue)) !== null) {
|
|
834
|
+
if (policy.preserveLetterSuffix) {
|
|
835
|
+
return { [type]: strValue };
|
|
836
|
+
}
|
|
837
|
+
return { [type]: m[1], part: new NistPart({ type: "", value: m[2] }) };
|
|
838
|
+
}
|
|
839
|
+
return { [type]: strValue };
|
|
840
|
+
}
|
|
841
|
+
class NistBuilder {
|
|
842
|
+
build(data, parsedFormat) {
|
|
843
|
+
const h = { ...flatten(data) };
|
|
844
|
+
h["parsed_format"] = parsedFormat;
|
|
845
|
+
normalizeParsedHash(h);
|
|
846
|
+
if (h["supplement_date_range"] !== undefined ||
|
|
847
|
+
h["supplement_slash_year"] !== undefined ||
|
|
848
|
+
h["supplement_month_year"] !== undefined ||
|
|
849
|
+
h["supplement_year"] !== undefined ||
|
|
850
|
+
h["supplement"] !== undefined ||
|
|
851
|
+
h["supplement_empty"] !== undefined ||
|
|
852
|
+
// The circ_series route marks the bare "NBS.CIRC.sup" head: the
|
|
853
|
+
// edition-2 grammar cannot carry the zero-width supplement_empty
|
|
854
|
+
// marker the Parslet tree used, so the series wrapper IS the
|
|
855
|
+
// supplement signal.
|
|
856
|
+
h["circ_series"] !== undefined ||
|
|
857
|
+
h["base_portion"] !== undefined) {
|
|
858
|
+
return this.buildCircularSupplement(h);
|
|
859
|
+
}
|
|
860
|
+
const klass = locateIdentifierKlass(h);
|
|
861
|
+
const policy = seriesPolicy(s(h["series"]));
|
|
862
|
+
const identifier = new klass();
|
|
863
|
+
// The default-series plain-number branch (pubid#711): the grammar's
|
|
864
|
+
// trailing alternatives carry no series token ("800-90B" /
|
|
865
|
+
// "NIST 800-90B"), so the identity gains the class's default series
|
|
866
|
+
// and parses == to the spelled "NIST SP 800-90B" form. The bare
|
|
867
|
+
// publisher rides the series-default-publisher fill at the tail
|
|
868
|
+
// (the #704 shape: filled after publisher_was_parsed is recorded,
|
|
869
|
+
// so the bare face keeps rendering bare). The policy stays the
|
|
870
|
+
// series-less Base one — Ruby's Series.for reads parsed_hash, not
|
|
871
|
+
// the filled attribute (SP's own policy is Base anyway).
|
|
872
|
+
if (h["series"] === undefined) {
|
|
873
|
+
const defaultSeries = klass.nistDefaultSeries;
|
|
874
|
+
if (defaultSeries !== undefined) {
|
|
875
|
+
identifier["series"] = new NistCode({ value: defaultSeries });
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
const attrs = {};
|
|
879
|
+
const toEdition = (v) => {
|
|
880
|
+
if (isObj(v)) {
|
|
881
|
+
return new NistEdition({
|
|
882
|
+
type: s(v["type"]),
|
|
883
|
+
id: s(v["id"]),
|
|
884
|
+
additional_text: s(v["additional_text"]),
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
return undefined;
|
|
888
|
+
};
|
|
889
|
+
for (const editionKey of ["edition_with_year", "edition_from_year", "edition"]) {
|
|
890
|
+
if (h[editionKey] !== undefined) {
|
|
891
|
+
const edition = toEdition(h[editionKey]);
|
|
892
|
+
if (edition !== undefined)
|
|
893
|
+
attrs["edition"] = edition;
|
|
894
|
+
delete h[editionKey];
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
const supp = { value: undefined, hasRevision: false, rangeStart: undefined, rangeEnd: undefined, present: false };
|
|
898
|
+
const captureSupplement = (key, value) => {
|
|
899
|
+
if (key === "supplement") {
|
|
900
|
+
supp.value = value === undefined || value === null ? undefined : String(value);
|
|
901
|
+
}
|
|
902
|
+
else if (key === "supplement_has_revision") {
|
|
903
|
+
supp.hasRevision = value === true;
|
|
904
|
+
}
|
|
905
|
+
else if (key === "supplement_date_range_start") {
|
|
906
|
+
supp.rangeStart = s(value);
|
|
907
|
+
}
|
|
908
|
+
else if (key === "supplement_date_range_end") {
|
|
909
|
+
supp.rangeEnd = s(value);
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
supp.present = true;
|
|
915
|
+
return true;
|
|
916
|
+
};
|
|
917
|
+
let firstNum;
|
|
918
|
+
let secondNum;
|
|
919
|
+
let secondNumRaw;
|
|
920
|
+
let decimalNum;
|
|
921
|
+
let letterNum;
|
|
922
|
+
let partNum;
|
|
923
|
+
let extractedRevision;
|
|
924
|
+
const seriesToken = s(h["series"]);
|
|
925
|
+
for (const [key, rawValue] of Object.entries(h)) {
|
|
926
|
+
const realized = cast(key, rawValue, h, policy, seriesToken);
|
|
927
|
+
if (realized === undefined)
|
|
928
|
+
continue;
|
|
929
|
+
if (typeof realized !== "object" || realized === null) {
|
|
930
|
+
if (captureSupplement(key, realized))
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
if (key === "first_number" && typeof realized === "string") {
|
|
934
|
+
firstNum = realized;
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
if (key === "second_number" && typeof realized === "string") {
|
|
938
|
+
secondNum = realized;
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
if (key === "second_number" && isObj(realized) && isObj(realized["second_number"])) {
|
|
942
|
+
secondNumRaw = realized["second_number"];
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
if (key === "crpl_range" && typeof realized === "object" && realized !== null && !Array.isArray(realized)) {
|
|
946
|
+
const rec = realized;
|
|
947
|
+
const sn = rec["second_number"];
|
|
948
|
+
if (typeof sn === "string")
|
|
949
|
+
secondNum = sn;
|
|
950
|
+
if (rec["part"] !== undefined)
|
|
951
|
+
attrs["part"] = rec["part"];
|
|
952
|
+
if (rec["supplement"] !== undefined)
|
|
953
|
+
captureSupplement("supplement", rec["supplement"]);
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
if (key === "part_number") {
|
|
957
|
+
partNum = s(rawValue);
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
if (key === "decimal_number" && isObj(rawValue)) {
|
|
961
|
+
decimalNum = rawValue;
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
if (key === "letter_number" && isObj(rawValue)) {
|
|
965
|
+
letterNum = rawValue;
|
|
966
|
+
if (isObj(realized) && "part" in realized)
|
|
967
|
+
attrs["part"] = realized["part"];
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
if (isObj(realized)) {
|
|
971
|
+
for (const [subKey, subValue] of Object.entries(realized)) {
|
|
972
|
+
if (subKey === "first_number" && typeof subValue === "string") {
|
|
973
|
+
firstNum = subValue;
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
if (subKey === "second_number" && typeof subValue === "string") {
|
|
977
|
+
secondNum = subValue;
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (subKey === "second_number" && isObj(subValue)) {
|
|
981
|
+
secondNumRaw = subValue;
|
|
982
|
+
extractedRevision = "r";
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
if (subKey === "revision") {
|
|
986
|
+
extractedRevision = s(subValue);
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
if (captureSupplement(subKey, subValue))
|
|
990
|
+
continue;
|
|
991
|
+
attrs[subKey] = subValue;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
else {
|
|
995
|
+
attrs[key] = realized;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
Object.assign(identifier, attrs);
|
|
999
|
+
// Compound number construction.
|
|
1000
|
+
const self = identifier;
|
|
1001
|
+
if (firstNum !== undefined && self["number"] === undefined) {
|
|
1002
|
+
if (self["volume"] !== undefined && self["issue_number"] !== undefined) {
|
|
1003
|
+
// v#n# handled as Part during cast.
|
|
1004
|
+
}
|
|
1005
|
+
else if (decimalNum !== undefined) {
|
|
1006
|
+
self["number"] = `${firstNum}-${s(decimalNum["decimal_base"])}.${s(decimalNum["decimal_suffix"])}`;
|
|
1007
|
+
}
|
|
1008
|
+
else if (letterNum !== undefined) {
|
|
1009
|
+
const letterBase = s(letterNum["letter_base"]) ?? "";
|
|
1010
|
+
const letterSuffix = s(letterNum["letter_suffix"]) ?? "";
|
|
1011
|
+
const extra = s(letterNum["letter_suffix_extra"]) ?? "";
|
|
1012
|
+
const full = extra === "" ? letterSuffix : `${letterSuffix}${extra}`;
|
|
1013
|
+
if (policy === seriesPolicy("IR") && full === "R") {
|
|
1014
|
+
self["number"] = `${firstNum}-${letterBase}`;
|
|
1015
|
+
self["edition"] = new NistEdition({ type: "r", id: "1" });
|
|
1016
|
+
}
|
|
1017
|
+
else if (self["part"] !== undefined) {
|
|
1018
|
+
self["number"] = `${firstNum}-${letterBase}`;
|
|
1019
|
+
}
|
|
1020
|
+
else {
|
|
1021
|
+
self["number"] = `${firstNum}-${letterBase}${full}`;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
else if (secondNumRaw !== undefined && secondNumRaw["number_only"] !== undefined && secondNumRaw["edition_id"] !== undefined) {
|
|
1025
|
+
self["number"] = `${firstNum}-${s(secondNumRaw["number_only"])}`;
|
|
1026
|
+
self["edition"] = new NistEdition({ type: "r", id: s(secondNumRaw["edition_id"]) });
|
|
1027
|
+
}
|
|
1028
|
+
else if (secondNum !== undefined) {
|
|
1029
|
+
let m = /^e(\d{3})$/.exec(firstNum);
|
|
1030
|
+
if (m !== null && /^\d{2}$/.test(secondNum)) {
|
|
1031
|
+
self["number"] = m[1];
|
|
1032
|
+
self["edition"] = new NistEdition({ type: "e", id: `19${secondNum}` });
|
|
1033
|
+
}
|
|
1034
|
+
else if ((m = /^(\d+)e(\d+)$/.exec(firstNum)) !== null && /^\d{2,4}$/.test(secondNum)) {
|
|
1035
|
+
let yearPart = secondNum;
|
|
1036
|
+
if (yearPart.length === 2)
|
|
1037
|
+
yearPart = `19${yearPart}`;
|
|
1038
|
+
self["number"] = m[1];
|
|
1039
|
+
self["edition"] = new NistEdition({ type: "e", id: m[2], additional_text: yearPart });
|
|
1040
|
+
}
|
|
1041
|
+
else if ((m = /^(\d+)supp?$/.exec(firstNum)) !== null && /^\d{4}$/.test(secondNum)) {
|
|
1042
|
+
self["number"] = m[1];
|
|
1043
|
+
supp.value = secondNum;
|
|
1044
|
+
supp.present = true;
|
|
1045
|
+
}
|
|
1046
|
+
else if ((m = /^(\d+)supp?$/.exec(secondNum)) !== null) {
|
|
1047
|
+
self["number"] = `${firstNum}-${m[1]}`;
|
|
1048
|
+
supp.value = "";
|
|
1049
|
+
supp.present = true;
|
|
1050
|
+
}
|
|
1051
|
+
else if (klass === classForKind("technical-note") && /^(19|20)\d{2}$/.test(secondNum)) {
|
|
1052
|
+
self["number"] = firstNum;
|
|
1053
|
+
self["edition"] = new NistEdition({ type: "e", id: secondNum });
|
|
1054
|
+
self["edition_year"] = secondNum;
|
|
1055
|
+
}
|
|
1056
|
+
else if (partNum !== undefined && policy.partNumAsComponent) {
|
|
1057
|
+
self["part"] = new NistPart({ type: "pt", value: partNum });
|
|
1058
|
+
self["number"] = `${firstNum}-${secondNum}`;
|
|
1059
|
+
}
|
|
1060
|
+
else {
|
|
1061
|
+
let compound = `${firstNum}-${secondNum}`;
|
|
1062
|
+
if (partNum !== undefined)
|
|
1063
|
+
compound += `-${partNum}`;
|
|
1064
|
+
self["number"] = compound;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
else {
|
|
1068
|
+
self["number"] = firstNum;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (extractedRevision !== undefined && extractedRevision !== "r" && self["edition"] === undefined) {
|
|
1072
|
+
self["edition"] = new NistEdition({ type: "r", id: extractedRevision });
|
|
1073
|
+
}
|
|
1074
|
+
// SP subseries metadata.
|
|
1075
|
+
if (klass === classForKind("special-publication") && firstNum !== undefined) {
|
|
1076
|
+
if (SP_SUBSERIES.includes(firstNum)) {
|
|
1077
|
+
self["subseries"] = new NistCode({ value: firstNum });
|
|
1078
|
+
}
|
|
1079
|
+
else {
|
|
1080
|
+
const m = /^(\d+GB)\b/.exec(firstNum);
|
|
1081
|
+
if (m !== null && SP_SUBSERIES.includes(m[1])) {
|
|
1082
|
+
self["subseries"] = new NistCode({ value: m[1] });
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
// IR reverses the "84e2946" form back to "84-2946".
|
|
1087
|
+
if (policy === seriesPolicy("IR") && typeof self["number"] === "string") {
|
|
1088
|
+
const m = /^(\d+)e(\d{4})$/.exec(self["number"]);
|
|
1089
|
+
if (m !== null) {
|
|
1090
|
+
self["number"] = `${m[1]}-${m[2]}`;
|
|
1091
|
+
self["edition"] = undefined;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
if (self["publisher"] === undefined) {
|
|
1095
|
+
self["publisher_was_parsed"] = false;
|
|
1096
|
+
}
|
|
1097
|
+
// TN bare "-upd": Ruby's TechnicalNote#update_component= replaces a
|
|
1098
|
+
// dash-prefix update that has no year with the default Feb-2021 update.
|
|
1099
|
+
const tnSeriesCode = identifier.seriesCode?.();
|
|
1100
|
+
const bareUpdate = self["update_component"] instanceof NistUpdate ? self["update_component"] : undefined;
|
|
1101
|
+
if (tnSeriesCode === "TN" && bareUpdate !== undefined && bareUpdate.prefix === "dash" && bareUpdate.year === undefined) {
|
|
1102
|
+
const defaulted = new NistUpdate({
|
|
1103
|
+
number: bareUpdate.number ?? "1",
|
|
1104
|
+
year: "2021",
|
|
1105
|
+
month: "02",
|
|
1106
|
+
prefix: "slash",
|
|
1107
|
+
});
|
|
1108
|
+
self["update_component"] = defaulted;
|
|
1109
|
+
self["update"] = defaulted;
|
|
1110
|
+
}
|
|
1111
|
+
// Revision with month+year → update component (V1 compatibility).
|
|
1112
|
+
if (h["revision_month"] !== undefined && h["revision_year"] !== undefined) {
|
|
1113
|
+
const monthNum = MONTH_NUMBERS[s(h["revision_month"]) ?? ""] ?? 1;
|
|
1114
|
+
const update = new NistUpdate({
|
|
1115
|
+
number: "1",
|
|
1116
|
+
year: s(h["revision_year"]),
|
|
1117
|
+
month: String(monthNum).padStart(2, "0"),
|
|
1118
|
+
prefix: "slash",
|
|
1119
|
+
});
|
|
1120
|
+
self["update_component"] = update;
|
|
1121
|
+
self["update"] = update;
|
|
1122
|
+
self["revision_year"] = undefined;
|
|
1123
|
+
self["revision_month"] = undefined;
|
|
1124
|
+
}
|
|
1125
|
+
if ((supp.present || supp.hasRevision) && "supplement" in identifier.constructor.attributes) {
|
|
1126
|
+
if (supp.rangeStart !== undefined || supp.rangeEnd !== undefined) {
|
|
1127
|
+
const component = {};
|
|
1128
|
+
const sm = /^([A-Za-z]{3,9})?(\d{4})$/.exec(supp.rangeStart ?? "");
|
|
1129
|
+
if (supp.rangeStart !== undefined && sm !== null) {
|
|
1130
|
+
component["month"] = sm[1];
|
|
1131
|
+
component["year"] = sm[2];
|
|
1132
|
+
}
|
|
1133
|
+
const em = /^([A-Za-z]{3,9})?(\d{4})$/.exec(supp.rangeEnd ?? "");
|
|
1134
|
+
if (supp.rangeEnd !== undefined && em !== null) {
|
|
1135
|
+
component["month_end"] = em[1];
|
|
1136
|
+
component["year_end"] = em[2];
|
|
1137
|
+
}
|
|
1138
|
+
self["supplement"] = new NistSupplement(component);
|
|
1139
|
+
}
|
|
1140
|
+
else {
|
|
1141
|
+
self["supplement"] = NistSupplement.fromRaw(supp.value, supp.hasRevision);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
// apply_series_default_publisher (the #704 rule): a series that
|
|
1145
|
+
// implies its publisher (bare "FIPS 197" is "NIST FIPS 197"; bare
|
|
1146
|
+
// "800-90B" is "NIST SP 800-90B" — pubid#712) gets it now, after the
|
|
1147
|
+
// publisher_was_parsed: false above, so the two spellings are ==
|
|
1148
|
+
// while the bare face keeps rendering bare (the printed-publisher
|
|
1149
|
+
// views read the flag, not the filled value). Runs only when the
|
|
1150
|
+
// publisher is absent AND unspelled — at this point that is exactly
|
|
1151
|
+
// `publisher === undefined` (the flag was recorded false above iff
|
|
1152
|
+
// no publisher was parsed).
|
|
1153
|
+
if (self["publisher"] === undefined) {
|
|
1154
|
+
const defaultPublisher = identifier.constructor.nistDefaultPublisher;
|
|
1155
|
+
if (defaultPublisher !== undefined && defaultPublisher !== "") {
|
|
1156
|
+
self["publisher"] = defaultPublisher;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return identifier;
|
|
1160
|
+
}
|
|
1161
|
+
buildCircularSupplement(h) {
|
|
1162
|
+
if (isObj(h["supplement_slash_year"]) || isObj(h["implicit_supplement"])) {
|
|
1163
|
+
return this.buildCircularSupplementWrapper(h);
|
|
1164
|
+
}
|
|
1165
|
+
const seriesValue = isObj(h["circ_series"]) ? s(h["circ_series"]["series"]) : s(h["series"]);
|
|
1166
|
+
// The dotted series literal ("NBS.CIRC") names its publisher in the
|
|
1167
|
+
// first token; the builder default would render "NIST" instead.
|
|
1168
|
+
const seriesPublisher = seriesValue?.startsWith("NBS") ? "NBS" : undefined;
|
|
1169
|
+
if (isObj(h["supplement_date_range"])) {
|
|
1170
|
+
const range = h["supplement_date_range"];
|
|
1171
|
+
const identifier = this.build({ series: seriesValue, publisher: seriesPublisher }, "short");
|
|
1172
|
+
const ms = s(range["supp_month_start"]);
|
|
1173
|
+
const ys = s(range["supp_year_start"]);
|
|
1174
|
+
const me = s(range["supp_month_end"]);
|
|
1175
|
+
const ye = s(range["supp_year_end"]);
|
|
1176
|
+
identifier["supplement"] = new NistSupplement({
|
|
1177
|
+
month: ms,
|
|
1178
|
+
year: ys,
|
|
1179
|
+
month_end: me,
|
|
1180
|
+
year_end: ye,
|
|
1181
|
+
});
|
|
1182
|
+
return identifier;
|
|
1183
|
+
}
|
|
1184
|
+
const base = this.buildCircularSupplementBase(h, seriesValue, seriesPublisher);
|
|
1185
|
+
const self = base;
|
|
1186
|
+
const raw = h["supplement_month_year"] !== undefined
|
|
1187
|
+
? s(h["supplement_month_year"])
|
|
1188
|
+
: h["supplement_year"] !== undefined
|
|
1189
|
+
? s(h["supplement_year"])
|
|
1190
|
+
: "";
|
|
1191
|
+
self["supplement"] = NistSupplement.fromRaw(raw);
|
|
1192
|
+
return base;
|
|
1193
|
+
}
|
|
1194
|
+
buildCircularSupplementBase(h, seriesValue, seriesPublisher) {
|
|
1195
|
+
const basePortion = h["base_portion"];
|
|
1196
|
+
if (!isObj(basePortion)) {
|
|
1197
|
+
return this.build({
|
|
1198
|
+
publisher: s(h["publisher"]) ?? seriesPublisher,
|
|
1199
|
+
series: seriesValue ?? s(h["series"]),
|
|
1200
|
+
first_number: s(h["first_number"]),
|
|
1201
|
+
}, s(h["parsed_format"]) ?? "short");
|
|
1202
|
+
}
|
|
1203
|
+
const baseNumber = s(basePortion["simple_number"]) ?? s(basePortion["base_number"]);
|
|
1204
|
+
let letterSuffix;
|
|
1205
|
+
if (basePortion["letter_suffix"] !== undefined) {
|
|
1206
|
+
letterSuffix = (s(basePortion["letter_suffix"]) ?? "").toUpperCase();
|
|
1207
|
+
}
|
|
1208
|
+
let publisherValue;
|
|
1209
|
+
if (isObj(h["circ_series"]) && h["circ_series"]["series"] !== undefined) {
|
|
1210
|
+
const seriesStr = s(h["circ_series"]["series"]) ?? "";
|
|
1211
|
+
if (seriesStr.includes(" "))
|
|
1212
|
+
publisherValue = seriesStr.split(" ")[0];
|
|
1213
|
+
}
|
|
1214
|
+
const hasEdition = basePortion["edition_number"] !== undefined;
|
|
1215
|
+
let baseNumberWithSuffix = baseNumber ?? "";
|
|
1216
|
+
if (letterSuffix !== undefined)
|
|
1217
|
+
baseNumberWithSuffix += letterSuffix;
|
|
1218
|
+
if (hasEdition)
|
|
1219
|
+
baseNumberWithSuffix += `e${s(basePortion["edition_number"])}`;
|
|
1220
|
+
const baseHash = {
|
|
1221
|
+
series: seriesValue,
|
|
1222
|
+
first_number: baseNumberWithSuffix,
|
|
1223
|
+
};
|
|
1224
|
+
if (publisherValue !== undefined)
|
|
1225
|
+
baseHash["publisher"] = publisherValue;
|
|
1226
|
+
if (hasEdition)
|
|
1227
|
+
baseHash["edition_e"] = { edition_id: s(basePortion["edition_number"]) };
|
|
1228
|
+
return this.build(baseHash, s(h["parsed_format"]) ?? "short");
|
|
1229
|
+
}
|
|
1230
|
+
buildCircularSupplementWrapper(h) {
|
|
1231
|
+
const klass = classForKind("circular-supplement");
|
|
1232
|
+
const supplement = new klass();
|
|
1233
|
+
const self = supplement;
|
|
1234
|
+
const seriesValue = isObj(h["circ_series"])
|
|
1235
|
+
? s(h["circ_series"]["series"])
|
|
1236
|
+
: s(h["series"]);
|
|
1237
|
+
if (isObj(h["supplement_date_range"])) {
|
|
1238
|
+
const range = h["supplement_date_range"];
|
|
1239
|
+
const ms = s(range["supp_month_start"]);
|
|
1240
|
+
const ys = s(range["supp_year_start"]);
|
|
1241
|
+
const me = s(range["supp_month_end"]);
|
|
1242
|
+
const ye = s(range["supp_year_end"]);
|
|
1243
|
+
if (ms !== undefined && ys !== undefined)
|
|
1244
|
+
self["supplement_date_range_start"] = `${ms}${ys}`;
|
|
1245
|
+
if (me !== undefined && ye !== undefined)
|
|
1246
|
+
self["supplement_date_range_end"] = `${me}${ye}`;
|
|
1247
|
+
return supplement;
|
|
1248
|
+
}
|
|
1249
|
+
if (isObj(h["base_portion"])) {
|
|
1250
|
+
const basePortion = h["base_portion"];
|
|
1251
|
+
const baseNumber = s(basePortion["simple_number"]) ?? s(basePortion["base_number"]);
|
|
1252
|
+
let letterSuffix;
|
|
1253
|
+
if (basePortion["letter_suffix"] !== undefined) {
|
|
1254
|
+
letterSuffix = (s(basePortion["letter_suffix"]) ?? "").toUpperCase();
|
|
1255
|
+
}
|
|
1256
|
+
let publisherValue;
|
|
1257
|
+
if (isObj(h["circ_series"]) && h["circ_series"]["series"] !== undefined) {
|
|
1258
|
+
const seriesStr = s(h["circ_series"]["series"]) ?? "";
|
|
1259
|
+
if (seriesStr.includes(" "))
|
|
1260
|
+
publisherValue = seriesStr.split(" ")[0];
|
|
1261
|
+
}
|
|
1262
|
+
const hasRevision = basePortion["revision_letter"] !== undefined && basePortion["revision_number"] !== undefined;
|
|
1263
|
+
const hasEdition = basePortion["edition_number"] !== undefined;
|
|
1264
|
+
let baseNumberWithSuffix = baseNumber ?? "";
|
|
1265
|
+
if (letterSuffix !== undefined)
|
|
1266
|
+
baseNumberWithSuffix += letterSuffix;
|
|
1267
|
+
if (hasEdition)
|
|
1268
|
+
baseNumberWithSuffix += `e${s(basePortion["edition_number"])}`;
|
|
1269
|
+
const baseHash = { series: seriesValue, first_number: baseNumberWithSuffix };
|
|
1270
|
+
if (publisherValue !== undefined)
|
|
1271
|
+
baseHash["publisher"] = publisherValue;
|
|
1272
|
+
if (hasEdition)
|
|
1273
|
+
baseHash["edition_e"] = { edition_id: s(basePortion["edition_number"]) };
|
|
1274
|
+
self["base"] = this.build(baseHash, s(h["parsed_format"]) ?? "short");
|
|
1275
|
+
if (hasRevision && isObj(h["implicit_supplement"])) {
|
|
1276
|
+
const revisionNumber = s(basePortion["revision_number"]) ?? "";
|
|
1277
|
+
const supplementYear = s(h["implicit_supplement"]["implicit_supplement_year"]) ?? "";
|
|
1278
|
+
self["update"] = new NistUpdate({ number: "1", year: `${supplementYear}${revisionNumber}`, prefix: "slash" });
|
|
1279
|
+
self["implicit_supplement"] = true;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
else if (h["first_number"] !== undefined) {
|
|
1283
|
+
self["base"] = this.build({
|
|
1284
|
+
publisher: s(h["publisher"]),
|
|
1285
|
+
series: seriesValue ?? s(h["series"]),
|
|
1286
|
+
first_number: s(h["first_number"]),
|
|
1287
|
+
}, s(h["parsed_format"]) ?? "short");
|
|
1288
|
+
}
|
|
1289
|
+
if (h["supplement_month_year"] !== undefined) {
|
|
1290
|
+
self["edition"] = new NistEdition({ type: "s", id: s(h["supplement_month_year"]) });
|
|
1291
|
+
}
|
|
1292
|
+
else if (h["supplement_year"] !== undefined) {
|
|
1293
|
+
self["edition"] = new NistEdition({ type: "s", id: s(h["supplement_year"]) });
|
|
1294
|
+
}
|
|
1295
|
+
else if (isObj(h["supplement_slash_year"])) {
|
|
1296
|
+
const suppHash = h["supplement_slash_year"];
|
|
1297
|
+
const suppNumber = s(suppHash["supp_number"]) ?? "";
|
|
1298
|
+
const suppYear = s(suppHash["supp_year"]) ?? "";
|
|
1299
|
+
self["update"] = new NistUpdate({ number: "1", year: `${suppYear}${suppNumber.padStart(2, "0")}`, prefix: "slash" });
|
|
1300
|
+
}
|
|
1301
|
+
return supplement;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
export function makeNistGrammarImplementation(deps) {
|
|
1305
|
+
const builder = new NistBuilder();
|
|
1306
|
+
return {
|
|
1307
|
+
parse(input) {
|
|
1308
|
+
const { cleaned, format } = preprocessNist(input);
|
|
1309
|
+
const base = cleaned.replace(/\s*\(all parts\)\s*$/, "");
|
|
1310
|
+
const tree = toBuilderTree(deps.parseShape(base));
|
|
1311
|
+
// The reference's language_code rule captures its separator with
|
|
1312
|
+
// the code (".uppl"); the baked nist artifact labels the code
|
|
1313
|
+
// alone. Restore the reference's slice for a trailing dot-prefixed
|
|
1314
|
+
// code, so the renderer prints the canonical double-dot face
|
|
1315
|
+
// ("NIST.SP.955-S..uppl").
|
|
1316
|
+
const dotted = /\.([a-z]{2,4})$/.exec(base);
|
|
1317
|
+
if (dotted && tree["translation"] === dotted[1]) {
|
|
1318
|
+
tree["translation"] = `.${dotted[1]}`;
|
|
1319
|
+
}
|
|
1320
|
+
const marked = base !== cleaned
|
|
1321
|
+
? { ...tree, all_parts: true }
|
|
1322
|
+
: tree;
|
|
1323
|
+
return builder.build(marked, format);
|
|
1324
|
+
},
|
|
1325
|
+
};
|
|
1326
|
+
}
|