pubid 2.0.1 → 2.0.3

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 (216) hide show
  1. checksums.yaml +4 -4
  2. data/data/ieee/update_codes.yaml +2 -2
  3. data/data/parg/adobe.json +1 -1
  4. data/data/parg/aiee.json +1 -1
  5. data/data/parg/aiee.parg +99 -9
  6. data/data/parg/amca.json +1 -1
  7. data/data/parg/ansi.json +1 -1
  8. data/data/parg/api.json +1 -1
  9. data/data/parg/ashrae.json +1 -1
  10. data/data/parg/asme.json +1 -1
  11. data/data/parg/astm.json +1 -1
  12. data/data/parg/bipm.json +1 -1
  13. data/data/parg/bsi.json +1 -1
  14. data/data/parg/ccsds.json +1 -1
  15. data/data/parg/cen_cenelec.json +1 -1
  16. data/data/parg/cie.json +1 -1
  17. data/data/parg/csa.json +1 -1
  18. data/data/parg/ecma.json +1 -1
  19. data/data/parg/etsi.json +1 -1
  20. data/data/parg/evs.json +1 -1
  21. data/data/parg/gost.json +1 -1
  22. data/data/parg/iala.json +1 -1
  23. data/data/parg/iana.json +1 -1
  24. data/data/parg/idf.json +1 -1
  25. data/data/parg/iec.json +1 -1
  26. data/data/parg/ieee.json +1 -1
  27. data/data/parg/iho.json +1 -0
  28. data/data/parg/ire.json +1 -1
  29. data/data/parg/ire.parg +51 -12
  30. data/data/parg/isbn.json +1 -1
  31. data/data/parg/iso.json +1 -1
  32. data/data/parg/iso.parg +751 -0
  33. data/data/parg/itu.json +1 -1
  34. data/data/parg/jcgm.json +1 -1
  35. data/data/parg/jis.json +1 -1
  36. data/data/parg/nesc.json +1 -1
  37. data/data/parg/nesc.parg +97 -12
  38. data/data/parg/nist.json +1 -1
  39. data/data/parg/oiml.json +1 -1
  40. data/data/parg/omg.json +1 -1
  41. data/data/parg/parg.json +1 -1
  42. data/data/parg/plateau.json +1 -1
  43. data/data/parg/tgpp.json +1 -1
  44. data/data/parg/un.json +1 -1
  45. data/lib/pubid/adobe/identifier.rb +1 -1
  46. data/lib/pubid/adobe/parser.rb +2 -113
  47. data/lib/pubid/amca/identifiers/base.rb +1 -1
  48. data/lib/pubid/amca/parser.rb +1 -145
  49. data/lib/pubid/ansi/identifier.rb +1 -1
  50. data/lib/pubid/ansi/parser.rb +1 -82
  51. data/lib/pubid/api/builder.rb +32 -1
  52. data/lib/pubid/api/identifier.rb +1 -1
  53. data/lib/pubid/api/parser.rb +1 -131
  54. data/lib/pubid/ashrae/identifiers/base.rb +1 -1
  55. data/lib/pubid/ashrae/parser.rb +3 -710
  56. data/lib/pubid/asme/builder.rb +6 -4
  57. data/lib/pubid/asme/identifier.rb +1 -2
  58. data/lib/pubid/asme/parser.rb +1 -328
  59. data/lib/pubid/astm/builder.rb +12 -3
  60. data/lib/pubid/astm/identifier.rb +1 -2
  61. data/lib/pubid/astm/parser.rb +1 -227
  62. data/lib/pubid/bipm/identifier.rb +8 -1
  63. data/lib/pubid/bipm/parser.rb +2 -224
  64. data/lib/pubid/bsi/builder.rb +2 -4
  65. data/lib/pubid/bsi/parser.rb +1 -666
  66. data/lib/pubid/bsi/single_identifier.rb +38 -1
  67. data/lib/pubid/calconnect/parser.rb +2 -40
  68. data/lib/pubid/ccsds/identifier.rb +1 -1
  69. data/lib/pubid/ccsds/parser.rb +1 -66
  70. data/lib/pubid/cen_cenelec/identifier.rb +16 -1
  71. data/lib/pubid/cen_cenelec/parser.rb +3 -136
  72. data/lib/pubid/cie/identifier.rb +1 -1
  73. data/lib/pubid/cie/parser.rb +3 -378
  74. data/lib/pubid/conformance.rb +1 -1
  75. data/lib/pubid/csa/builder.rb +41 -18
  76. data/lib/pubid/csa/identifier.rb +12 -4
  77. data/lib/pubid/csa/identifiers/amendment.rb +28 -0
  78. data/lib/pubid/csa/identifiers.rb +1 -0
  79. data/lib/pubid/csa/parser.rb +16 -397
  80. data/lib/pubid/doi/parser.rb +2 -37
  81. data/lib/pubid/easc/builder.rb +1 -1
  82. data/lib/pubid/easc/parser.rb +2 -70
  83. data/lib/pubid/ecma/CLAUDE.md +8 -1
  84. data/lib/pubid/ecma/identifier.rb +13 -8
  85. data/lib/pubid/ecma/parser.rb +2 -54
  86. data/lib/pubid/ecma/renderer.rb +3 -7
  87. data/lib/pubid/errors.rb +18 -13
  88. data/lib/pubid/etsi/builder.rb +8 -5
  89. data/lib/pubid/etsi/identifiers/base.rb +1 -1
  90. data/lib/pubid/etsi/parser.rb +1 -132
  91. data/lib/pubid/evs/identifier.rb +7 -0
  92. data/lib/pubid/evs/parser.rb +1 -8
  93. data/lib/pubid/evs.rb +1 -1
  94. data/lib/pubid/gb/identifier.rb +6 -0
  95. data/lib/pubid/gb/parser.rb +2 -51
  96. data/lib/pubid/gost/identifier.rb +9 -1
  97. data/lib/pubid/gost/parser.rb +4 -81
  98. data/lib/pubid/iala/builder.rb +48 -39
  99. data/lib/pubid/iala/identifier.rb +1 -1
  100. data/lib/pubid/iala/parser.rb +2 -121
  101. data/lib/pubid/iana/identifier.rb +1 -1
  102. data/lib/pubid/iana/parser.rb +2 -24
  103. data/lib/pubid/identifier.rb +78 -1
  104. data/lib/pubid/idf/builder.rb +42 -0
  105. data/lib/pubid/idf/identifier.rb +1 -1
  106. data/lib/pubid/idf/parser.rb +1 -137
  107. data/lib/pubid/idf.rb +1 -2
  108. data/lib/pubid/iec/builder.rb +158 -50
  109. data/lib/pubid/iec/identifier.rb +1 -1
  110. data/lib/pubid/iec/parser.rb +3 -430
  111. data/lib/pubid/ieee/CLAUDE.md +2 -0
  112. data/lib/pubid/ieee/aiee/identifier.rb +2 -1
  113. data/lib/pubid/ieee/aiee.rb +0 -1
  114. data/lib/pubid/ieee/builder.rb +177 -30
  115. data/lib/pubid/ieee/components/code.rb +46 -7
  116. data/lib/pubid/ieee/identifiers/base.rb +5 -2
  117. data/lib/pubid/ieee/identifiers/joint_development.rb +7 -3
  118. data/lib/pubid/ieee/ire/identifier.rb +2 -1
  119. data/lib/pubid/ieee/ire.rb +0 -1
  120. data/lib/pubid/ieee/nesc/builder.rb +1 -1
  121. data/lib/pubid/ieee/nesc.rb +0 -1
  122. data/lib/pubid/ieee/parser.rb +1 -1257
  123. data/lib/pubid/ieee/project_renderer.rb +5 -1
  124. data/lib/pubid/ieee/renderer.rb +4 -2
  125. data/lib/pubid/ieee/urn_generator.rb +4 -1
  126. data/lib/pubid/ietf/identifiers/base.rb +17 -1
  127. data/lib/pubid/ietf/parser.rb +2 -47
  128. data/lib/pubid/ietf/renderer.rb +17 -2
  129. data/lib/pubid/iho/CLAUDE.md +98 -0
  130. data/lib/pubid/iho/builder.rb +4 -1
  131. data/lib/pubid/iho/identifiers/base.rb +28 -2
  132. data/lib/pubid/iho/renderer.rb +8 -0
  133. data/lib/pubid/iho/urn_generator.rb +14 -1
  134. data/lib/pubid/iho/urn_parser.rb +45 -32
  135. data/lib/pubid/iho.rb +0 -1
  136. data/lib/pubid/isbn/identifier.rb +1 -1
  137. data/lib/pubid/isbn/parser.rb +2 -31
  138. data/lib/pubid/iso/CLAUDE.md +66 -0
  139. data/lib/pubid/iso/builder.rb +229 -15
  140. data/lib/pubid/iso/identifier.rb +22 -12
  141. data/lib/pubid/iso/identifiers/directives.rb +6 -3
  142. data/lib/pubid/iso/identifiers/guide.rb +6 -3
  143. data/lib/pubid/iso/identifiers/international_workshop_agreement.rb +6 -3
  144. data/lib/pubid/iso/normalizer.rb +5 -4
  145. data/lib/pubid/iso/parser.rb +1 -539
  146. data/lib/pubid/iso/supplement_identifier.rb +6 -3
  147. data/lib/pubid/iso/urn_parser.rb +13 -8
  148. data/lib/pubid/iso/utilities.rb +4 -5
  149. data/lib/pubid/iso.rb +1 -19
  150. data/lib/pubid/itu/builder.rb +36 -20
  151. data/lib/pubid/itu/identifiers/base.rb +15 -2
  152. data/lib/pubid/itu/parser.rb +1 -775
  153. data/lib/pubid/jcgm/builder.rb +35 -0
  154. data/lib/pubid/jcgm/parser.rb +1 -151
  155. data/lib/pubid/jcgm.rb +1 -2
  156. data/lib/pubid/jis/CLAUDE.md +36 -0
  157. data/lib/pubid/jis/builder.rb +30 -41
  158. data/lib/pubid/jis/identifier.rb +12 -2
  159. data/lib/pubid/jis/identifiers/welding_engineering_standard.rb +35 -0
  160. data/lib/pubid/jis/identifiers.rb +2 -0
  161. data/lib/pubid/jis/parser.rb +1 -128
  162. data/lib/pubid/jis/renderer.rb +1 -1
  163. data/lib/pubid/jis/supplement_identifier.rb +5 -5
  164. data/lib/pubid/jis/urn_parser.rb +2 -1
  165. data/lib/pubid/jis.rb +3 -2
  166. data/lib/pubid/nist/builder.rb +5 -1
  167. data/lib/pubid/nist/caster.rb +13 -3
  168. data/lib/pubid/nist/identifiers/base.rb +37 -2
  169. data/lib/pubid/nist/identifiers/circular.rb +2 -2
  170. data/lib/pubid/nist/identifiers/circular_supplement.rb +2 -2
  171. data/lib/pubid/nist/identifiers/commercial_standards_monthly.rb +2 -2
  172. data/lib/pubid/nist/identifiers/crpl_report.rb +2 -2
  173. data/lib/pubid/nist/identifiers/handbook.rb +2 -2
  174. data/lib/pubid/nist/identifiers/internal_report.rb +2 -2
  175. data/lib/pubid/nist/identifiers/miscellaneous_publication.rb +2 -2
  176. data/lib/pubid/nist/identifiers/monograph.rb +2 -2
  177. data/lib/pubid/nist/identifiers/report.rb +2 -2
  178. data/lib/pubid/nist/parser.rb +19 -775
  179. data/lib/pubid/nist/router.rb +4 -1
  180. data/lib/pubid/nist/supplement_identifier.rb +2 -2
  181. data/lib/pubid/oasis/parser.rb +2 -16
  182. data/lib/pubid/ogc/parser.rb +2 -26
  183. data/lib/pubid/oiml/identifiers/certification_system.rb +7 -0
  184. data/lib/pubid/oiml/identifiers/dual_published.rb +2 -2
  185. data/lib/pubid/oiml/parser.rb +1 -303
  186. data/lib/pubid/oiml.rb +1 -2
  187. data/lib/pubid/omg/identifier.rb +6 -1
  188. data/lib/pubid/omg/parser.rb +2 -76
  189. data/lib/pubid/parser.rb +5 -4
  190. data/lib/pubid/parsers/mr_string.rb +1 -1
  191. data/lib/pubid/plateau/parser.rb +1 -66
  192. data/lib/pubid/plateau.rb +1 -2
  193. data/lib/pubid/renderers/directives_renderer.rb +1 -1
  194. data/lib/pubid/renderers/iwa_renderer.rb +1 -1
  195. data/lib/pubid/renderers/publisher_stripper.rb +82 -0
  196. data/lib/pubid/renderers/supplement_renderer.rb +1 -1
  197. data/lib/pubid/renderers.rb +1 -0
  198. data/lib/pubid/sae/parser.rb +1 -48
  199. data/lib/pubid/tgpp/identifier.rb +1 -1
  200. data/lib/pubid/tgpp/parser.rb +2 -59
  201. data/lib/pubid/un/identifier.rb +1 -1
  202. data/lib/pubid/un/parser.rb +1 -18
  203. data/lib/pubid/version.rb +1 -1
  204. data/lib/pubid/w3c/parser.rb +2 -27
  205. data/lib/pubid/xsf/identifier.rb +10 -6
  206. data/lib/pubid/xsf/parser.rb +3 -31
  207. data/lib/pubid/xsf/renderer.rb +2 -4
  208. data/lib/pubid.rb +8 -9
  209. metadata +9 -23
  210. data/lib/pubid/ieee/aiee/parser.rb +0 -130
  211. data/lib/pubid/ieee/ire/parser.rb +0 -109
  212. data/lib/pubid/ieee/nesc/parser.rb +0 -155
  213. data/lib/pubid/iho/parser.rb +0 -68
  214. data/lib/pubid/parser/common_parse_methods.rb +0 -13
  215. data/lib/pubid/parser/common_parse_rules.rb +0 -56
  216. data/lib/pubid/parser/grammar.rb +0 -96
