@pubid/pubid 0.1.58 → 0.1.60

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 CHANGED
@@ -25,7 +25,7 @@ consumed here at a **pinned ref** and are never edited from this repo.
25
25
 
26
26
  ## Status
27
27
 
28
- **All 42 flavors supported in corpus mode.** The pubid-testsuite corpus is
28
+ **All 46 flavors supported in corpus mode.** The pubid-testsuite corpus is
29
29
  a **closed universe**: every canonical spelling, canonical hash and URN,
30
30
  plus every attested non-normalized alias. pubid-ts resolves and normalizes
31
31
  any identifier IN that universe, and nothing outside it:
@@ -84,12 +84,12 @@ package — though it still uses Node's `fs`/`zlib` to read it, so
84
84
  browser runtimes remain out of scope.
85
85
 
86
86
  The conformance gate enforces corpus mode over the whole testsuite on
87
- every CI run: 42/42 flavors, canonical hash, human form, URN, alias
87
+ every CI run: 46/46 flavors, canonical hash, human form, URN, alias
88
88
  normalization, negative rejection and deserialize idempotency.
89
89
 
90
90
  ## Grammar mode: open-universe runtime parsing
91
91
 
92
- All 42 flavors are grammar-backed and ship the wave plan end to end
92
+ All 46 flavors are grammar-backed and ship the wave plan end to end
93
93
  (core model → parser engine → builder → normalizer → renderer → urn →
94
94
  per-flavor grammars). Grammar implementations parse real-world
95
95
  identifiers far beyond the published corpus — novel spellings, unseen
Binary file
@@ -1,24 +1,3 @@
1
- import { Grammar } from "../../grammar/engine.js";
2
1
  import type { FlavorImplementation } from "../../conformance/implementation.js";
