@pubid/pubid 0.1.57 → 0.1.59
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/dist/flavors/ansi/index.d.ts +1 -22
- package/dist/flavors/ansi/index.js +106 -132
- package/dist/flavors/ansi/model.d.ts +60 -0
- package/dist/flavors/ansi/model.js +107 -0
- package/dist/flavors/arxiv/index.d.ts +3 -0
- package/dist/flavors/arxiv/index.js +105 -0
- package/dist/flavors/arxiv/model.d.ts +51 -0
- package/dist/flavors/arxiv/model.js +79 -0
- package/dist/flavors/eu/index.d.ts +3 -0
- package/dist/flavors/eu/index.js +113 -0
- package/dist/flavors/eu/model.d.ts +108 -0
- package/dist/flavors/eu/model.js +155 -0
- package/dist/flavors/gost/index.js +2 -2
- package/dist/flavors/index.js +9 -0
- package/dist/flavors/jis/index.js +9 -0
- package/dist/flavors/register-types.d.ts +4 -1
- package/dist/flavors/register-types.js +4 -1
- package/dist/flavors/wmo/index.d.ts +3 -0
- package/dist/flavors/wmo/index.js +47 -0
- package/dist/flavors/wmo/model.d.ts +82 -0
- package/dist/flavors/wmo/model.js +135 -0
- package/dist/model/subset-match.d.ts +10 -1
- package/dist/model/subset-match.js +35 -1
- package/dist/pubid-urn/schemas/ansi.js +3 -0
- package/dist/pubid-urn/schemas/arxiv.d.ts +8 -0
- package/dist/pubid-urn/schemas/arxiv.js +15 -0
- package/dist/pubid-urn/schemas/eu.d.ts +8 -0
- package/dist/pubid-urn/schemas/eu.js +15 -0
- package/dist/pubid-urn/schemas/index.js +6 -0
- package/dist/pubid-urn/schemas/wmo.d.ts +8 -0
- package/dist/pubid-urn/schemas/wmo.js +16 -0
- package/dist/urn/parsers.js +76 -0
- package/package.json +1 -1
- package/vendor/parg/ansi.json +1 -1
- package/vendor/parg/arxiv.json +1 -0
- package/vendor/parg/bsi_pfs.json +1 -1
- package/vendor/parg/csv.json +1 -1
- package/vendor/parg/eu.json +1 -0
- package/vendor/parg/ini.json +1 -1
- package/vendor/parg/itu.json +1 -1
- package/vendor/parg/json.json +1 -1
- package/vendor/parg/lua.json +1 -0
- package/vendor/parg/toml.json +1 -0
- package/vendor/parg/wmo.json +1 -0
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
import { Grammar } from "../../grammar/engine.js";
|
|
2
1
|
import type { FlavorImplementation } from "../../conformance/implementation.js";
|
|
3
|
-
|
|
4
|
-
import { BaseUrnGenerator } from "../../model/urn-generator.js";
|
|
5
|
-
import { Publisher, Language } from "../../model/component.js";
|
|
6
|
-
export declare const ansiGrammar: Grammar;
|
|
7
|
-
declare class AnsiUrnGenerator extends BaseUrnGenerator<AnsiIdentifier> {
|
|
8
|
-
generate(): string;
|
|
9
|
-
}
|
|
10
|
-
export declare class AnsiIdentifier extends BaseIdentifier {
|
|
11
|
-
static polymorphicName: string;
|
|
12
|
-
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
13
|
-
static mappings: import("../../model/attribute.js").FieldMapping[];
|
|
14
|
-
static urnGenerator: typeof AnsiUrnGenerator;
|
|
15
|
-
readonly number: string;
|
|
16
|
-
readonly part: string | undefined;
|
|
17
|
-
readonly year: string | undefined;
|
|
18
|
-
readonly publisher: Publisher;
|
|
19
|
-
readonly copublishers: Publisher[];
|
|
20
|
-
readonly languages: Language[];
|
|
21
|
-
render(): string;
|
|
22
|
-
}
|
|
2
|
+
export * from "./model.js";
|
|
23
3
|
export declare function ansiGrammarImplementation(): FlavorImplementation;
|
|
24
|
-
export {};
|
|
@@ -1,147 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { BaseBuilder } from "../../model/builder.js";
|
|
7
|
-
import { Publisher, Language } from "../../model/component.js";
|
|
1
|
+
import { ParseFailed } from "../../grammar/engine.js";
|
|
2
|
+
import { PubidRuntime } from "../../parg/runtime.js";
|
|
3
|
+
import { Publisher, PubidDate, Language } from "../../model/component.js";
|
|
4
|
+
import { AnsiStandard } from "./model.js";
|
|
5
|
+
export * from "./model.js";
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
10
|
-
* (
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* The ansi parse entry — the same baked artifact the Ruby flavor runs
|
|
8
|
+
* (pubid data/parg/ansi.json, sealed at parsanol 1.5.1.0; the gem's
|
|
9
|
+
* artifact runs AHEAD of the pubid-grammar checkout, the known
|
|
10
|
+
* artifact-ahead-of-source drift), loaded through the artifact runtime.
|
|
11
|
+
* The builder mirrors Pubid::Ansi::Builder: the grammar checks the
|
|
12
|
+
* shape, this side splits the number group on dashes and reclassifies a
|
|
13
|
+
* trailing dash-year.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.repeat(2, Infinity)
|
|
39
|
-
.then(str(",").maybe())
|
|
40
|
-
.repeat(0, Infinity)
|
|
41
|
-
.as("languages"), str(")")));
|
|
42
|
-
rule("identifier_with_copublishers", () => str("ANSI")
|
|
43
|
-
.as("publisher")
|
|
44
|
-
.then(rules["copublishers"], space, rules["std_keyword"])
|
|
45
|
-
.then(rules["number_with_part"])
|
|
46
|
-
.then(rules["date"].maybe())
|
|
47
|
-
.then(rules["language"].maybe()));
|
|
48
|
-
rule("identifier_sole", () => str("ANSI")
|
|
49
|
-
.as("publisher")
|
|
50
|
-
.then(space, rules["std_keyword"], rules["number_with_part"])
|
|
51
|
-
.then(rules["date"].maybe())
|
|
52
|
-
.then(rules["language"].maybe()));
|
|
53
|
-
rule("identifier", () => rules["identifier_with_copublishers"].or(rules["identifier_sole"]));
|
|
54
|
-
rule("root", () => rules["identifier"]);
|
|
55
|
-
return rules;
|
|
56
|
-
}
|
|
57
|
-
export const ansiGrammar = { rules: buildRules(), root: "root" };
|
|
58
|
-
class AnsiUrnGenerator extends BaseUrnGenerator {
|
|
59
|
-
generate() {
|
|
60
|
-
const id = this.identifier;
|
|
61
|
-
const parts = ["urn", "ansi", id.number];
|
|
62
|
-
if (id.part !== undefined)
|
|
63
|
-
parts.push(`-${id.part}`);
|
|
64
|
-
if (id.year !== undefined)
|
|
65
|
-
parts.push(id.year);
|
|
66
|
-
if (id.copublishers.length > 0) {
|
|
67
|
-
parts[1] = ["ansi", ...id.copublishers.map((c) => c.body.toLowerCase())].join("-");
|
|
68
|
-
}
|
|
69
|
-
if (id.languages.length > 0) {
|
|
70
|
-
parts.push(id.languages.map((l) => l.code).join(","));
|
|
71
|
-
}
|
|
72
|
-
return parts.join(":");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export class AnsiIdentifier extends BaseIdentifier {
|
|
76
|
-
static polymorphicName = "pubid:ansi:standard";
|
|
77
|
-
static attributes = extendAttributes(BaseIdentifier, {
|
|
78
|
-
number: { type: "string" },
|
|
79
|
-
part: { type: "string" },
|
|
80
|
-
year: { type: "string" },
|
|
81
|
-
copublishers: { type: Publisher, collection: true, initializeEmpty: true },
|
|
82
|
-
languages: { type: Language, collection: true, initializeEmpty: true },
|
|
83
|
-
});
|
|
84
|
-
static mappings = keyValue({ wire: "number", to: "number" }, { wire: "part", to: "part" }, { wire: "year", to: "year" }, { wire: "publisher", to: "publisher" }, { wire: "copublishers", to: "copublishers" }, { wire: "languages", to: "languages" });
|
|
85
|
-
static urnGenerator = AnsiUrnGenerator;
|
|
86
|
-
render() {
|
|
87
|
-
const publisherPortion = this.copublishers.length > 0
|
|
88
|
-
? [this.publisher.body, ...this.copublishers.map((p) => p.body)].join("/")
|
|
89
|
-
: this.publisher.body;
|
|
90
|
-
let numberPortion = this.number;
|
|
91
|
-
if (this.part !== undefined)
|
|
92
|
-
numberPortion += `-${this.part}`;
|
|
93
|
-
if (this.year !== undefined)
|
|
94
|
-
numberPortion += `:${this.year}`;
|
|
95
|
-
let result = `${publisherPortion} ${numberPortion}`;
|
|
96
|
-
if (this.languages.length > 0)
|
|
97
|
-
result += `(${this.languages.map((l) => l.code).join(",")})`;
|
|
98
|
-
return result;
|
|
15
|
+
// --- Builder (lib/pubid/ansi/builder.rb) -------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* A trailing "-" + 4 digits (19xx/20xx) is the publication year, not a
|
|
18
|
+
* part: "ANSI X9.62-2005" (relaton#45). Only when no ":YYYY" follows,
|
|
19
|
+
* so the part of "ANSI X9.8-1:2007" stays a part.
|
|
20
|
+
*/
|
|
21
|
+
const DASH_YEAR = /^(?:19|20)\d{2}$/;
|
|
22
|
+
/**
|
|
23
|
+
* Ruby Builder split_number_with_part: a third dash group is always the
|
|
24
|
+
* year ("ANSI/ISA-61511-1-2018") — the grammar admits only a 19xx/20xx
|
|
25
|
+
* group there. At most one part group reaches the tree, so three
|
|
26
|
+
* segments is the maximum.
|
|
27
|
+
*/
|
|
28
|
+
function splitNumberWithPart(value) {
|
|
29
|
+
const segments = value.split("-");
|
|
30
|
+
const [number, part, dashYear] = segments;
|
|
31
|
+
const attrs = {};
|
|
32
|
+
if (number !== undefined)
|
|
33
|
+
attrs["number"] = number;
|
|
34
|
+
if (part !== undefined)
|
|
35
|
+
attrs["part"] = part;
|
|
36
|
+
if (dashYear !== undefined) {
|
|
37
|
+
attrs["date"] = new PubidDate({ year: dashYear });
|
|
38
|
+
attrs["date_separator"] = "-";
|
|
99
39
|
}
|
|
40
|
+
return attrs;
|
|
100
41
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
42
|
+
/**
|
|
43
|
+
* read_dash_year: a trailing "-" + 4 digits is the publication year,
|
|
44
|
+
* not a part — unless a date or a revision already claimed the slot (a
|
|
45
|
+
* revision follows the part, so "568-2009-D" keeps 2009 as a part:
|
|
46
|
+
* read as a year, it would render after the revision).
|
|
47
|
+
*/
|
|
48
|
+
function readDashYear(identifier) {
|
|
49
|
+
const record = identifier;
|
|
50
|
+
if (record["date"] !== undefined || record["revision"] !== undefined)
|
|
51
|
+
return;
|
|
52
|
+
const part = record["part"];
|
|
53
|
+
if (typeof part !== "string" || !DASH_YEAR.test(part))
|
|
54
|
+
return;
|
|
55
|
+
record["date"] = new PubidDate({ year: part });
|
|
56
|
+
record["date_separator"] = "-";
|
|
57
|
+
record["part"] = undefined;
|
|
110
58
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
59
|
+
function buildAnsi(data) {
|
|
60
|
+
const attrs = {};
|
|
61
|
+
for (const [key, value] of Object.entries(data)) {
|
|
62
|
+
if (value === undefined || value === null)
|
|
63
|
+
continue;
|
|
64
|
+
switch (key) {
|
|
65
|
+
case "publisher":
|
|
66
|
+
attrs["publisher"] = new Publisher({ body: String(value) });
|
|
67
|
+
break;
|
|
68
|
+
case "std_keyword":
|
|
69
|
+
// Consumed and dropped: no identifier attribute reads it.
|
|
70
|
+
break;
|
|
71
|
+
case "copublishers": {
|
|
72
|
+
const list = Array.isArray(value) ? value : [value];
|
|
73
|
+
if (list.length === 0)
|
|
74
|
+
break;
|
|
75
|
+
attrs["copublishers"] = list.map((entry) => {
|
|
76
|
+
const body = typeof entry === "object" && entry !== null && "copublisher" in entry
|
|
77
|
+
? String(entry["copublisher"])
|
|
78
|
+
: String(entry);
|
|
79
|
+
return new Publisher({ body });
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "number_with_part":
|
|
84
|
+
Object.assign(attrs, splitNumberWithPart(String(value)));
|
|
85
|
+
break;
|
|
86
|
+
case "number_separator":
|
|
87
|
+
case "revision":
|
|
88
|
+
attrs[key] = String(value);
|
|
89
|
+
break;
|
|
90
|
+
case "date":
|
|
91
|
+
attrs["date"] = new PubidDate({ year: String(value) });
|
|
92
|
+
break;
|
|
93
|
+
case "languages":
|
|
94
|
+
attrs["languages"] = String(value)
|
|
95
|
+
.split(",")
|
|
96
|
+
.map((lang) => new Language({ code: lang.trim() }));
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
// Unknown captures raise in the Ruby builder; the grammar binds
|
|
100
|
+
// exactly the keys above, so this is unreachable today.
|
|
101
|
+
throw new Error(`Unknown parameter type: ${key}`);
|
|
132
102
|
}
|
|
133
|
-
return value;
|
|
134
103
|
}
|
|
104
|
+
const identifier = new AnsiStandard(attrs);
|
|
105
|
+
readDashYear(identifier);
|
|
106
|
+
return identifier;
|
|
135
107
|
}
|
|
108
|
+
// --- Implementation ----------------------------------------------------------
|
|
109
|
+
let cachedRuntime;
|
|
136
110
|
export function ansiGrammarImplementation() {
|
|
137
|
-
const builder = new AnsiBuilder();
|
|
138
111
|
return {
|
|
139
112
|
parse(input) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
113
|
+
cachedRuntime ??= PubidRuntime.load("ansi");
|
|
114
|
+
const bound = cachedRuntime.parseAndBind(input);
|
|
115
|
+
if (bound === null || typeof bound !== "object" || Array.isArray(bound)) {
|
|
116
|
+
throw new ParseFailed("ansi: the artifact rejected the input", 0);
|
|
143
117
|
}
|
|
144
|
-
return
|
|
118
|
+
return buildAnsi(bound);
|
|
145
119
|
},
|
|
146
120
|
};
|
|
147
121
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BaseIdentifier } from "../../model/identifier.js";
|
|
2
|
+
import { PubidDate } from "../../model/component.js";
|
|
3
|
+
import { BaseUrnGenerator } from "../../model/urn-generator.js";
|
|
4
|
+
/**
|
|
5
|
+
* The ansi identifier model — lib/pubid/ansi/identifier.rb plus its
|
|
6
|
+
* Identifiers::* leaves. Registration lives HERE (parg-free) so the
|
|
7
|
+
* worker manifest (src/flavors/register-types.ts) can import it without
|
|
8
|
+
* reaching the artifact runtime; the parse entry (./index.js) is the
|
|
9
|
+
* parg-backed half.
|
|
10
|
+
*
|
|
11
|
+
* The relaton#45 round: any uppercase developer acronym co-publishes,
|
|
12
|
+
* the publisher group may join the number with a dash
|
|
13
|
+
* (number_separator), the year may join the number with a dash
|
|
14
|
+
* (date_separator — the "ANSI X9.62-2005" spelling), and a trailing
|
|
15
|
+
* revision letter ("ANSI/TIA-568.2-D") is identity. Both separators are
|
|
16
|
+
* spelling-only facets: they serialize but `==` skips them
|
|
17
|
+
* (equality_ignored).
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The URN generator (lib/pubid/ansi/urn_generator.rb): the namespace
|
|
21
|
+
* slot carries the publisher and copublishers joined with dashes
|
|
22
|
+
* ("ansi-tia"), the revision is identity so it reaches the URN too
|
|
23
|
+
* ("rev-D").
|
|
24
|
+
*/
|
|
25
|
+
declare class AnsiUrnGenerator extends BaseUrnGenerator<AnsiIdentifier> {
|
|
26
|
+
generate(): string;
|
|
27
|
+
}
|
|
28
|
+
/** The base ANSI identifier (Pubid::Ansi::Identifier): render, URN and
|
|
29
|
+
* hash behavior shared by every leaf. */
|
|
30
|
+
export declare class AnsiIdentifier extends BaseIdentifier {
|
|
31
|
+
static polymorphicName: string;
|
|
32
|
+
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
33
|
+
static urnGenerator: typeof AnsiUrnGenerator;
|
|
34
|
+
readonly number: string | undefined;
|
|
35
|
+
readonly part: string | undefined;
|
|
36
|
+
readonly date: PubidDate | undefined;
|
|
37
|
+
readonly date_separator: string | undefined;
|
|
38
|
+
readonly number_separator: string | undefined;
|
|
39
|
+
readonly revision: string | undefined;
|
|
40
|
+
readonly publisher: {
|
|
41
|
+
body: string;
|
|
42
|
+
} | undefined;
|
|
43
|
+
readonly copublishers: {
|
|
44
|
+
body: string;
|
|
45
|
+
}[] | undefined;
|
|
46
|
+
readonly languages: {
|
|
47
|
+
code: string;
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
render(): string;
|
|
50
|
+
private datePresent;
|
|
51
|
+
}
|
|
52
|
+
/** Identifiers::Standard — the default leaf every parse builds. */
|
|
53
|
+
export declare class AnsiStandard extends AnsiIdentifier {
|
|
54
|
+
static polymorphicName: string;
|
|
55
|
+
}
|
|
56
|
+
/** Identifiers::AmericanNationalStandard — the explicit ANS type. */
|
|
57
|
+
export declare class AnsiAmericanNationalStandard extends AnsiIdentifier {
|
|
58
|
+
static polymorphicName: string;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BaseIdentifier, registerType } from "../../model/identifier.js";
|
|
2
|
+
import { extendAttributes } from "../../model/attribute.js";
|
|
3
|
+
import { BaseUrnGenerator } from "../../model/urn-generator.js";
|
|
4
|
+
/**
|
|
5
|
+
* The ansi identifier model — lib/pubid/ansi/identifier.rb plus its
|
|
6
|
+
* Identifiers::* leaves. Registration lives HERE (parg-free) so the
|
|
7
|
+
* worker manifest (src/flavors/register-types.ts) can import it without
|
|
8
|
+
* reaching the artifact runtime; the parse entry (./index.js) is the
|
|
9
|
+
* parg-backed half.
|
|
10
|
+
*
|
|
11
|
+
* The relaton#45 round: any uppercase developer acronym co-publishes,
|
|
12
|
+
* the publisher group may join the number with a dash
|
|
13
|
+
* (number_separator), the year may join the number with a dash
|
|
14
|
+
* (date_separator — the "ANSI X9.62-2005" spelling), and a trailing
|
|
15
|
+
* revision letter ("ANSI/TIA-568.2-D") is identity. Both separators are
|
|
16
|
+
* spelling-only facets: they serialize but `==` skips them
|
|
17
|
+
* (equality_ignored).
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The URN generator (lib/pubid/ansi/urn_generator.rb): the namespace
|
|
21
|
+
* slot carries the publisher and copublishers joined with dashes
|
|
22
|
+
* ("ansi-tia"), the revision is identity so it reaches the URN too
|
|
23
|
+
* ("rev-D").
|
|
24
|
+
*/
|
|
25
|
+
class AnsiUrnGenerator extends BaseUrnGenerator {
|
|
26
|
+
generate() {
|
|
27
|
+
const id = this.identifier;
|
|
28
|
+
const parts = ["urn", "ansi"];
|
|
29
|
+
const push = (v) => {
|
|
30
|
+
if (v !== undefined && v !== null && v !== "")
|
|
31
|
+
parts.push(v);
|
|
32
|
+
};
|
|
33
|
+
push(this.urnNumber());
|
|
34
|
+
push(this.urnPart());
|
|
35
|
+
push(this.urnSubpart());
|
|
36
|
+
push(this.urnYear());
|
|
37
|
+
// "568.2-C" and "568.2-D" are two documents: keep them apart.
|
|
38
|
+
push(id.revision !== undefined ? `rev-${id.revision}` : undefined);
|
|
39
|
+
push(this.urnEdition());
|
|
40
|
+
if (id.publisher !== undefined) {
|
|
41
|
+
parts[1] = id.publisher.body.toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
if (id.copublishers !== undefined && id.copublishers.length > 0) {
|
|
44
|
+
const copubs = id.copublishers.map((cp) => cp.body.toLowerCase());
|
|
45
|
+
parts[1] = `${parts[1]}-${copubs.join("-")}`;
|
|
46
|
+
}
|
|
47
|
+
if (id.languages !== undefined && id.languages.length > 0) {
|
|
48
|
+
parts.push(id.languages.map((l) => l.code).join(","));
|
|
49
|
+
}
|
|
50
|
+
return parts.join(":");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The base ANSI identifier (Pubid::Ansi::Identifier): render, URN and
|
|
54
|
+
* hash behavior shared by every leaf. */
|
|
55
|
+
export class AnsiIdentifier extends BaseIdentifier {
|
|
56
|
+
static polymorphicName = "pubid:ansi:identifier";
|
|
57
|
+
static attributes = extendAttributes(BaseIdentifier, {
|
|
58
|
+
date_separator: { type: "string", equalityIgnored: true },
|
|
59
|
+
number_separator: { type: "string", equalityIgnored: true },
|
|
60
|
+
revision: { type: "string" },
|
|
61
|
+
});
|
|
62
|
+
// The gem declares no key_value block: every attribute serializes
|
|
63
|
+
// under its own name (the date component's degenerate year flattens).
|
|
64
|
+
static urnGenerator = AnsiUrnGenerator;
|
|
65
|
+
render() {
|
|
66
|
+
// The renderer (lib/pubid/ansi/renderer.rb): "ANSI/ISA-5.1-2009"
|
|
67
|
+
// keeps its dash; the space is the default publisher join.
|
|
68
|
+
const publisherPortion = this.copublishers !== undefined && this.copublishers.length > 0
|
|
69
|
+
? [this.publisher, ...this.copublishers]
|
|
70
|
+
.map((p) => (p === undefined ? "" : p.body))
|
|
71
|
+
.join("/")
|
|
72
|
+
: this.publisher?.body ?? "";
|
|
73
|
+
const numberPortion = (this.number ?? "") +
|
|
74
|
+
(this.part !== undefined ? `-${this.part}` : "") +
|
|
75
|
+
(this.revision !== undefined ? `-${this.revision}` : "") +
|
|
76
|
+
// "ANSI X9.62-2005" keeps its dash; the colon is the default.
|
|
77
|
+
(this.datePresent() ? `${this.date_separator ?? ":"}${this.date?.year}` : "");
|
|
78
|
+
let result = this.number_separator !== undefined
|
|
79
|
+
? `${publisherPortion}${this.number_separator}${numberPortion}`
|
|
80
|
+
: `${publisherPortion} ${numberPortion}`;
|
|
81
|
+
if (this.languages !== undefined && this.languages.length > 0) {
|
|
82
|
+
result += `(${this.languages.map((l) => l.code).join(",")})`;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
datePresent() {
|
|
87
|
+
const date = this.date;
|
|
88
|
+
if (date === undefined)
|
|
89
|
+
return false;
|
|
90
|
+
if (date.undated)
|
|
91
|
+
return true;
|
|
92
|
+
return date.year !== undefined && date.year !== "";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Identifiers::Standard — the default leaf every parse builds. */
|
|
96
|
+
export class AnsiStandard extends AnsiIdentifier {
|
|
97
|
+
static polymorphicName = "pubid:ansi:standard";
|
|
98
|
+
}
|
|
99
|
+
/** Identifiers::AmericanNationalStandard — the explicit ANS type. */
|
|
100
|
+
export class AnsiAmericanNationalStandard extends AnsiIdentifier {
|
|
101
|
+
static polymorphicName = "pubid:ansi:american-national-standard";
|
|
102
|
+
}
|
|
103
|
+
// The ANSI_TYPE_MAP role: the base plus the two concrete leaves (the
|
|
104
|
+
// schema's pubid:ansi:{identifier,standard,american-national-standard}).
|
|
105
|
+
registerType(AnsiIdentifier);
|
|
106
|
+
registerType(AnsiStandard);
|
|
107
|
+
registerType(AnsiAmericanNationalStandard);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ParseFailed } from "../../grammar/engine.js";
|
|
2
|
+
import { PubidRuntime } from "../../parg/runtime.js";
|
|
3
|
+
import { ArxivEprint } from "./model.js";
|
|
4
|
+
export * from "./model.js";
|
|
5
|
+
/**
|
|
6
|
+
* The arxiv parse entry — the same baked artifact the Ruby flavor runs
|
|
7
|
+
* (pubid-grammar grammars/arxiv.parg -> artifacts/arxiv.json, sealed at
|
|
8
|
+
* parsanol 1.5.1.0), loaded through the artifact runtime. The builder
|
|
9
|
+
* mirrors Pubid::Arxiv::Builder: the grammar checks the shape, this
|
|
10
|
+
* side checks the rules the shape cannot express, raising (which the
|
|
11
|
+
* parse entry surfaces as a rejection):
|
|
12
|
+
*
|
|
13
|
+
* - the month is 01-12;
|
|
14
|
+
* - a 4-digit new number has a YYMM from 0704 to 1412;
|
|
15
|
+
* - a 5-digit new number has a YYMM from 1501;
|
|
16
|
+
* - an old-form id has a YYMM from 9108 to 0703;
|
|
17
|
+
* - the version is 1 or more, with no leading zero (so to_s is exact).
|
|
18
|
+
*/
|
|
19
|
+
// --- Builder (lib/pubid/arxiv/builder.rb) ------------------------------------
|
|
20
|
+
const s = (v) => {
|
|
21
|
+
if (v === undefined || v === null)
|
|
22
|
+
return undefined;
|
|
23
|
+
const text = String(v);
|
|
24
|
+
return text.length > 0 ? text : undefined;
|
|
25
|
+
};
|
|
26
|
+
/** Old-form ids run from 9108 to 0703, so 91-99 is the 1990s; a new id
|
|
27
|
+
* is always in the 2000s. */
|
|
28
|
+
function yearMonth(yymmRaw, old) {
|
|
29
|
+
const yymm = String(yymmRaw ?? "");
|
|
30
|
+
const twoDigit = Number(yymm.slice(0, 2));
|
|
31
|
+
const month = Number(yymm.slice(2, 4));
|
|
32
|
+
if (!(month >= 1 && month <= 12)) {
|
|
33
|
+
throw new Error(`month out of range in YYMM ${yymm}`);
|
|
34
|
+
}
|
|
35
|
+
const century = old && twoDigit >= 91 ? 1900 : 2000;
|
|
36
|
+
return [century + twoDigit, month];
|
|
37
|
+
}
|
|
38
|
+
const ym = (year, month) => year * 100 + month;
|
|
39
|
+
function validateRange(year, month, number, old) {
|
|
40
|
+
if (old) {
|
|
41
|
+
if (!(ym(year, month) >= 199108 && ym(year, month) <= 200703)) {
|
|
42
|
+
throw new Error("an old-form id dates from 9108 to 0703");
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const valid = number.length === 4
|
|
47
|
+
? ym(year, month) >= 200704 && ym(year, month) <= 201412
|
|
48
|
+
: ym(year, month) >= 201501;
|
|
49
|
+
if (!valid) {
|
|
50
|
+
const yy = String(year % 100).padStart(2, "0");
|
|
51
|
+
const mm = String(month).padStart(2, "0");
|
|
52
|
+
throw new Error(`a ${number.length}-digit number does not fit YYMM ${yy}${mm}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** The version is 1 or more, with no leading zero (v01 would render v1,
|
|
56
|
+
* so to_s would not be exact). */
|
|
57
|
+
function parseVersion(value) {
|
|
58
|
+
const raw = s(value);
|
|
59
|
+
if (raw === undefined)
|
|
60
|
+
return undefined;
|
|
61
|
+
if (raw.startsWith("0")) {
|
|
62
|
+
throw new Error(`version v${raw} is not 1 or more without a leading zero`);
|
|
63
|
+
}
|
|
64
|
+
return Number(raw);
|
|
65
|
+
}
|
|
66
|
+
function buildArxiv(data) {
|
|
67
|
+
const archive = s(data["archive"]);
|
|
68
|
+
const [year, month] = yearMonth(String(data["yymm"] ?? ""), archive !== undefined);
|
|
69
|
+
const number = String(data["number"] ?? "");
|
|
70
|
+
validateRange(year, month, number, archive !== undefined);
|
|
71
|
+
return new ArxivEprint({
|
|
72
|
+
...(archive !== undefined ? { archive } : {}),
|
|
73
|
+
...(s(data["subject_class"]) !== undefined
|
|
74
|
+
? { subject_class: s(data["subject_class"]) }
|
|
75
|
+
: {}),
|
|
76
|
+
year,
|
|
77
|
+
month,
|
|
78
|
+
number,
|
|
79
|
+
...(parseVersion(data["version"]) !== undefined
|
|
80
|
+
? { version: parseVersion(data["version"]) }
|
|
81
|
+
: {}),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// --- Implementation ----------------------------------------------------------
|
|
85
|
+
let cachedRuntime;
|
|
86
|
+
export function arxivGrammarImplementation() {
|
|
87
|
+
return {
|
|
88
|
+
parse(input) {
|
|
89
|
+
cachedRuntime ??= PubidRuntime.load("arxiv");
|
|
90
|
+
const bound = cachedRuntime.parseAndBind(input);
|
|
91
|
+
if (bound === null || typeof bound !== "object") {
|
|
92
|
+
throw new ParseFailed("arxiv: the artifact rejected the input", 0);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
return buildArxiv(bound);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
// The builder checks the date ranges, the month and the version;
|
|
99
|
+
// surface that as a parse failure, the class a grammar rejection
|
|
100
|
+
// has (the gem turns its ArgumentError into ParseError here).
|
|
101
|
+
throw new Error(`invalid arXiv identifier '${input}': ${e.message}`);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BaseIdentifier } from "../../model/identifier.js";
|
|
2
|
+
/**
|
|
3
|
+
* The arxiv identifier model — lib/pubid/arxiv/identifiers/eprint.rb.
|
|
4
|
+
* Registration lives HERE (parg-free) so the worker manifest
|
|
5
|
+
* (src/flavors/register-types.ts) can import it without reaching the
|
|
6
|
+
* artifact runtime; the parse entry (./index.js) is the parg-backed half.
|
|
7
|
+
*
|
|
8
|
+
* An arXiv e-print, new form (`2301.00001`) or old form
|
|
9
|
+
* (`hep-th/9901001`, `math.GT/0309136`). `archive`/`subject_class`
|
|
10
|
+
* (old ids only) are STRICT in the subset match — a nil archive means
|
|
11
|
+
* "this id has none", so a new id never matches an old one and
|
|
12
|
+
* `math/...` never matches `math.GT/...`. The `version` is the only
|
|
13
|
+
* === wildcard. `year`/`month` name the paper (its YYMM), not an
|
|
14
|
+
* edition.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ArxivIdentifier extends BaseIdentifier {
|
|
17
|
+
static polymorphicName: string;
|
|
18
|
+
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
19
|
+
static mappings: import("../../model/attribute.js").FieldMapping[];
|
|
20
|
+
static subsetStrict: string[];
|
|
21
|
+
readonly archive: string | undefined;
|
|
22
|
+
readonly subject_class: string | undefined;
|
|
23
|
+
readonly year: number | undefined;
|
|
24
|
+
readonly month: number | undefined;
|
|
25
|
+
readonly version: number | undefined;
|
|
26
|
+
readonly number: string | undefined;
|
|
27
|
+
/** The four-digit YYMM the id prints. */
|
|
28
|
+
yymm(): string;
|
|
29
|
+
/** True for an old-form (archive) id. */
|
|
30
|
+
oldStyle(): boolean;
|
|
31
|
+
/** The canonical colon form `arXiv:<id>` — whatever prefix the input
|
|
32
|
+
* used; the `arXiv:` token is constant and every surface prints it. */
|
|
33
|
+
render(): string;
|
|
34
|
+
/** to_s(with_publisher: false): the bare id — the form the arXiv API
|
|
35
|
+
* takes in id_list (handled here, not by a publisher-stripper: the
|
|
36
|
+
* stripper cuts only before a space, "-", "/" or ".", never before
|
|
37
|
+
* the colon, and publisher_prefixes is [] for that reason). */
|
|
38
|
+
toHuman(opts?: {
|
|
39
|
+
withPublisher?: boolean;
|
|
40
|
+
}): string;
|
|
41
|
+
/** arXiv registers no official URN namespace, and the base fallback
|
|
42
|
+
* (urn:arxiv:<number>:<year>) maps different papers to one URN, so
|
|
43
|
+
* the official form is the lossless pubid-scheme URN. */
|
|
44
|
+
toUrn(): string;
|
|
45
|
+
protected body(): string;
|
|
46
|
+
protected versionSuffix(): string;
|
|
47
|
+
}
|
|
48
|
+
export declare class ArxivEprint extends ArxivIdentifier {
|
|
49
|
+
static polymorphicName: string;
|
|
50
|
+
}
|
|
51
|
+
export type ArxivLeafClass = typeof ArxivEprint;
|