data/data/parg/tgpp.json CHANGED
@@ -1 +1 @@
1
- {"bindings":null,"version":"0.1.0","grammar":"PubidTgpp","shape":"parsanol-tree/v2","binding_version":1,"entries":{"identifier":{"root":"identifier","grammar":{"atoms":[{"Str":{"pattern":"3GPP "}},{"Repetition":{"atom":0,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":6}},{"Str":{"pattern":"TR"}},{"Str":{"pattern":"TS"}},{"Alternative":{"atoms":[3,4]}},{"Named":{"name":"type","atom":5}},{"Entity":{"atom":8}},{"Str":{"pattern":" "}},{"Entity":{"atom":17}},{"Entity":{"atom":11}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":10,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Repetition":{"atom":14,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[12,13,15]}},{"Named":{"name":"number","atom":16}},{"Entity":{"atom":24}},{"Entity":{"atom":22}},{"Re":{"pattern":"[\\x41-\\x5a]"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Alternative":{"atoms":[20,21]}},{"Repetition":{"atom":19,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"suffix","atom":23}},{"Repetition":{"atom":18,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":34}},{"Entity":{"atom":32}},{"Str":{"pattern":"-"}},{"Entity":{"atom":11}},{"Repetition":{"atom":29,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"part","atom":30}},{"Sequence":{"atoms":[28,31]}},{"Repetition":{"atom":27,"min":0,"max":null,"tag":"Repetition"}},{"Named":{"name":"parts","atom":33}},{"Entity":{"atom":36}},{"Str":{"pattern":":"}},{"Entity":{"atom":60}},{"Entity":{"atom":47}},{"Entity":{"atom":11}},{"Repetition":{"atom":39,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Repetition":{"atom":42,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Repetition":{"atom":45,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[40,41,43,44,46]}},{"Entity":{"atom":49}},{"Re":{"pattern":"[\\x01-\\u{10ffff}]"}},{"Lookahead":{"atom":48,"positive":false}},{"Sequence":{"atoms":[38,50]}},{"Lookahead":{"atom":51,"positive":false}},{"Entity":{"atom":57}},{"Re":{"pattern":"[\\x01-\\x2e]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Re":{"pattern":"[\\x3b-\\u{10ffff}]"}},{"Alternative":{"atoms":[54,55,56]}},{"Repetition":{"atom":53,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"release","atom":58}},{"Sequence":{"atoms":[52,59]}},{"Sequence":{"atoms":[35,37]}},{"Repetition":{"atom":61,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":64}},{"Str":{"pattern":"/"}},{"Entity":{"atom":67}},{"Entity":{"atom":47}},{"Named":{"name":"version","atom":66}},{"Sequence":{"atoms":[63,65]}},{"Repetition":{"atom":68,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[1,2,7,9,25,26,62,69]}}],"root":70},"bindings":[]}},"preprocess":{},"tables":{},"lint":{"order_warnings":["rule release_char: branches 1 and 3 are order-dependent (first set not statically known)","rule release_char: branches 2 and 3 are order-dependent (first set not statically known)"]},"default_entry":"identifier","render":{},"derive":{},"tests":[{"entry":"identifier","kind":"accept","input":"3GPP TS 21.101","expect":{}},{"entry":"identifier","kind":"accept","input":"TS 25.999","expect":{}},{"entry":"identifier","kind":"reject","input":"nonsense","expect":{}}],"docs":{},"source":"# Port of lib/pubid/tgpp/parser.rb:\n# [3GPP ]<TR|TS> <NN.NNN>[suffix][-part…][:<release>][/<version>]\n# The release excludes \"/\" and \":\" (match[\"^/:\"]), byte-wise here; the\n# mistyped-version guard (!version…!any) is ported literally.\n\ngrammar PubidTgpp version \"0.1.0\" mode \"v1\" {\n release_char = %x01-2E / %x30-39 / %x3B-10FFFF\n any_char = %x01-10FFFF\n type = (\"TR\" / \"TS\") as type\n number = (1*digit \".\" 1*digit) as number\n suffix = (1*letter) as suffix\n part = \"-\" (1*digit) as part\n parts = (*part) as parts\n version_core = 1*digit \".\" 1*digit \".\" 1*digit\n release = !(version_core !any_char) (1*release_char) as release\n version = version_core as version\n identifier = [\"3GPP \"] type space number [suffix] parts [(colon release)] [(slash version)]\n letter = %x41-5A / %x61-7A\n digit = %x30-39\n space = \" \"\n colon = \":\"\n slash = \"/\"\n entry identifier: identifier\n\n test {\n accept \"3GPP TS 21.101\"\n accept \"TS 25.999\"\n reject \"nonsense\"\n }\n}\n","source_hash":"3f3bba714488dcad3057d1a3d86f1d02b854ff34d8e2173bd0ce5b92238d034c","unicode_tables":"onigmo (Ruby 3.4.8)","compiler_version":"1.3.114","edition":1,"checksum":"sha256:b60ab478f1cb8cb5e5bb1d5a72f709d2de8d6bbb21d24c6cc1bc609dc45dc2e0"}
1
+ {"bindings":null,"version":"0.1.0","grammar":"PubidTgpp","shape":"parsanol-tree/v2","binding_version":1,"entries":{"identifier":{"root":"identifier","grammar":{"atoms":[{"Str":{"pattern":"3GPP "}},{"Repetition":{"atom":0,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":6}},{"Str":{"pattern":"TR"}},{"Str":{"pattern":"TS"}},{"Alternative":{"atoms":[3,4]}},{"Named":{"name":"type","atom":5}},{"Entity":{"atom":8}},{"Str":{"pattern":" "}},{"Entity":{"atom":17}},{"Entity":{"atom":11}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":10,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Repetition":{"atom":14,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[12,13,15]}},{"Named":{"name":"number","atom":16}},{"Entity":{"atom":24}},{"Entity":{"atom":22}},{"Re":{"pattern":"[\\x41-\\x5a]"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Alternative":{"atoms":[20,21]}},{"Repetition":{"atom":19,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"suffix","atom":23}},{"Repetition":{"atom":18,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":34}},{"Entity":{"atom":32}},{"Str":{"pattern":"-"}},{"Entity":{"atom":11}},{"Repetition":{"atom":29,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"part","atom":30}},{"Sequence":{"atoms":[28,31]}},{"Repetition":{"atom":27,"min":0,"max":null,"tag":"Repetition"}},{"Named":{"name":"parts","atom":33}},{"Entity":{"atom":36}},{"Str":{"pattern":":"}},{"Named":{"name":"colon","atom":35}},{"Entity":{"atom":64}},{"Entity":{"atom":51}},{"Entity":{"atom":11}},{"Named":{"name":"digit","atom":40}},{"Repetition":{"atom":41,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Named":{"name":"digit","atom":44}},{"Repetition":{"atom":45,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Named":{"name":"digit","atom":48}},{"Repetition":{"atom":49,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[42,43,46,47,50]}},{"Entity":{"atom":53}},{"Re":{"pattern":"[\\x01-\\u{10ffff}]"}},{"Lookahead":{"atom":52,"positive":false}},{"Sequence":{"atoms":[39,54]}},{"Lookahead":{"atom":55,"positive":false}},{"Entity":{"atom":61}},{"Re":{"pattern":"[\\x01-\\x2e]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Re":{"pattern":"[\\x3b-\\u{10ffff}]"}},{"Alternative":{"atoms":[58,59,60]}},{"Repetition":{"atom":57,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"release","atom":62}},{"Sequence":{"atoms":[56,63]}},{"Sequence":{"atoms":[37,38]}},{"Repetition":{"atom":65,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":68}},{"Str":{"pattern":"/"}},{"Named":{"name":"slash","atom":67}},{"Entity":{"atom":80}},{"Entity":{"atom":11}},{"Repetition":{"atom":71,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Repetition":{"atom":74,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":11}},{"Repetition":{"atom":77,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[72,73,75,76,78]}},{"Named":{"name":"version","atom":79}},{"Sequence":{"atoms":[69,70]}},{"Repetition":{"atom":81,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[1,2,7,9,25,26,66,82]}}],"root":83},"bindings":[{"capture":"type","path":"type","type":"string","card":null,"preprocess":null},{"capture":"number","path":"number","type":"string","card":null,"preprocess":null},{"capture":"suffix","path":"suffix","type":"string","card":null,"preprocess":null},{"capture":"part","path":"parts[].part","type":"string","card":null,"preprocess":null},{"capture":"release","path":"release","type":"string","card":null,"preprocess":null},{"capture":"version","path":"version","type":"string","card":null,"preprocess":null}]}},"preprocess":{},"tables":{},"lint":{"order_warnings":["rule release_char: branches 1 and 3 are order-dependent (first set not statically known)","rule release_char: branches 2 and 3 are order-dependent (first set not statically known)"]},"default_entry":"identifier","render":{},"derive":{},"tests":[{"entry":"identifier","kind":"accept","input":"3GPP TS 21.101","expect":{}},{"entry":"identifier","kind":"accept","input":"TS 25.999","expect":{}},{"entry":"identifier","kind":"reject","input":"nonsense","expect":{}}],"docs":{},"source":"# Port of lib/pubid/tgpp/parser.rb:\n# [3GPP ]<TR|TS> <NN.NNN>[suffix][-part…][:<release>][/<version>]\n# The release excludes \"/\" and \":\" (match[\"^/:\"]), byte-wise here; the\n# mistyped-version guard (!version…!any) is ported literally.\n\ngrammar PubidTgpp version \"0.1.0\" edition 2 {\n release_char = %x01-2E / %x30-39 / %x3B-10FFFF\n any_char = %x01-10FFFF\n type = (\"TR\" / \"TS\") as type\n number = (1*digit \".\" 1*digit) as number\n suffix = (1*letter) as suffix\n part = \"-\" (1*digit) as part\n parts = (*part) as parts\n version_core = 1*digit \".\" 1*digit \".\" 1*digit\n release = !(version_core !any_char) (1*release_char) as release\n version = (1*digit \".\" 1*digit \".\" 1*digit) as version\n identifier = [\"3GPP \"] type space number [suffix] parts [(colon release)] [(slash version)]\n letter = %x41-5A / %x61-7A\n digit = %x30-39\n space = \" \"\n colon = \":\"\n slash = \"/\"\n entry identifier: identifier\n\n bindings identifier {\n type -> type (string)\n number -> number (string)\n suffix -> suffix (string)\n part -> parts[].part (string)\n release -> release (string)\n version -> version (string)\n }\n\n\n test {\n accept \"3GPP TS 21.101\"\n accept \"TS 25.999\"\n reject \"nonsense\"\n }\n}\n","source_hash":"8208f08be56685a980b7c3adeb2a58d64b962c148028fe676b3e00eede72f13a","unicode_tables":"onigmo (Ruby 3.4.8)","compiler_version":"1.3.114","edition":2,"checksum":"sha256:9bdb1d70089ba09ad10fcf091475fb938c7570282c26a20652df304e7f9693af"}
data/data/parg/un.json CHANGED
@@ -1 +1 @@
1
- {"bindings":null,"version":"0.1.0","grammar":"PubidUn","shape":"parsanol-tree/v2","binding_version":1,"entries":{"identifier":{"root":"identifier","grammar":{"atoms":[{"Str":{"pattern":"UN "}},{"Repetition":{"atom":0,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":9}},{"Entity":{"atom":7}},{"Re":{"pattern":"[\\x41-\\x5a]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Re":{"pattern":"[.]"}},{"Alternative":{"atoms":[4,5,6]}},{"Repetition":{"atom":3,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"token","atom":8}},{"Entity":{"atom":11}},{"Str":{"pattern":"/"}},{"Entity":{"atom":9}},{"Sequence":{"atoms":[10,12]}},{"Repetition":{"atom":13,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[1,2,14]}}],"root":15},"bindings":[]}},"preprocess":{},"tables":{},"lint":{"order_warnings":[]},"default_entry":"identifier","render":{},"derive":{},"tests":[{"entry":"identifier","kind":"accept","input":"UN/CEFACT/TBG14","expect":{}},{"entry":"identifier","kind":"accept","input":"CEFACT/TBG14","expect":{}},{"entry":"identifier","kind":"reject","input":"nonsense","expect":{}}],"docs":{},"source":"# Port of lib/pubid/un/parser.rb. `token` matches [A-Z0-9.] runs.\n\ngrammar PubidUn version \"0.1.0\" mode \"v1\" {\n token_char = %x41-5A / %x30-39 / %x2E\n token = (1*token_char) as token\n identifier = [\"UN \"] token 1*(slash token)\n slash = \"/\"\n entry identifier: identifier\n\n test {\n accept \"UN/CEFACT/TBG14\"\n accept \"CEFACT/TBG14\"\n reject \"nonsense\"\n }\n}\n","source_hash":"8af25923f5616b2ebe0443dc994d305d8f4390efe46bb685d8aebf89c68c66e2","unicode_tables":"onigmo (Ruby 3.4.8)","compiler_version":"1.3.114","edition":1,"checksum":"sha256:634305272bf558b8cb9193a1af8e75b9cc799d75386dd4d4a53e42d4d66cce1b"}
1
+ {"bindings":null,"version":"0.1.0","grammar":"PubidUn","shape":"parsanol-tree/v2","binding_version":1,"entries":{"identifier":{"root":"identifier","grammar":{"atoms":[{"Str":{"pattern":"UN "}},{"Repetition":{"atom":0,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":8}},{"Re":{"pattern":"[\\x41-\\x5a]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Re":{"pattern":"[.]"}},{"Alternative":{"atoms":[3,4,5]}},{"Repetition":{"atom":6,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"token","atom":7}},{"Str":{"pattern":"/"}},{"Entity":{"atom":8}},{"Sequence":{"atoms":[9,10]}},{"Repetition":{"atom":11,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[1,2,12]}}],"root":13},"bindings":[{"capture":"token","path":"token[].token","type":"string","card":null,"preprocess":null}]}},"preprocess":{},"tables":{},"lint":{"order_warnings":[]},"default_entry":"identifier","render":{},"derive":{},"tests":[{"entry":"identifier","kind":"accept","input":"UN/CEFACT/TBG14","expect":{}},{"entry":"identifier","kind":"accept","input":"CEFACT/TBG14","expect":{}},{"entry":"identifier","kind":"reject","input":"nonsense","expect":{}}],"docs":{},"source":"# Port of lib/pubid/un/parser.rb. `token` matches [A-Z0-9.] runs.\n#\n# Edition-2 typed bindings: `token` repeats (one per slash-separated\n# segment) and the builder walks every occurrence as a path element, so\n# the repeats collect under token[].token — a scalar binding would keep\n# only the first segment. The separator stays a raw \"/\" literal: a\n# parenthesized slash ref materializes a {slash:} node whose presence\n# the token-walking builder would read as an empty token.\n\ngrammar PubidUn version \"0.1.0\" edition 2 {\n token_char = %x41-5A / %x30-39 / %x2E\n token = ( 1*(%x41-5A / %x30-39 / %x2E) ) as token\n identifier = [\"UN \"] token 1*( \"/\" token )\n slash = \"/\"\n\n entry identifier: identifier\n\n bindings identifier {\n token -> token[].token (string)\n }\n\n test {\n accept \"UN/CEFACT/TBG14\"\n accept \"CEFACT/TBG14\"\n reject \"nonsense\"\n }\n}\n","source_hash":"ba53a065d999fb151e5b557dafbf245bcb4d8a6948017b198444242eee47fcfb","unicode_tables":"onigmo (Ruby 3.4.8)","compiler_version":"1.3.114","edition":2,"checksum":"sha256:a71b6cfba806bd0802198e7cacb532cbb06136a375bf937f37823f7531f0e327"}
@@ -28,7 +28,7 @@ module Pubid
28
28
  end
29
29
 
30
30
  # R1 parser swap: the baked PG artifact is the parser of record.
31
- parsed = Pubid::Parg::Backend.parse(:adobe, identifier.strip)
31
+ parsed = Pubid::Parg::Model.bound(:adobe, identifier.strip)
32
32
  Builder.build(parsed)
33
33
  end
34
34
 
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parslet"
4
-
5
3
  module Pubid
6
4
  module Adobe
7
- # Parslet grammar for Adobe identifiers.
5
+ # Grammar for Adobe identifiers.
8
6
  #
9
7
  # Canonical citation forms (what the renderer produces):
10
8
  #
@@ -21,116 +19,7 @@ module Pubid
21
19
  # ATN5014 (short alias)
22
20
  # 5014 (bare number; data-repo context)
23
21
  # adobe-glyph-list (bare slug)
24
- class Parser < ::Pubid::Parser::Grammar
25
- include ::Pubid::Parser::CommonParseRules
26
-
27
- root :identifier
28
-
29
- rule(:space) { str(" ") }
30
- rule(:space?) { space.maybe }
31
- rule(:hash) { str("#") }
32
- rule(:dot) { str(".") }
33
- rule(:dash) { str("-") }
34
-
35
- # Canonical short prefix: "Adobe TN" with optional trailing space.
36
- # Matches both "Adobe TN 5014" and "Adobe TN5014".
37
- rule(:tech_note_tn_prefix) do
38
- str("Adobe") >> space >> str("TN") >> space?.maybe
39
- end
40
-
41
- # Legacy long prefix: "Adobe Technical Note" with optional "#".
42
- rule(:tech_note_long_prefix) do
43
- str("Adobe") >> space >> str("Technical") >> space >> str("Note") >>
44
- (space? >> hash.maybe >> space?).maybe
45
- end
46
-
47
- # Legacy short alias: "ATN" with optional trailing space.
48
- rule(:tech_note_atn_prefix) do
49
- str("ATN") >> space?.maybe
50
- end
51
-
52
- rule(:tech_note_prefix) do
53
- tech_note_tn_prefix | tech_note_long_prefix | tech_note_atn_prefix
54
- end
55
-
56
- rule(:digits) do
57
- match("[0-9]").repeat(1)
58
- end
59
-
60
- # 4-digit tech note number, optionally followed by ".<Slug>" from
61
- # the filename form. The slug is captured but not required.
62
- rule(:slug_chars) do
63
- match("[A-Za-z0-9_]").repeat(1)
64
- end
65
-
66
- rule(:tech_note) do
67
- (tech_note_prefix >>
68
- digits.as(:number) >>
69
- (dot >> slug_chars.as(:slug)).maybe).as(:tech_note)
70
- end
71
-
72
- # Bare number form (e.g. when the data repo passes just "5014"
73
- # extracted from a filename). Not advertised in user docs; used
74
- # internally by AdobeFetcher::Docid.
75
- rule(:bare_number) do
76
- digits.as(:number).as(:tech_note_bare)
77
- end
78
-
79
- # "Adobe Publication " prefix. Matched literally then discarded —
80
- # the publication slug/version is parsed by the inner rule.
81
- rule(:publication_prefix) do
82
- str("Adobe") >> space >> str("Publication") >> space
83
- end
84
-
85
- # Publication slug. Lowercase ASCII letters and digits joined by `-`.
86
- # Each segment starts with a letter (so a trailing `-<digits>` is
87
- # unambiguously a version suffix, not part of the slug).
88
- rule(:slug_segment) do
89
- match("[a-z]") >> match("[a-z0-9]").repeat
90
- end
91
-
92
- rule(:slug_inner) do
93
- slug_segment >> (dash >> slug_segment).repeat
94
- end
95
-
96
- rule(:publication_with_version) do
97
- (slug_inner.as(:slug) >> dash >> digits.as(:version)).as(:publication_version)
98
- end
99
-
100
- rule(:publication_slug_or_version) do
101
- # Try with-version first so `adobe-japan1-7` doesn't get captured
102
- # as slug `adobe-japan1-7` with no version. The flat `:slug` form
103
- # is the fallback for unversioned slugs.
104
- publication_with_version | slug_inner.as(:slug)
105
- end
106
-
107
- rule(:publication) do
108
- # Optional "Adobe Publication " prefix. The prefix is consumed
109
- # but not captured — the inner rule produces :slug or
110
- # :publication_version as before.
111
- publication_prefix.maybe >> publication_slug_or_version
112
- end
113
-
114
- rule(:identifier) do
115
- tech_note | bare_number | publication
116
- end
117
-
118
- # Parse a string and return the raw parslet tree.
119
- # @param string [String]
120
- # @return [Hash]
121
- def self.parse(string)
122
- unless string.is_a?(String)
123
- raise ::Pubid::Errors::InvalidInputError,
124
- ::Pubid::INPUT_NOT_A_STRING_MESSAGE
125
- end
126
-
127
- if string.length > ::Pubid::MAX_INPUT_LENGTH
128
- raise ::Pubid::Errors::InvalidInputError,
129
- ::Pubid::INPUT_TOO_LONG_MESSAGE
130
- end
131
-
132
- new.parse(string.strip)
133
- end
22
+ class Parser
134
23
  end
135
24
  end
136
25
  end
@@ -17,7 +17,7 @@ module Pubid
17
17
  raise Pubid::Errors::InvalidInputError, Pubid::INPUT_TOO_LONG_MESSAGE
18
18
  end
19
19
 
20
- parsed = Pubid::Parg::Backend.parse(:amca, identifier)
20
+ parsed = Pubid::Parg::Model.bound(:amca, identifier)
21
21
  Builder.build(parsed)
22
22
  end
23
23
 
@@ -4,151 +4,7 @@ module Pubid
4
4
  module Amca
5
5
  # Parser class for ACMA identifiers
6
6
  # Single Responsibility: Parsing ACMA identifier syntax
7
- class Parser < ::Pubid::Parser::Grammar
8
- # Basic building blocks
9
- rule(:space) { str(" ") }
10
- rule(:space?) { space.maybe }
11
- rule(:dash) { str("-") }
12
- rule(:slash) { str("/") }
13
- rule(:lparen) { str("(") }
14
- rule(:rparen) { str(")") }
15
- rule(:dot) { str(".") }
16
-
17
- rule(:digit) { match("[0-9]") }
18
- rule(:digits) { digit.repeat(1) }
19
- rule(:letter) { match("[A-Za-z]") }
20
-
21
- # Year pattern (2 digits starting with 0-1, or 4 digits starting with 19 or 20)
22
- rule(:year_digits) do
23
- ((str("19") | str("20")) >> digit.repeat(2, 2)) |
24
- digit.repeat(2, 2)
25
- end
26
-
27
- # Copublisher (ANSI/AMCA or AMCA)
28
- rule(:copublisher) do
29
- (str("ANSI") >> slash >> str("AMCA")) |
30
- str("AMCA")
31
- end
32
-
33
- # Additional copublisher after year (e.g., /ASHRAE 51-16)
34
- rule(:additional_copublisher) do
35
- slash >> letter.repeat(2,
36
- 10) >> space >> digits >> (dash >> digits).maybe
37
- end
38
-
39
- # Code pattern (e.g., 210, 500-D, 99, 204)
40
- rule(:code) do
41
- (
42
- digits >> # Main number
43
- (dash >> letter).maybe >> # Optional letter suffix (500-D)
44
- (dot >> digits).maybe # Optional decimal (not in fixtures but possible)
45
- ).as(:code)
46
- end
47
-
48
- # Type (Standard or Publication)
49
- rule(:type) do
50
- str("Standard") | str("Publication")
51
- end
52
-
53
- # Reaffirmation year (R2008, R2010, etc.)
54
- rule(:reaffirmation) do
55
- lparen >> str("R") >> digits.as(:reaffirmed) >> rparen
56
- end
57
-
58
- # Suffix
59
- rule(:suffix) do
60
- str("R") | str("P")
61
- end
62
-
63
- # Publication revision (Rev. 01-23)
64
- rule(:revision) do
65
- lparen >> str("Rev") >> dot.maybe >> space >>
66
- (digits >> dash >> digits).as(:revision) >> rparen
67
- end
68
-
69
- # Interpretation code (JW, KB, RG, AW, AH, or just a number)
70
- rule(:interpretation_code) do
71
- letter.repeat(2).as(:interpretation_code) | # Two-letter code
72
- digits.as(:interpretation_code) # Number
73
- end
74
-
75
- # Interpretation keyword
76
- rule(:interp_keyword) do
77
- space >> str("Interp")
78
- end
79
-
80
- # Main identifier rule
81
- rule(:identifier) do
82
- # Interpretation patterns (must come first as they're more specific)
83
- interpretation_identifier |
84
- # Publication patterns
85
- publication_identifier |
86
- # Standard patterns (must come last as they're the most general)
87
- standard_identifier
88
- end
89
-
90
- # Interpretation pattern (e.g., AMCA 99 JW Interp, AMCA 204 – 1)
91
- rule(:interpretation_identifier) do
92
- (
93
- copublisher.as(:copublisher).maybe >> space >>
94
- code >>
95
- space >>
96
- # Either a letter code (JW, KB, etc.) or a dash-number pattern
97
- (
98
- (interpretation_code >> interp_keyword) |
99
- ((str("–") | str("-")) >> digits.as(:interpretation_year) >> interp_keyword.maybe)
100
- )
101
- ).as(:interpretation) |
102
- # Simple interpretation: AMCA 511 Interp
103
- (
104
- copublisher.as(:copublisher).maybe >> space >>
105
- code >>
106
- interp_keyword
107
- ).as(:interpretation)
108
- end
109
-
110
- # Publication pattern (e.g., AMCA Publication 211-22 (Rev. 01-23))
111
- rule(:publication_identifier) do
112
- (
113
- copublisher.as(:copublisher).maybe >> space >>
114
- str("Publication").as(:publication_keyword) >> space >>
115
- code >>
116
- (dash >> year_digits.as(:year)).maybe >>
117
- (space >> revision).maybe >>
118
- (space >> reaffirmation).maybe
119
- ).as(:publication)
120
- end
121
-
122
- # Standard pattern (e.g., ANSI/AMCA 210-16, ANSI/AMCA Standard 99-25)
123
- rule(:standard_identifier) do
124
- (
125
- copublisher.as(:copublisher).maybe >> space >>
126
- type.as(:type).maybe >> space.maybe >>
127
- code >>
128
- (dash >> year_digits.as(:year)).maybe >>
129
- (space >> additional_copublisher).maybe >>
130
- suffix.maybe >>
131
- (space >> reaffirmation).maybe
132
- ).as(:standard)
133
- end
134
-
135
- root(:identifier)
136
-
137
- def self.parse(string)
138
- # Strip leading/trailing whitespace
139
- cleaned = string.strip
140
-
141
- # Normalize multiple spaces to single space
142
- cleaned = cleaned.gsub(/\s+/, " ")
143
-
144
- # Normalize en dash to regular dash
145
- cleaned = cleaned.gsub("–", "-")
146
-
147
- # Remove trailing periods and commas
148
- cleaned = cleaned.gsub(/[,.]$/, "")
149
-
150
- new.parse(cleaned)
151
- end
7
+ class Parser
152
8
  end
153
9
  end
154
10
  end
@@ -23,7 +23,7 @@ module Pubid
23
23
  raise Pubid::Errors::InvalidInputError, Pubid::INPUT_TOO_LONG_MESSAGE
24
24
  end
25
25
 
26
- parsed = Pubid::Parg::Backend.parse(:ansi, string)
26
+ parsed = Pubid::Parg::Model.bound(:ansi, string)
27
27
  Pubid::Ansi::Builder.new.build(parsed)
28
28
  end
29
29
  end
@@ -4,88 +4,7 @@ module Pubid
4
4
  module Ansi
5
5
  # Parser for ANSI (American National Standards Institute) identifiers
6
6
  # Examples: ANSI X3.4-1986, ANSI C63.4-2014, ANSI/ISO 9899:1990
7
- class Parser < ::Pubid::Parser::Grammar
8
- include ::Pubid::Parser::CommonParseRules
9
- include ::Pubid::Parser::CommonParseMethods
10
-
11
- root :identifier
12
-
13
- # ANSI as sole publisher
14
- rule(:publisher) do
15
- str("ANSI").as(:publisher)
16
- end
17
-
18
- # Copublishers: ISO, IEEE, IEC, etc.
19
- ORGANIZATIONS = %w[ISO IEC IEEE SAE ASME ASTM].freeze
20
- rule(:copublishers) do
21
- (str("/") >> space? >> array_to_str(ORGANIZATIONS).as(:copublisher)).repeat(1).as(:copublishers)
22
- end
23
-
24
- # Optional "Std" keyword
25
- rule(:std_keyword) do
26
- (str("Std") >> space).maybe
27
- end
28
-
29
- # Number with optional parts and subparts
30
- # Examples:
31
- # - X3.4-1986 (letter prefix, one dot, year)
32
- # - C63.4-2014 (letter prefix, one dot, year)
33
- # - C37.06.1-2000 (letter prefix, two dots, year)
34
- # - C57.12.10-1988 (letter prefix, three dots, year)
35
- # - N323A-1997 (letter prefix, number, letter suffix, year)
36
- # - N42.49A-2011 (letter prefix, dot, number, letter suffix, year)
37
- # - 9899 (just digits)
38
- # - 802.3-2012 (digits with dot and year)
39
- # - 802.1b-1995 (digits, dot, digits, letter, year)
40
- rule(:number_with_part) do
41
- (
42
- # Letter prefix with multiple dots and optional letter suffix
43
- # C37.06.1, C57.12.10, C63.25.1, N323A, N42.49A
44
- (match["A-Z"].repeat(1) >>
45
- digits >>
46
- (str(".") >> digits).repeat(0, 3) >> # Allow up to 3 additional dot-separated parts
47
- match["A-Z"].maybe >> # Optional letter suffix (A, B, etc.)
48
- (str("-") >> digits).maybe) | # Optional dash-year part
49
- # Just digits with optional dots and letter suffix: 9899, 802.3-2012, 802.1b-1995
50
- (digits >>
51
- (str(".") >> digits >> match["a-z"].maybe).repeat(0, 2) >> # Dots with optional lowercase letter
52
- (str("-") >> digits).maybe)
53
- ).as(:number_with_part)
54
- end
55
-
56
- # Date - year only
57
- rule(:date) do
58
- str(":") >> year_digits.as(:date)
59
- end
60
-
61
- # Language codes
62
- rule(:language) do
63
- str("(") >>
64
- (match["a-z"].repeat(2) >> str(",").maybe).repeat.as(:languages) >>
65
- str(")")
66
- end
67
-
68
- # Main identifier for ANSI with copublishers
69
- # ANSI/ISO 9899:1990, ANSI/IEEE Std 1-1986
70
- rule(:identifier_with_copublishers) do
71
- publisher >> copublishers >>
72
- space >> std_keyword >>
73
- number_with_part >>
74
- date.maybe >> language.maybe
75
- end
76
-
77
- # Main identifier for ANSI alone
78
- # ANSI X3.4-1986, ANSI Std C63.4-1991
79
- rule(:identifier_sole) do
80
- publisher >> space >>
81
- std_keyword >>
82
- number_with_part >>
83
- date.maybe >> language.maybe
84
- end
85
-
86
- rule(:identifier) do
87
- identifier_with_copublishers | identifier_sole
88
- end
7
+ class Parser
89
8
  end
90
9
  end
91
10
  end
@@ -14,8 +14,35 @@ module Pubid
14
14
  "PUBL" => Identifiers::Publication,
15
15
  }.freeze
16
16
 
17
+ # The bound grammar flattens the combined form's first/second
18
+ # wrappers (the bindings cannot nest): the second identifier's
19
+ # fields capture under second_* names. The tree backend folded
20
+ # first and second into one hash in parse order, so the second
21
+ # side's assignments came last and its number/part/year overwrite
22
+ # the first's — and select_class saw no top-level :type, so a
23
+ # combined form always built the typeless class. Reproduce both.
24
+ SECOND_KEYS = %i[second_number second_part second_year second_type].freeze
25
+ SECOND_OVERWRITES = { number: :second_number,
26
+ part: :second_part,
27
+ year: :second_year }.freeze
28
+
29
+ def build(data)
30
+ super(unflatten_combined(data))
31
+ end
32
+
17
33
  private
18
34
 
35
+ def unflatten_combined(data)
36
+ return data unless SECOND_KEYS.any? { |k| data.key?(k) }
37
+
38
+ data = data.dup
39
+ data.delete(:type)
40
+ SECOND_OVERWRITES.each do |target, source|
41
+ data[target] = data.delete(source) if data.key?(source)
42
+ end
43
+ data
44
+ end
45
+
19
46
  def default_identifier_class
20
47
  Identifiers::TypelessStandard
21
48
  end
@@ -29,7 +56,11 @@ module Pubid
29
56
  # `:type` is consumed only by select_class for dispatch; it is not an
30
57
  # identifier attribute (the concrete class is pinned by `_type`). Drop it
31
58
  # so the raw Parslet::Slice never lands in the inherited :type attribute.
32
- when :type then nil
59
+ # `:second_type` is the combined form's second type token, with
60
+ # the same dispatch-only role (unflatten_combined has already
61
+ # removed the first side's :type so the typeless class wins,
62
+ # exactly as the tree backend's wrapper nesting did).
63
+ when :type, :second_type then nil
33
64
  when :reaffirmation
34
65
  value.is_a?(Hash) ? (value[:year] || value).to_s : value.to_s
35
66
  # Every remaining key is a bare scalar. `:chapter` is a PARSE-TREE key
@@ -34,7 +34,7 @@ module Pubid
34
34
  # this was the one public parse in the gem that could return nil, which
35
35
  # a caller reading `id.to_s` sees as a NoMethodError far from the cause.
36
36
  # Both API fixture loaders already drop `#` lines themselves.
37
- tree = Pubid::Parg::Backend.parse(:api, Api::Parser.normalize_input(input))
37
+ tree = Pubid::Parg::Model.bound(:api, Api::Parser.normalize_input(input))
38
38
  Builder.new.build(tree)
39
39
  end
40
40
  end
@@ -1,144 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parslet"
4
-
5
3
  module Pubid
6
4
  module Api
7
- class Parser < ::Pubid::Parser::Grammar
8
- # Basic building blocks
9
- rule(:space) { str(" ") }
10
- rule(:dash) { str("-") }
11
- rule(:slash) { str("/") }
12
- rule(:colon) { str(":") }
13
- rule(:dot) { str(".") }
14
- rule(:digit) { match("[0-9]") }
15
- rule(:digits) { digit.repeat(1) }
16
- rule(:letter) { match("[A-Z]") }
17
- rule(:letters) { letter.repeat(1) }
18
-
19
- # Publisher
20
- rule(:publisher) { str("API") >> space }
21
-
22
- # Document types (longest first for proper matching)
23
- rule(:doc_type) do
24
- (
25
- str("MPMS") |
26
- str("BULL") |
27
- str("SPEC") |
28
- str("STD") |
29
- str("RP") |
30
- str("TR") |
31
- str("COS") |
32
- str("PUBL")
33
- ).as(:type)
34
- end
35
-
36
- # Chapter notation for MPMS (e.g., "CH 10")
37
- rule(:chapter_notation) do
38
- space >> str("CH") >> space >> digits.as(:chapter)
39
- end
40
-
41
- # Number with optional part (e.g., "579-2", "1104", "6D", "D16", "17TR7")
42
- # Allow any mix of digits and letters
43
- rule(:number_with_part) do
44
- match("[0-9A-Z]").repeat(1).as(:number) >>
45
- (dash >> match("[0-9A-Z]").repeat(1).as(:part)).maybe
46
- end
47
-
48
- # Digits with optional letter suffix (for MPMS sections: 6.4A, 3.1A)
49
- rule(:digits_with_letter) do
50
- digits >> letter.maybe
51
- end
52
-
53
- # Year (4-digit)
54
- rule(:year) { digit.repeat(4, 4).as(:year) }
55
-
56
- # Date with dash (e.g., "-2023")
57
- rule(:date_dash) { dash >> year }
58
-
59
- # Date with colon (e.g., ":2023")
60
- rule(:date_colon) { colon >> year }
61
-
62
- # Reaffirmation notation (e.g., "(R2020)")
63
- rule(:reaffirmation) do
64
- space >> str("(R") >> year >> str(")")
65
- end
66
-
67
- # Part notation (e.g., ", Part 2")
68
- rule(:part_notation) do
69
- str(", Part ") >> digits.as(:part_number)
70
- end
71
-
72
- # Edition notation (e.g., ", 4th edition")
73
- rule(:edition_notation) do
74
- str(", ") >>
75
- digits.as(:edition_number) >>
76
- (str("st") | str("nd") | str("rd") | str("th")) >>
77
- str(" edition")
78
- end
79
-
80
- # MPMS identifier (special format with CH)
81
- rule(:mpms_identifier) do
82
- publisher >>
83
- str("MPMS").as(:type) >>
84
- chapter_notation >>
85
- (dot >> digits_with_letter.as(:section)).maybe >>
86
- (dot >> digits_with_letter.as(:subsection)).maybe >>
87
- (date_dash | date_colon).maybe
88
- end
89
-
90
- # Standard identifier with type
91
- rule(:typed_identifier) do
92
- publisher >>
93
- doc_type >> space >>
94
- number_with_part >>
95
- part_notation.maybe >>
96
- (date_dash | date_colon).maybe >>
97
- reaffirmation.maybe
98
- end
99
-
100
- # Typeless identifier (just API + number)
101
- rule(:typeless_identifier) do
102
- publisher >>
103
- number_with_part >>
104
- part_notation.maybe >>
105
- (date_dash | date_colon).maybe >>
106
- reaffirmation.maybe
107
- end
108
-
109
- # Second identifier in combined (no API prefix, just type + number)
110
- rule(:second_identifier) do
111
- doc_type >> space >>
112
- number_with_part >>
113
- part_notation.maybe >>
114
- (date_dash | date_colon).maybe
115
- end
116
-
117
- # Combined identifier (two identifiers separated by slash)
118
- rule(:combined_identifier) do
119
- (mpms_identifier | typed_identifier | typeless_identifier).as(:first) >>
120
- slash >>
121
- second_identifier.as(:second) >>
122
- edition_notation.maybe
123
- end
124
-
125
- # Main identifier (try combined first, then MPMS, then typed, then typeless)
126
- rule(:identifier) do
127
- combined_identifier | mpms_identifier | typed_identifier | typeless_identifier
128
- end
129
-
130
- root(:identifier)
131
-
5
+ class Parser
132
6
  # Pre-parse ingestion normalization (R2): every parse path feeds
133
7
  # the grammar the same normalized string.
134
8
  def self.normalize_input(input)
135
9
  # Normalize MPMP typo to MPMS
136
10
  input.gsub("API MPMP", "API MPMS")
137
11
  end
138
-
139
- def parse(input)
140
- super(self.class.normalize_input(input))
141
- end
142
12
  end
143
13
  end
144
14
  end
@@ -19,7 +19,7 @@ module Pubid
19
19
  raise Pubid::Errors::InvalidInputError, Pubid::INPUT_TOO_LONG_MESSAGE
20
20
  end
21
21
 
22
- parsed = Pubid::Parg::Backend.parse(:ashrae, Parser.normalize_input(identifier))
22
+ parsed = Pubid::Parg::Model.bound(:ashrae, Parser.normalize_input(identifier))
23
23
  Builder.build(parsed)
24
24
  end
25
25