@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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { BaseIdentifier, registerType } from "../../model/identifier.js";
|
|
2
|
+
import { extendAttributes, keyValue } from "../../model/attribute.js";
|
|
3
|
+
/**
|
|
4
|
+
* The arxiv identifier model — lib/pubid/arxiv/identifiers/eprint.rb.
|
|
5
|
+
* Registration lives HERE (parg-free) so the worker manifest
|
|
6
|
+
* (src/flavors/register-types.ts) can import it without reaching the
|
|
7
|
+
* artifact runtime; the parse entry (./index.js) is the parg-backed half.
|
|
8
|
+
*
|
|
9
|
+
* An arXiv e-print, new form (`2301.00001`) or old form
|
|
10
|
+
* (`hep-th/9901001`, `math.GT/0309136`). `archive`/`subject_class`
|
|
11
|
+
* (old ids only) are STRICT in the subset match — a nil archive means
|
|
12
|
+
* "this id has none", so a new id never matches an old one and
|
|
13
|
+
* `math/...` never matches `math.GT/...`. The `version` is the only
|
|
14
|
+
* === wildcard. `year`/`month` name the paper (its YYMM), not an
|
|
15
|
+
* edition.
|
|
16
|
+
*/
|
|
17
|
+
export class ArxivIdentifier extends BaseIdentifier {
|
|
18
|
+
static polymorphicName = "pubid:arxiv:identifier";
|
|
19
|
+
static attributes = extendAttributes(BaseIdentifier, {
|
|
20
|
+
archive: { type: "string" },
|
|
21
|
+
subject_class: { type: "string" },
|
|
22
|
+
year: { type: "integer" },
|
|
23
|
+
month: { type: "integer" },
|
|
24
|
+
version: { type: "integer" },
|
|
25
|
+
});
|
|
26
|
+
// The gem's key_value whitelist.
|
|
27
|
+
static mappings = keyValue({ wire: "archive", to: "archive" }, { wire: "subject_class", to: "subject_class" }, { wire: "year", to: "year" }, { wire: "month", to: "month" }, { wire: "number", to: "number" }, { wire: "version", to: "version" });
|
|
28
|
+
// subset_strict :archive, :subject_class, :year, :month, :number — the
|
|
29
|
+
// version stays the only wildcard.
|
|
30
|
+
static subsetStrict = ["archive", "subject_class", "year", "month", "number"];
|
|
31
|
+
/** The four-digit YYMM the id prints. */
|
|
32
|
+
yymm() {
|
|
33
|
+
const yy = String((this.year ?? 0) % 100).padStart(2, "0");
|
|
34
|
+
const mm = String(this.month ?? 0).padStart(2, "0");
|
|
35
|
+
return `${yy}${mm}`;
|
|
36
|
+
}
|
|
37
|
+
/** True for an old-form (archive) id. */
|
|
38
|
+
oldStyle() {
|
|
39
|
+
return this.archive !== undefined && this.archive !== null;
|
|
40
|
+
}
|
|
41
|
+
/** The canonical colon form `arXiv:<id>` — whatever prefix the input
|
|
42
|
+
* used; the `arXiv:` token is constant and every surface prints it. */
|
|
43
|
+
render() {
|
|
44
|
+
return `arXiv:${this.body()}${this.versionSuffix()}`;
|
|
45
|
+
}
|
|
46
|
+
/** to_s(with_publisher: false): the bare id — the form the arXiv API
|
|
47
|
+
* takes in id_list (handled here, not by a publisher-stripper: the
|
|
48
|
+
* stripper cuts only before a space, "-", "/" or ".", never before
|
|
49
|
+
* the colon, and publisher_prefixes is [] for that reason). */
|
|
50
|
+
toHuman(opts) {
|
|
51
|
+
const human = super.toHuman();
|
|
52
|
+
if (opts?.withPublisher !== false)
|
|
53
|
+
return human;
|
|
54
|
+
return human.replace(/^arXiv:/, "");
|
|
55
|
+
}
|
|
56
|
+
/** arXiv registers no official URN namespace, and the base fallback
|
|
57
|
+
* (urn:arxiv:<number>:<year>) maps different papers to one URN, so
|
|
58
|
+
* the official form is the lossless pubid-scheme URN. */
|
|
59
|
+
toUrn() {
|
|
60
|
+
return this.toPubidUrn();
|
|
61
|
+
}
|
|
62
|
+
body() {
|
|
63
|
+
if (!this.oldStyle())
|
|
64
|
+
return `${this.yymm()}.${this.number ?? ""}`;
|
|
65
|
+
const archive = [this.archive, this.subject_class].filter((v) => v !== undefined).join(".");
|
|
66
|
+
return `${archive}/${this.yymm()}${this.number ?? ""}`;
|
|
67
|
+
}
|
|
68
|
+
versionSuffix() {
|
|
69
|
+
return this.version !== undefined && this.version !== null ? `v${this.version}` : "";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class ArxivEprint extends ArxivIdentifier {
|
|
73
|
+
static polymorphicName = "pubid:arxiv:eprint";
|
|
74
|
+
}
|
|
75
|
+
// The ARXIV_TYPE_MAP role: the concrete e-print plus the base (a
|
|
76
|
+
// hand-built hash serializes as pubid:arxiv:identifier — the gem's
|
|
77
|
+
// Identifier class itself).
|
|
78
|
+
registerType(ArxivIdentifier);
|
|
79
|
+
registerType(ArxivEprint);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ParseFailed } from "../../grammar/engine.js";
|
|
2
|
+
import { PubidRuntime } from "../../parg/runtime.js";
|
|
3
|
+
import { EuDecision, EuDirective, EuRegulation, isPlausibleYear, numberFirstFor, stripLeadingZeros, } from "./model.js";
|
|
4
|
+
export * from "./model.js";
|
|
5
|
+
/**
|
|
6
|
+
* The eu parse entry — the same baked artifact the Ruby flavor runs
|
|
7
|
+
* (pubid-grammar grammars/eu.parg -> artifacts/eu.json, sealed at
|
|
8
|
+
* parsanol 1.5.1.0), loaded through the artifact runtime so grammar
|
|
9
|
+
* changes land once and this side cannot drift. The builder mirrors
|
|
10
|
+
* Pubid::Eu::Builder: CELEX and ELI fix year/number by position, the
|
|
11
|
+
* canonical and Official-Journal forms carry two numbers whose ORDER is
|
|
12
|
+
* not in the grammar (number_first_for), and the renderer's "No"
|
|
13
|
+
* disambiguation lives on the model (EuIdentifier#numbers).
|
|
14
|
+
*/
|
|
15
|
+
// --- Builder (lib/pubid/eu/builder.rb) ---------------------------------------
|
|
16
|
+
const TYPES_BY_WORD = {
|
|
17
|
+
Regulation: EuRegulation,
|
|
18
|
+
Directive: EuDirective,
|
|
19
|
+
Decision: EuDecision,
|
|
20
|
+
};
|
|
21
|
+
const TYPES_BY_CELEX = {
|
|
22
|
+
R: EuRegulation,
|
|
23
|
+
L: EuDirective,
|
|
24
|
+
D: EuDecision,
|
|
25
|
+
};
|
|
26
|
+
const TYPES_BY_ELI = {
|
|
27
|
+
reg: EuRegulation,
|
|
28
|
+
dir: EuDirective,
|
|
29
|
+
dec: EuDecision,
|
|
30
|
+
};
|
|
31
|
+
const s = (v) => {
|
|
32
|
+
if (v === undefined || v === null)
|
|
33
|
+
return undefined;
|
|
34
|
+
const text = String(v);
|
|
35
|
+
return text.length > 0 ? text : undefined;
|
|
36
|
+
};
|
|
37
|
+
function positional(data) {
|
|
38
|
+
const letter = s(data["celex_letter"]);
|
|
39
|
+
const eli = s(data["eli_type"]);
|
|
40
|
+
const klass = letter !== undefined
|
|
41
|
+
? TYPES_BY_CELEX[letter]
|
|
42
|
+
: eli !== undefined
|
|
43
|
+
? TYPES_BY_ELI[eli]
|
|
44
|
+
: undefined;
|
|
45
|
+
if (klass === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
// CELEX and ELI: the year and the number have fixed places.
|
|
48
|
+
return {
|
|
49
|
+
klass,
|
|
50
|
+
year: String(data["year"] ?? ""),
|
|
51
|
+
number: String(data["number"] ?? ""),
|
|
52
|
+
numberFirst: undefined,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function fromPair(data) {
|
|
56
|
+
const klass = TYPES_BY_WORD[String(data["type_word"])];
|
|
57
|
+
if (klass === undefined) {
|
|
58
|
+
throw new Error(`EU legal act: unknown act type ${String(data["type_word"])}`);
|
|
59
|
+
}
|
|
60
|
+
const first = String(data["first"] ?? "");
|
|
61
|
+
const second = String(data["second"] ?? "");
|
|
62
|
+
// "No" marks <number>/<year> (Regulation (EU) No 1227/2011, Decision
|
|
63
|
+
// No 1082/2013/EU); every other pair reads by the rule.
|
|
64
|
+
const numberFirst = (data["no"] !== undefined && data["no"] !== null) ||
|
|
65
|
+
numberFirstFor(klass.euType.title, first, second);
|
|
66
|
+
if (numberFirst === undefined) {
|
|
67
|
+
throw new Error(`EU legal act: no year in ${first}/${second}`);
|
|
68
|
+
}
|
|
69
|
+
const [year, number] = numberFirst ? [second, first] : [first, second];
|
|
70
|
+
return { klass, year, number, numberFirst };
|
|
71
|
+
}
|
|
72
|
+
function family(data) {
|
|
73
|
+
const bracket = s(data["family"]);
|
|
74
|
+
const suffix = s(data["family_suffix"]);
|
|
75
|
+
if (bracket !== undefined && suffix !== undefined && bracket !== suffix) {
|
|
76
|
+
throw new Error(`EU legal act: two families, ${bracket} and ${suffix}`);
|
|
77
|
+
}
|
|
78
|
+
return bracket ?? suffix;
|
|
79
|
+
}
|
|
80
|
+
function buildEu(data) {
|
|
81
|
+
const act = positional(data) ?? fromPair(data);
|
|
82
|
+
if (!isPlausibleYear(act.year)) {
|
|
83
|
+
throw new Error(`EU legal act: ${act.year} is not a year`);
|
|
84
|
+
}
|
|
85
|
+
const number = stripLeadingZeros(act.number);
|
|
86
|
+
if (number === "0") {
|
|
87
|
+
throw new Error("EU legal act: number 0");
|
|
88
|
+
}
|
|
89
|
+
const id = new act.klass({
|
|
90
|
+
number,
|
|
91
|
+
date: { year: act.year },
|
|
92
|
+
...(family(data) !== undefined ? { family: family(data) } : {}),
|
|
93
|
+
});
|
|
94
|
+
// Keep the order only when it is not what the render rule prints.
|
|
95
|
+
if (act.numberFirst !== undefined && act.numberFirst !== id.defaultNumberFirst()) {
|
|
96
|
+
id["number_first"] = act.numberFirst;
|
|
97
|
+
}
|
|
98
|
+
return id;
|
|
99
|
+
}
|
|
100
|
+
// --- Implementation ----------------------------------------------------------
|
|
101
|
+
let cachedRuntime;
|
|
102
|
+
export function euGrammarImplementation() {
|
|
103
|
+
return {
|
|
104
|
+
parse(input) {
|
|
105
|
+
cachedRuntime ??= PubidRuntime.load("eu");
|
|
106
|
+
const bound = cachedRuntime.parseAndBind(input);
|
|
107
|
+
if (bound === null || typeof bound !== "object") {
|
|
108
|
+
throw new ParseFailed("eu: the artifact rejected the input", 0);
|
|
109
|
+
}
|
|
110
|
+
return buildEu(bound);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { BaseIdentifier } from "../../model/identifier.js";
|
|
2
|
+
import type { PubidDate } from "../../model/component.js";
|
|
3
|
+
/**
|
|
4
|
+
* The eu identifier model — the classes of lib/pubid/eu/identifiers.rb.
|
|
5
|
+
* Registration lives HERE (parg-free) so the worker manifest
|
|
6
|
+
* (src/flavors/register-types.ts) can import it without reaching the
|
|
7
|
+
* artifact runtime; the parse entry (./index.js) is the parg-backed half.
|
|
8
|
+
*
|
|
9
|
+
* Identity is the leaf class (the act type), the year (`date`) and the
|
|
10
|
+
* `number` — the three parts of a CELEX number. `family` is the
|
|
11
|
+
* bracketed legal family of the Official Journal form ("(EU)", "(EC)"
|
|
12
|
+
* ...); the canonical reference omits it, so a reference with no family
|
|
13
|
+
* matches a row that has one (the subset-match wildcard).
|
|
14
|
+
* `number_first` is the print ORDER of the two numbers — spelling, not
|
|
15
|
+
* identity: it serializes but `==` skips it (equality_ignored), so
|
|
16
|
+
* "EU Decision 1082/2013" equals the CELEX number 32013D1082.
|
|
17
|
+
*/
|
|
18
|
+
/** The act-type metadata each leaf class carries (Ruby self.type). */
|
|
19
|
+
export interface EuType {
|
|
20
|
+
key: string;
|
|
21
|
+
title: string;
|
|
22
|
+
celex: string | null;
|
|
23
|
+
eli: string | null;
|
|
24
|
+
}
|
|
25
|
+
/** From 2015 every act prints <year>/<number>; before it, a regulation
|
|
26
|
+
* printed <number>/<year> (the first Official Journal acts, ECSC,
|
|
27
|
+
* date from 1952). */
|
|
28
|
+
export declare const FIXED_ORDER_YEAR = 2015;
|
|
29
|
+
/** The canonical reference's publisher — the PUBLISHER constant, not an
|
|
30
|
+
* attribute: every surface prints it, so nothing stores it. */
|
|
31
|
+
export declare const EU_PUBLISHER = "EU";
|
|
32
|
+
export declare class EuIdentifier extends BaseIdentifier {
|
|
33
|
+
static polymorphicName: string;
|
|
34
|
+
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
35
|
+
static mappings: import("../../model/attribute.js").FieldMapping[];
|
|
36
|
+
static euType: EuType;
|
|
37
|
+
readonly number: string | undefined;
|
|
38
|
+
readonly date: PubidDate | undefined;
|
|
39
|
+
readonly family: string | undefined;
|
|
40
|
+
readonly number_first: boolean | undefined;
|
|
41
|
+
/** The year, read off the date component (Ruby #year). */
|
|
42
|
+
get year(): string | undefined;
|
|
43
|
+
/** A regulation with a year before 2015 prints <number>/<year>;
|
|
44
|
+
* everything else prints <year>/<number>. (Ruby year.to_i: a missing
|
|
45
|
+
* year reads as 0, so a year-less regulation defaults number-first.) */
|
|
46
|
+
defaultNumberFirst(): boolean;
|
|
47
|
+
/** The effective print order: the stored flag when the builder set it
|
|
48
|
+
* (the input used the non-default order), else the default rule. */
|
|
49
|
+
numberFirst(): boolean;
|
|
50
|
+
/** The act-type key of the leaf class ("regulation" / "directive" /
|
|
51
|
+
* "decision" / the base's "identifier"). */
|
|
52
|
+
euTypeKey(): string;
|
|
53
|
+
/** The act-type title of the leaf class ("" on the base). */
|
|
54
|
+
euTitle(): string;
|
|
55
|
+
/** The CELEX type letter of the leaf class (R / L / D). */
|
|
56
|
+
euCelexLetter(): string | null;
|
|
57
|
+
/** The ELI segment of the leaf class (reg / dir / dec). */
|
|
58
|
+
euEliSegment(): string | null;
|
|
59
|
+
render(): string;
|
|
60
|
+
/** to_s(with_publisher: false): the Official-Journal-citable form
|
|
61
|
+
* without the leading "EU " (the PublisherStripper cut). */
|
|
62
|
+
toHuman(opts?: {
|
|
63
|
+
withPublisher?: boolean;
|
|
64
|
+
}): string;
|
|
65
|
+
/** The CELEX number: sector 3, year, type letter, number padded to 4.
|
|
66
|
+
* (The base class carries no type letter — the segments join empty.) */
|
|
67
|
+
toCelex(): string;
|
|
68
|
+
/** The ELI of the act as published in the Official Journal. */
|
|
69
|
+
toEli(): string;
|
|
70
|
+
/** The EU has no registered URN namespace (the ELI is its official
|
|
71
|
+
* identifier). This pubid-invented form keeps the act type, so a
|
|
72
|
+
* regulation and a decision with the same numbers do not collide. */
|
|
73
|
+
toUrn(): string;
|
|
74
|
+
/** The two numbers in print order, or the bare number without a year.
|
|
75
|
+
* When the plain pair would read back as ANOTHER act (two acts share
|
|
76
|
+
* one plain print — 32015R2014 and 32014R2015 both give "2015/2014"),
|
|
77
|
+
* "No" marks <number>/<year>, which always reads back as this act. */
|
|
78
|
+
protected numbers(): string;
|
|
79
|
+
}
|
|
80
|
+
export declare class EuRegulation extends EuIdentifier {
|
|
81
|
+
static polymorphicName: string;
|
|
82
|
+
static euType: EuType;
|
|
83
|
+
}
|
|
84
|
+
export declare class EuDirective extends EuIdentifier {
|
|
85
|
+
static polymorphicName: string;
|
|
86
|
+
static euType: EuType;
|
|
87
|
+
}
|
|
88
|
+
export declare class EuDecision extends EuIdentifier {
|
|
89
|
+
static polymorphicName: string;
|
|
90
|
+
static euType: EuType;
|
|
91
|
+
}
|
|
92
|
+
export type EuLeafClass = typeof EuRegulation | typeof EuDirective | typeof EuDecision;
|
|
93
|
+
/**
|
|
94
|
+
* Which of two printed numbers is the year, when the input has no "No".
|
|
95
|
+
* Only one plausible year: that one. Both: a first value from 2015 is
|
|
96
|
+
* the year (every act prints <year>/<number> from 2015); otherwise a
|
|
97
|
+
* regulation prints <number>/<year> and other acts <year>/<number>.
|
|
98
|
+
* Neither plausible: undefined. The renderer calls this too, to know
|
|
99
|
+
* when a plain print would read back as another act. `klass` is the
|
|
100
|
+
* Ruby class-name fragment the gem's Builder.number_first_for compares
|
|
101
|
+
* ("Regulation" — the leaf title — or "Identifier" on the base).
|
|
102
|
+
*/
|
|
103
|
+
export declare function numberFirstFor(klass: string, first: string, second: string): boolean | undefined;
|
|
104
|
+
/** The first Official Journal acts (ECSC) date from 1952. */
|
|
105
|
+
export declare function isPlausibleYear(value: string): boolean;
|
|
106
|
+
/** "0079" -> "79", "0" stays "0" (Ruby strip_zeros: leading zeros only,
|
|
107
|
+
* never the bare zero). */
|
|
108
|
+
export declare function stripLeadingZeros(number: string): string;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { BaseIdentifier, registerType } from "../../model/identifier.js";
|
|
2
|
+
import { extendAttributes, keyValue } from "../../model/attribute.js";
|
|
3
|
+
/** From 2015 every act prints <year>/<number>; before it, a regulation
|
|
4
|
+
* printed <number>/<year> (the first Official Journal acts, ECSC,
|
|
5
|
+
* date from 1952). */
|
|
6
|
+
export const FIXED_ORDER_YEAR = 2015;
|
|
7
|
+
/** The canonical reference's publisher — the PUBLISHER constant, not an
|
|
8
|
+
* attribute: every surface prints it, so nothing stores it. */
|
|
9
|
+
export const EU_PUBLISHER = "EU";
|
|
10
|
+
export class EuIdentifier extends BaseIdentifier {
|
|
11
|
+
static polymorphicName = "pubid:eu:identifier";
|
|
12
|
+
static attributes = extendAttributes(BaseIdentifier, {
|
|
13
|
+
family: { type: "string" },
|
|
14
|
+
number_first: { type: "boolean", equalityIgnored: true },
|
|
15
|
+
});
|
|
16
|
+
// The gem's key_value whitelist: only the four slots hit the wire; the
|
|
17
|
+
// base's part/edition/publisher/... slots stay off it.
|
|
18
|
+
static mappings = keyValue({ wire: "number", to: "number" }, { wire: "date", to: "date" }, { wire: "family", to: "family" }, { wire: "number_first", to: "number_first" });
|
|
19
|
+
static euType = { key: "identifier", title: "", celex: null, eli: null };
|
|
20
|
+
/** The year, read off the date component (Ruby #year). */
|
|
21
|
+
get year() {
|
|
22
|
+
return this.date?.year;
|
|
23
|
+
}
|
|
24
|
+
/** A regulation with a year before 2015 prints <number>/<year>;
|
|
25
|
+
* everything else prints <year>/<number>. (Ruby year.to_i: a missing
|
|
26
|
+
* year reads as 0, so a year-less regulation defaults number-first.) */
|
|
27
|
+
defaultNumberFirst() {
|
|
28
|
+
return this.euTypeKey() === "regulation" &&
|
|
29
|
+
(Number(this.year) || 0) < FIXED_ORDER_YEAR;
|
|
30
|
+
}
|
|
31
|
+
/** The effective print order: the stored flag when the builder set it
|
|
32
|
+
* (the input used the non-default order), else the default rule. */
|
|
33
|
+
numberFirst() {
|
|
34
|
+
return this.number_first ?? this.defaultNumberFirst();
|
|
35
|
+
}
|
|
36
|
+
/** The act-type key of the leaf class ("regulation" / "directive" /
|
|
37
|
+
* "decision" / the base's "identifier"). */
|
|
38
|
+
euTypeKey() {
|
|
39
|
+
return this.constructor.euType.key;
|
|
40
|
+
}
|
|
41
|
+
/** The act-type title of the leaf class ("" on the base). */
|
|
42
|
+
euTitle() {
|
|
43
|
+
return this.constructor.euType.title;
|
|
44
|
+
}
|
|
45
|
+
/** The CELEX type letter of the leaf class (R / L / D). */
|
|
46
|
+
euCelexLetter() {
|
|
47
|
+
return this.constructor.euType.celex;
|
|
48
|
+
}
|
|
49
|
+
/** The ELI segment of the leaf class (reg / dir / dec). */
|
|
50
|
+
euEliSegment() {
|
|
51
|
+
return this.constructor.euType.eli;
|
|
52
|
+
}
|
|
53
|
+
render() {
|
|
54
|
+
return `${EU_PUBLISHER} ${this.euTitle()} ${this.numbers()}`;
|
|
55
|
+
}
|
|
56
|
+
/** to_s(with_publisher: false): the Official-Journal-citable form
|
|
57
|
+
* without the leading "EU " (the PublisherStripper cut). */
|
|
58
|
+
toHuman(opts) {
|
|
59
|
+
const human = super.toHuman();
|
|
60
|
+
if (opts?.withPublisher !== false)
|
|
61
|
+
return human;
|
|
62
|
+
return human.replace(/^EU(?<sep>\s+)/, "");
|
|
63
|
+
}
|
|
64
|
+
/** The CELEX number: sector 3, year, type letter, number padded to 4.
|
|
65
|
+
* (The base class carries no type letter — the segments join empty.) */
|
|
66
|
+
toCelex() {
|
|
67
|
+
return `3${this.year ?? ""}${this.euCelexLetter() ?? ""}${(this.number ?? "").padStart(4, "0")}`;
|
|
68
|
+
}
|
|
69
|
+
/** The ELI of the act as published in the Official Journal. */
|
|
70
|
+
toEli() {
|
|
71
|
+
return `http://data.europa.eu/eli/${this.euEliSegment() ?? ""}/${this.year ?? ""}/${this.number ?? ""}/oj`;
|
|
72
|
+
}
|
|
73
|
+
/** The EU has no registered URN namespace (the ELI is its official
|
|
74
|
+
* identifier). This pubid-invented form keeps the act type, so a
|
|
75
|
+
* regulation and a decision with the same numbers do not collide. */
|
|
76
|
+
toUrn() {
|
|
77
|
+
return `urn:eu:${this.euEliSegment() ?? ""}:${this.year ?? ""}:${this.number ?? ""}`;
|
|
78
|
+
}
|
|
79
|
+
/** The two numbers in print order, or the bare number without a year.
|
|
80
|
+
* When the plain pair would read back as ANOTHER act (two acts share
|
|
81
|
+
* one plain print — 32015R2014 and 32014R2015 both give "2015/2014"),
|
|
82
|
+
* "No" marks <number>/<year>, which always reads back as this act. */
|
|
83
|
+
numbers() {
|
|
84
|
+
const number = this.number;
|
|
85
|
+
const year = this.year;
|
|
86
|
+
if (number === undefined)
|
|
87
|
+
return "";
|
|
88
|
+
if (year === undefined || year === null)
|
|
89
|
+
return String(number);
|
|
90
|
+
const numberFirst = this.numberFirst();
|
|
91
|
+
const pair = numberFirst ? [number, year] : [year, number];
|
|
92
|
+
const klass = this.euTypeKey() === "identifier"
|
|
93
|
+
? "Identifier"
|
|
94
|
+
: this.euTitle();
|
|
95
|
+
if (numberFirstFor(klass, String(pair[0]), String(pair[1])) === numberFirst) {
|
|
96
|
+
return pair.join("/");
|
|
97
|
+
}
|
|
98
|
+
return `No ${number}/${year}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export class EuRegulation extends EuIdentifier {
|
|
102
|
+
static polymorphicName = "pubid:eu:regulation";
|
|
103
|
+
static euType = {
|
|
104
|
+
key: "regulation", title: "Regulation", celex: "R", eli: "reg",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export class EuDirective extends EuIdentifier {
|
|
108
|
+
static polymorphicName = "pubid:eu:directive";
|
|
109
|
+
static euType = {
|
|
110
|
+
key: "directive", title: "Directive", celex: "L", eli: "dir",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export class EuDecision extends EuIdentifier {
|
|
114
|
+
static polymorphicName = "pubid:eu:decision";
|
|
115
|
+
static euType = {
|
|
116
|
+
key: "decision", title: "Decision", celex: "D", eli: "dec",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Which of two printed numbers is the year, when the input has no "No".
|
|
121
|
+
* Only one plausible year: that one. Both: a first value from 2015 is
|
|
122
|
+
* the year (every act prints <year>/<number> from 2015); otherwise a
|
|
123
|
+
* regulation prints <number>/<year> and other acts <year>/<number>.
|
|
124
|
+
* Neither plausible: undefined. The renderer calls this too, to know
|
|
125
|
+
* when a plain print would read back as another act. `klass` is the
|
|
126
|
+
* Ruby class-name fragment the gem's Builder.number_first_for compares
|
|
127
|
+
* ("Regulation" — the leaf title — or "Identifier" on the base).
|
|
128
|
+
*/
|
|
129
|
+
export function numberFirstFor(klass, first, second) {
|
|
130
|
+
const firstYear = isPlausibleYear(first);
|
|
131
|
+
const secondYear = isPlausibleYear(second);
|
|
132
|
+
if (!firstYear && !secondYear)
|
|
133
|
+
return undefined;
|
|
134
|
+
if (firstYear !== secondYear)
|
|
135
|
+
return !firstYear;
|
|
136
|
+
if (Number(first) >= FIXED_ORDER_YEAR)
|
|
137
|
+
return false;
|
|
138
|
+
return klass === "Regulation";
|
|
139
|
+
}
|
|
140
|
+
/** The first Official Journal acts (ECSC) date from 1952. */
|
|
141
|
+
export function isPlausibleYear(value) {
|
|
142
|
+
return value.length === 4 && Number(value) >= 1952 && Number(value) <= 2099;
|
|
143
|
+
}
|
|
144
|
+
/** "0079" -> "79", "0" stays "0" (Ruby strip_zeros: leading zeros only,
|
|
145
|
+
* never the bare zero). */
|
|
146
|
+
export function stripLeadingZeros(number) {
|
|
147
|
+
return number.replace(/^0+(?=\d)/, "");
|
|
148
|
+
}
|
|
149
|
+
// The *_TYPE_MAP role: polymorphic dispatch for the three leaves plus
|
|
150
|
+
// the base (a hand-built hash without a leaf class serializes as
|
|
151
|
+
// pubid:eu:identifier — the gem's Identifier class itself).
|
|
152
|
+
registerType(EuIdentifier);
|
|
153
|
+
registerType(EuRegulation);
|
|
154
|
+
registerType(EuDirective);
|
|
155
|
+
registerType(EuDecision);
|
|
@@ -21,10 +21,10 @@ const NUMBER_YEAR_SPLIT = /^(.+?)\s*[-—–]\s*(\d{2}|\d{4})$/;
|
|
|
21
21
|
// flavor's identifier — that is what routes the joint "ISO/IEC …"
|
|
22
22
|
// adoptions to the ISO flavor ahead of IEC.
|
|
23
23
|
const FOREIGN_FALLBACK_ORDER = [
|
|
24
|
-
"tgpp", "ansi", "astm", "bipm",
|
|
24
|
+
"tgpp", "ansi", "arxiv", "astm", "bipm",
|
|
25
25
|
"bsi",
|
|
26
26
|
"calconnect", "ccsds", "cen_cenelec", "cie", "doi", "easc", "ecma",
|
|
27
|
-
"etsi", "gb", "iala", "iana", "idf", "iec", "ieee", "ietf", "iho",
|
|
27
|
+
"etsi", "eu", "gb", "iala", "iana", "idf", "iec", "ieee", "ietf", "iho",
|
|
28
28
|
"isbn", "iso", "itu", "jcgm", "jis", "nist", "oasis", "ogc", "oiml",
|
|
29
29
|
"omg", "plateau", "un", "w3c", "xsf",
|
|
30
30
|
];
|
package/dist/flavors/index.js
CHANGED
|
@@ -45,6 +45,9 @@ import { apiGrammarImplementation } from "./api/index.js";
|
|
|
45
45
|
import { ituGrammarImplementation } from "./itu/index.js";
|
|
46
46
|
import { ietfGrammarImplementation } from "./ietf/index.js";
|
|
47
47
|
import { ialaGrammarImplementation } from "./iala/index.js";
|
|
48
|
+
import { euGrammarImplementation } from "./eu/index.js";
|
|
49
|
+
import { arxivGrammarImplementation } from "./arxiv/index.js";
|
|
50
|
+
import { wmoGrammarImplementation } from "./wmo/index.js";
|
|
48
51
|
/**
|
|
49
52
|
* The grammar-wave registry: flavors whose Ruby grammar has been ported
|
|
50
53
|
* to a TypeScript implementation. A flavor listed here parses
|
|
@@ -172,6 +175,12 @@ function grammarImplementationSwitch(flavor) {
|
|
|
172
175
|
return ietfGrammarImplementation();
|
|
173
176
|
case "iala":
|
|
174
177
|
return ialaGrammarImplementation();
|
|
178
|
+
case "eu":
|
|
179
|
+
return euGrammarImplementation();
|
|
180
|
+
case "arxiv":
|
|
181
|
+
return arxivGrammarImplementation();
|
|
182
|
+
case "wmo":
|
|
183
|
+
return wmoGrammarImplementation();
|
|
175
184
|
default:
|
|
176
185
|
return undefined;
|
|
177
186
|
}
|
|
@@ -93,6 +93,15 @@ const KIND_PREFIXES = {
|
|
|
93
93
|
"technical-specification": "TS",
|
|
94
94
|
};
|
|
95
95
|
class JisIdentifier extends BaseIdentifier {
|
|
96
|
+
// The bare SYMBOL face (`symbol: ""`, rendered "…SYMBOL") and the
|
|
97
|
+
// no-symbol face (`symbol` undefined) are distinct states of a
|
|
98
|
+
// two-valued attribute — the match is absolute equality, blank-vs-blank
|
|
99
|
+
// included (the gem's subset_attribute_match? override, pubid main
|
|
100
|
+
// ef8f041c / 2.0.45). Declared exact-blank rather than strict: the
|
|
101
|
+
// strict nil≈empty shortcut is exactly the tolerance this law rejects,
|
|
102
|
+
// and the gem likewise routes :symbol before both strict and value
|
|
103
|
+
// matching.
|
|
104
|
+
static subsetExactBlanks = ["symbol"];
|
|
96
105
|
/** The rendered document code, e.g. "B 0205-1". */
|
|
97
106
|
code() {
|
|
98
107
|
if (this.base !== undefined)
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
* codec with no node-only module in the graph.
|
|
35
35
|
*/
|
|
36
36
|
import "./amca/model.js";
|
|
37
|
+
import "./ansi/model.js";
|
|
37
38
|
import "./api/model.js";
|
|
39
|
+
import "./arxiv/model.js";
|
|
38
40
|
import "./ashrae/model.js";
|
|
39
41
|
import "./asme/model.js";
|
|
40
42
|
import "./astm/model.js";
|
|
@@ -42,6 +44,7 @@ import "./bsi/model.js";
|
|
|
42
44
|
import "./cen_cenelec/model.js";
|
|
43
45
|
import "./cie/model.js";
|
|
44
46
|
import "./csa/model.js";
|
|
47
|
+
import "./eu/model.js";
|
|
45
48
|
import "./evs/model.js";
|
|
46
49
|
import "./gost/model.js";
|
|
47
50
|
import "./idf/model.js";
|
|
@@ -51,7 +54,7 @@ import "./iso/model.js";
|
|
|
51
54
|
import "./itu/model.js";
|
|
52
55
|
import "./nist/model.js";
|
|
53
56
|
import "./oiml/model.js";
|
|
54
|
-
import "./
|
|
57
|
+
import "./wmo/model.js";
|
|
55
58
|
import "./bipm/index.js";
|
|
56
59
|
import "./calconnect/index.js";
|
|
57
60
|
import "./ccsds/model.js";
|
|
@@ -35,7 +35,9 @@
|
|
|
35
35
|
*/
|
|
36
36
|
// Model-registrant flavors: registration lives in <flavor>/model.js.
|
|
37
37
|
import "./amca/model.js";
|
|
38
|
+
import "./ansi/model.js";
|
|
38
39
|
import "./api/model.js";
|
|
40
|
+
import "./arxiv/model.js";
|
|
39
41
|
import "./ashrae/model.js";
|
|
40
42
|
import "./asme/model.js";
|
|
41
43
|
import "./astm/model.js";
|
|
@@ -43,6 +45,7 @@ import "./bsi/model.js";
|
|
|
43
45
|
import "./cen_cenelec/model.js";
|
|
44
46
|
import "./cie/model.js";
|
|
45
47
|
import "./csa/model.js";
|
|
48
|
+
import "./eu/model.js";
|
|
46
49
|
import "./evs/model.js";
|
|
47
50
|
import "./gost/model.js";
|
|
48
51
|
import "./idf/model.js";
|
|
@@ -52,8 +55,8 @@ import "./iso/model.js";
|
|
|
52
55
|
import "./itu/model.js";
|
|
53
56
|
import "./nist/model.js";
|
|
54
57
|
import "./oiml/model.js";
|
|
58
|
+
import "./wmo/model.js";
|
|
55
59
|
// Index-registrant flavors: registration lives in <flavor>/index.js.
|
|
56
|
-
import "./ansi/index.js";
|
|
57
60
|
import "./bipm/index.js";
|
|
58
61
|
import "./calconnect/index.js";
|
|
59
62
|
// ccsds (pubid-ts#178): the registration classes live on ccsds/model.js
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ParseFailed } from "../../grammar/engine.js";
|
|
2
|
+
import { PubidRuntime } from "../../parg/runtime.js";
|
|
3
|
+
import { WmoAnnex, WmoPublication, WmoStandard } from "./model.js";
|
|
4
|
+
export * from "./model.js";
|
|
5
|
+
/**
|
|
6
|
+
* The wmo parse entry — the same baked artifact the Ruby flavor runs
|
|
7
|
+
* (pubid-grammar grammars/wmo.parg -> artifacts/wmo.json, sealed at
|
|
8
|
+
* parsanol 1.5.1.0), loaded through the artifact runtime. The builder
|
|
9
|
+
* mirrors Pubid::Wmo::Builder: the grammar carries exactly one
|
|
10
|
+
* doc_number and edition_value per alternative path, so one flat bound
|
|
11
|
+
* map serves all three types and the dispatch keys off `annex_marker`
|
|
12
|
+
* and `wmomarker`.
|
|
13
|
+
*/
|
|
14
|
+
function buildWmo(data) {
|
|
15
|
+
const number = data["doc_number"] === undefined ? undefined : String(data["doc_number"]);
|
|
16
|
+
const edition = data["edition_value"] === undefined ? undefined : String(data["edition_value"]);
|
|
17
|
+
const annexMarker = data["annex_marker"] === undefined ? undefined : String(data["annex_marker"]);
|
|
18
|
+
const annexLetter = data["annex_letter"] === undefined ? undefined : String(data["annex_letter"]);
|
|
19
|
+
if (annexMarker !== undefined) {
|
|
20
|
+
const attrs = {
|
|
21
|
+
base: new WmoStandard({ number }),
|
|
22
|
+
annex_form: annexMarker,
|
|
23
|
+
};
|
|
24
|
+
if (annexLetter !== undefined)
|
|
25
|
+
attrs["letter"] = annexLetter;
|
|
26
|
+
if (edition !== undefined)
|
|
27
|
+
attrs["edition"] = edition;
|
|
28
|
+
return new WmoAnnex(attrs);
|
|
29
|
+
}
|
|
30
|
+
if (data["wmomarker"] !== undefined) {
|
|
31
|
+
return new WmoPublication(edition !== undefined ? { number, edition } : { number });
|
|
32
|
+
}
|
|
33
|
+
return new WmoStandard(edition !== undefined ? { number, edition } : { number });
|
|
34
|
+
}
|
|
35
|
+
let cachedRuntime;
|
|
36
|
+
export function wmoGrammarImplementation() {
|
|
37
|
+
return {
|
|
38
|
+
parse(input) {
|
|
39
|
+
cachedRuntime ??= PubidRuntime.load("wmo");
|
|
40
|
+
const bound = cachedRuntime.parseAndBind(input);
|
|
41
|
+
if (bound === null || typeof bound !== "object" || Array.isArray(bound)) {
|
|
42
|
+
throw new ParseFailed("wmo: the artifact rejected the input", 0);
|
|
43
|
+
}
|
|
44
|
+
return buildWmo(bound);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|