3
- import { BaseIdentifier } from "../../model/identifier.js";
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 { match, str } from "../../grammar/engine.js";
2
- import { ParseFailed, parseGrammar } from "../../grammar/engine.js";
3
- import { BaseIdentifier, registerType } from "../../model/identifier.js";
4
- import { extendAttributes, keyValue } from "../../model/attribute.js";
5
- import { BaseUrnGenerator } from "../../model/urn-generator.js";
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
- * 1:1 port of lib/pubid/ansi/ on the unified model. Copublishers
10
- * (controlled vocabulary) rewrite the URN namespace; the dash segment
11
- * serializes as `part` (Ruby Builder split-on-dash), the ":YYYY" form as
12
- * `year`; "Std" is consumed and dropped; languages round-trip.
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
- const ORGANIZATIONS = ["ISO", "IEC", "IEEE", "SAE", "ASME", "ASTM"];
15
- function buildRules() {
16
- const rules = {};
17
- const rule = (name, build) => {
18
- rules[name] = build();
19
- };
20
- const space = str(" ");
21
- const spaceQ = space.maybe();
22
- const digits = match("[0-9]").repeat(1, Infinity);
23
- const dashDigits = str("-").then(digits).maybe();
24
- rule("copublishers", () => str("/")
25
- .then(spaceQ, ORGANIZATIONS.reduce((acc, org) => acc.or(str(org)), str(ORGANIZATIONS[0])).as("copublisher"))
26
- .repeat(1, Infinity)
27
- .as("copublishers"));
28
- rule("std_keyword", () => str("Std").then(space).maybe());
29
- rule("number_with_part", () => match("[A-Z]")
30
- .repeat(1, Infinity)
31
- .then(digits, str(".").then(digits).repeat(0, 3), match("[A-Z]").maybe(), dashDigits)
32
- .or(digits.then(str(".").then(digits, match("[a-z]").maybe()).repeat(0, 2), dashDigits))
33
- .as("number_with_part"));
34
- rule("year_digits", () => str("19").or(str("20")).then(match("\\d").repeat(2, 2), digits.absent()));
35
- rule("date", () => str(":").then(rules["year_digits"].as("date")));
36
- rule("language", () => str("(")
37
- .then(match("[a-z]")
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
- registerType(AnsiIdentifier);
102
- function extractCopublishers(raw) {
103
- const list = Array.isArray(raw) ? raw : [raw];
104
- return list.map((p) => {
105
- const body = typeof p === "object" && p !== null && "copublisher" in p
106
- ? String(p["copublisher"])
107
- : String(p);
108
- return new Publisher({ body });
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
- class AnsiBuilder extends BaseBuilder {
112
- defaultIdentifierClass() {
113
- return AnsiIdentifier;
114
- }
115
- cast(key, value) {
116
- if (key === "number_with_part") {
117
- // Ruby Builder: split on "-", first segment = number, second = part.
118
- const segments = String(value).split("-");
119
- return segments[1] === undefined ? { number: segments[0] } : { number: segments[0], part: segments[1] };
120
- }
121
- if (key === "publisher") {
122
- return { publisher: new Publisher({ body: String(value) }) };
123
- }
124
- if (key === "copublishers") {
125
- return { copublishers: extractCopublishers(value) };
126
- }
127
- if (key === "date") {
128
- return { year: String(value) };
129
- }
130
- if (key === "languages") {
131
- return { languages: this.parseLanguages(value) };
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
- const tree = parseGrammar(ansiGrammar, input);
141
- if (typeof tree !== "object" || tree === null || Array.isArray(tree)) {
142
- throw new ParseFailed("ANSI: unexpected parse tree", 0);
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 builder.build(tree);
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);
@@ -10,7 +10,9 @@ export * from "./model.js";
10
10
  * Pubid::Eu::Builder: CELEX and ELI fix year/number by position, the
11
11
  * canonical and Official-Journal forms carry two numbers whose ORDER is
12
12
  * not in the grammar (number_first_for), and the renderer's "No"
13
- * disambiguation lives on the model (EuIdentifier#numbers).
13
+ * disambiguation lives on the model (EuIdentifier#numbers). The ELI
14
+ * subtype ("reg_impl") is stripped before the grammar and carried as an
15
+ * equality-ignored facet, as Identifier.bound_without_subtype does.
14
16
  */
15
17
  // --- Builder (lib/pubid/eu/builder.rb) ---------------------------------------
16
18
  const TYPES_BY_WORD = {
@@ -34,6 +36,27 @@ const s = (v) => {
34
36
  const text = String(v);
35
37
  return text.length > 0 ? text : undefined;
36
38
  };
39
+ // The subtypes CELLAR gives each ELI type: implementing and delegated
40
+ // acts of every type, and the financial regulation (Identifier::
41
+ // ELI_SUBTYPES).
42
+ const ELI_SUBTYPES = {
43
+ reg: ["impl", "del", "financ"],
44
+ dir: ["impl", "del"],
45
+ dec: ["impl", "del"],
46
+ };
47
+ // The subtype of an ELI input, removed before the baked grammar (which
48
+ // knows only reg/dir/dec), as BSI and IETF strip their prefixes
49
+ // (Identifier::ELI_SUBTYPE).
50
+ const ELI_SUBTYPE = /^(https?:\/\/data\.europa\.eu\/eli\/(reg|dir|dec))_([a-z]+)\//;
51
+ /** A known subtype of a known ELI type, or undefined. An unknown one
52
+ * stays in the input, so the grammar rejects it. */
53
+ function eliSubtype(identifier) {
54
+ const match = ELI_SUBTYPE.exec(identifier);
55
+ if (match === null)
56
+ return undefined;
57
+ const subtype = match[3];
58
+ return (ELI_SUBTYPES[match[2]] ?? []).includes(subtype) ? subtype : undefined;
59
+ }
37
60
  function positional(data) {
38
61
  const letter = s(data["celex_letter"]);
39
62
  const eli = s(data["eli_type"]);
@@ -77,7 +100,7 @@ function family(data) {
77
100
  }
78
101
  return bracket ?? suffix;
79
102
  }
80
- function buildEu(data) {
103
+ function buildEu(data, subtype) {
81
104
  const act = positional(data) ?? fromPair(data);
82
105
  if (!isPlausibleYear(act.year)) {
83
106
  throw new Error(`EU legal act: ${act.year} is not a year`);
@@ -86,10 +109,12 @@ function buildEu(data) {
86
109
  if (number === "0") {
87
110
  throw new Error("EU legal act: number 0");
88
111
  }
112
+ const fam = family(data);
89
113
  const id = new act.klass({
90
114
  number,
91
115
  date: { year: act.year },
92
- ...(family(data) !== undefined ? { family: family(data) } : {}),
116
+ ...(fam !== undefined ? { family: fam } : {}),
117
+ ...(subtype !== undefined ? { subtype } : {}),
93
118
  });
94
119
  // Keep the order only when it is not what the render rule prints.
95
120
  if (act.numberFirst !== undefined && act.numberFirst !== id.defaultNumberFirst()) {
@@ -103,11 +128,18 @@ export function euGrammarImplementation() {
103
128
  return {
104
129
  parse(input) {
105
130
  cachedRuntime ??= PubidRuntime.load("eu");
106
- const bound = cachedRuntime.parseAndBind(input);
131
+ // An ELI subtype ("reg_impl") is stripped before the grammar, as
132
+ // the reference's bound_without_subtype does; the subtype rides
133
+ // the build as an equality-ignored facet.
134
+ const subtype = eliSubtype(input);
135
+ const stripped = subtype !== undefined
136
+ ? input.replace(ELI_SUBTYPE, "$1/")
137
+ : input;
138
+ const bound = cachedRuntime.parseAndBind(stripped);
107
139
  if (bound === null || typeof bound !== "object") {
108
140
  throw new ParseFailed("eu: the artifact rejected the input", 0);
109
141
  }
110
- return buildEu(bound);
142
+ return buildEu(bound, subtype);
111
143
  },
112
144
  };
113
145
  }
@@ -14,6 +14,13 @@ import type { PubidDate } from "../../model/component.js";
14
14
  * `number_first` is the print ORDER of the two numbers — spelling, not
15
15
  * identity: it serializes but `==` skips it (equality_ignored), so
16
16
  * "EU Decision 1082/2013" equals the CELEX number 32013D1082.
17
+ * `subtype` is the ELI type subtype ("impl" implementing act, "del"
18
+ * delegated act, "financ" financial regulation) from an ELI such as
19
+ * http://data.europa.eu/eli/reg_impl/2016/1356/oj. Such an act shares
20
+ * the numbering of its type (the Official Journal cites it as
21
+ * "Commission Implementing Regulation (EU) 2016/1356"), so the subtype
22
+ * is not identity either: "EU Regulation 2016/1356" is the same act.
23
+ * Only #toEli reads it, to give the ELI back.
17
24
  */
18
25
  /** The act-type metadata each leaf class carries (Ruby self.type). */
19
26
  export interface EuType {
@@ -38,6 +45,7 @@ export declare class EuIdentifier extends BaseIdentifier {
38
45
  readonly date: PubidDate | undefined;
39
46
  readonly family: string | undefined;
40
47
  readonly number_first: boolean | undefined;
48
+ readonly subtype: string | undefined;
41
49
  /** The year, read off the date component (Ruby #year). */
42
50
  get year(): string | undefined;
43
51
  /** A regulation with a year before 2015 prints <number>/<year>;
@@ -65,7 +73,8 @@ export declare class EuIdentifier extends BaseIdentifier {
65
73
  /** The CELEX number: sector 3, year, type letter, number padded to 4.
66
74
  * (The base class carries no type letter — the segments join empty.) */
67
75
  toCelex(): string;
68
- /** The ELI of the act as published in the Official Journal. */
76
+ /** The ELI of the act as published in the Official Journal — the
77
+ * subtype rides the type segment ("reg_impl") when the input had one. */
69
78
  toEli(): string;
70
79
  /** The EU has no registered URN namespace (the ELI is its official
71
80
  * identifier). This pubid-invented form keeps the act type, so a
@@ -12,10 +12,11 @@ export class EuIdentifier extends BaseIdentifier {
12
12
  static attributes = extendAttributes(BaseIdentifier, {
13
13
  family: { type: "string" },
14
14
  number_first: { type: "boolean", equalityIgnored: true },
15
+ subtype: { type: "string", equalityIgnored: true },
15
16
  });
16
- // The gem's key_value whitelist: only the four slots hit the wire; the
17
+ // The gem's key_value whitelist: only the five slots hit the wire; the
17
18
  // 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 mappings = keyValue({ wire: "number", to: "number" }, { wire: "date", to: "date" }, { wire: "family", to: "family" }, { wire: "number_first", to: "number_first" }, { wire: "subtype", to: "subtype" });
19
20
  static euType = { key: "identifier", title: "", celex: null, eli: null };
20
21
  /** The year, read off the date component (Ruby #year). */
21
22
  get year() {
@@ -66,9 +67,12 @@ export class EuIdentifier extends BaseIdentifier {
66
67
  toCelex() {
67
68
  return `3${this.year ?? ""}${this.euCelexLetter() ?? ""}${(this.number ?? "").padStart(4, "0")}`;
68
69
  }
69
- /** The ELI of the act as published in the Official Journal. */
70
+ /** The ELI of the act as published in the Official Journal — the
71
+ * subtype rides the type segment ("reg_impl") when the input had one. */
70
72
  toEli() {
71
- return `http://data.europa.eu/eli/${this.euEliSegment() ?? ""}/${this.year ?? ""}/${this.number ?? ""}/oj`;
73
+ const eli = this.euEliSegment() ?? "";
74
+ const typed = this.subtype !== undefined ? `${eli}_${this.subtype}` : eli;
75
+ return `http://data.europa.eu/eli/${typed}/${this.year ?? ""}/${this.number ?? ""}/oj`;
72
76
  }
73
77
  /** The EU has no registered URN namespace (the ELI is its official
74
78
  * identifier). This pubid-invented form keeps the act type, so a
@@ -47,6 +47,7 @@ import { ietfGrammarImplementation } from "./ietf/index.js";
47
47
  import { ialaGrammarImplementation } from "./iala/index.js";
48
48
  import { euGrammarImplementation } from "./eu/index.js";
49
49
  import { arxivGrammarImplementation } from "./arxiv/index.js";
50
+ import { wmoGrammarImplementation } from "./wmo/index.js";
50
51
  /**
51
52
  * The grammar-wave registry: flavors whose Ruby grammar has been ported
52
53
  * to a TypeScript implementation. A flavor listed here parses
@@ -178,6 +179,8 @@ function grammarImplementationSwitch(flavor) {
178
179
  return euGrammarImplementation();
179
180
  case "arxiv":
180
181
  return arxivGrammarImplementation();
182
+ case "wmo":
183
+ return wmoGrammarImplementation();
181
184
  default:
182
185
  return undefined;
183
186
  }