@pubid/pubid 0.1.3 → 0.1.5

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.
Files changed (185) hide show
  1. package/artifact/corpus.json.gz +0 -0
  2. package/dist/conformance/cli.js +5 -1
  3. package/dist/flavors/amca/grammar.d.ts +4 -0
  4. package/dist/flavors/amca/grammar.js +87 -0
  5. package/dist/flavors/amca/index.d.ts +4 -0
  6. package/dist/flavors/amca/index.js +76 -0
  7. package/dist/flavors/amca/model.d.ts +29 -0
  8. package/dist/flavors/amca/model.js +146 -0
  9. package/dist/flavors/ansi/index.d.ts +24 -0
  10. package/dist/flavors/ansi/index.js +147 -0
  11. package/dist/flavors/api/grammar.d.ts +4 -0
  12. package/dist/flavors/api/grammar.js +79 -0
  13. package/dist/flavors/api/index.d.ts +4 -0
  14. package/dist/flavors/api/index.js +71 -0
  15. package/dist/flavors/api/model.d.ts +27 -0
  16. package/dist/flavors/api/model.js +114 -0
  17. package/dist/flavors/ashrae/grammar.d.ts +2 -0
  18. package/dist/flavors/ashrae/grammar.js +667 -0
  19. package/dist/flavors/ashrae/index.d.ts +4 -0
  20. package/dist/flavors/ashrae/index.js +306 -0
  21. package/dist/flavors/ashrae/model.d.ts +87 -0
  22. package/dist/flavors/ashrae/model.js +335 -0
  23. package/dist/flavors/ashrae/preprocessor.d.ts +7 -0
  24. package/dist/flavors/ashrae/preprocessor.js +44 -0
  25. package/dist/flavors/asme/grammar.d.ts +2 -0
  26. package/dist/flavors/asme/grammar.js +200 -0
  27. package/dist/flavors/asme/index.d.ts +4 -0
  28. package/dist/flavors/asme/index.js +138 -0
  29. package/dist/flavors/asme/model.d.ts +34 -0
  30. package/dist/flavors/asme/model.js +123 -0
  31. package/dist/flavors/astm/grammar.d.ts +2 -0
  32. package/dist/flavors/astm/grammar.js +110 -0
  33. package/dist/flavors/astm/index.d.ts +2 -0
  34. package/dist/flavors/astm/index.js +127 -0
  35. package/dist/flavors/astm/model.d.ts +42 -0
  36. package/dist/flavors/astm/model.js +263 -0
  37. package/dist/flavors/bipm/index.d.ts +30 -0
  38. package/dist/flavors/bipm/index.js +434 -0
  39. package/dist/flavors/bsi/grammar.d.ts +4 -0
  40. package/dist/flavors/bsi/grammar.js +535 -0
  41. package/dist/flavors/bsi/index.d.ts +4 -0
  42. package/dist/flavors/bsi/index.js +941 -0
  43. package/dist/flavors/bsi/model.d.ts +127 -0
  44. package/dist/flavors/bsi/model.js +863 -0
  45. package/dist/flavors/calconnect/index.d.ts +21 -0
  46. package/dist/flavors/calconnect/index.js +113 -0
  47. package/dist/flavors/cen_cenelec/grammar.d.ts +4 -0
  48. package/dist/flavors/cen_cenelec/grammar.js +107 -0
  49. package/dist/flavors/cen_cenelec/index.d.ts +5 -0
  50. package/dist/flavors/cen_cenelec/index.js +263 -0
  51. package/dist/flavors/cen_cenelec/model.d.ts +45 -0
  52. package/dist/flavors/cen_cenelec/model.js +490 -0
  53. package/dist/flavors/cie/grammar.d.ts +5 -0
  54. package/dist/flavors/cie/grammar.js +127 -0
  55. package/dist/flavors/cie/index.d.ts +2 -0
  56. package/dist/flavors/cie/index.js +311 -0
  57. package/dist/flavors/cie/model.d.ts +122 -0
  58. package/dist/flavors/cie/model.js +464 -0
  59. package/dist/flavors/csa/grammar.d.ts +6 -0
  60. package/dist/flavors/csa/grammar.js +239 -0
  61. package/dist/flavors/csa/index.d.ts +2 -0
  62. package/dist/flavors/csa/index.js +634 -0
  63. package/dist/flavors/csa/model.d.ts +33 -0
  64. package/dist/flavors/csa/model.js +505 -0
  65. package/dist/flavors/doi/index.d.ts +13 -0
  66. package/dist/flavors/doi/index.js +65 -0
  67. package/dist/flavors/easc/index.d.ts +4 -0
  68. package/dist/flavors/easc/index.js +107 -0
  69. package/dist/flavors/ecma/index.d.ts +4 -0
  70. package/dist/flavors/ecma/index.js +117 -0
  71. package/dist/flavors/etsi/index.d.ts +14 -0
  72. package/dist/flavors/etsi/index.js +307 -0
  73. package/dist/flavors/evs/grammar.d.ts +2 -0
  74. package/dist/flavors/evs/grammar.js +22 -0
  75. package/dist/flavors/evs/index.d.ts +2 -0
  76. package/dist/flavors/evs/index.js +24 -0
  77. package/dist/flavors/evs/model.d.ts +19 -0
  78. package/dist/flavors/evs/model.js +36 -0
  79. package/dist/flavors/gb/index.d.ts +31 -0
  80. package/dist/flavors/gb/index.js +159 -0
  81. package/dist/flavors/gost/grammar.d.ts +2 -0
  82. package/dist/flavors/gost/grammar.js +46 -0
  83. package/dist/flavors/gost/index.d.ts +2 -0
  84. package/dist/flavors/gost/index.js +165 -0
  85. package/dist/flavors/gost/model.d.ts +61 -0
  86. package/dist/flavors/gost/model.js +147 -0
  87. package/dist/flavors/gost/prefix_routes.d.ts +15 -0
  88. package/dist/flavors/gost/prefix_routes.js +192 -0
  89. package/dist/flavors/iala/index.d.ts +32 -0
  90. package/dist/flavors/iala/index.js +300 -0
  91. package/dist/flavors/iana/index.d.ts +19 -0
  92. package/dist/flavors/iana/index.js +71 -0
  93. package/dist/flavors/idf/grammar.d.ts +2 -0
  94. package/dist/flavors/idf/grammar.js +71 -0
  95. package/dist/flavors/idf/index.d.ts +2 -0
  96. package/dist/flavors/idf/index.js +100 -0
  97. package/dist/flavors/idf/model.d.ts +54 -0
  98. package/dist/flavors/idf/model.js +359 -0
  99. package/dist/flavors/iec/grammar.d.ts +3 -0
  100. package/dist/flavors/iec/grammar.js +187 -0
  101. package/dist/flavors/iec/index.d.ts +4 -0
  102. package/dist/flavors/iec/index.js +507 -0
  103. package/dist/flavors/iec/model.d.ts +54 -0
  104. package/dist/flavors/iec/model.js +437 -0
  105. package/dist/flavors/ieee/grammar.d.ts +2 -0
  106. package/dist/flavors/ieee/grammar.js +697 -0
  107. package/dist/flavors/ieee/index.d.ts +3 -0
  108. package/dist/flavors/ieee/index.js +1258 -0
  109. package/dist/flavors/ieee/model.d.ts +144 -0
  110. package/dist/flavors/ieee/model.js +1237 -0
  111. package/dist/flavors/ieee/preprocessor.d.ts +8 -0
  112. package/dist/flavors/ieee/preprocessor.js +410 -0
  113. package/dist/flavors/ieee/update_codes.d.ts +8 -0
  114. package/dist/flavors/ieee/update_codes.js +197 -0
  115. package/dist/flavors/ietf/index.d.ts +30 -0
  116. package/dist/flavors/ietf/index.js +151 -0
  117. package/dist/flavors/iho/index.d.ts +4 -0
  118. package/dist/flavors/iho/index.js +126 -0
  119. package/dist/flavors/index.d.ts +9 -0
  120. package/dist/flavors/index.js +136 -0
  121. package/dist/flavors/isbn/index.d.ts +13 -0
  122. package/dist/flavors/isbn/index.js +97 -0
  123. package/dist/flavors/iso/grammar.d.ts +2 -0
  124. package/dist/flavors/iso/grammar.js +207 -0
  125. package/dist/flavors/iso/index.d.ts +2 -0
  126. package/dist/flavors/iso/index.js +343 -0
  127. package/dist/flavors/iso/model.d.ts +159 -0
  128. package/dist/flavors/iso/model.js +802 -0
  129. package/dist/flavors/iso/stages.generated.d.ts +13 -0
  130. package/dist/flavors/iso/stages.generated.js +391 -0
  131. package/dist/flavors/itu/grammar.d.ts +4 -0
  132. package/dist/flavors/itu/grammar.js +205 -0
  133. package/dist/flavors/itu/index.d.ts +2 -0
  134. package/dist/flavors/itu/index.js +224 -0
  135. package/dist/flavors/itu/model.d.ts +184 -0
  136. package/dist/flavors/itu/model.js +599 -0
  137. package/dist/flavors/jcgm/index.d.ts +7 -0
  138. package/dist/flavors/jcgm/index.js +300 -0
  139. package/dist/flavors/jis/index.d.ts +4 -0
  140. package/dist/flavors/jis/index.js +267 -0
  141. package/dist/flavors/nist/grammar.d.ts +2 -0
  142. package/dist/flavors/nist/grammar.js +287 -0
  143. package/dist/flavors/nist/index.d.ts +2 -0
  144. package/dist/flavors/nist/index.js +1244 -0
  145. package/dist/flavors/nist/model.d.ts +155 -0
  146. package/dist/flavors/nist/model.js +823 -0
  147. package/dist/flavors/nist/preprocessor.d.ts +11 -0
  148. package/dist/flavors/nist/preprocessor.js +281 -0
  149. package/dist/flavors/oasis/index.d.ts +23 -0
  150. package/dist/flavors/oasis/index.js +110 -0
  151. package/dist/flavors/ogc/index.d.ts +20 -0
  152. package/dist/flavors/ogc/index.js +75 -0
  153. package/dist/flavors/oiml/grammar.d.ts +2 -0
  154. package/dist/flavors/oiml/grammar.js +206 -0
  155. package/dist/flavors/oiml/implementation.d.ts +9 -0
  156. package/dist/flavors/oiml/implementation.js +45 -0
  157. package/dist/flavors/oiml/model.d.ts +23 -0
  158. package/dist/flavors/oiml/model.js +592 -0
  159. package/dist/flavors/omg/index.d.ts +14 -0
  160. package/dist/flavors/omg/index.js +73 -0
  161. package/dist/flavors/plateau/index.d.ts +4 -0
  162. package/dist/flavors/plateau/index.js +97 -0
  163. package/dist/flavors/tgpp/index.d.ts +4 -0
  164. package/dist/flavors/tgpp/index.js +122 -0
  165. package/dist/flavors/un/index.d.ts +13 -0
  166. package/dist/flavors/un/index.js +90 -0
  167. package/dist/flavors/w3c/index.d.ts +14 -0
  168. package/dist/flavors/w3c/index.js +148 -0
  169. package/dist/flavors/xsf/index.d.ts +18 -0
  170. package/dist/flavors/xsf/index.js +65 -0
  171. package/dist/grammar/engine.d.ts +78 -0
  172. package/dist/grammar/engine.js +351 -0
  173. package/dist/index.d.ts +1 -0
  174. package/dist/index.js +3 -0
  175. package/dist/model/attribute.d.ts +54 -0
  176. package/dist/model/attribute.js +53 -0
  177. package/dist/model/builder.d.ts +39 -0
  178. package/dist/model/builder.js +124 -0
  179. package/dist/model/component.d.ts +70 -0
  180. package/dist/model/component.js +170 -0
  181. package/dist/model/identifier.d.ts +84 -0
  182. package/dist/model/identifier.js +270 -0
  183. package/dist/model/urn-generator.d.ts +27 -0
  184. package/dist/model/urn-generator.js +91 -0
  185. package/package.json +1 -1
