@pubid/pubid 0.1.71 → 0.1.72

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 (438) hide show
  1. package/artifact/corpus.json.gz +0 -0
  2. package/dist/flavors/ansi/generated/substrate.d.ts +78 -0
  3. package/dist/flavors/ansi/generated/substrate.js +105 -0
  4. package/dist/flavors/ansi/implementation.d.ts +5 -0
  5. package/dist/flavors/ansi/implementation.js +125 -0
  6. package/dist/flavors/ansi/index.js +14 -117
  7. package/dist/flavors/api/generated/substrate.d.ts +78 -0
  8. package/dist/flavors/api/generated/substrate.js +105 -0
  9. package/dist/flavors/api/grammar.worker.d.ts +6 -0
  10. package/dist/flavors/api/{grammar.js → grammar.worker.js} +60 -16
  11. package/dist/flavors/api/implementation.d.ts +11 -0
  12. package/dist/flavors/api/implementation.js +106 -0
  13. package/dist/flavors/api/index.d.ts +1 -3
  14. package/dist/flavors/api/index.js +14 -98
  15. package/dist/flavors/arxiv/generated/substrate.d.ts +75 -0
  16. package/dist/flavors/arxiv/generated/substrate.js +102 -0
  17. package/dist/flavors/arxiv/index.js +17 -11
  18. package/dist/flavors/ashrae/generated/substrate.d.ts +78 -0
  19. package/dist/flavors/ashrae/generated/substrate.js +105 -0
  20. package/dist/flavors/ashrae/grammar.worker.d.ts +6 -0
  21. package/dist/flavors/ashrae/{grammar.js → grammar.worker.js} +76 -39
  22. package/dist/flavors/ashrae/implementation.d.ts +7 -0
  23. package/dist/flavors/ashrae/implementation.js +316 -0
  24. package/dist/flavors/ashrae/index.d.ts +1 -3
  25. package/dist/flavors/ashrae/index.js +14 -304
  26. package/dist/flavors/asme/generated/substrate.d.ts +78 -0
  27. package/dist/flavors/asme/generated/substrate.js +105 -0
  28. package/dist/flavors/asme/grammar.worker.d.ts +6 -0
  29. package/dist/flavors/asme/{grammar.js → grammar.worker.js} +41 -2
  30. package/dist/flavors/asme/implementation.d.ts +7 -0
  31. package/dist/flavors/asme/implementation.js +152 -0
  32. package/dist/flavors/asme/index.d.ts +1 -3
  33. package/dist/flavors/asme/index.js +14 -136
  34. package/dist/flavors/astm/generated/substrate.d.ts +78 -0
  35. package/dist/flavors/astm/generated/substrate.js +105 -0
  36. package/dist/flavors/astm/grammar.worker.d.ts +6 -0
  37. package/dist/flavors/astm/{grammar.js → grammar.worker.js} +39 -5
  38. package/dist/flavors/astm/implementation.d.ts +6 -0
  39. package/dist/flavors/astm/implementation.js +135 -0
  40. package/dist/flavors/astm/index.js +14 -125
  41. package/dist/flavors/bipm/generated/substrate.d.ts +78 -0
  42. package/dist/flavors/bipm/generated/substrate.js +105 -0
  43. package/dist/flavors/bipm/grammar.worker.d.ts +6 -0
  44. package/dist/flavors/bipm/grammar.worker.js +180 -0
  45. package/dist/flavors/bipm/implementation.d.ts +6 -0
  46. package/dist/flavors/bipm/implementation.js +244 -0
  47. package/dist/flavors/bipm/index.d.ts +1 -28
  48. package/dist/flavors/bipm/index.js +16 -650
  49. package/dist/flavors/bipm/model.d.ts +80 -0
  50. package/dist/flavors/bipm/model.js +271 -0
  51. package/dist/flavors/bipm/worker.d.ts +2 -0
  52. package/dist/flavors/bipm/worker.js +19 -0
  53. package/dist/flavors/bsi/generated/substrate.d.ts +78 -0
  54. package/dist/flavors/bsi/generated/substrate.js +105 -0
  55. package/dist/flavors/bsi/grammar.worker.d.ts +6 -0
  56. package/dist/flavors/bsi/{grammar.js → grammar.worker.js} +36 -7
  57. package/dist/flavors/bsi/implementation.d.ts +12 -0
  58. package/dist/flavors/bsi/implementation.js +967 -0
  59. package/dist/flavors/bsi/index.d.ts +1 -3
  60. package/dist/flavors/bsi/index.js +15 -940
  61. package/dist/flavors/bsi/model.js +16 -0
  62. package/dist/flavors/bsi/worker.js +11 -4
  63. package/dist/flavors/bsi_pfs/index.d.ts +25 -0
  64. package/dist/flavors/bsi_pfs/index.js +73 -10
  65. package/dist/flavors/calconnect/generated/substrate.d.ts +75 -0
  66. package/dist/flavors/calconnect/generated/substrate.js +102 -0
  67. package/dist/flavors/calconnect/grammar.worker.d.ts +6 -0
  68. package/dist/flavors/calconnect/grammar.worker.js +60 -0
  69. package/dist/flavors/calconnect/implementation.d.ts +6 -0
  70. package/dist/flavors/calconnect/implementation.js +69 -0
  71. package/dist/flavors/calconnect/index.d.ts +1 -19
  72. package/dist/flavors/calconnect/index.js +15 -111
  73. package/dist/flavors/calconnect/model.d.ts +26 -0
  74. package/dist/flavors/calconnect/model.js +52 -0
  75. package/dist/flavors/ccsds/generated/substrate.d.ts +75 -0
  76. package/dist/flavors/ccsds/generated/substrate.js +102 -0
  77. package/dist/flavors/ccsds/implementation.d.ts +5 -0
  78. package/dist/flavors/ccsds/implementation.js +67 -0
  79. package/dist/flavors/ccsds/index.js +13 -57
  80. package/dist/flavors/cen_cenelec/generated/substrate.d.ts +78 -0
  81. package/dist/flavors/cen_cenelec/generated/substrate.js +105 -0
  82. package/dist/flavors/cen_cenelec/grammar.worker.d.ts +6 -0
  83. package/dist/flavors/cen_cenelec/{grammar.js → grammar.worker.js} +41 -13
  84. package/dist/flavors/cen_cenelec/implementation.d.ts +15 -0
  85. package/dist/flavors/cen_cenelec/implementation.js +322 -0
  86. package/dist/flavors/cen_cenelec/index.d.ts +2 -4
  87. package/dist/flavors/cen_cenelec/index.js +16 -286
  88. package/dist/flavors/cen_cenelec/model.js +16 -1
  89. package/dist/flavors/cen_cenelec/worker.js +10 -4
  90. package/dist/flavors/cen_pfs/index.d.ts +5 -0
  91. package/dist/flavors/cen_pfs/index.js +28 -2
  92. package/dist/flavors/cie/generated/substrate.d.ts +78 -0
  93. package/dist/flavors/cie/generated/substrate.js +105 -0
  94. package/dist/flavors/cie/grammar.worker.d.ts +6 -0
  95. package/dist/flavors/cie/{grammar.js → grammar.worker.js} +71 -18
  96. package/dist/flavors/cie/implementation.d.ts +9 -0
  97. package/dist/flavors/cie/implementation.js +331 -0
  98. package/dist/flavors/cie/index.js +14 -309
  99. package/dist/flavors/csa/generated/substrate.d.ts +78 -0
  100. package/dist/flavors/csa/generated/substrate.js +105 -0
  101. package/dist/flavors/csa/grammar.worker.d.ts +12 -0
  102. package/dist/flavors/csa/{grammar.js → grammar.worker.js} +143 -27
  103. package/dist/flavors/csa/implementation.d.ts +9 -0
  104. package/dist/flavors/csa/implementation.js +661 -0
  105. package/dist/flavors/csa/index.js +14 -631
  106. package/dist/flavors/csa/worker.js +10 -4
  107. package/dist/flavors/easc/generated/substrate.d.ts +75 -0
  108. package/dist/flavors/easc/generated/substrate.js +102 -0
  109. package/dist/flavors/easc/grammar.worker.d.ts +6 -0
  110. package/dist/flavors/easc/grammar.worker.js +66 -0
  111. package/dist/flavors/easc/implementation.d.ts +6 -0
  112. package/dist/flavors/easc/implementation.js +58 -0
  113. package/dist/flavors/easc/index.d.ts +1 -2
  114. package/dist/flavors/easc/index.js +15 -105
  115. package/dist/flavors/easc/model.d.ts +10 -0
  116. package/dist/flavors/easc/model.js +43 -0
  117. package/dist/flavors/ecma/generated/substrate.d.ts +75 -0
  118. package/dist/flavors/ecma/generated/substrate.js +102 -0
  119. package/dist/flavors/ecma/grammar.worker.d.ts +6 -0
  120. package/dist/flavors/ecma/grammar.worker.js +63 -0
  121. package/dist/flavors/ecma/implementation.d.ts +6 -0
  122. package/dist/flavors/ecma/implementation.js +95 -0
  123. package/dist/flavors/ecma/index.d.ts +1 -2
  124. package/dist/flavors/ecma/index.js +15 -152
  125. package/dist/flavors/ecma/model.d.ts +10 -0
  126. package/dist/flavors/ecma/model.js +61 -0
  127. package/dist/flavors/etsi/generated/substrate.d.ts +75 -0
  128. package/dist/flavors/etsi/generated/substrate.js +102 -0
  129. package/dist/flavors/etsi/grammar.worker.d.ts +6 -0
  130. package/dist/flavors/etsi/grammar.worker.js +86 -0
  131. package/dist/flavors/etsi/implementation.d.ts +6 -0
  132. package/dist/flavors/etsi/implementation.js +110 -0
  133. package/dist/flavors/etsi/index.d.ts +2 -12
  134. package/dist/flavors/etsi/index.js +16 -305
  135. package/dist/flavors/etsi/model.d.ts +37 -0
  136. package/dist/flavors/etsi/model.js +169 -0
  137. package/dist/flavors/eu/generated/substrate.d.ts +75 -0
  138. package/dist/flavors/eu/generated/substrate.js +102 -0
  139. package/dist/flavors/eu/implementation.d.ts +7 -0
  140. package/dist/flavors/eu/implementation.js +150 -0
  141. package/dist/flavors/eu/index.js +14 -141
  142. package/dist/flavors/evs/generated/substrate.d.ts +78 -0
  143. package/dist/flavors/evs/generated/substrate.js +105 -0
  144. package/dist/flavors/evs/grammar.worker.d.ts +6 -0
  145. package/dist/flavors/evs/grammar.worker.js +98 -0
  146. package/dist/flavors/evs/implementation.d.ts +7 -0
  147. package/dist/flavors/evs/implementation.js +114 -0
  148. package/dist/flavors/evs/index.d.ts +1 -1
  149. package/dist/flavors/evs/index.js +14 -89
  150. package/dist/flavors/evs/worker.js +10 -4
  151. package/dist/flavors/gb/generated/substrate.d.ts +75 -0
  152. package/dist/flavors/gb/generated/substrate.js +102 -0
  153. package/dist/flavors/gb/grammar.worker.d.ts +6 -0
  154. package/dist/flavors/gb/grammar.worker.js +73 -0
  155. package/dist/flavors/gb/implementation.d.ts +6 -0
  156. package/dist/flavors/gb/implementation.js +87 -0
  157. package/dist/flavors/gb/index.d.ts +1 -29
  158. package/dist/flavors/gb/index.js +15 -157
  159. package/dist/flavors/gb/model.d.ts +36 -0
  160. package/dist/flavors/gb/model.js +79 -0
  161. package/dist/flavors/gost/generated/substrate.d.ts +78 -0
  162. package/dist/flavors/gost/generated/substrate.js +105 -0
  163. package/dist/flavors/gost/grammar.worker.d.ts +6 -0
  164. package/dist/flavors/gost/grammar.worker.js +82 -0
  165. package/dist/flavors/gost/implementation.d.ts +7 -0
  166. package/dist/flavors/gost/implementation.js +177 -0
  167. package/dist/flavors/gost/index.js +14 -162
  168. package/dist/flavors/gost/worker.js +12 -5
  169. package/dist/flavors/iala/generated/substrate.d.ts +78 -0
  170. package/dist/flavors/iala/generated/substrate.js +105 -0
  171. package/dist/flavors/iala/grammar.worker.d.ts +6 -0
  172. package/dist/flavors/iala/grammar.worker.js +127 -0
  173. package/dist/flavors/iala/implementation.d.ts +6 -0
  174. package/dist/flavors/iala/implementation.js +250 -0
  175. package/dist/flavors/iala/index.d.ts +1 -56
  176. package/dist/flavors/iala/index.js +17 -484
  177. package/dist/flavors/iala/model.d.ts +93 -0
  178. package/dist/flavors/iala/model.js +194 -0
  179. package/dist/flavors/iana/generated/substrate.d.ts +75 -0
  180. package/dist/flavors/iana/generated/substrate.js +102 -0
  181. package/dist/flavors/iana/grammar.worker.d.ts +6 -0
  182. package/dist/flavors/iana/grammar.worker.js +51 -0
  183. package/dist/flavors/iana/implementation.d.ts +6 -0
  184. package/dist/flavors/iana/implementation.js +47 -0
  185. package/dist/flavors/iana/index.d.ts +1 -17
  186. package/dist/flavors/iana/index.js +15 -69
  187. package/dist/flavors/iana/model.d.ts +22 -0
  188. package/dist/flavors/iana/model.js +33 -0
  189. package/dist/flavors/idf/generated/substrate.d.ts +78 -0
  190. package/dist/flavors/idf/generated/substrate.js +105 -0
  191. package/dist/flavors/idf/grammar.worker.d.ts +6 -0
  192. package/dist/flavors/idf/{grammar.js → grammar.worker.js} +58 -2
  193. package/dist/flavors/idf/implementation.d.ts +6 -0
  194. package/dist/flavors/idf/implementation.js +129 -0
  195. package/dist/flavors/idf/index.js +14 -98
  196. package/dist/flavors/iec/generated/substrate.d.ts +78 -0
  197. package/dist/flavors/iec/generated/substrate.js +105 -0
  198. package/dist/flavors/iec/grammar.worker.d.ts +6 -0
  199. package/dist/flavors/iec/grammar.worker.js +231 -0
  200. package/dist/flavors/iec/implementation.d.ts +15 -0
  201. package/dist/flavors/iec/implementation.js +956 -0
  202. package/dist/flavors/iec/index.d.ts +1 -2
  203. package/dist/flavors/iec/index.js +16 -869
  204. package/dist/flavors/iec/model.js +13 -1
  205. package/dist/flavors/iec/worker.d.ts +2 -0
  206. package/dist/flavors/iec/worker.js +19 -0
  207. package/dist/flavors/ieee/generated/substrate.d.ts +78 -0
  208. package/dist/flavors/ieee/generated/substrate.js +105 -0
  209. package/dist/flavors/ieee/implementation.d.ts +4 -0
  210. package/dist/flavors/ieee/implementation.js +48 -10
  211. package/dist/flavors/ieee/index.d.ts +3 -2
  212. package/dist/flavors/ieee/index.js +30 -12
  213. package/dist/flavors/ieee/model.js +3 -0
  214. package/dist/flavors/ieee/preprocessor.js +10 -10
  215. package/dist/flavors/ieee/worker.js +33 -11
  216. package/dist/flavors/ietf/generated/substrate.d.ts +75 -0
  217. package/dist/flavors/ietf/generated/substrate.js +102 -0
  218. package/dist/flavors/ietf/grammar.worker.d.ts +6 -0
  219. package/dist/flavors/ietf/grammar.worker.js +63 -0
  220. package/dist/flavors/ietf/implementation.d.ts +6 -0
  221. package/dist/flavors/ietf/implementation.js +60 -0
  222. package/dist/flavors/ietf/index.d.ts +1 -28
  223. package/dist/flavors/ietf/index.js +15 -149
  224. package/dist/flavors/ietf/model.d.ts +47 -0
  225. package/dist/flavors/ietf/model.js +92 -0
  226. package/dist/flavors/iho/generated/substrate.d.ts +78 -0
  227. package/dist/flavors/iho/generated/substrate.js +105 -0
  228. package/dist/flavors/iho/grammar.worker.d.ts +6 -0
  229. package/dist/flavors/iho/grammar.worker.js +150 -0
  230. package/dist/flavors/iho/implementation.d.ts +6 -0
  231. package/dist/flavors/iho/implementation.js +221 -0
  232. package/dist/flavors/iho/index.d.ts +1 -2
  233. package/dist/flavors/iho/index.js +15 -619
  234. package/dist/flavors/iho/model.d.ts +11 -0
  235. package/dist/flavors/iho/model.js +315 -0
  236. package/dist/flavors/index.js +3 -0
  237. package/dist/flavors/iso/generated/substrate.d.ts +93 -0
  238. package/dist/flavors/iso/generated/substrate.js +133 -0
  239. package/dist/flavors/iso/grammar.worker.d.ts +7 -0
  240. package/dist/flavors/iso/grammar.worker.js +406 -0
  241. package/dist/flavors/iso/implementation.d.ts +4 -0
  242. package/dist/flavors/iso/implementation.js +880 -0
  243. package/dist/flavors/iso/index.js +16 -706
  244. package/dist/flavors/iso/model.js +21 -2
  245. package/dist/flavors/iso/worker.d.ts +2 -0
  246. package/dist/flavors/iso/worker.js +19 -0
  247. package/dist/flavors/itu/generated/substrate.d.ts +78 -0
  248. package/dist/flavors/itu/generated/substrate.js +105 -0
  249. package/dist/flavors/itu/grammar.worker.d.ts +6 -0
  250. package/dist/flavors/itu/grammar.worker.js +306 -0
  251. package/dist/flavors/itu/implementation.d.ts +10 -0
  252. package/dist/flavors/itu/implementation.js +285 -0
  253. package/dist/flavors/itu/index.js +15 -246
  254. package/dist/flavors/itu/worker.d.ts +2 -0
  255. package/dist/flavors/itu/worker.js +19 -0
  256. package/dist/flavors/jcgm/generated/substrate.d.ts +78 -0
  257. package/dist/flavors/jcgm/generated/substrate.js +105 -0
  258. package/dist/flavors/jcgm/grammar.worker.d.ts +6 -0
  259. package/dist/flavors/jcgm/grammar.worker.js +98 -0
  260. package/dist/flavors/jcgm/implementation.d.ts +6 -0
  261. package/dist/flavors/jcgm/implementation.js +187 -0
  262. package/dist/flavors/jcgm/index.d.ts +1 -5
  263. package/dist/flavors/jcgm/index.js +16 -364
  264. package/dist/flavors/jcgm/model.d.ts +43 -0
  265. package/dist/flavors/jcgm/model.js +168 -0
  266. package/dist/flavors/jis/generated/substrate.d.ts +78 -0
  267. package/dist/flavors/jis/generated/substrate.js +105 -0
  268. package/dist/flavors/jis/grammar.worker.d.ts +6 -0
  269. package/dist/flavors/jis/grammar.worker.js +132 -0
  270. package/dist/flavors/jis/implementation.d.ts +6 -0
  271. package/dist/flavors/jis/implementation.js +129 -0
  272. package/dist/flavors/jis/index.d.ts +0 -2
  273. package/dist/flavors/jis/index.js +15 -390
  274. package/dist/flavors/jis/model.d.ts +30 -0
  275. package/dist/flavors/jis/model.js +205 -0
  276. package/dist/flavors/jis/worker.d.ts +2 -0
  277. package/dist/flavors/jis/worker.js +19 -0
  278. package/dist/flavors/nist/generated/substrate.d.ts +78 -0
  279. package/dist/flavors/nist/generated/substrate.js +105 -0
  280. package/dist/flavors/nist/index.js +18 -11
  281. package/dist/flavors/nist/worker.js +8 -4
  282. package/dist/flavors/oasis/generated/substrate.d.ts +75 -0
  283. package/dist/flavors/oasis/generated/substrate.js +102 -0
  284. package/dist/flavors/oasis/grammar.worker.d.ts +6 -0
  285. package/dist/flavors/oasis/grammar.worker.js +50 -0
  286. package/dist/flavors/oasis/implementation.d.ts +6 -0
  287. package/dist/flavors/oasis/implementation.js +80 -0
  288. package/dist/flavors/oasis/index.d.ts +1 -21
  289. package/dist/flavors/oasis/index.js +16 -108
  290. package/dist/flavors/oasis/model.d.ts +27 -0
  291. package/dist/flavors/oasis/model.js +34 -0
  292. package/dist/flavors/ogc/generated/substrate.d.ts +75 -0
  293. package/dist/flavors/ogc/generated/substrate.js +102 -0
  294. package/dist/flavors/ogc/grammar.worker.d.ts +6 -0
  295. package/dist/flavors/ogc/grammar.worker.js +55 -0
  296. package/dist/flavors/ogc/implementation.d.ts +6 -0
  297. package/dist/flavors/ogc/implementation.js +49 -0
  298. package/dist/flavors/ogc/index.d.ts +1 -18
  299. package/dist/flavors/ogc/index.js +15 -73
  300. package/dist/flavors/ogc/model.d.ts +23 -0
  301. package/dist/flavors/ogc/model.js +32 -0
  302. package/dist/flavors/oiml/generated/substrate.d.ts +78 -0
  303. package/dist/flavors/oiml/generated/substrate.js +105 -0
  304. package/dist/flavors/oiml/grammar.worker.d.ts +6 -0
  305. package/dist/flavors/oiml/grammar.worker.js +239 -0
  306. package/dist/flavors/oiml/implementation.d.ts +2 -1
  307. package/dist/flavors/oiml/implementation.js +16 -7
  308. package/dist/flavors/oiml/index.js +15 -6
  309. package/dist/flavors/oiml/model.js +19 -19
  310. package/dist/flavors/oiml/worker.js +14 -6
  311. package/dist/flavors/omg/generated/substrate.d.ts +78 -0
  312. package/dist/flavors/omg/generated/substrate.js +105 -0
  313. package/dist/flavors/omg/grammar.worker.d.ts +6 -0
  314. package/dist/flavors/omg/grammar.worker.js +64 -0
  315. package/dist/flavors/omg/implementation.d.ts +7 -0
  316. package/dist/flavors/omg/implementation.js +33 -0
  317. package/dist/flavors/omg/index.d.ts +1 -12
  318. package/dist/flavors/omg/index.js +15 -71
  319. package/dist/flavors/omg/model.d.ts +16 -0
  320. package/dist/flavors/omg/model.js +26 -0
  321. package/dist/flavors/plateau/generated/substrate.d.ts +78 -0
  322. package/dist/flavors/plateau/generated/substrate.js +105 -0
  323. package/dist/flavors/plateau/grammar.worker.d.ts +6 -0
  324. package/dist/flavors/plateau/grammar.worker.js +78 -0
  325. package/dist/flavors/plateau/implementation.d.ts +6 -0
  326. package/dist/flavors/plateau/implementation.js +74 -0
  327. package/dist/flavors/plateau/index.d.ts +1 -2
  328. package/dist/flavors/plateau/index.js +18 -114
  329. package/dist/flavors/plateau/model.d.ts +11 -0
  330. package/dist/flavors/plateau/model.js +51 -0
  331. package/dist/flavors/register-types.d.ts +20 -19
  332. package/dist/flavors/register-types.js +44 -19
  333. package/dist/flavors/sae/generated/substrate.d.ts +75 -0
  334. package/dist/flavors/sae/generated/substrate.js +102 -0
  335. package/dist/flavors/sae/grammar.worker.d.ts +6 -0
  336. package/dist/flavors/sae/grammar.worker.js +84 -0
  337. package/dist/flavors/sae/implementation.d.ts +11 -0
  338. package/dist/flavors/sae/implementation.js +109 -0
  339. package/dist/flavors/sae/index.d.ts +3 -0
  340. package/dist/flavors/sae/index.js +19 -0
  341. package/dist/flavors/sae/model.d.ts +86 -0
  342. package/dist/flavors/sae/model.js +185 -0
  343. package/dist/flavors/tgpp/generated/substrate.d.ts +78 -0
  344. package/dist/flavors/tgpp/generated/substrate.js +105 -0
  345. package/dist/flavors/tgpp/grammar.worker.d.ts +6 -0
  346. package/dist/flavors/tgpp/grammar.worker.js +69 -0
  347. package/dist/flavors/tgpp/implementation.d.ts +8 -0
  348. package/dist/flavors/tgpp/implementation.js +56 -0
  349. package/dist/flavors/tgpp/index.d.ts +1 -2
  350. package/dist/flavors/tgpp/index.js +15 -120
  351. package/dist/flavors/tgpp/model.d.ts +13 -0
  352. package/dist/flavors/tgpp/model.js +52 -0
  353. package/dist/flavors/w3c/generated/substrate.d.ts +78 -0
  354. package/dist/flavors/w3c/generated/substrate.js +105 -0
  355. package/dist/flavors/w3c/grammar.worker.d.ts +6 -0
  356. package/dist/flavors/w3c/grammar.worker.js +55 -0
  357. package/dist/flavors/w3c/implementation.d.ts +7 -0
  358. package/dist/flavors/w3c/implementation.js +49 -0
  359. package/dist/flavors/w3c/index.d.ts +1 -12
  360. package/dist/flavors/w3c/index.js +15 -146
  361. package/dist/flavors/w3c/model.d.ts +15 -0
  362. package/dist/flavors/w3c/model.js +103 -0
  363. package/dist/flavors/wmo/generated/substrate.d.ts +78 -0
  364. package/dist/flavors/wmo/generated/substrate.js +105 -0
  365. package/dist/flavors/wmo/implementation.d.ts +5 -0
  366. package/dist/flavors/wmo/implementation.js +79 -0
  367. package/dist/flavors/wmo/index.js +14 -68
  368. package/dist/flavors/worker-registry.js +246 -68
  369. package/dist/flavors/xsf/generated/substrate.d.ts +75 -0
  370. package/dist/flavors/xsf/generated/substrate.js +102 -0
  371. package/dist/flavors/xsf/grammar.worker.d.ts +6 -0
  372. package/dist/flavors/xsf/grammar.worker.js +53 -0
  373. package/dist/flavors/xsf/implementation.d.ts +6 -0
  374. package/dist/flavors/xsf/implementation.js +34 -0
  375. package/dist/flavors/xsf/index.d.ts +1 -16
  376. package/dist/flavors/xsf/index.js +16 -63
  377. package/dist/flavors/xsf/model.d.ts +20 -0
  378. package/dist/flavors/xsf/model.js +26 -0
  379. package/dist/model/identifier.d.ts +13 -1
  380. package/dist/model/identifier.js +71 -9
  381. package/dist/model/relation.d.ts +36 -0
  382. package/dist/model/relation.js +93 -0
  383. package/dist/parg/artifacts/ieee.d.ts +1 -1
  384. package/dist/parg/artifacts/ieee.js +1 -1
  385. package/dist/parg/worker.d.ts +4 -2
  386. package/dist/parg/worker.js +5 -3
  387. package/dist/parse-surface.js +4 -2
  388. package/dist/pubid-urn/decoder.d.ts +8 -0
  389. package/dist/pubid-urn/decoder.js +43 -0
  390. package/dist/pubid-urn/encoder.js +31 -0
  391. package/dist/pubid-urn/schema.d.ts +1 -1
  392. package/dist/pubid-urn/schema.js +1 -1
  393. package/dist/pubid-urn/schemas/bsi.js +1 -0
  394. package/dist/pubid-urn/schemas/bsi_pfs.js +9 -7
  395. package/dist/pubid-urn/schemas/cen_pfs.js +1 -0
  396. package/dist/pubid-urn/schemas/cencenelec.js +1 -0
  397. package/dist/pubid-urn/schemas/iec.js +1 -0
  398. package/dist/pubid-urn/schemas/ieee.js +1 -0
  399. package/dist/pubid-urn/schemas/iso.js +1 -0
  400. package/package.json +1 -1
  401. package/vendor/parg/bsi_pfs.json +1 -1
  402. package/vendor/parg/calconnect_pfs.json +1 -1
  403. package/vendor/parg/cen_pfs.json +1 -1
  404. package/vendor/parg/doi_pfs.json +1 -1
  405. package/vendor/parg/etsi_pfs.json +1 -1
  406. package/vendor/parg/ieee.json +1 -1
  407. package/vendor/parg/iho.json +1 -1
  408. package/vendor/parg/plateau.json +1 -1
  409. package/dist/flavors/api/grammar.d.ts +0 -4
  410. package/dist/flavors/ashrae/grammar.d.ts +0 -2
  411. package/dist/flavors/asme/grammar.d.ts +0 -2
  412. package/dist/flavors/astm/grammar.d.ts +0 -2
  413. package/dist/flavors/bsi/grammar.d.ts +0 -4
  414. package/dist/flavors/cen_cenelec/grammar.d.ts +0 -4
  415. package/dist/flavors/cie/grammar.d.ts +0 -5
  416. package/dist/flavors/csa/grammar.d.ts +0 -6
  417. package/dist/flavors/evs/grammar.d.ts +0 -2
  418. package/dist/flavors/evs/grammar.js +0 -68
  419. package/dist/flavors/gost/grammar.d.ts +0 -2
  420. package/dist/flavors/gost/grammar.js +0 -46
  421. package/dist/flavors/idf/grammar.d.ts +0 -2
  422. package/dist/flavors/iec/grammar.d.ts +0 -3
  423. package/dist/flavors/iec/grammar.js +0 -234
  424. package/dist/flavors/ieee/grammar.d.ts +0 -2
  425. package/dist/flavors/ieee/grammar.js +0 -777
  426. package/dist/flavors/iso/grammar.d.ts +0 -7
  427. package/dist/flavors/iso/grammar.js +0 -282
  428. package/dist/flavors/itu/grammar.d.ts +0 -4
  429. package/dist/flavors/itu/grammar.js +0 -276
  430. package/dist/flavors/nist/grammar.d.ts +0 -2
  431. package/dist/flavors/nist/grammar.js +0 -342
  432. package/dist/flavors/oiml/grammar.d.ts +0 -2
  433. package/dist/flavors/oiml/grammar.js +0 -206
  434. package/vendor/parg/csv.json +0 -1
  435. package/vendor/parg/ini.json +0 -1
  436. package/vendor/parg/json.json +0 -1
  437. package/vendor/parg/lua.json +0 -1
  438. package/vendor/parg/toml.json +0 -1
