@pubid/pubid 0.1.3 → 0.1.4
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/artifact/corpus.json.gz +0 -0
- package/dist/conformance/cli.js +5 -1
- package/dist/flavors/amca/grammar.d.ts +4 -0
- package/dist/flavors/amca/grammar.js +87 -0
- package/dist/flavors/amca/index.d.ts +4 -0
- package/dist/flavors/amca/index.js +76 -0
- package/dist/flavors/amca/model.d.ts +29 -0
- package/dist/flavors/amca/model.js +146 -0
- package/dist/flavors/ansi/index.d.ts +24 -0
- package/dist/flavors/ansi/index.js +147 -0
- package/dist/flavors/api/grammar.d.ts +4 -0
- package/dist/flavors/api/grammar.js +79 -0
- package/dist/flavors/api/index.d.ts +4 -0
- package/dist/flavors/api/index.js +71 -0
- package/dist/flavors/api/model.d.ts +27 -0
- package/dist/flavors/api/model.js +114 -0
- package/dist/flavors/ashrae/grammar.d.ts +2 -0
- package/dist/flavors/ashrae/grammar.js +667 -0
- package/dist/flavors/ashrae/index.d.ts +4 -0
- package/dist/flavors/ashrae/index.js +306 -0
- package/dist/flavors/ashrae/model.d.ts +87 -0
- package/dist/flavors/ashrae/model.js +335 -0
- package/dist/flavors/ashrae/preprocessor.d.ts +7 -0
- package/dist/flavors/ashrae/preprocessor.js +44 -0
- package/dist/flavors/asme/grammar.d.ts +2 -0
- package/dist/flavors/asme/grammar.js +200 -0
- package/dist/flavors/asme/index.d.ts +4 -0
- package/dist/flavors/asme/index.js +138 -0
- package/dist/flavors/asme/model.d.ts +34 -0
- package/dist/flavors/asme/model.js +123 -0
- package/dist/flavors/astm/grammar.d.ts +2 -0
- package/dist/flavors/astm/grammar.js +110 -0
- package/dist/flavors/astm/index.d.ts +2 -0
- package/dist/flavors/astm/index.js +127 -0
- package/dist/flavors/astm/model.d.ts +42 -0
- package/dist/flavors/astm/model.js +263 -0
- package/dist/flavors/bipm/index.d.ts +30 -0
- package/dist/flavors/bipm/index.js +434 -0
- package/dist/flavors/bsi/grammar.d.ts +4 -0
- package/dist/flavors/bsi/grammar.js +535 -0
- package/dist/flavors/bsi/index.d.ts +4 -0
- package/dist/flavors/bsi/index.js +941 -0
- package/dist/flavors/bsi/model.d.ts +127 -0
- package/dist/flavors/bsi/model.js +863 -0
- package/dist/flavors/calconnect/index.d.ts +21 -0
- package/dist/flavors/calconnect/index.js +113 -0
- package/dist/flavors/cen_cenelec/grammar.d.ts +4 -0
- package/dist/flavors/cen_cenelec/grammar.js +107 -0
- package/dist/flavors/cen_cenelec/index.d.ts +5 -0
- package/dist/flavors/cen_cenelec/index.js +263 -0
- package/dist/flavors/cen_cenelec/model.d.ts +45 -0
- package/dist/flavors/cen_cenelec/model.js +490 -0
- package/dist/flavors/cie/grammar.d.ts +5 -0
- package/dist/flavors/cie/grammar.js +127 -0
- package/dist/flavors/cie/index.d.ts +2 -0
- package/dist/flavors/cie/index.js +311 -0
- package/dist/flavors/cie/model.d.ts +122 -0
- package/dist/flavors/cie/model.js +464 -0
- package/dist/flavors/csa/grammar.d.ts +6 -0
- package/dist/flavors/csa/grammar.js +239 -0
- package/dist/flavors/csa/index.d.ts +2 -0
- package/dist/flavors/csa/index.js +634 -0
- package/dist/flavors/csa/model.d.ts +33 -0
- package/dist/flavors/csa/model.js +505 -0
- package/dist/flavors/doi/index.d.ts +13 -0
- package/dist/flavors/doi/index.js +65 -0
- package/dist/flavors/easc/index.d.ts +4 -0
- package/dist/flavors/easc/index.js +107 -0
- package/dist/flavors/ecma/index.d.ts +4 -0
- package/dist/flavors/ecma/index.js +117 -0
- package/dist/flavors/etsi/index.d.ts +14 -0
- package/dist/flavors/etsi/index.js +307 -0
- package/dist/flavors/evs/grammar.d.ts +2 -0
- package/dist/flavors/evs/grammar.js +22 -0
- package/dist/flavors/evs/index.d.ts +2 -0
- package/dist/flavors/evs/index.js +24 -0
- package/dist/flavors/evs/model.d.ts +19 -0
- package/dist/flavors/evs/model.js +36 -0
- package/dist/flavors/gb/index.d.ts +24 -0
- package/dist/flavors/gb/index.js +111 -0
- package/dist/flavors/gost/grammar.d.ts +2 -0
- package/dist/flavors/gost/grammar.js +46 -0
- package/dist/flavors/gost/index.d.ts +2 -0
- package/dist/flavors/gost/index.js +165 -0
- package/dist/flavors/gost/model.d.ts +61 -0
- package/dist/flavors/gost/model.js +147 -0
- package/dist/flavors/gost/prefix_routes.d.ts +15 -0
- package/dist/flavors/gost/prefix_routes.js +192 -0
- package/dist/flavors/iala/index.d.ts +32 -0
- package/dist/flavors/iala/index.js +300 -0
- package/dist/flavors/iana/index.d.ts +19 -0
- package/dist/flavors/iana/index.js +71 -0
- package/dist/flavors/idf/grammar.d.ts +2 -0
- package/dist/flavors/idf/grammar.js +71 -0
- package/dist/flavors/idf/index.d.ts +2 -0
- package/dist/flavors/idf/index.js +100 -0
- package/dist/flavors/idf/model.d.ts +54 -0
- package/dist/flavors/idf/model.js +359 -0
- package/dist/flavors/iec/grammar.d.ts +3 -0
- package/dist/flavors/iec/grammar.js +187 -0
- package/dist/flavors/iec/index.d.ts +4 -0
- package/dist/flavors/iec/index.js +507 -0
- package/dist/flavors/iec/model.d.ts +54 -0
- package/dist/flavors/iec/model.js +437 -0
- package/dist/flavors/ieee/grammar.d.ts +2 -0
- package/dist/flavors/ieee/grammar.js +626 -0
- package/dist/flavors/ieee/index.d.ts +3 -0
- package/dist/flavors/ieee/index.js +1186 -0
- package/dist/flavors/ieee/model.d.ts +142 -0
- package/dist/flavors/ieee/model.js +1148 -0
- package/dist/flavors/ieee/preprocessor.d.ts +8 -0
- package/dist/flavors/ieee/preprocessor.js +410 -0
- package/dist/flavors/ieee/update_codes.d.ts +8 -0
- package/dist/flavors/ieee/update_codes.js +191 -0
- package/dist/flavors/ietf/index.d.ts +30 -0
- package/dist/flavors/ietf/index.js +151 -0
- package/dist/flavors/iho/index.d.ts +4 -0
- package/dist/flavors/iho/index.js +126 -0
- package/dist/flavors/index.d.ts +9 -0
- package/dist/flavors/index.js +136 -0
- package/dist/flavors/isbn/index.d.ts +13 -0
- package/dist/flavors/isbn/index.js +97 -0
- package/dist/flavors/iso/grammar.d.ts +2 -0
- package/dist/flavors/iso/grammar.js +207 -0
- package/dist/flavors/iso/index.d.ts +2 -0
- package/dist/flavors/iso/index.js +343 -0
- package/dist/flavors/iso/model.d.ts +159 -0
- package/dist/flavors/iso/model.js +802 -0
- package/dist/flavors/iso/stages.generated.d.ts +13 -0
- package/dist/flavors/iso/stages.generated.js +391 -0
- package/dist/flavors/itu/grammar.d.ts +4 -0
- package/dist/flavors/itu/grammar.js +205 -0
- package/dist/flavors/itu/index.d.ts +2 -0
- package/dist/flavors/itu/index.js +224 -0
- package/dist/flavors/itu/model.d.ts +184 -0
- package/dist/flavors/itu/model.js +599 -0
- package/dist/flavors/jcgm/index.d.ts +7 -0
- package/dist/flavors/jcgm/index.js +300 -0
- package/dist/flavors/jis/index.d.ts +4 -0
- package/dist/flavors/jis/index.js +267 -0
- package/dist/flavors/nist/grammar.d.ts +2 -0
- package/dist/flavors/nist/grammar.js +287 -0
- package/dist/flavors/nist/index.d.ts +2 -0
- package/dist/flavors/nist/index.js +1244 -0
- package/dist/flavors/nist/model.d.ts +155 -0
- package/dist/flavors/nist/model.js +823 -0
- package/dist/flavors/nist/preprocessor.d.ts +11 -0
- package/dist/flavors/nist/preprocessor.js +281 -0
- package/dist/flavors/oasis/index.d.ts +23 -0
- package/dist/flavors/oasis/index.js +110 -0
- package/dist/flavors/ogc/index.d.ts +20 -0
- package/dist/flavors/ogc/index.js +75 -0
- package/dist/flavors/oiml/grammar.d.ts +2 -0
- package/dist/flavors/oiml/grammar.js +180 -0
- package/dist/flavors/oiml/implementation.d.ts +9 -0
- package/dist/flavors/oiml/implementation.js +16 -0
- package/dist/flavors/oiml/model.d.ts +4 -0
- package/dist/flavors/oiml/model.js +462 -0
- package/dist/flavors/omg/index.d.ts +14 -0
- package/dist/flavors/omg/index.js +73 -0
- package/dist/flavors/plateau/index.d.ts +4 -0
- package/dist/flavors/plateau/index.js +97 -0
- package/dist/flavors/tgpp/index.d.ts +4 -0
- package/dist/flavors/tgpp/index.js +122 -0
- package/dist/flavors/un/index.d.ts +13 -0
- package/dist/flavors/un/index.js +90 -0
- package/dist/flavors/w3c/index.d.ts +14 -0
- package/dist/flavors/w3c/index.js +148 -0
- package/dist/flavors/xsf/index.d.ts +18 -0
- package/dist/flavors/xsf/index.js +65 -0
- package/dist/grammar/engine.d.ts +78 -0
- package/dist/grammar/engine.js +351 -0
- package/dist/model/attribute.d.ts +54 -0
- package/dist/model/attribute.js +53 -0
- package/dist/model/builder.d.ts +39 -0
- package/dist/model/builder.js +124 -0
- package/dist/model/component.d.ts +70 -0
- package/dist/model/component.js +170 -0
- package/dist/model/identifier.d.ts +83 -0
- package/dist/model/identifier.js +270 -0
- package/dist/model/urn-generator.d.ts +27 -0
- package/dist/model/urn-generator.js +91 -0
- package/package.json +1 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { match, ref, str } from "../../grammar/engine.js";
|
|
2
|
+
/**
|
|
3
|
+
* Port of lib/pubid/csa/parser.rb — 1:1. Root: identifier.
|
|
4
|
+
*
|
|
5
|
+
* Branch order: ISO/IEC adoption, series, CEC, bundled (+), combined
|
|
6
|
+
* slash, combined comma, single, code-only.
|
|
7
|
+
*/
|
|
8
|
+
function buildRules() {
|
|
9
|
+
const rules = {};
|
|
10
|
+
const rule = (name, build) => {
|
|
11
|
+
rules[name] = build();
|
|
12
|
+
};
|
|
13
|
+
rule("space", () => str(" "));
|
|
14
|
+
rule("dash", () => str("-"));
|
|
15
|
+
rule("slash", () => str("/"));
|
|
16
|
+
rule("colon", () => str(":"));
|
|
17
|
+
rule("comma", () => str(","));
|
|
18
|
+
rule("dot", () => str("."));
|
|
19
|
+
rule("ampersand", () => str("&"));
|
|
20
|
+
rule("plus", () => str(" + "));
|
|
21
|
+
rule("digit", () => match("[0-9]"));
|
|
22
|
+
rule("digits", () => ref(rules, "digit").repeat(1, Infinity));
|
|
23
|
+
rule("letter", () => match("[A-Z]"));
|
|
24
|
+
rule("letters", () => ref(rules, "letter").repeat(1, Infinity));
|
|
25
|
+
rule("publisher", () => str("CSA").then(ref(rules, "space"))
|
|
26
|
+
.then(str("").as("has_publisher").or(str("0").as("has_publisher"))));
|
|
27
|
+
rule("code_pattern", () =>
|
|
28
|
+
// Pattern 1: pure dotted numbers (12.4, 2.15) + optional single
|
|
29
|
+
// dash-part + optional letter suffix.
|
|
30
|
+
match("[0-9]").repeat(1, Infinity)
|
|
31
|
+
.then(ref(rules, "dot"))
|
|
32
|
+
.then(match("[0-9]").repeat(1, Infinity))
|
|
33
|
+
.then((ref(rules, "dash").then(match("[0-9]").repeat(1, Infinity))).repeat(0, 1))
|
|
34
|
+
.then(ref(rules, "letter").repeat(2, 6).maybe())
|
|
35
|
+
.as("code")
|
|
36
|
+
.or(
|
|
37
|
+
// Pattern 2: pure numbers with HB-style suffix (15189HB)
|
|
38
|
+
match("[0-9]").repeat(1, Infinity)
|
|
39
|
+
.then(ref(rules, "letter").repeat(2, 6))
|
|
40
|
+
.as("code"))
|
|
41
|
+
.or(
|
|
42
|
+
// Pattern 3: letter + numbers with dots then dashes
|
|
43
|
+
ref(rules, "letter")
|
|
44
|
+
.then(match("[0-9]").repeat(1, Infinity))
|
|
45
|
+
.then((ref(rules, "dot").then(match("[0-9]").repeat(1, Infinity))).repeat(0, Infinity))
|
|
46
|
+
.then((ref(rules, "dash").then(match("[0-9]").then(match("[0-9]").absent())
|
|
47
|
+
.or(match("[0-9]").repeat(3, Infinity))
|
|
48
|
+
.or(match("[0-9]").repeat(1, Infinity).then(ref(rules, "letter").repeat(1, 1))))).repeat(0, Infinity))
|
|
49
|
+
.then(ref(rules, "letter").repeat(2, 6).maybe())
|
|
50
|
+
.as("code"))
|
|
51
|
+
.or(
|
|
52
|
+
// Pattern 4: letter + number + dot + optional number
|
|
53
|
+
ref(rules, "letter")
|
|
54
|
+
.then(match("[0-9]").repeat(1, Infinity))
|
|
55
|
+
.then(ref(rules, "dot"))
|
|
56
|
+
.then(match("[0-9]").repeat(1, Infinity).maybe())
|
|
57
|
+
.as("code"))
|
|
58
|
+
.or(
|
|
59
|
+
// Pattern 5: letter + multi-digit number (Z240, A220)
|
|
60
|
+
ref(rules, "letter")
|
|
61
|
+
.then(match("[0-9]").repeat(2, Infinity))
|
|
62
|
+
.as("code")));
|
|
63
|
+
rule("no_notation", () => ref(rules, "space")
|
|
64
|
+
.then(str("NO.").or(str("No.")).as("no_notation"))
|
|
65
|
+
.then(ref(rules, "space")));
|
|
66
|
+
rule("no_number", () => (match("[0-9]").repeat(1, Infinity)
|
|
67
|
+
.then((ref(rules, "dash").then(match("[0-9]").repeat(1, Infinity))).repeat(2, 10))
|
|
68
|
+
.or(match("[0-9]").repeat(5, Infinity).then(ref(rules, "dash")).then(match("[0-9]").repeat(1, Infinity)))
|
|
69
|
+
.or(match("[0-9]").repeat(3, 4)
|
|
70
|
+
.then(ref(rules, "dash"))
|
|
71
|
+
.then(match("[0-9]").then(match("[0-9]").absent())
|
|
72
|
+
.or(match("[0-9]").repeat(3, Infinity))))
|
|
73
|
+
.or(match("[0-9]").repeat(1, Infinity)
|
|
74
|
+
.then((ref(rules, "dot").then(match("[0-9]").repeat(1, Infinity))).repeat(1, 3)))
|
|
75
|
+
.or(match("[0-9]").repeat(1, Infinity))).as("no_number"));
|
|
76
|
+
rule("year_prefix", () => str("F").or(str("M")).as("year_prefix").maybe());
|
|
77
|
+
rule("year_2digit", () => ref(rules, "digit").repeat(2, 2));
|
|
78
|
+
rule("year_4digit", () => ref(rules, "digit").repeat(4, 4));
|
|
79
|
+
const yearBody = () => ref(rules, "year_prefix")
|
|
80
|
+
.then(ref(rules, "year_4digit").or(ref(rules, "year_2digit")).as("year"))
|
|
81
|
+
.or(ref(rules, "year_4digit").or(ref(rules, "year_2digit")).as("year"));
|
|
82
|
+
rule("colon_year", () => str("").as("colon_format")
|
|
83
|
+
.then(ref(rules, "colon"))
|
|
84
|
+
.then(yearBody()));
|
|
85
|
+
rule("dash_year", () => str("").as("dash_format")
|
|
86
|
+
.then(ref(rules, "dash"))
|
|
87
|
+
.then(yearBody()));
|
|
88
|
+
rule("reaffirmation", () => ref(rules, "space")
|
|
89
|
+
.then(str("(R"))
|
|
90
|
+
.then(ref(rules, "year_4digit").as("reaffirmation_4digit")
|
|
91
|
+
.or(ref(rules, "year_2digit").as("reaffirmation_2digit")))
|
|
92
|
+
.then(str(")")));
|
|
93
|
+
rule("amendment_slash", () => ref(rules, "slash")
|
|
94
|
+
.then((str("Amd").then(ref(rules, "space"))).maybe())
|
|
95
|
+
.then(str("A").maybe())
|
|
96
|
+
.then(ref(rules, "digits").as("amendment_number"))
|
|
97
|
+
.then((ref(rules, "colon").then(ref(rules, "year_2digit").as("amendment_year"))).maybe()));
|
|
98
|
+
rule("package_keyword", () => str("Code").or(str("Handbook")).or(str("Training Package")).or(str("Package")));
|
|
99
|
+
rule("package_portion", () => ref(rules, "space")
|
|
100
|
+
.then(ref(rules, "package_keyword"))
|
|
101
|
+
.then((ref(rules, "comma").then(ref(rules, "space")).then(ref(rules, "package_keyword"))
|
|
102
|
+
.or(ref(rules, "space").then(ref(rules, "ampersand")).then(ref(rules, "space"))
|
|
103
|
+
.then(ref(rules, "package_keyword")))).repeat(0, Infinity)));
|
|
104
|
+
rule("series_prefix", () => ref(rules, "letter").repeat(2, 3).as("series_prefix"));
|
|
105
|
+
rule("series_keyword", () => str("SERIES"));
|
|
106
|
+
rule("series_identifier", () => ref(rules, "publisher")
|
|
107
|
+
.then(ref(rules, "code_pattern")
|
|
108
|
+
.or(ref(rules, "letter").then(match("[0-9]").repeat(2, Infinity)).as("code"))
|
|
109
|
+
.or(match("[0-9]").repeat(1, Infinity).then(ref(rules, "dot"))
|
|
110
|
+
.then(match("[0-9]").repeat(1, Infinity)).as("code")))
|
|
111
|
+
.then(ref(rules, "space"))
|
|
112
|
+
.then((ref(rules, "series_prefix").then(ref(rules, "space"))).maybe())
|
|
113
|
+
.then(ref(rules, "series_keyword").as("series_type"))
|
|
114
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year")).maybe())
|
|
115
|
+
.then(ref(rules, "reaffirmation").maybe()));
|
|
116
|
+
rule("cec_identifier", () => ref(rules, "publisher")
|
|
117
|
+
.then(str("C22.2").or(str("C22.3")).or(str("C22.4")).or(str("C22.6")).as("cec_part"))
|
|
118
|
+
.then(ref(rules, "no_notation"))
|
|
119
|
+
.then(ref(rules, "no_number"))
|
|
120
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year")).maybe())
|
|
121
|
+
.then(ref(rules, "reaffirmation").maybe()));
|
|
122
|
+
const adoptionNumber = () => str("ISO/IEC").as("adoption_org")
|
|
123
|
+
.then(ref(rules, "space"))
|
|
124
|
+
.then(str("TR").or(str("TS")).as("iso_type"))
|
|
125
|
+
.then(ref(rules, "space"))
|
|
126
|
+
.then(match("[0-9-]").repeat(1, Infinity).as("adoption_number"))
|
|
127
|
+
.or(str("ISO/IEC").as("adoption_org_with_type")
|
|
128
|
+
.then(ref(rules, "space"))
|
|
129
|
+
.then(match("[0-9-]").repeat(1, Infinity).as("adoption_number")))
|
|
130
|
+
.or(str("ISO").as("adoption_org")
|
|
131
|
+
.then(ref(rules, "space"))
|
|
132
|
+
.then(match("[0-9-]").repeat(1, Infinity).as("adoption_number")))
|
|
133
|
+
.or(str("IEC").as("adoption_org")
|
|
134
|
+
.then(ref(rules, "space"))
|
|
135
|
+
.then(match("[0-9-]").repeat(1, Infinity).as("adoption_number")))
|
|
136
|
+
.or(str("CEI/IEC").as("adoption_org")
|
|
137
|
+
.then(ref(rules, "space"))
|
|
138
|
+
.then(match("[0-9-]").repeat(1, Infinity).as("adoption_number")))
|
|
139
|
+
.or(str("CISPR").as("adoption_org")
|
|
140
|
+
.then(ref(rules, "space"))
|
|
141
|
+
.then(match("[0-9-]").repeat(1, Infinity).as("adoption_number")));
|
|
142
|
+
rule("adoption_identifier", () => ref(rules, "publisher").as("adoption_pub")
|
|
143
|
+
.then(adoptionNumber())
|
|
144
|
+
.then(ref(rules, "colon").or(ref(rules, "dash")).as("adoption_year_sep"))
|
|
145
|
+
.then(ref(rules, "year_4digit").or(ref(rules, "year_2digit")).as("adoption_year"))
|
|
146
|
+
.then((ref(rules, "slash").then(str("A")).then(ref(rules, "digit").as("adoption_amendment"))
|
|
147
|
+
.then(ref(rules, "colon").or(ref(rules, "dash")))
|
|
148
|
+
.then(ref(rules, "year_4digit").or(ref(rules, "year_2digit")).as("adoption_amendment_year"))).maybe())
|
|
149
|
+
.then(ref(rules, "reaffirmation").maybe()));
|
|
150
|
+
rule("iso_iec_adoption", () => ref(rules, "adoption_identifier"));
|
|
151
|
+
const codeTail = () => (ref(rules, "no_notation").then(ref(rules, "no_number"))
|
|
152
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year")))
|
|
153
|
+
.or(ref(rules, "space").then(ref(rules, "series_prefix")).then(ref(rules, "space"))
|
|
154
|
+
.then(ref(rules, "series_keyword").as("series"))
|
|
155
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year"))))
|
|
156
|
+
.or(ref(rules, "space").then(ref(rules, "series_keyword").as("series"))
|
|
157
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year"))))
|
|
158
|
+
.or(ref(rules, "colon_year").or(ref(rules, "dash_year")))).maybe();
|
|
159
|
+
rule("csa_code", () => ref(rules, "publisher")
|
|
160
|
+
.then(ref(rules, "code_pattern"))
|
|
161
|
+
.then(codeTail())
|
|
162
|
+
.then(ref(rules, "amendment_slash").maybe()));
|
|
163
|
+
rule("base_csa_code", () => ref(rules, "publisher")
|
|
164
|
+
.then(ref(rules, "code_pattern"))
|
|
165
|
+
.then(codeTail()));
|
|
166
|
+
rule("continuation_code", () => ref(rules, "publisher").as("has_publisher").maybe()
|
|
167
|
+
.then(ref(rules, "code_pattern"))
|
|
168
|
+
.then(codeTail())
|
|
169
|
+
.then(ref(rules, "amendment_slash").maybe()));
|
|
170
|
+
rule("bundled_portion", () => ref(rules, "code_pattern")
|
|
171
|
+
.then((ref(rules, "no_notation").then(ref(rules, "no_number"))
|
|
172
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year")).maybe())
|
|
173
|
+
.or(ref(rules, "colon_year").or(ref(rules, "dash_year")).maybe()))));
|
|
174
|
+
rule("bundled_identifier", () => ref(rules, "csa_code").as("base")
|
|
175
|
+
.then(ref(rules, "plus"))
|
|
176
|
+
.then(ref(rules, "bundled_portion").as("bundled_first"))
|
|
177
|
+
.then((ref(rules, "plus").then(ref(rules, "bundled_portion"))).repeat(0, Infinity).as("bundled_rest"))
|
|
178
|
+
.then(ref(rules, "reaffirmation").maybe()));
|
|
179
|
+
rule("combined_slash", () => ref(rules, "base_csa_code").as("first")
|
|
180
|
+
.then(ref(rules, "slash"))
|
|
181
|
+
.then(ref(rules, "continuation_code").as("second"))
|
|
182
|
+
.then((ref(rules, "slash").then(ref(rules, "continuation_code").as("third"))).maybe())
|
|
183
|
+
.then(ref(rules, "reaffirmation").maybe())
|
|
184
|
+
.then(ref(rules, "package_portion").maybe()));
|
|
185
|
+
rule("combined_comma", () => ref(rules, "csa_code").as("first")
|
|
186
|
+
.then(ref(rules, "comma"))
|
|
187
|
+
.then(ref(rules, "space"))
|
|
188
|
+
.then(ref(rules, "csa_code").as("second"))
|
|
189
|
+
.then(ref(rules, "reaffirmation").maybe())
|
|
190
|
+
.then((ref(rules, "space").then(ref(rules, "ampersand")).then(ref(rules, "package_portion"))
|
|
191
|
+
.or(ref(rules, "package_portion"))).as("package_portion").maybe())
|
|
192
|
+
.then(str("").as("comma_separator")));
|
|
193
|
+
rule("single_identifier", () => ref(rules, "csa_code")
|
|
194
|
+
.then(ref(rules, "reaffirmation").maybe())
|
|
195
|
+
.then(ref(rules, "package_portion").as("package_portion").maybe()));
|
|
196
|
+
rule("code_only_identifier", () => ref(rules, "code_pattern")
|
|
197
|
+
.then((ref(rules, "space").then(ref(rules, "series_prefix")).then(ref(rules, "space"))
|
|
198
|
+
.then(ref(rules, "series_keyword").as("series"))
|
|
199
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year")))
|
|
200
|
+
.or(ref(rules, "space").then(ref(rules, "series_keyword").as("series"))
|
|
201
|
+
.then(ref(rules, "colon_year").or(ref(rules, "dash_year"))))
|
|
202
|
+
.or(ref(rules, "colon_year").or(ref(rules, "dash_year")))).maybe())
|
|
203
|
+
.then((ref(rules, "space").then(str("PACKAGE"))).as("package_portion").maybe()));
|
|
204
|
+
rule("identifier", () => ref(rules, "iso_iec_adoption")
|
|
205
|
+
.or(ref(rules, "series_identifier"))
|
|
206
|
+
.or(ref(rules, "cec_identifier"))
|
|
207
|
+
.or(ref(rules, "bundled_identifier"))
|
|
208
|
+
.or(ref(rules, "combined_slash"))
|
|
209
|
+
.or(ref(rules, "combined_comma"))
|
|
210
|
+
.or(ref(rules, "single_identifier"))
|
|
211
|
+
.or(ref(rules, "code_only_identifier")));
|
|
212
|
+
return rules;
|
|
213
|
+
}
|
|
214
|
+
export const csaGrammar = {
|
|
215
|
+
rules: buildRules(),
|
|
216
|
+
root: "identifier",
|
|
217
|
+
};
|
|
218
|
+
/** Parser#parse normalization (parser.rb): CONSOLIDATED, (R spacing, CEI. */
|
|
219
|
+
export function normalizeCsa(input) {
|
|
220
|
+
let normalized = input.replaceAll(/\s*\(\s*CONSOLIDATED\s*\)\s*/g, " ");
|
|
221
|
+
normalized = normalized.replaceAll(/\s*\bCONSOLIDATED\b\s*/g, " ");
|
|
222
|
+
normalized = normalized.replaceAll(/(\S)\(R(\d{2,4})\)/g, "$1 (R$2)");
|
|
223
|
+
normalized = normalized.replaceAll("CEI/IEC", "IEC");
|
|
224
|
+
normalized = normalized.replaceAll(/\bCEI\b/g, "IEC");
|
|
225
|
+
normalized = normalized.replaceAll("CAN/CSA-", "CSA ");
|
|
226
|
+
normalized = normalized.replaceAll("CAN3-", "CSA ");
|
|
227
|
+
normalized = normalized.replaceAll(/\s+/g, " ").trim();
|
|
228
|
+
return normalized;
|
|
229
|
+
}
|
|
230
|
+
/** The original publisher prefix the normalized input printed. */
|
|
231
|
+
export function csaPublisherPrefix(normalized) {
|
|
232
|
+
if (normalized.startsWith("CAN/CSA-"))
|
|
233
|
+
return "CAN/CSA-";
|
|
234
|
+
if (normalized.startsWith("CAN3-"))
|
|
235
|
+
return "CAN3-";
|
|
236
|
+
if (normalized.startsWith("CSA "))
|
|
237
|
+
return "CSA";
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|