@@ -0,0 +1,535 @@
1
+ import { match, ref, str } from "../../grammar/engine.js";
2
+ /**
3
+ * Port of lib/pubid/bsi/parser.rb — 1:1. Root: identifier.
4
+ *
5
+ * Branch order (most specific first): standalone amendment, committee
6
+ * document, index/supplementary-index/explanatory-supplement/method/
7
+ * test-method/section/detailed-spec, aerospace with letter edition,
8
+ * DISC, supplement document (reverse then forward), addendum document,
9
+ * set, bundled, bare adopted, flex, regular.
10
+ */
11
+ /** Case-insensitive string match (parser.rb #stri). */
12
+ function stri(input) {
13
+ const parts = [];
14
+ for (const char of input) {
15
+ if (/[a-z]/i.test(char)) {
16
+ parts.push(match(`[${char.toUpperCase()}${char.toLowerCase()}]`));
17
+ }
18
+ else {
19
+ parts.push(str(char));
20
+ }
21
+ }
22
+ return parts.reduce((a, b) => a.then(b));
23
+ }
24
+ const alt = (tokens) => tokens.map((t) => str(t)).reduce((a, b) => a.or(b));
25
+ function buildRules() {
26
+ const rules = {};
27
+ const rule = (name, build) => {
28
+ rules[name] = build();
29
+ };
30
+ rule("digit", () => match("[0-9]"));
31
+ rule("digits", () => ref(rules, "digit").repeat(1, Infinity));
32
+ rule("space", () => str(" "));
33
+ rule("dash", () => str("-"));
34
+ rule("slash", () => str("/"));
35
+ rule("plus", () => str("+"));
36
+ rule("colon", () => str(":"));
37
+ rule("bs", () => str("BS").or(str("BSI")));
38
+ rule("multi_letter_prefix", () => alt([
39
+ "E9111", "CECC", "CISPR",
40
+ "2HC", "2HR", "2SP", "2TA", "3HR", "3TA",
41
+ "2A", "2B", "2C", "2F", "2G", "2L", "2M", "2S",
42
+ "3B", "3F", "3G", "3J", "3L", "3S",
43
+ "4F", "4L", "4S", "5S", "7S",
44
+ "SP",
45
+ ]));
46
+ rule("single_letter_prefix", () => alt(["AU", "HC", "MA", "PL", "QC", "TA", "A", "B", "C", "F", "G", "L", "M", "S", "X"]));
47
+ rule("specialized_prefix", () => ref(rules, "multi_letter_prefix")
48
+ .or(ref(rules, "single_letter_prefix"))
49
+ .as("prefix"));
50
+ rule("flex", () => str("BSI Flex").or(str("BS Flex")).or(str("Flex")));
51
+ rule("dd", () => str("DD"));
52
+ rule("pd", () => str("PD"));
53
+ rule("pas", () => str("PAS"));
54
+ rule("na", () => str("NA"));
55
+ rule("ts", () => str("TS"));
56
+ rule("handbook", () => str("Handbook").or(str("HB")));
57
+ rule("pp", () => str("PP"));
58
+ rule("bip", () => str("BIP"));
59
+ rule("ep_type", () => str("EP").or(str("ep")));
60
+ rule("index_suffix", () => ref(rules, "space").then(str("Index")).then(ref(rules, "space")).then(str("Issue"))
61
+ .then(ref(rules, "space")).then(ref(rules, "digits").as("issue_number"))
62
+ .or(ref(rules, "colon").as("colon_sep").then(str("Index")))
63
+ .or(ref(rules, "space").then(str("Index"))));
64
+ rule("supplementary_index_suffix", () => ref(rules, "space").then(str("Supplementary Index")));
65
+ rule("explanatory_supplement_suffix", () => ref(rules, "colon").then(str("Explanatory Supplement")));
66
+ rule("method_code", () => match("[0-9A-Z]").repeat(1, Infinity));
67
+ rule("method_suffix", () => ref(rules, "colon").then(str("Methods")).then(ref(rules, "space"))
68
+ .then(ref(rules, "method_code").as("method_code"))
69
+ .then(ref(rules, "space")).then(str("to")).then(ref(rules, "space"))
70
+ .then(ref(rules, "method_code").as("method_to"))
71
+ .or(ref(rules, "colon").then(str("Methods")).then(ref(rules, "space"))
72
+ .then(ref(rules, "method_code").as("method_code"))
73
+ .then(ref(rules, "space")).then(str("and")).then(ref(rules, "space"))
74
+ .then(ref(rules, "method_code").as("method_and")))
75
+ .or(ref(rules, "colon").then(str("Method")).then(ref(rules, "space"))
76
+ .then(ref(rules, "method_code").as("method_code"))));
77
+ rule("test_method_suffix", () => ref(rules, "colon")
78
+ .then(match("[0-9A-Z]").repeat(1, Infinity).as("test_series"))
79
+ .then(ref(rules, "colon"))
80
+ .then(match("[0-9A-Z]").repeat(1, Infinity).as("test_id")));
81
+ rule("set_separator", () => ref(rules, "space").maybe().then(str("+")).then(ref(rules, "space").maybe()));
82
+ rule("set_item", () => ref(rules, "bs").as("publisher")
83
+ .then(ref(rules, "space"))
84
+ .then(ref(rules, "adopted_org_prefix").as("adopted_org")
85
+ .then(ref(rules, "space"))
86
+ .maybe())
87
+ .then(ref(rules, "number"))
88
+ .then(ref(rules, "parts").maybe())
89
+ .then(ref(rules, "year").maybe())
90
+ .as("set_item"));
91
+ rule("set_items", () => ref(rules, "set_item")
92
+ .then((ref(rules, "set_separator").then(ref(rules, "set_item"))).repeat(1, Infinity)));
93
+ rule("set_identifier", () => ref(rules, "set_items").as("set"));
94
+ rule("section_id", () => match("[0-9A-Za-z]").repeat(1, Infinity));
95
+ rule("section_suffix", () => ref(rules, "colon").as("colon_sep").then(str("Section")).then(ref(rules, "space"))
96
+ .then(ref(rules, "section_id").as("section_id"))
97
+ .or(ref(rules, "space").then(str("Section")).then(ref(rules, "space"))
98
+ .then(ref(rules, "section_id").as("section_id"))));
99
+ rule("detailed_spec_suffix", () => ref(rules, "space")
100
+ .then(str("C")
101
+ .then(match("[0-9]").repeat(1, 3))
102
+ .then(ref(rules, "dash"))
103
+ .then(match("[0-9]").repeat(1, 3))
104
+ .as("spec_code")
105
+ .or(str("N")
106
+ .then(match("[0-9]").repeat(1, 4))
107
+ .then((ref(rules, "dash").then(match("[0-9]").repeat(1, Infinity))).maybe())
108
+ .as("spec_code"))));
109
+ rule("committee_document", () => ref(rules, "digit").repeat(2, 2).as("year")
110
+ .then(ref(rules, "slash"))
111
+ .then(match("[0-9]").repeat(8, 8).as("document_number"))
112
+ .then(ref(rules, "space"))
113
+ .then(str("DC"))
114
+ .as("committee_document"));
115
+ rule("standalone_amendment", () => str("(").then(str("AMD")).then(ref(rules, "space"))
116
+ .then(str("Corrigendum").as("corrigendum"))
117
+ .then(ref(rules, "space"))
118
+ .then(ref(rules, "digits").as("amendment_number"))
119
+ .then(str(")"))
120
+ .as("parenthesized_amd")
121
+ .or(str("(").then(str("AMD")).then(ref(rules, "space"))
122
+ .then(ref(rules, "digits").as("amendment_number"))
123
+ .then(str(")"))
124
+ .as("parenthesized_amd"))
125
+ .or(str("AMD").then(ref(rules, "space"))
126
+ .then(str("Corrigendum").as("corrigendum"))
127
+ .then(ref(rules, "space"))
128
+ .then(ref(rules, "digits").as("amendment_number"))
129
+ .as("standalone_amendment"))
130
+ .or(str("AMD").then(ref(rules, "space"))
131
+ .then(ref(rules, "digits").as("amendment_number"))
132
+ .as("standalone_amendment")));
133
+ rule("disc_prefix", () => str("DISC PD "));
134
+ rule("draft", () => str("Draft BS").or(str("DBS")));
135
+ rule("en", () => str("EN"));
136
+ rule("iso", () => str("ISO"));
137
+ rule("iec", () => str("IEC"));
138
+ rule("cispr", () => str("CISPR"));
139
+ rule("cen", () => str("CEN"));
140
+ rule("clc", () => str("CLC"));
141
+ rule("na_with_supplements", () => str("NA")
142
+ .then(ref(rules, "any_supplement").repeat(1, Infinity).as("na_supplements"))
143
+ .then(ref(rules, "space"))
144
+ .then(str("to ")));
145
+ rule("na_simple", () => str("NA to "));
146
+ rule("na_prefix", () => ref(rules, "na_with_supplements").or(ref(rules, "na_simple")).as("na_prefix"));
147
+ rule("publisher_or_type", () => ref(rules, "na_prefix")
148
+ .then(ref(rules, "draft").as("stage")
149
+ .or(ref(rules, "dd").as("type"))
150
+ .or(ref(rules, "pd").as("type"))
151
+ .or(ref(rules, "bs").as("publisher")))
152
+ .or(ref(rules, "flex").as("flex_type"))
153
+ .or(ref(rules, "handbook").as("type"))
154
+ .or(ref(rules, "bip").as("type"))
155
+ .or(ref(rules, "ts").as("type"))
156
+ .or(ref(rules, "ep_type").as("type"))
157
+ .or(ref(rules, "draft").as("stage"))
158
+ .or(ref(rules, "dd").as("type"))
159
+ .or(ref(rules, "pd").as("type"))
160
+ .or(ref(rules, "pas").as("type"))
161
+ .or(ref(rules, "pp").as("type"))
162
+ .or(ref(rules, "na").as("type"))
163
+ .or(ref(rules, "bs").as("publisher")
164
+ .then(ref(rules, "space"))
165
+ .then(ref(rules, "specialized_prefix")))
166
+ .or(ref(rules, "bs").as("publisher")));
167
+ rule("number", () => match("[0-9A-Z]").repeat(1, Infinity).as("number"));
168
+ rule("bracket_iteration", () => str("[").then(match("[0-9]").repeat(1, Infinity).as("iteration")).then(str("]")));
169
+ rule("part_with_subpart", () => ref(rules, "dash").then(ref(rules, "digits").as("part"))
170
+ .then(ref(rules, "dash"))
171
+ .then(ref(rules, "digits").as("subpart")));
172
+ rule("part", () => ref(rules, "dash").then(match("[0-9A-Za-z.& ]").repeat(1, Infinity).as("part")));
173
+ rule("parts", () => ref(rules, "part_with_subpart").or(ref(rules, "part")).repeat(0, Infinity).as("parts"));
174
+ rule("letter_edition", () => match("[a-zA-Z]").as("letter_edition"));
175
+ rule("part_with_letter_edition", () => ref(rules, "dash").then(match("[0-9.]").repeat(1, Infinity).as("part"))
176
+ .then(ref(rules, "letter_edition").as("letter_edition"))
177
+ .or(ref(rules, "dash").then(match("[0-9.]").repeat(1, Infinity).as("part"))));
178
+ rule("number_with_letter_edition", () => match("[0-9]").repeat(1, Infinity).as("number")
179
+ .then(ref(rules, "letter_edition").as("letter_edition"))
180
+ .or(match("[0-9]").repeat(1, Infinity).as("number")));
181
+ rule("space_separated_part", () => ref(rules, "space")
182
+ .then((match("[A-Z]").repeat(1, Infinity).then(match("[0-9]").repeat(1, Infinity))).as("part")));
183
+ rule("iteration", () => ref(rules, "bracket_iteration").repeat(0, Infinity).as("iteration"));
184
+ rule("year", () => ref(rules, "colon").then(ref(rules, "digit").repeat(3, 4).as("year")));
185
+ rule("base_year", () => ref(rules, "colon").then(ref(rules, "digit").repeat(4, 4).as("base_year")));
186
+ rule("month", () => ref(rules, "dash").then(ref(rules, "digit").repeat(2, 2).as("month")));
187
+ rule("flex_edition", () => ref(rules, "space").then(str("v")).then(match("[0-9.]").repeat(1, Infinity).as("edition")));
188
+ rule("edition", () => ref(rules, "space").then(str("ED")).then(ref(rules, "digits").as("edition")));
189
+ const sepAlt = () => ref(rules, "plus").as("amd_sep_plus").or(ref(rules, "slash").as("amd_sep_slash"));
190
+ rule("amendment_impl", () => sepAlt()
191
+ .then(str("A"))
192
+ .then(ref(rules, "digits").as("amd_number"))
193
+ .then((ref(rules, "colon").then(ref(rules, "digit").repeat(2, 4).as("amd_year"))).maybe())
194
+ .or(sepAlt()
195
+ .then(str("Amd"))
196
+ .then(ref(rules, "space"))
197
+ .then(ref(rules, "digits").as("amd_number"))
198
+ .then((ref(rules, "colon").then(ref(rules, "digit").repeat(4, 4).as("amd_year"))).maybe())));
199
+ rule("corrigendum_impl", () => sepAlt()
200
+ .then(str("AC"))
201
+ .then(ref(rules, "digits").maybe().as("cor_number"))
202
+ .then((ref(rules, "colon").then(ref(rules, "digit").repeat(2, 4).as("cor_year"))).maybe())
203
+ .or(sepAlt()
204
+ .then(str("C"))
205
+ .then(ref(rules, "digits").as("cor_number"))
206
+ .then((ref(rules, "colon").then(ref(rules, "digit").repeat(2, 4).as("cor_year"))).maybe())));
207
+ rule("amd_suffix", () => ref(rules, "space").then(str("AMD")).then(ref(rules, "space").maybe())
208
+ .then(match("[0-9]").repeat(1, Infinity).as("amd_number")
209
+ .or(match("[A-Z]").repeat(1, Infinity).as("amd_letter"))));
210
+ rule("amd_verbose", () => ref(rules, "space")
211
+ .then(str("Amd").or(str("Amendment")).as("amd_verbose_type"))
212
+ .then(ref(rules, "space"))
213
+ .then(match("[0-9]").repeat(1, Infinity).as("amd_number"))
214
+ .then((ref(rules, "space").then(str("(")).then(match("[0-9/]").repeat(1, Infinity).as("amd_date")).then(str(")"))).maybe())
215
+ .then((ref(rules, "colon").then(match("[A-Za-z]").repeat(1, Infinity).as("amd_month"))
216
+ .then(ref(rules, "space"))
217
+ .then(ref(rules, "digit").repeat(4, 4).as("amd_year"))).maybe()));
218
+ const suppDocPrefix = (prefixRule) => ref(rules, "bs").as("publisher")
219
+ .then(ref(rules, "space"))
220
+ .then(ref(rules, prefixRule).as("flex_prefix"))
221
+ .then(ref(rules, "space"))
222
+ .then(ref(rules, "number").as("number"))
223
+ .then(ref(rules, "iteration").as("iteration"))
224
+ .then(ref(rules, "parts").as("parts"));
225
+ const plainDocPrefix = () => ref(rules, "bs").as("publisher")
226
+ .then(ref(rules, "space"))
227
+ .then(ref(rules, "number").as("number"))
228
+ .then(ref(rules, "iteration").as("iteration"))
229
+ .then(ref(rules, "parts").as("parts"));
230
+ // The renderer prints "Addendum"/"Supplement" + (" No.")? + TWO
231
+ // spaces before the number; both seams accept one-or-more spaces.
232
+ const supplementTail = (word, sepKey, noKey, numKey, yearKey) => (ref(rules, "colon").or(ref(rules, "space"))).as(sepKey)
233
+ .then(str(word))
234
+ .then(ref(rules, "space").repeat(1, Infinity))
235
+ .then(str("No.").as(noKey))
236
+ .then(ref(rules, "space").repeat(1, Infinity))
237
+ .then(ref(rules, "digits").as(numKey))
238
+ .then(ref(rules, "colon"))
239
+ .then(ref(rules, "digit").repeat(4, 4).as(yearKey))
240
+ .or((ref(rules, "colon").or(ref(rules, "space"))).as(sepKey)
241
+ .then(str(word))
242
+ .then(ref(rules, "space").repeat(1, Infinity))
243
+ .then(ref(rules, "digits").as(numKey))
244
+ .then(ref(rules, "colon"))
245
+ .then(ref(rules, "digit").repeat(4, 4).as(yearKey)));
246
+ rule("supplement_document_forward", () => suppDocPrefix("multi_letter_prefix")
247
+ .then(supplementTail("Supplement", "supp_sep", "supp_no_prefix", "supplement_number", "supplement_year"))
248
+ .as("supplement_document")
249
+ .or(suppDocPrefix("single_letter_prefix")
250
+ .then(supplementTail("Supplement", "supp_sep", "supp_no_prefix", "supplement_number", "supplement_year"))
251
+ .as("supplement_document"))
252
+ .or(plainDocPrefix()
253
+ .then(supplementTail("Supplement", "supp_sep", "supp_no_prefix", "supplement_number", "supplement_year"))
254
+ .as("supplement_document")));
255
+ rule("supplement_document_reverse", () => str("Supplement").then(ref(rules, "space"))
256
+ .then(str("No.").as("supp_no_prefix"))
257
+ .then(ref(rules, "space"))
258
+ .then(ref(rules, "digits").as("supplement_number"))
259
+ .then(ref(rules, "space"))
260
+ .then(str("("))
261
+ .then(ref(rules, "digit").repeat(4, 4).as("supplement_year"))
262
+ .then(str(")"))
263
+ .then(ref(rules, "space"))
264
+ .then(str("to "))
265
+ .then(ref(rules, "bs").as("publisher"))
266
+ .then(ref(rules, "space"))
267
+ .then(ref(rules, "number").as("number"))
268
+ .then(ref(rules, "iteration").as("iteration"))
269
+ .then(ref(rules, "parts").as("parts"))
270
+ .then(ref(rules, "colon"))
271
+ .then(ref(rules, "digit").repeat(4, 4).as("base_year"))
272
+ .as("supplement_document")
273
+ .or(str("Supplement").then(ref(rules, "space"))
274
+ .then(ref(rules, "digits").as("supplement_number"))
275
+ .then(ref(rules, "space"))
276
+ .then(str("("))
277
+ .then(ref(rules, "digit").repeat(4, 4).as("supplement_year"))
278
+ .then(str(")"))
279
+ .then(ref(rules, "space"))
280
+ .then(str("to "))
281
+ .then(ref(rules, "bs").as("publisher"))
282
+ .then(ref(rules, "space"))
283
+ .then(ref(rules, "number").as("number"))
284
+ .then(ref(rules, "iteration").as("iteration"))
285
+ .then(ref(rules, "parts").as("parts"))
286
+ .then(ref(rules, "colon"))
287
+ .then(ref(rules, "digit").repeat(4, 4).as("base_year"))
288
+ .as("supplement_document")));
289
+ rule("addendum_document", () => suppDocPrefix("multi_letter_prefix")
290
+ .then(supplementTail("Addendum", "add_sep", "add_no_prefix", "addendum_number", "addendum_year"))
291
+ .as("addendum_document")
292
+ .or(suppDocPrefix("single_letter_prefix")
293
+ .then(supplementTail("Addendum", "add_sep", "add_no_prefix", "addendum_number", "addendum_year"))
294
+ .as("addendum_document"))
295
+ .or(plainDocPrefix()
296
+ .then(ref(rules, "base_year"))
297
+ .then(ref(rules, "space").as("add_sep"))
298
+ .then(str("Addendum"))
299
+ .then(ref(rules, "space").repeat(1, Infinity))
300
+ .then(str("No.").as("add_no_prefix"))
301
+ .then(ref(rules, "space").repeat(1, Infinity))
302
+ .then(ref(rules, "digits").as("addendum_number"))
303
+ .then(ref(rules, "colon"))
304
+ .then(ref(rules, "digit").repeat(4, 4).as("addendum_year"))
305
+ .as("addendum_document"))
306
+ .or(plainDocPrefix()
307
+ .then(ref(rules, "base_year"))
308
+ .then(ref(rules, "colon").as("add_sep"))
309
+ .then(str("Addendum"))
310
+ .then(ref(rules, "space").repeat(1, Infinity))
311
+ .then(str("No.").as("add_no_prefix"))
312
+ .then(ref(rules, "space").repeat(1, Infinity))
313
+ .then(ref(rules, "digits").as("addendum_number"))
314
+ .then(ref(rules, "colon"))
315
+ .then(ref(rules, "digit").repeat(4, 4).as("addendum_year"))
316
+ .as("addendum_document"))
317
+ .or(plainDocPrefix()
318
+ .then(supplementTail("Addendum", "add_sep", "add_no_prefix", "addendum_number", "addendum_year"))
319
+ .as("addendum_document")));
320
+ rule("bundle_sep_and", () => ref(rules, "space").then(str("and")).then(ref(rules, "space")));
321
+ rule("bundle_sep_to", () => ref(rules, "space").then(str("TO").or(str("to")).as("to_case")).then(ref(rules, "space")));
322
+ rule("bundle_sep_ampersand", () => ref(rules, "space").then(str("&")).then(ref(rules, "space")));
323
+ rule("bundle_sep_semicolon", () => str(";").then(ref(rules, "space")));
324
+ rule("bundle_sep_comma", () => str(","));
325
+ rule("bundle_separator", () => ref(rules, "bundle_sep_and").as("sep_and")
326
+ .or(ref(rules, "bundle_sep_to").as("sep_to"))
327
+ .or(ref(rules, "bundle_sep_ampersand").as("sep_ampersand"))
328
+ .or(ref(rules, "bundle_sep_semicolon").as("sep_semicolon"))
329
+ .or(ref(rules, "bundle_sep_comma").as("sep_comma")));
330
+ rule("parts_bundle", () => str("Parts").or(str("Sections")).as("bundle_type")
331
+ .then(ref(rules, "space"))
332
+ .then(match("[0-9]").repeat(1, Infinity).as("part1"))
333
+ .then(ref(rules, "bundle_sep_and"))
334
+ .then(match("[0-9.]").repeat(1, Infinity).as("part2")));
335
+ rule("bundle_item", () => ref(rules, "bs").as("publisher")
336
+ .then(ref(rules, "space"))
337
+ .then(ref(rules, "multi_letter_prefix").as("prefix"))
338
+ .then(ref(rules, "space"))
339
+ .then(ref(rules, "number"))
340
+ .then(ref(rules, "parts"))
341
+ .as("bundle_item")
342
+ .or(ref(rules, "bs").as("publisher")
343
+ .then(ref(rules, "space"))
344
+ .then(ref(rules, "single_letter_prefix").as("prefix"))
345
+ .then(ref(rules, "space"))
346
+ .then(ref(rules, "number"))
347
+ .then(ref(rules, "parts"))
348
+ .as("bundle_item"))
349
+ .or(ref(rules, "bs").as("publisher")
350
+ .then(ref(rules, "space"))
351
+ .then(ref(rules, "number"))
352
+ .then(ref(rules, "space_separated_part"))
353
+ .as("bundle_item"))
354
+ .or(ref(rules, "bs").as("publisher")
355
+ .then(ref(rules, "space"))
356
+ .then(ref(rules, "number"))
357
+ .then(ref(rules, "parts"))
358
+ .as("bundle_item"))
359
+ .or(ref(rules, "multi_letter_prefix").as("prefix")
360
+ .then(ref(rules, "space"))
361
+ .then(ref(rules, "number"))
362
+ .then(ref(rules, "parts"))
363
+ .as("bundle_item"))
364
+ .or(ref(rules, "single_letter_prefix").as("prefix")
365
+ .then(ref(rules, "space"))
366
+ .then(ref(rules, "number"))
367
+ .then(ref(rules, "parts"))
368
+ .as("bundle_item"))
369
+ .or(ref(rules, "number")
370
+ .then(ref(rules, "space_separated_part"))
371
+ .as("bundle_item"))
372
+ .or((match("[A-Z]").repeat(1, Infinity).then(match("[0-9]").repeat(1, Infinity))).as("bundle_item"))
373
+ .or(ref(rules, "number")
374
+ .then(ref(rules, "parts"))
375
+ .as("bundle_item")));
376
+ rule("bundled_identifier", () => ref(rules, "publisher_or_type")
377
+ .then(ref(rules, "space"))
378
+ .then(ref(rules, "number"))
379
+ .then(ref(rules, "colon"))
380
+ .then(ref(rules, "parts_bundle"))
381
+ .then(ref(rules, "year"))
382
+ .as("bundled_parts")
383
+ .or(ref(rules, "publisher_or_type")
384
+ .then(ref(rules, "space"))
385
+ .then(ref(rules, "bundle_item"))
386
+ .then((ref(rules, "bundle_separator").then(ref(rules, "bundle_item"))).repeat(1, Infinity))
387
+ .then(ref(rules, "year").maybe())
388
+ .as("bundled_list")));
389
+ // supplement = amendment | corrigendum | amd_suffix | amd_verbose
390
+ rule("any_supplement", () => ref(rules, "amendment_impl")
391
+ .or(ref(rules, "corrigendum_impl"))
392
+ .or(ref(rules, "amd_suffix"))
393
+ .or(ref(rules, "amd_verbose"))
394
+ .as("supplement"));
395
+ rule("supplements", () => ref(rules, "any_supplement").repeat(0, Infinity).as("supplements"));
396
+ rule("expert_commentary", () => ref(rules, "space")
397
+ .then(stri("Expert Commentary").as("expert_commentary_full")
398
+ .or(stri("ExComm")
399
+ .then((ref(rules, "space").then(str("("))
400
+ .then(match("[A-Za-z]").repeat(1, Infinity).as("expert_commentary_topic"))
401
+ .then(str(")"))).maybe())
402
+ .as("expert_commentary"))));
403
+ rule("tracked_changes", () => ref(rules, "space").then(ref(rules, "dash")).then(ref(rules, "space")).then(str("TC").as("tracked_changes")));
404
+ rule("pdf_suffix", () => ref(rules, "space").then(str("PDF").as("pdf")));
405
+ rule("translation", () => ref(rules, "space").then(str("("))
406
+ .then(match("[A-Za-z]").repeat(1, Infinity).as("translation_lang")
407
+ .then((ref(rules, "space").then(str("Translation").or(str("version")))).maybe()))
408
+ .then(str(")"))
409
+ .or(ref(rules, "space")
410
+ .then(alt(["SPANISH", "FRENCH", "GERMAN", "ITALIAN"]).as("translation_upper"))
411
+ .then(ref(rules, "space"))
412
+ .then(str("TRANSLATION"))));
413
+ rule("collection_number", () => ref(rules, "slash").then(ref(rules, "digits").as("second_number")));
414
+ rule("adopted_org_prefix", () => alt(["EN", "ISO", "IEC", "CISPR", "CEN", "CLC", "CR", "ES", "ENV", "HD", "CWA"]));
415
+ rule("adopted_string_no_expert", () => ref(rules, "adopted_org_prefix")
416
+ .then(match("[^E\\n]").repeat(1, Infinity).as("adopted_string_no_expert")));
417
+ rule("adopted_string_content", () => ref(rules, "any_supplement").absent()
418
+ .then(ref(rules, "amd_suffix").absent())
419
+ .then(ref(rules, "amd_verbose").absent())
420
+ .then(ref(rules, "expert_commentary").absent())
421
+ .then(ref(rules, "tracked_changes").absent())
422
+ .then(ref(rules, "pdf_suffix").absent())
423
+ .then(ref(rules, "translation").absent())
424
+ .then(match("[^\\n]").repeat(1, Infinity)));
425
+ rule("adopted_string", () => ref(rules, "adopted_org_prefix")
426
+ .then(ref(rules, "adopted_string_content"))
427
+ .as("adopted_string"));
428
+ rule("bare_adopted", () => ref(rules, "bs").absent()
429
+ .then(ref(rules, "adopted_org_prefix"))
430
+ .then((ref(rules, "any_supplement").absent()
431
+ .then(ref(rules, "amd_suffix").absent())
432
+ .then(ref(rules, "amd_verbose").absent())
433
+ .then(ref(rules, "tracked_changes").absent())
434
+ .then(ref(rules, "pdf_suffix").absent())
435
+ .then(ref(rules, "translation").absent())
436
+ .then(match("[^\\n]"))).repeat(0, Infinity))
437
+ .as("adopted_string"));
438
+ rule("vapSuffix", () => ref(rules, "space").then(str("PDF").as("pdf_format"))
439
+ .or(ref(rules, "space").then(str("BOOK").as("book_format")))
440
+ .or(ref(rules, "space").then(ref(rules, "dash")).then(ref(rules, "space")).then(str("TC").as("tc_format"))));
441
+ rule("identifier", () => ref(rules, "standalone_amendment")
442
+ .or(ref(rules, "committee_document"))
443
+ .or(ref(rules, "bs").as("publisher").then(ref(rules, "space"))
444
+ .then(ref(rules, "number"))
445
+ .then(ref(rules, "index_suffix").as("index_suffix"))
446
+ .then(ref(rules, "year"))
447
+ .as("index_identifier"))
448
+ .or(ref(rules, "bs").as("publisher").then(ref(rules, "space"))
449
+ .then(ref(rules, "number"))
450
+ .then(ref(rules, "supplementary_index_suffix").as("supplementary_index_suffix"))
451
+ .then(ref(rules, "year"))
452
+ .as("supplementary_index_identifier"))
453
+ .or(ref(rules, "bs").as("publisher").then(ref(rules, "space"))
454
+ .then(ref(rules, "number"))
455
+ .then(ref(rules, "parts"))
456
+ .then(ref(rules, "explanatory_supplement_suffix").as("explanatory_supplement_suffix"))
457
+ .then(ref(rules, "year"))
458
+ .as("explanatory_supplement_identifier"))
459
+ .or(ref(rules, "bs").as("publisher").then(ref(rules, "space"))
460
+ .then(ref(rules, "number"))
461
+ .then(ref(rules, "parts"))
462
+ .then(ref(rules, "method_suffix").as("method_suffix"))
463
+ .then(ref(rules, "year"))
464
+ .as("method_identifier"))
465
+ .or(ref(rules, "bs").as("publisher").then(ref(rules, "space"))
466
+ .then(ref(rules, "number"))
467
+ .then(ref(rules, "test_method_suffix").as("test_method_suffix"))
468
+ .then(ref(rules, "year"))
469
+ .as("test_method_identifier"))
470
+ .or(ref(rules, "publisher_or_type")
471
+ .then(ref(rules, "space"))
472
+ .then(ref(rules, "number"))
473
+ .then(ref(rules, "section_suffix").as("section_suffix"))
474
+ .then(ref(rules, "year"))
475
+ .as("section_identifier"))
476
+ .or(ref(rules, "bs").as("publisher").then(ref(rules, "space"))
477
+ .then(ref(rules, "number"))
478
+ .then(ref(rules, "detailed_spec_suffix").as("detailed_spec_suffix"))
479
+ .then(ref(rules, "year"))
480
+ .as("detailed_specification"))
481
+ .or(ref(rules, "bs").as("publisher").then(ref(rules, "space"))
482
+ .then(ref(rules, "single_letter_prefix").or(ref(rules, "multi_letter_prefix")).as("prefix"))
483
+ .then(ref(rules, "space"))
484
+ .then(ref(rules, "number_with_letter_edition"))
485
+ .then(ref(rules, "part_with_letter_edition").maybe())
486
+ .then(ref(rules, "iteration").as("iteration").maybe())
487
+ .then(ref(rules, "year"))
488
+ .then(ref(rules, "supplements"))
489
+ .as("aerospace_identifier"))
490
+ .or(ref(rules, "disc_prefix")
491
+ .then(ref(rules, "number"))
492
+ .then(ref(rules, "parts").maybe())
493
+ .then(ref(rules, "year"))
494
+ .as("disc_identifier"))
495
+ // The reverse rule already .as-wraps itself; an outer wrap would
496
+ // nest supplement_document twice and the builder sees empty keys.
497
+ .or(ref(rules, "supplement_document_reverse"))
498
+ .or(ref(rules, "supplement_document_forward"))
499
+ .or(ref(rules, "addendum_document"))
500
+ // set_identifier already .as-wraps as "set"; an outer wrap nests twice.
501
+ .or(ref(rules, "set_identifier"))
502
+ .or(ref(rules, "bundled_identifier"))
503
+ .or(ref(rules, "bare_adopted").as("adopted_string"))
504
+ .or(ref(rules, "flex").as("flex_type")
505
+ .then(ref(rules, "space"))
506
+ .then(ref(rules, "number"))
507
+ .then(ref(rules, "parts"))
508
+ .then(ref(rules, "flex_edition").maybe())
509
+ .then((ref(rules, "year").then(ref(rules, "month").maybe())).maybe())
510
+ .then(ref(rules, "supplements")))
511
+ .or(ref(rules, "publisher_or_type")
512
+ .then((ref(rules, "space").then(ref(rules, "adopted_string"))).maybe())
513
+ .then((ref(rules, "space")
514
+ .then(ref(rules, "number"))
515
+ .then(ref(rules, "parts"))
516
+ .then(ref(rules, "collection_number").maybe())
517
+ .then((ref(rules, "year").then(ref(rules, "month").maybe())).maybe())
518
+ .then(ref(rules, "flex_edition").maybe())).maybe())
519
+ .then(ref(rules, "supplements").maybe())
520
+ .then(ref(rules, "edition").maybe())
521
+ .then(ref(rules, "expert_commentary").maybe())
522
+ .then(ref(rules, "translation").maybe())
523
+ .then(ref(rules, "vapSuffix").maybe())));
524
+ return rules;
525
+ }
526
+ export const bsiGrammar = {
527
+ rules: buildRules(),
528
+ root: "identifier",
529
+ };
530
+ /** Parser.parse normalization: "BSI " → "BS " except "BSI Flex". */
531
+ export function preprocessBsi(input) {
532
+ return input.startsWith("BSI Flex")
533
+ ? input
534
+ : input.replaceAll(/\bBSI\s+/g, "BS ");
535
+ }
@@ -0,0 +1,4 @@
1
+ import type { Tree } from "../../grammar/engine.js";
2
+ import type { FlavorImplementation, Identifier } from "../../conformance/implementation.js";
3
+ export declare function buildBsiIdentifier(tree: Tree): Identifier;
4
+ export declare function bsiGrammarImplementation(): FlavorImplementation;