@@ -0,0 +1,956 @@
1
+ //! The iec semantic delta over the generated substrate
2
+ //! (pubid/pubid-grammar#164): the builder - the flat-hash dispatch the
3
+ //! reference pins (the disjoint layer key sets, the peeled supplement
4
+ //! fields, the standalone decode) - plus the parseUrn inversion, the
5
+ //! positional URN machine and the parse-shape rejects. Pure - no
6
+ //! `node:*` module, no engine import - so both entries (the node barrel
7
+ //! over the wasm artifact runtime, the worker entry over the pure-TS
8
+ //! worker engine) run the same delta.
9
+ //!
10
+ //! The parse function is injected: the entry binds it to
11
+ //! `substrate.boundToWire(substrate.parseBound(body))` (node) or the
12
+ //! worker engine's equivalent (worker), both producing the artifact's
13
+ //! declared wire shape. The wire is FLAT - no `base` wrappers: the
14
+ //! supplement layers capture into the position-scoped supp_*/supp2_*
15
+ //! names and peel by key.
16
+ import { ParseFailed } from "../../grammar/engine.js";
17
+ import { TYPED_STAGES } from "./model.js";
18
+ import { Language, PubidDate, Iteration } from "../../model/component.js";
19
+ import { locateStage, IEC_CLASSES, } from "./model.js";
20
+ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
21
+ const s = (v) => v === undefined || v === null ? undefined : String(v);
22
+ function flatten(data) {
23
+ return Array.isArray(data) ? Object.assign({}, ...data) : data;
24
+ }
25
+ /** Splits a number_with_part wire into number/part/subpart: the
26
+ * artifact binds ONE scalar ("60038-1-2" - '1' is the part, '2' the
27
+ * subpart), split on the dash after the dash normalization (the
28
+ * reference's parse_number_with_part); the worker engine carries the
29
+ * hand-shaped object form beside it. */
30
+ function numberComponents(tree) {
31
+ const obj = isObj(tree) ? tree : undefined;
32
+ if (obj === undefined) {
33
+ const raw = s(tree);
34
+ if (raw === undefined)
35
+ return {};
36
+ const pieces = raw.replaceAll("\u2010", "-").replaceAll("\u2011", "-").split("-").filter((p) => p !== "");
37
+ const number = pieces.shift();
38
+ if (number === undefined)
39
+ return {};
40
+ const out = { number };
41
+ const part = pieces.shift();
42
+ if (part !== undefined)
43
+ out["part"] = part;
44
+ if (pieces.length > 0)
45
+ out["subpart"] = pieces.join("-");
46
+ return out;
47
+ }
48
+ const raw = s(obj["number"]);
49
+ if (raw === undefined)
50
+ return {};
51
+ const out = { number: raw };
52
+ const part = s(obj["part"]);
53
+ const subpart = s(obj["subpart"]);
54
+ if (part !== undefined)
55
+ out["part"] = part;
56
+ if (subpart !== undefined)
57
+ out["subpart"] = subpart;
58
+ return out;
59
+ }
60
+ function buildDate(tree) {
61
+ const dateStr = s(flatten(tree));
62
+ if (dateStr === undefined)
63
+ return undefined;
64
+ const parts = dateStr.split("-");
65
+ return new PubidDate({ year: parts[0], month: parts[1], day: parts[2] });
66
+ }
67
+ function parseLanguages(tree) {
68
+ const raw = s(tree);
69
+ if (raw === undefined)
70
+ return [];
71
+ const tokens = raw.split(",").flatMap((chunk) => chunk.split("/"));
72
+ return tokens
73
+ .map((token) => token.trim())
74
+ .filter((token) => token !== "")
75
+ .map((original) => {
76
+ const code = original.length === 1
77
+ ? (Language.CHAR_MAP[original] ?? original.toLowerCase())
78
+ : original;
79
+ return new Language({ code, originalCode: original });
80
+ });
81
+ }
82
+ /** Bound-hash layer fields: the base, the first supplement and the
83
+ * second supplement capture into disjoint key sets, so each wrapper's
84
+ * data can be peeled off the flat hash by name (the reference's
85
+ * SUPP_KEYS / SUPP2_KEYS). */
86
+ const SUPP_KEYS = [
87
+ "supp_type_with_stage", "supp_number_with_part", "supp_stage_iteration",
88
+ "supp_date", "supp_undated_marker", "supp_edition",
89
+ ];
90
+ const SUPP2_KEYS = [
91
+ "supp2_type_with_stage", "supp2_number_with_part", "supp2_stage_iteration",
92
+ "supp2_date", "supp2_undated_marker", "supp2_edition",
93
+ ];
94
+ /** A shallow copy without the listed keys (the reference's
95
+ * parsed_hash.reject). */
96
+ function rejectKeys(tree, keys) {
97
+ const out = { ...tree };
98
+ for (const key of keys)
99
+ delete out[key];
100
+ return out;
101
+ }
102
+ /** FRAG typed-stage abbreviations beside the FRAGC notation (the
103
+ * reference's FRAG_ABBRS over the FragmentIdentifier registry; the
104
+ * registry row's abbr is a single token here). */
105
+ const FRAG_ABBRS = new Set([
106
+ ...(Array.isArray(locateStage("FRAG")?.abbr)
107
+ ? locateStage("FRAG")?.abbr
108
+ : [locateStage("FRAG")?.abbr]),
109
+ "FRAGC",
110
+ ].filter((a) => a !== undefined));
111
+ class IecBuilder {
112
+ build(data) {
113
+ return this.buildInner(data);
114
+ }
115
+ buildInner(data) {
116
+ const tree = flatten(data);
117
+ // third_part's /FRAGN notation wraps the OUTERMOST layer (the
118
+ // reference's apply_fragment_notation at every early return, one
119
+ // dispatch ahead of it): strip, build the rest, wrap.
120
+ if (tree["fragment_type"] !== undefined) {
121
+ const innerTree = { ...tree };
122
+ delete innerTree["fragment_type"];
123
+ delete innerTree["fragment_number"];
124
+ const inner = this.buildInner(innerTree);
125
+ const fragmentNumber = s(tree["fragment_number"]);
126
+ return new IEC_CLASSES.FRAGMENT_CLASS({
127
+ base: inner,
128
+ ...(fragmentNumber !== undefined ? { fragment_number: fragmentNumber } : {}),
129
+ });
130
+ }
131
+ // --- working programme / working document ---
132
+ if (tree["wp_stage"] !== undefined)
133
+ return this.buildWorkingProgramme(tree);
134
+ if (tree["technical_committee"] !== undefined && tree["wd_number"] !== undefined) {
135
+ return this.buildWorkingDocument(tree);
136
+ }
137
+ if (tree["technical_committee"] !== undefined) {
138
+ throw new ParseFailed("IEC: technical groups are not corpus-covered", 0);
139
+ }
140
+ // --- the legacy DAM-family prefix face (decode-to-modern) ---
141
+ if (tree["legacy_stage"] !== undefined) {
142
+ return this.buildLegacySupplement(tree);
143
+ }
144
+ // Second supplement layer (/AMD1:2018/COR1:2019): build the
145
+ // first-supplement form, then wrap the second supplement around it.
146
+ if (tree["supp2_type_with_stage"] !== undefined) {
147
+ const supp = this.supplementFields(tree, SUPP2_KEYS);
148
+ const inner = this.buildInner(rejectKeys(tree, SUPP2_KEYS));
149
+ return this.wrapSupplementLayer(inner, supp);
150
+ }
151
+ // Sheet + supplement (.../1:1994/COR1): the sheet wraps the base,
152
+ // the supplement wraps the sheet. build re-enters the sheet branch
153
+ // for the base.
154
+ if (tree["sheet_number"] !== undefined && tree["supp_type_with_stage"] !== undefined) {
155
+ const supp = this.supplementFields(tree, SUPP_KEYS);
156
+ const sheetId = this.buildInner(rejectKeys(tree, SUPP_KEYS));
157
+ return this.wrapSupplementLayer(sheetId, supp);
158
+ }
159
+ // Sheet notation (.../1:1994 or .../1): the remaining fields are the
160
+ // sheet's base identifier.
161
+ if (tree["sheet_number"] !== undefined) {
162
+ return this.buildSheet(tree);
163
+ }
164
+ // Standalone supplement (IEC/AMD 1:2017 - no base designation):
165
+ // the supplement's own fields are the primary ones.
166
+ if (tree["supp_type_with_stage"] !== undefined &&
167
+ tree["number_with_part"] === undefined &&
168
+ tree["trf_org"] === undefined &&
169
+ tree["technical_committee"] === undefined) {
170
+ return this.buildInner(this.standaloneSupplementHash(tree));
171
+ }
172
+ // FRAG/FRAGC riding the supplement layer over a base designation:
173
+ // the base is the rest, the fragment wraps it.
174
+ const suppAbbr = s(tree["supp_type_with_stage"]);
175
+ if (suppAbbr !== undefined && FRAG_ABBRS.has(suppAbbr) &&
176
+ (tree["number_with_part"] !== undefined || tree["trf_org"] !== undefined)) {
177
+ const baseId = this.buildInner(rejectKeys(tree, SUPP_KEYS));
178
+ const typedStage = locateStage(suppAbbr) ?? locateStage("FRAG");
179
+ return this.wrapFragment(baseId, s(tree["supp_number_with_part"]), s(tree["supp_edition"]), typedStage);
180
+ }
181
+ // Supplement over a base designation (.../AMD1:2021): build the
182
+ // base from the remaining fields, then wrap.
183
+ if (tree["supp_type_with_stage"] !== undefined) {
184
+ const supp = this.supplementFields(tree, SUPP_KEYS);
185
+ const base = this.buildInner(rejectKeys(tree, SUPP_KEYS));
186
+ return this.wrapSupplementLayer(base, supp);
187
+ }
188
+ return this.buildSingle(tree);
189
+ }
190
+ /** One supplement layer's fields, peeled off the flat hash by name
191
+ * and renamed onto the primary spellings (the reference's
192
+ * supplement_fields transform_keys). */
193
+ supplementFields(tree, keys) {
194
+ const out = {};
195
+ for (const key of keys) {
196
+ if (tree[key] !== undefined)
197
+ out[key.replace(/^supp2?_/, "")] = tree[key];
198
+ }
199
+ return out;
200
+ }
201
+ /** Wraps one supplement layer around its base: a FRAG/FRAGC layer is
202
+ * a FragmentIdentifier wrapper, anything else is an
203
+ * Amendment/Corrigendum built from the layer's fields. */
204
+ wrapSupplementLayer(base, supp) {
205
+ const abbr = s(supp["type_with_stage"]) ?? "";
206
+ if (FRAG_ABBRS.has(abbr)) {
207
+ const typedStage = locateStage(abbr) ?? locateStage("FRAG");
208
+ return this.wrapFragment(base, s(supp["number_with_part"]), s(supp["edition"]), typedStage);
209
+ }
210
+ return this.buildSupplementLayer(base, supp);
211
+ }
212
+ wrapFragment(base, fragmentNumber, edition, typedStage) {
213
+ const fragment = new IEC_CLASSES.FRAGMENT_CLASS({
214
+ base,
215
+ ...(fragmentNumber !== undefined ? { fragment_number: fragmentNumber } : {}),
216
+ ...(edition !== undefined ? { edition } : {}),
217
+ });
218
+ fragment.typedStage = typedStage;
219
+ return fragment;
220
+ }
221
+ /** The standalone supplement's fields become the primary's (the
222
+ * reference's standalone_supplement_hash slice-and-merge). */
223
+ standaloneSupplementHash(tree) {
224
+ const out = {};
225
+ for (const key of ["publisher", "copublishers", "type_with_stage_fr", "languages", "all_parts"]) {
226
+ if (tree[key] !== undefined)
227
+ out[key] = tree[key];
228
+ }
229
+ const renames = {
230
+ supp_type_with_stage: "type_with_stage",
231
+ supp_number_with_part: "number_with_part",
232
+ supp_stage_iteration: "stage_iteration",
233
+ supp_date: "date",
234
+ supp_undated_marker: "undated_marker",
235
+ supp_edition: "edition",
236
+ };
237
+ for (const [wire, primary] of Object.entries(renames)) {
238
+ if (tree[wire] !== undefined)
239
+ out[primary] = tree[wire];
240
+ }
241
+ return out;
242
+ }
243
+ commonAttrs(tree, attrs) {
244
+ Object.assign(attrs, numberComponents(tree["number_with_part"]));
245
+ // Letters-prefixed numbers (IECEE "CAB", "AD") only take digit-first
246
+ // parts — "CAB-G01" rejects (Ruby parity; digit numbers like 61158-X
247
+ // keep letter parts). "DIR" is the exception: the Directives number
248
+ // is its own grammar branch and takes letter parts ("DIR-IEC-SUP").
249
+ const number = attrs["number"];
250
+ const part = attrs["part"];
251
+ if (number !== undefined && /^[A-Z]{2,4}$/.test(number) && number !== "DIR" &&
252
+ part !== undefined && /^[A-Za-z]/.test(part)) {
253
+ throw new ParseFailed(`IEC: letter part ${part} after letters number ${number}`, 0);
254
+ }
255
+ const dateTree = tree["date"];
256
+ if (dateTree !== undefined) {
257
+ const date = buildDate(dateTree);
258
+ if (date)
259
+ attrs["date"] = date;
260
+ }
261
+ // The designation's dotted sub-number ("60038-2.3", "/DAM 2.3:2022" —
262
+ // pubid#725): the shared second_part token binds it next to the
263
+ // number, and every layer that carries a designation holds it as the
264
+ // Iteration facet — the way the ISO flavor does.
265
+ const stageIteration = s(tree["stage_iteration"]);
266
+ if (stageIteration !== undefined) {
267
+ attrs["stage_iteration"] = new Iteration({ string: stageIteration });
268
+ }
269
+ if (tree["undated_marker"] !== undefined)
270
+ attrs["date"] = new PubidDate({ undated: true });
271
+ const edition = s(tree["edition"]);
272
+ if (edition !== undefined)
273
+ attrs["edition"] = edition;
274
+ if (tree["languages"] !== undefined) {
275
+ attrs["languages"] = parseLanguages(tree["languages"]);
276
+ }
277
+ const publisher = s(tree["publisher"]);
278
+ if (publisher !== undefined)
279
+ attrs["publisher"] = publisher;
280
+ const copubTree = tree["copublishers"];
281
+ if (copubTree !== undefined && copubTree !== null && copubTree !== "") {
282
+ const list = Array.isArray(copubTree) ? copubTree : [copubTree];
283
+ const bodies = list
284
+ .map((c) => (isObj(c) ? String(c["copublisher"]) : String(c)))
285
+ .filter((b) => b !== "" && b !== "null" && b !== "undefined");
286
+ if (bodies.length > 0)
287
+ attrs["copublishers"] = bodies;
288
+ }
289
+ if (tree["all_parts"] !== undefined)
290
+ attrs["all_parts"] = true;
291
+ if (tree["database"] !== undefined)
292
+ attrs["database"] = true;
293
+ }
294
+ buildSingle(tree) {
295
+ const stageAbbr = s(tree["type_with_stage"]) ?? s(tree["type_with_stage_fr"]) ?? "";
296
+ const typedStage = locateStage(stageAbbr) ?? locateStage("IS");
297
+ // The kind IS the type code: every IecTypeCode slot carries its own
298
+ // class now, including "wp" — the White Paper deliverable
299
+ // (pubid-ts#195), not the working document (which the work-programme
300
+ // and working-document builders construct through
301
+ // WORKING_DOCUMENT_CLASS directly).
302
+ const kind = typedStage.typeCode;
303
+ const attrs = {};
304
+ this.commonAttrs(tree, attrs);
305
+ // TRF with an embedded CISPR document: the form itself has no number
306
+ // — the document it reports on is built as the nested identifier and
307
+ // serializes under `cispr_identifier` (pubid#687). The runtime
308
+ // columns stay for the renderer and the official-URN slot.
309
+ if (tree["trf_org"] !== undefined) {
310
+ const cisprComponents = numberComponents(tree["number_with_part"]);
311
+ attrs["cispr_number"] = cisprComponents["number"];
312
+ attrs["cispr_part"] = cisprComponents["part"];
313
+ const cispr = new IEC_CLASSES.KIND_CLASSES["is"]({ publisher: "CISPR", ...cisprComponents });
314
+ attrs["cispr_identifier"] = cispr;
315
+ delete attrs["number"];
316
+ delete attrs["part"];
317
+ delete attrs["subpart"];
318
+ }
319
+ // The supplement-of-supplement path stores the base separately.
320
+ const parsed = {
321
+ typedStage,
322
+ kind: kind,
323
+ attrs,
324
+ };
325
+ // The ensure_base decode (ruby SupplementIdentifier#ensure_base;
326
+ // the 2026-11-12 owner ruling reversing #693): a standalone draft
327
+ // face whose designation is designation-shaped ("IEC/DCOR 60038-1",
328
+ // "IEC CDISH 60050-191") moves the designation WHOLE onto a
329
+ // concrete InternationalStandard base — number, part, subpart and
330
+ // the date (old notation prints the base's year) — while the
331
+ // supplement keeps a number of its own, defaulting to 1 (the
332
+ // no-number rule: an unnumbered DCOR/DISH/CDISH means
333
+ // Corrigendum/Interpretation-Sheet 1). The concrete base is what
334
+ // makes the decode hash-match (and equal) the modern on-base parse
335
+ // of the same document. A supplement with no part (a true
336
+ // standalone like "IEC/AMD 1:2017") keeps its own number below.
337
+ if ((kind === "amd" || kind === "cor" || kind === "ish") &&
338
+ tree["base"] === undefined &&
339
+ attrs["part"] !== undefined) {
340
+ const baseAttrs = {};
341
+ // The designation's dotted sub-part moves with it (pubid#725):
342
+ // "IEC/DCOR 60038-2.3" is base 60038-2 with stage iteration 3 —
343
+ // the same identity the plain on-base parse holds — not a facet of
344
+ // the implied supplement. Only the designation-shaped layout (a
345
+ // part present) carries it; a true standalone's own iteration
346
+ // ("IEC/AMD 1.2:2017", no part) stays where it is.
347
+ for (const key of ["publisher", "copublishers", "number", "part", "subpart", "date", "stage_iteration"]) {
348
+ if (attrs[key] !== undefined)
349
+ baseAttrs[key] = attrs[key];
350
+ }
351
+ const base = new IEC_CLASSES.KIND_CLASSES["is"](baseAttrs);
352
+ const suppAttrs = { base, number: "1" };
353
+ // Supplements copy the delegated publisher/copublishers level
354
+ // (ruby reads them through the base; the stored wire copies the
355
+ // non-default level).
356
+ if (attrs["publisher"] !== undefined && attrs["publisher"] !== "IEC") {
357
+ suppAttrs["publisher"] = attrs["publisher"];
358
+ }
359
+ if (Array.isArray(attrs["copublishers"]) && attrs["copublishers"].length > 0) {
360
+ suppAttrs["copublishers"] = attrs["copublishers"];
361
+ }
362
+ const supplement = this.construct({ kind: kind, attrs: suppAttrs, typedStage }, suppAttrs);
363
+ supplement["base"] = base;
364
+ return supplement;
365
+ }
366
+ // Consolidated supplements (+AMD…+AMD…)
367
+ const consolidated = tree["consolidated_supplements"];
368
+ let identifier = this.construct(parsed, attrs);
369
+ if (consolidated !== undefined) {
370
+ identifier = this.wrapConsolidated(identifier, consolidated);
371
+ }
372
+ const vapSuffix = s(tree["vap_suffix"]);
373
+ if (vapSuffix !== undefined) {
374
+ identifier = this.wrapVap(identifier, vapSuffix);
375
+ }
376
+ return identifier;
377
+ }
378
+ construct(parsed, attrs) {
379
+ const klass = IEC_CLASSES.KIND_CLASSES[parsed.kind];
380
+ if (klass === undefined)
381
+ throw new ParseFailed(`IEC: unknown kind ${String(parsed.kind)}`, 0);
382
+ const identifier = new klass(attrs);
383
+ identifier.typedStage = parsed.typedStage;
384
+ // The wire "stage" is the draft stage code (published stages drop).
385
+ const ts = parsed.typedStage;
386
+ if (ts !== undefined && ts.stageCode !== "published") {
387
+ identifier["stage"] = ts.code;
388
+ }
389
+ return identifier;
390
+ }
391
+ wrapConsolidated(base, data) {
392
+ const list = Array.isArray(data) ? data : [data];
393
+ const members = [base];
394
+ for (const raw of list) {
395
+ if (!isObj(raw))
396
+ continue;
397
+ const type = s(raw["supplement_type"]);
398
+ const number = s(raw["supplement_number"]);
399
+ if (type === undefined || number === undefined)
400
+ continue;
401
+ const date = s(raw["supplement_year"]);
402
+ const attrs = {
403
+ number,
404
+ ...(date !== undefined ? { date: new PubidDate({ year: date }) } : {}),
405
+ };
406
+ const kind = type === "AMD" ? "amd" : "cor";
407
+ const member = this.construct({ kind: kind, attrs, typedStage: locateStage(type) }, attrs);
408
+ members.push(member);
409
+ }
410
+ return new IEC_CLASSES.CONSOLIDATED_CLASS({
411
+ identifiers: members,
412
+ });
413
+ }
414
+ wrapVap(base, vapSuffix) {
415
+ const vap = vapSuffix.split("-");
416
+ let edition;
417
+ // A consolidated base carries the edition on its FIRST member (Ruby).
418
+ const kind = base.constructor.polymorphicName.slice("pubid:iec:".length);
419
+ const holder = kind === "consolidated-identifier"
420
+ ? base.identifiers[0]
421
+ : base;
422
+ if (holder["edition"] !== undefined) {
423
+ edition = String(holder["edition"]);
424
+ delete holder["edition"];
425
+ }
426
+ return new IEC_CLASSES.VAP_CLASS({
427
+ base,
428
+ vap,
429
+ ...(edition !== undefined ? { edition } : {}),
430
+ });
431
+ }
432
+ /**
433
+ * The legacy DAM-family prefix face (IEC/FDAM 60038-1, ISO/IEC PDAM
434
+ * 2 10646:2012, ISO/IEC FPDAM 9075/1): the JTC1 ballot spelling puts
435
+ * the stage token before the base designation. Decode onto the
436
+ * modern identity (owner ruling 2026-11-12): the designation is the
437
+ * BASE's, kept whole — the old slash-part spelling "9075/1" is base
438
+ * 9075 part 1 — and the supplement's number is the captured N,
439
+ * defaulting to 1 (the no-number rule). The date rides with the
440
+ * designation (old notation prints the base's year); a draft
441
+ * supplement carries none of its own. The base builds through the
442
+ * ordinary single-document path, so it is the same
443
+ * InternationalStandard the modern on-base parse holds and
444
+ * parse(legacy) == parse(modern).
445
+ */
446
+ buildLegacySupplement(tree) {
447
+ const baseTree = {};
448
+ if (tree["publisher"] !== undefined)
449
+ baseTree["publisher"] = tree["publisher"];
450
+ if (tree["legacy_copublisher"] !== undefined) {
451
+ baseTree["copublishers"] = [s(tree["legacy_copublisher"])];
452
+ }
453
+ if (tree["legacy_base_number"] !== undefined) {
454
+ // The slash-part designation ("9075/1") captured number and part
455
+ // separately; they go on straight as the object the splitter reads.
456
+ baseTree["number_with_part"] = {
457
+ number: s(tree["legacy_base_number"]),
458
+ ...(s(tree["legacy_base_part"]) !== undefined ? { part: s(tree["legacy_base_part"]) } : {}),
459
+ };
460
+ }
461
+ else if (tree["legacy_base_number_with_part"] !== undefined) {
462
+ baseTree["number_with_part"] = tree["legacy_base_number_with_part"];
463
+ }
464
+ if (tree["date"] !== undefined)
465
+ baseTree["date"] = tree["date"];
466
+ if (tree["undated_marker"] !== undefined)
467
+ baseTree["undated_marker"] = tree["undated_marker"];
468
+ if (tree["edition"] !== undefined)
469
+ baseTree["edition"] = tree["edition"];
470
+ if (tree["languages"] !== undefined)
471
+ baseTree["languages"] = tree["languages"];
472
+ // The designation's dotted sub-number is the BASE's ("IEC/FDAM
473
+ // 60038-2.3" - base 60038-2, stage iteration 3; pubid#725).
474
+ if (tree["stage_iteration"] !== undefined)
475
+ baseTree["stage_iteration"] = tree["stage_iteration"];
476
+ const base = this.buildInner(baseTree);
477
+ // The wrap: one amendment/corrigendum layer over the whole base; the
478
+ // third_part's fragment notation rode the outermost layer (applied by
479
+ // the dispatch ahead of this branch).
480
+ const suppTree = {
481
+ type_with_stage: s(tree["legacy_stage"]),
482
+ number_with_part: s(tree["legacy_supplement_number"]) ?? "1",
483
+ };
484
+ return this.wrapSupplementLayer(base, suppTree);
485
+ }
486
+ buildSheet(tree) {
487
+ const sheetNumber = s(tree["sheet_number"]);
488
+ const sheetYear = s(tree["sheet_year"]);
489
+ const rest = { ...tree };
490
+ delete rest["sheet_number"];
491
+ delete rest["sheet_year"];
492
+ const base = this.buildInner(rest);
493
+ return new IEC_CLASSES.SHEET_CLASS({
494
+ base,
495
+ ...(sheetNumber !== undefined ? { sheet_number: sheetNumber } : {}),
496
+ ...(sheetYear !== undefined ? { sheet_year: sheetYear } : {}),
497
+ });
498
+ }
499
+ buildWorkingProgramme(tree) {
500
+ // The grammar captures a trailing space on wp_type ("PWI TR 100-36"
501
+ // -> "TR "); ruby strips it at the construction site (its builder's
502
+ // :wp_type cast) so the stored value — and the hash and URN — is the
503
+ // stripped form, an all-space value dropping out entirely.
504
+ const wpTypeRaw = s(tree["wp_type"])?.replace(/\s+$/, "");
505
+ const attrs = {
506
+ wp_stage: s(tree["wp_stage"]),
507
+ wp_type: wpTypeRaw === "" ? undefined : wpTypeRaw,
508
+ };
509
+ Object.assign(attrs, numberComponents(tree["number_with_part"]));
510
+ const edition = s(tree["edition"]);
511
+ if (edition !== undefined)
512
+ attrs["edition"] = edition;
513
+ const identifier = new IEC_CLASSES.WORKING_DOCUMENT_CLASS(attrs);
514
+ const ts = locateStage(s(tree["wp_stage"]) === "PNW" ? "PNW" : "PWI");
515
+ identifier.typedStage = ts;
516
+ if (ts !== undefined && ts.stageCode !== "published") {
517
+ identifier["stage"] = ts.code;
518
+ }
519
+ return identifier;
520
+ }
521
+ buildWorkingDocument(tree) {
522
+ const attrs = {
523
+ technical_committee: s(tree["technical_committee"]),
524
+ // The document number is the inherited `number` (pubid#687: the
525
+ // parallel wd_number slot used to serialize nowhere).
526
+ number: s(tree["wd_number"]),
527
+ wd_language: s(tree["wd_language"]),
528
+ wd_stage: s(tree["wd_stage"]),
529
+ };
530
+ return new IEC_CLASSES.WORKING_DOCUMENT_CLASS(attrs);
531
+ }
532
+ /** Materializes one supplement (Amendment/Corrigendum/...) from its
533
+ * layer's fields and wraps the base. */
534
+ buildSupplementLayer(base, supp) {
535
+ const stageAbbr = s(supp["type_with_stage"]) ?? "";
536
+ const typedStage = locateStage(stageAbbr) ?? locateStage("AMD");
537
+ let kind;
538
+ if (typedStage.typeCode === "cor")
539
+ kind = "cor";
540
+ else if (typedStage.typeCode === "ish")
541
+ kind = "ish";
542
+ else
543
+ kind = "amd";
544
+ const attrs = {};
545
+ this.commonAttrs(supp, attrs);
546
+ // Supplements copy the delegated publisher/copublishers level.
547
+ const baseRec = base;
548
+ if (attrs["publisher"] === undefined && baseRec["publisher"] !== undefined && baseRec["publisher"] !== "IEC") {
549
+ attrs["publisher"] = baseRec["publisher"];
550
+ }
551
+ if (attrs["copublishers"] === undefined && Array.isArray(baseRec["copublishers"]) && baseRec["copublishers"].length > 0) {
552
+ attrs["copublishers"] = baseRec["copublishers"];
553
+ }
554
+ const supplement = this.construct({ kind: kind, attrs, typedStage }, attrs);
555
+ supplement["base"] = base;
556
+ return supplement;
557
+ }
558
+ }
559
+ /** --- URN: the positional-slot machine (lib/pubid/iec/urn_generator.rb) --- */
560
+ const TYPE_SLOT_CODES = new Set(["tr", "ts", "pas", "srd", "guide", "tec", "wp"]);
561
+ const DELIVERABLES = new Set(["cmv", "csv", "exv", "prv", "rlv", "ser"]);
562
+ const ADJUNCT_TOKENS = {
563
+ amendment: "amd",
564
+ corrigendum: "cor",
565
+ "interpretation-sheet": "ish",
566
+ };
567
+ function idKind(id) {
568
+ return id.constructor.polymorphicName.slice("pubid:iec:".length);
569
+ }
570
+ function maybeOf(id, attr) {
571
+ return id[attr];
572
+ }
573
+ function findDown(id, attr) {
574
+ let current = id;
575
+ while (current !== undefined) {
576
+ const value = maybeOf(current, attr);
577
+ if (value !== undefined && !(Array.isArray(value) && value.length === 0) && value !== "") {
578
+ return value;
579
+ }
580
+ current =
581
+ maybeOf(current, "base") ??
582
+ maybeOf(current, "identifiers")?.[0];
583
+ }
584
+ return undefined;
585
+ }
586
+ function rootOf(id) {
587
+ let current = id;
588
+ while (true) {
589
+ const base = maybeOf(current, "base");
590
+ if (base !== undefined) {
591
+ current = base;
592
+ continue;
593
+ }
594
+ const ids = maybeOf(current, "identifiers");
595
+ if (ids !== undefined && ids.length > 0 && ids[0] !== current) {
596
+ current = ids[0];
597
+ continue;
598
+ }
599
+ return current;
600
+ }
601
+ }
602
+ function adjunctFields(id, plus) {
603
+ const kind = idKind(id);
604
+ const token = ADJUNCT_TOKENS[kind];
605
+ if (token === undefined)
606
+ return [];
607
+ const date = maybeOf(id, "date");
608
+ // The supplement's dotted sub-number rides its number slot
609
+ // ("amd:2.3:2022"; pubid#725): ISO's official URN keeps the facet
610
+ // through its version atom, and this scheme has no version slot, so
611
+ // the number slot carries the designation as printed. The parser
612
+ // rebuilds "/AMD2.3:2022" from the slot, which re-parses losslessly.
613
+ const iteration = maybeOf(id, "stage_iteration");
614
+ const number = String(maybeOf(id, "number") ?? "") +
615
+ (iteration !== undefined ? `.${iteration.render()}` : "");
616
+ return [
617
+ plus ? "plus" : "",
618
+ token,
619
+ number,
620
+ date !== undefined ? (date.render() ?? "") : "",
621
+ ];
622
+ }
623
+ function adjunctSlots(id) {
624
+ if (id === undefined)
625
+ return [];
626
+ const kind = idKind(id);
627
+ if (kind === "consolidated-identifier") {
628
+ const members = maybeOf(id, "identifiers") ?? [];
629
+ return [
630
+ ...adjunctSlots(members[0]),
631
+ ...members.slice(1).flatMap((m) => adjunctFields(m, true)),
632
+ ];
633
+ }
634
+ const recursed = adjunctSlots(maybeOf(id, "base"));
635
+ if (ADJUNCT_TOKENS[kind] !== undefined) {
636
+ return [...recursed, ...adjunctFields(id, false)];
637
+ }
638
+ return recursed;
639
+ }
640
+ export function iecToUrn(identifier) {
641
+ // The document the URN names: the origin standard with wrappers peeled.
642
+ const doc = rootOf(identifier);
643
+ const trf = doc;
644
+ let docWithNumber;
645
+ if (maybeOf(trf, "number") === undefined && maybeOf(trf, "cispr_number") !== undefined) {
646
+ // TRF: read number/part from the runtime CISPR columns.
647
+ docWithNumber = {
648
+ get number() { return maybeOf(trf, "cispr_number"); },
649
+ get part() { return maybeOf(trf, "cispr_part"); },
650
+ get subpart() { return undefined; },
651
+ get publisher() { return "CISPR"; },
652
+ get copublishers() { return []; },
653
+ get date() { return undefined; },
654
+ get typedStage() { return trf.typedStage; },
655
+ };
656
+ }
657
+ else {
658
+ docWithNumber = maybeOf(doc, "number") !== undefined
659
+ ? doc
660
+ : maybeOf(doc, "cispr_identifier") ?? doc;
661
+ }
662
+ const number = maybeOf(docWithNumber, "number");
663
+ if (number === undefined)
664
+ return "urn:iec:std:";
665
+ const numSegment = [number, maybeOf(docWithNumber, "part"), maybeOf(docWithNumber, "subpart")]
666
+ .filter((v) => v !== undefined && v !== "")
667
+ .join("-")
668
+ .replace(/\s+/g, "-");
669
+ if (numSegment === "")
670
+ return "urn:iec:std:";
671
+ const publishers = [
672
+ maybeOf(docWithNumber, "publisher") ?? "IEC",
673
+ ...(maybeOf(docWithNumber, "copublishers") ?? []),
674
+ ]
675
+ .filter((p) => p !== undefined && p !== "")
676
+ .map((p) => p.split(/\s+/).at(-1))
677
+ .filter((p) => p !== "");
678
+ const authority = publishers.join("-");
679
+ const date = maybeOf(docWithNumber, "date");
680
+ const dateSlot = date !== undefined ? (date.render() ?? "") : "";
681
+ const ts = docWithNumber.typedStage;
682
+ const typeToken = ts !== undefined && TYPE_SLOT_CODES.has(ts.typeCode) ? ts.typeCode : "";
683
+ // The gem's stage_token (urn_generator.rb): nil when the stage is
684
+ // published OR when the typed stage carries no harmonized code — there
685
+ // is NO stage-code fallback, so a harmonized-less draft row (BPUB,
686
+ // the draft-supplement rows) leaves the slot empty (#187).
687
+ const stageToken = ts !== undefined && ts.stageCode !== "published" && ts.harmonized !== undefined
688
+ ? `stage-${ts.harmonized}`
689
+ : "";
690
+ const stageOrType = [typeToken, stageToken].filter((t) => t !== "").join("-");
691
+ const vap = findDown(identifier, "vap");
692
+ const vapCodes = (vap ?? [])
693
+ .map((c) => c.toLowerCase())
694
+ .filter((c) => DELIVERABLES.has(c));
695
+ let deliverable = vapCodes.join("-");
696
+ if (deliverable === "") {
697
+ const edition = findDown(identifier, "edition");
698
+ deliverable = edition !== undefined ? `ed-${edition}` : "";
699
+ }
700
+ const langs = maybeOf(identifier, "languages") ?? [];
701
+ const language = langs.map((l) => l.code).join("-");
702
+ const slots = ["urn", "iec", "std", authority, numSegment, dateSlot, stageOrType, deliverable];
703
+ const adjuncts = adjunctSlots(identifier);
704
+ const bareSeries = slots.at(-1) === "ser" &&
705
+ slots.slice(5, 7).every((x) => x === "") &&
706
+ adjuncts.length === 0 &&
707
+ language === "";
708
+ if (!bareSeries)
709
+ slots.push(language);
710
+ return [...slots, ...adjuncts].join(":").toLowerCase();
711
+ }
712
+ // Attach the URN generator to every registered IEC class (the base
713
+ // toUrn resolves constructor.urnGenerator).
714
+ class IecUrnGenerator {
715
+ identifier;
716
+ constructor(identifier) {
717
+ this.identifier = identifier;
718
+ }
719
+ generate() {
720
+ return iecToUrn(this.identifier);
721
+ }
722
+ }
723
+ for (const klass of [
724
+ ...Object.values(IEC_CLASSES.KIND_CLASSES),
725
+ IEC_CLASSES.WORKING_DOCUMENT_CLASS,
726
+ IEC_CLASSES.SHEET_CLASS,
727
+ IEC_CLASSES.VAP_CLASS,
728
+ IEC_CLASSES.CONSOLIDATED_CLASS,
729
+ IEC_CLASSES.FRAGMENT_CLASS,
730
+ ]) {
731
+ if (klass !== undefined) {
732
+ klass.urnGenerator = IecUrnGenerator;
733
+ }
734
+ }
735
+ // --- the standalone no-part dotted face reject (pubid#727) --------------
736
+ // A supplement's OWN dotted sub-number has nowhere to print on the
737
+ // standalone (no-part, self-base) face: the standalone renderer prints
738
+ // the base number and the supplement number only, so the parsed dot was
739
+ // dropped at render and parse(render) != parse. No IEC source prints a
740
+ // no-part standalone face with a dotted number — the facet is attested
741
+ // only on the on-base draft faces ("IEC 60038-2/DAM 2.3:2022") — so the
742
+ // shape is rejected at parse instead of being built unrenderable (the
743
+ // #726 ruling for unattested dotted shapes; the TS mirror of the gem's
744
+ // reject_standalone_dotted_supplement walk over the built base chain).
745
+ // The check is the SHAPE, not a grammar route: one condition covers the
746
+ // standalone branch ("IEC/AMD 1.2:2017"), the publisher-less plain route
747
+ // ("AMD 1.2:2017") and a dotted layer under an undotted second
748
+ // supplement ("IEC/AMD 1.2:2017/COR 1:2018"). The single-document draft
749
+ // faces ("IEC CD 1.2:2017"), the DAM-family decodes ("IEC/DAM 1.2") and
750
+ // the on-base faces (a real base) keep their dot on a printable layer
751
+ // and pass. from_hash deliberately still deserializes the shape (no
752
+ // stored row carries it; residue pinned).
753
+ const STANDALONE_DOTTED_SUPPLEMENT_MESSAGE = 'the standalone no-part supplement face carries a dotted sub-number ' +
754
+ '(e.g. "IEC/AMD 1.2:2017"): no IEC source prints one, and the ' +
755
+ "standalone face has no layer to print the dot on, so the stored " +
756
+ "sub-number would be dropped at render — the dotted sub-number is " +
757
+ "attested only on the on-base draft forms";
758
+ const SUPPLEMENT_POLYMORPHIC_NAMES = new Set([
759
+ "pubid:iec:amendment",
760
+ "pubid:iec:corrigendum",
761
+ "pubid:iec:interpretation-sheet",
762
+ ]);
763
+ export function rejectStandaloneDottedSupplement(id) {
764
+ let node = id;
765
+ while (node !== undefined && SUPPLEMENT_POLYMORPHIC_NAMES.has(node.constructor.polymorphicName)) {
766
+ const layer = node;
767
+ const iteration = layer["stage_iteration"];
768
+ const base = layer["base"];
769
+ if (iteration !== undefined && (base === undefined || layer["synthetic_base"] === true)) {
770
+ throw new ParseFailed(STANDALONE_DOTTED_SUPPLEMENT_MESSAGE, 0);
771
+ }
772
+ node = base;
773
+ }
774
+ }
775
+ // --- the un-renderable trailing-edition chain reject (pubid#788) --------
776
+ // The bare consolidated chain with a trailing edition
777
+ // ("IEC 60068:2005+AMD1:2012 ED2") parses, and then cannot render: the
778
+ // edition rides the base member, so the composition prints it onto the
779
+ // base designation ("IEC 60068:2005 ED2+AMD1:2012") — a face no IEC
780
+ // source prints (0 of the 33,070 primary docidentifiers in
781
+ // relaton-data-iec carry an edition facet on a chain) and the grammar
782
+ // rejects, so parse(render) raises. The consolidated edition IS the CSV
783
+ // product ("IEC 60034-18-41:2014+AMD1:2019 CSV", the OBP PDF named
784
+ // {ed1.1}); where the printed edition appears at all it is the CSV
785
+ // face's own facet ("IEC 60068:2005+AMD1:2012 CSV ED1" — the Vap carries
786
+ // the edition after the deliverable code and renders back parseably).
787
+ // So the shape is rejected at parse — the #727 ruling for unattested,
788
+ // un-renderable faces — rather than built unrenderable. The check is the
789
+ // SHAPE on the built object, not a grammar route (the same ruling as
790
+ // rejectStandaloneDottedSupplement): a bare ConsolidatedIdentifier with
791
+ // an edition on any member, found by the gem's descend_wrapper walk (a
792
+ // node with a `base` attribute descends to it, a node with `identifiers`
793
+ // to its first member). from_hash stays open (stored-data
794
+ // compatibility): parse can no longer produce the shape and no stored
795
+ // row carries it. The edition-bearing face that DOES round-trip is the
796
+ // CSV one ("IEC 60068:2005+AMD1:2012 CSV ED1" — the edition rides the
797
+ // Vap after the deliverable code).
798
+ const CONSOLIDATED_EDITION_MESSAGE = 'the bare consolidated chain carries a trailing edition ' +
799
+ '(e.g. "IEC 60068:2005+AMD1:2012 ED2"): no IEC source prints one — ' +
800
+ "0 of the 33,070 primary docidentifiers in relaton-data-iec carry an " +
801
+ "edition facet on a chain — and the canonical render prints the " +
802
+ 'edition onto the base designation ("IEC 60068:2005 ED2+AMD1:2012"), ' +
803
+ "which cannot be re-parsed. The consolidated edition is the CSV face " +
804
+ '("IEC 60034-18-41:2014+AMD1:2019 CSV", the OBP PDF named {ed1.1}); ' +
805
+ 'where the printed edition appears it rides the CSV face ("IEC ' +
806
+ '60068:2005+AMD1:2012 CSV ED1"), which parses and round-trips';
807
+ export function rejectUnrenderableConsolidatedEdition(id) {
808
+ let node = id;
809
+ while (node !== undefined) {
810
+ if (node.constructor.polymorphicName === "pubid:iec:consolidated-identifier") {
811
+ const members = node.identifiers ?? [];
812
+ if (members.some((member) => member["edition"] !== undefined &&
813
+ member["edition"] !== null)) {
814
+ throw new ParseFailed(CONSOLIDATED_EDITION_MESSAGE, 0);
815
+ }
816
+ }
817
+ // Ruby descend_wrapper: a node whose class declares a `base`
818
+ // attribute descends to it; a node with `identifiers` to its first
819
+ // member; a leaf ends the walk.
820
+ const attrs = node.constructor
821
+ .attributes;
822
+ if (attrs !== undefined && "base" in attrs) {
823
+ node = node["base"];
824
+ }
825
+ else if (attrs !== undefined && "identifiers" in attrs) {
826
+ node = node.identifiers?.[0];
827
+ }
828
+ else {
829
+ node = undefined;
830
+ }
831
+ }
832
+ }
833
+ /** The parse preprocessor (Ruby Parser.parse): tab and ", Ed."
834
+ * normalization plus the IEV shorthand expansion. A judgment about
835
+ * inputs - the CODEGEN-SPEC section 3 residue, hand-side ahead of the
836
+ * injected wire. */
837
+ export function preprocessIec(input) {
838
+ return input
839
+ .replaceAll("\t", " ")
840
+ .replace(/,\s+Ed\./, " Ed.")
841
+ .replace(/^IEV(?=$|[\s-])/, "IEC 60050");
842
+ }
843
+ /** The bound -> wire lane is injected so the node entry (the generated
844
+ * substrate over the wasm artifact runtime) and the worker entry (the
845
+ * pure-TS worker engine) share this delta byte for byte. */
846
+ export function makeIecGrammarImplementation(parseWire) {
847
+ const builder = new IecBuilder();
848
+ return {
849
+ // Inverse of the IEC UrnGenerator (lib/pubid/iec/urn_parser.rb):
850
+ // reassemble the positional URN fields into a text code, parse it, then
851
+ // attach languages and the all-parts wrap.
852
+ parseUrn(urn) {
853
+ const parsed = urnToCode(urn);
854
+ if (!parsed)
855
+ throw new Error(`Invalid IEC URN: ${urn}`);
856
+ let [code, lang, allParts] = parsed;
857
+ // The "ser" slot names every part of the document: the reference
858
+ // wraps via to_all_parts, which strips the part and the date (a
859
+ // series names the document across editions, "IEC 60034 (all
860
+ // parts)"). The part rides dash-joined on the number, the date in
861
+ // its own slot.
862
+ if (allParts) {
863
+ code = code
864
+ .replace(/:[^:]*$/, "")
865
+ .replace(/\s(19|20)\d\d(-\d\d)?$/, "")
866
+ .replace(/-[^\s:-]+$/, "");
867
+ }
868
+ // The reference parses the unprefixed rebuild and its grammar
869
+ // defaults the IEC publisher; the ts grammar needs it explicit.
870
+ const id = this.parse(code);
871
+ if (lang && lang !== "" && "languages" in id) {
872
+ id.languages = lang
873
+ .split("-")
874
+ .map((c) => new Language({ code: c }));
875
+ }
876
+ if (allParts) {
877
+ id.all_parts = true;
878
+ }
879
+ return id;
880
+ },
881
+ parse(input) {
882
+ let tree;
883
+ try {
884
+ tree = parseWire(preprocessIec(input));
885
+ }
886
+ catch {
887
+ throw new ParseFailed("IEC: parse failed", 0);
888
+ }
889
+ const built = builder.build(tree);
890
+ // The shape check runs on the BUILT object (ruby Identifier.parse
891
+ // walks the base chain after ensure_base) - BSI's delegation and
892
+ // every parse route raise through this entry; from_hash stays open.
893
+ rejectStandaloneDottedSupplement(built);
894
+ rejectUnrenderableConsolidatedEdition(built);
895
+ return built;
896
+ },
897
+ };
898
+ }
899
+ // Port of Relaton::Iec.urn_to_code + the slot helpers
900
+ // (lib/pubid/iec/urn_parser.rb): reassemble the positional URN fields into
901
+ // a text code. Returns [code, language, allParts].
902
+ function urnToCode(urn) {
903
+ const fields = urn.toUpperCase().split(":");
904
+ if (fields.length < 5)
905
+ return undefined;
906
+ const [head, num, date, type, deliv, lang] = fields.slice(3, 9);
907
+ let allParts = false;
908
+ let code = head.replaceAll("-", "/");
909
+ const typeCode = typeSlotToCode(type);
910
+ if (typeCode !== "")
911
+ code += ` ${typeCode}`;
912
+ code += ` ${num}`;
913
+ if (date !== undefined && date !== "")
914
+ code += `:${date}`;
915
+ code += adjunctToCode(fields.slice(9));
916
+ if ((deliv ?? "").toLowerCase() === "ser") {
917
+ allParts = true;
918
+ }
919
+ else if (deliv !== undefined) {
920
+ const edition = editionSlotToCode(deliv);
921
+ if (edition)
922
+ code += ` ${edition}`;
923
+ else if (deliv !== "")
924
+ code += ` ${deliv}`;
925
+ }
926
+ return [code, lang?.toLowerCase(), allParts];
927
+ }
928
+ // The type slot holds a legacy type token ("TS"), a stage
929
+ // ("STAGE-10.20"), or both ("TS-STAGE-50.00"); a stage is written back as
930
+ // the abbreviation resolved from the typed-stage registry.
931
+ function typeSlotToCode(type) {
932
+ if (type === undefined || type === "")
933
+ return "";
934
+ const match = type.match(/^([A-Z]+-)?STAGE-([\d.]+)$/);
935
+ if (!match)
936
+ return type;
937
+ const stageType = (match[1] ?? "IS-").replace("-", "").toLowerCase();
938
+ const stage = TYPED_STAGES.find((t) => t.typeCode === stageType && (t.harmonized ?? "") === match[2]);
939
+ return stage ? stage.abbr : "";
940
+ }
941
+ // "ED-7" in the deliverable slot is an edition, not a deliverable code.
942
+ function editionSlotToCode(deliv) {
943
+ const match = deliv?.match(/^ED-(.+)$/);
944
+ return match ? `ED${match[1]}` : undefined;
945
+ }
946
+ // Adjuncts are (relation, type, number, date) quartets; a "PLUS" relation
947
+ // yields "+", otherwise "/".
948
+ function adjunctToCode(fields) {
949
+ if (!fields.length)
950
+ return "";
951
+ const [rel = "", type = "", num = "", date = ""] = fields.slice(0, 4);
952
+ let code = (rel === "" ? "/" : "+") + type + num;
953
+ if (date !== "")
954
+ code += `:${date}`;
955
+ return code + adjunctToCode(fields.slice(4));
956
+ }