pubid 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/data/parg/adobe.json +1 -1
  3. data/data/parg/amca.json +1 -1
  4. data/data/parg/ansi.json +1 -1
  5. data/data/parg/api.json +1 -1
  6. data/data/parg/ashrae.json +1 -1
  7. data/data/parg/asme.json +1 -1
  8. data/data/parg/astm.json +1 -1
  9. data/data/parg/bipm.json +1 -1
  10. data/data/parg/bsi.json +1 -1
  11. data/data/parg/ccsds.json +1 -1
  12. data/data/parg/cen_cenelec.json +1 -1
  13. data/data/parg/cie.json +1 -1
  14. data/data/parg/csa.json +1 -1
  15. data/data/parg/ecma.json +1 -1
  16. data/data/parg/etsi.json +1 -1
  17. data/data/parg/evs.json +1 -1
  18. data/data/parg/gost.json +1 -1
  19. data/data/parg/iana.json +1 -1
  20. data/data/parg/idf.json +1 -1
  21. data/data/parg/iec.json +1 -1
  22. data/data/parg/iho.json +1 -0
  23. data/data/parg/isbn.json +1 -1
  24. data/data/parg/itu.json +1 -1
  25. data/data/parg/jcgm.json +1 -1
  26. data/data/parg/jis.json +1 -1
  27. data/data/parg/nist.json +1 -1
  28. data/data/parg/oiml.json +1 -1
  29. data/data/parg/omg.json +1 -1
  30. data/data/parg/plateau.json +1 -1
  31. data/data/parg/tgpp.json +1 -1
  32. data/data/parg/un.json +1 -1
  33. data/lib/pubid/adobe/identifier.rb +1 -1
  34. data/lib/pubid/adobe/parser.rb +2 -113
  35. data/lib/pubid/amca/identifiers/base.rb +1 -1
  36. data/lib/pubid/amca/parser.rb +1 -145
  37. data/lib/pubid/ansi/identifier.rb +1 -1
  38. data/lib/pubid/ansi/parser.rb +1 -82
  39. data/lib/pubid/api/builder.rb +32 -1
  40. data/lib/pubid/api/identifier.rb +1 -1
  41. data/lib/pubid/api/parser.rb +1 -131
  42. data/lib/pubid/ashrae/identifiers/base.rb +1 -1
  43. data/lib/pubid/ashrae/parser.rb +3 -710
  44. data/lib/pubid/asme/builder.rb +6 -4
  45. data/lib/pubid/asme/identifier.rb +1 -2
  46. data/lib/pubid/asme/parser.rb +1 -328
  47. data/lib/pubid/astm/builder.rb +12 -3
  48. data/lib/pubid/astm/identifier.rb +1 -2
  49. data/lib/pubid/astm/parser.rb +1 -227
  50. data/lib/pubid/bipm/identifier.rb +8 -1
  51. data/lib/pubid/bipm/parser.rb +2 -224
  52. data/lib/pubid/bsi/builder.rb +2 -4
  53. data/lib/pubid/bsi/parser.rb +1 -666
  54. data/lib/pubid/bsi/single_identifier.rb +38 -1
  55. data/lib/pubid/calconnect/parser.rb +2 -40
  56. data/lib/pubid/ccsds/identifier.rb +1 -1
  57. data/lib/pubid/ccsds/parser.rb +1 -66
  58. data/lib/pubid/cen_cenelec/identifier.rb +16 -1
  59. data/lib/pubid/cen_cenelec/parser.rb +3 -136
  60. data/lib/pubid/cie/identifier.rb +1 -1
  61. data/lib/pubid/cie/parser.rb +3 -378
  62. data/lib/pubid/conformance.rb +1 -1
  63. data/lib/pubid/csa/builder.rb +41 -18
  64. data/lib/pubid/csa/identifier.rb +12 -4
  65. data/lib/pubid/csa/identifiers/amendment.rb +28 -0
  66. data/lib/pubid/csa/identifiers.rb +1 -0
  67. data/lib/pubid/csa/parser.rb +16 -397
  68. data/lib/pubid/doi/parser.rb +2 -37
  69. data/lib/pubid/easc/builder.rb +1 -1
  70. data/lib/pubid/easc/parser.rb +2 -70
  71. data/lib/pubid/ecma/CLAUDE.md +8 -1
  72. data/lib/pubid/ecma/identifier.rb +13 -8
  73. data/lib/pubid/ecma/parser.rb +2 -54
  74. data/lib/pubid/ecma/renderer.rb +3 -7
  75. data/lib/pubid/errors.rb +18 -13
  76. data/lib/pubid/etsi/builder.rb +8 -5
  77. data/lib/pubid/etsi/identifiers/base.rb +1 -1
  78. data/lib/pubid/etsi/parser.rb +1 -132
  79. data/lib/pubid/evs/identifier.rb +7 -0
  80. data/lib/pubid/evs/parser.rb +1 -8
  81. data/lib/pubid/evs.rb +1 -1
  82. data/lib/pubid/gb/identifier.rb +6 -0
  83. data/lib/pubid/gb/parser.rb +2 -51
  84. data/lib/pubid/gost/identifier.rb +9 -1
  85. data/lib/pubid/gost/parser.rb +4 -81
  86. data/lib/pubid/iala/parser.rb +2 -121
  87. data/lib/pubid/iana/identifier.rb +1 -1
  88. data/lib/pubid/iana/parser.rb +2 -24
  89. data/lib/pubid/identifier.rb +78 -1
  90. data/lib/pubid/idf/builder.rb +42 -0
  91. data/lib/pubid/idf/identifier.rb +1 -1
  92. data/lib/pubid/idf/parser.rb +1 -137
  93. data/lib/pubid/idf.rb +1 -2
  94. data/lib/pubid/iec/builder.rb +158 -50
  95. data/lib/pubid/iec/identifier.rb +1 -1
  96. data/lib/pubid/iec/parser.rb +3 -430
  97. data/lib/pubid/ieee/aiee/identifier.rb +2 -1
  98. data/lib/pubid/ieee/aiee.rb +0 -1
  99. data/lib/pubid/ieee/builder.rb +2 -2
  100. data/lib/pubid/ieee/identifiers/base.rb +1 -1
  101. data/lib/pubid/ieee/ire/identifier.rb +2 -1
  102. data/lib/pubid/ieee/ire.rb +0 -1
  103. data/lib/pubid/ieee/nesc.rb +0 -1
  104. data/lib/pubid/ieee/parser.rb +1 -1257
  105. data/lib/pubid/ietf/identifiers/base.rb +17 -1
  106. data/lib/pubid/ietf/parser.rb +2 -47
  107. data/lib/pubid/ietf/renderer.rb +17 -2
  108. data/lib/pubid/iho/CLAUDE.md +89 -0
  109. data/lib/pubid/iho/builder.rb +4 -1
  110. data/lib/pubid/iho/identifiers/base.rb +28 -2
  111. data/lib/pubid/iho/renderer.rb +8 -0
  112. data/lib/pubid/iho/urn_generator.rb +11 -1
  113. data/lib/pubid/iho/urn_parser.rb +21 -11
  114. data/lib/pubid/iho.rb +0 -1
  115. data/lib/pubid/isbn/identifier.rb +1 -1
  116. data/lib/pubid/isbn/parser.rb +2 -31
  117. data/lib/pubid/iso/builder.rb +1 -1
  118. data/lib/pubid/iso/identifiers/directives.rb +6 -3
  119. data/lib/pubid/iso/identifiers/guide.rb +6 -3
  120. data/lib/pubid/iso/identifiers/international_workshop_agreement.rb +6 -3
  121. data/lib/pubid/iso/normalizer.rb +1 -1
  122. data/lib/pubid/iso/parser.rb +1 -539
  123. data/lib/pubid/iso/supplement_identifier.rb +6 -3
  124. data/lib/pubid/iso/utilities.rb +4 -5
  125. data/lib/pubid/iso.rb +1 -19
  126. data/lib/pubid/itu/builder.rb +36 -20
  127. data/lib/pubid/itu/identifiers/base.rb +15 -2
  128. data/lib/pubid/itu/parser.rb +1 -775
  129. data/lib/pubid/jcgm/builder.rb +35 -0
  130. data/lib/pubid/jcgm/parser.rb +1 -151
  131. data/lib/pubid/jcgm.rb +1 -2
  132. data/lib/pubid/jis/builder.rb +18 -29
  133. data/lib/pubid/jis/identifier.rb +1 -1
  134. data/lib/pubid/jis/parser.rb +1 -128
  135. data/lib/pubid/nist/builder.rb +5 -1
  136. data/lib/pubid/nist/caster.rb +13 -3
  137. data/lib/pubid/nist/identifiers/base.rb +37 -2
  138. data/lib/pubid/nist/identifiers/circular.rb +2 -2
  139. data/lib/pubid/nist/identifiers/circular_supplement.rb +2 -2
  140. data/lib/pubid/nist/identifiers/commercial_standards_monthly.rb +2 -2
  141. data/lib/pubid/nist/identifiers/crpl_report.rb +2 -2
  142. data/lib/pubid/nist/identifiers/handbook.rb +2 -2
  143. data/lib/pubid/nist/identifiers/internal_report.rb +2 -2
  144. data/lib/pubid/nist/identifiers/miscellaneous_publication.rb +2 -2
  145. data/lib/pubid/nist/identifiers/monograph.rb +2 -2
  146. data/lib/pubid/nist/identifiers/report.rb +2 -2
  147. data/lib/pubid/nist/parser.rb +19 -775
  148. data/lib/pubid/nist/router.rb +4 -1
  149. data/lib/pubid/nist/supplement_identifier.rb +2 -2
  150. data/lib/pubid/oasis/parser.rb +2 -16
  151. data/lib/pubid/ogc/parser.rb +2 -26
  152. data/lib/pubid/oiml/identifiers/certification_system.rb +7 -0
  153. data/lib/pubid/oiml/identifiers/dual_published.rb +2 -2
  154. data/lib/pubid/oiml/parser.rb +1 -303
  155. data/lib/pubid/oiml.rb +1 -2
  156. data/lib/pubid/omg/identifier.rb +6 -1
  157. data/lib/pubid/omg/parser.rb +2 -76
  158. data/lib/pubid/parser.rb +5 -4
  159. data/lib/pubid/parsers/mr_string.rb +1 -1
  160. data/lib/pubid/plateau/parser.rb +1 -66
  161. data/lib/pubid/plateau.rb +1 -2
  162. data/lib/pubid/renderers/directives_renderer.rb +1 -1
  163. data/lib/pubid/renderers/iwa_renderer.rb +1 -1
  164. data/lib/pubid/renderers/publisher_stripper.rb +82 -0
  165. data/lib/pubid/renderers/supplement_renderer.rb +1 -1
  166. data/lib/pubid/renderers.rb +1 -0
  167. data/lib/pubid/sae/parser.rb +1 -48
  168. data/lib/pubid/tgpp/identifier.rb +1 -1
  169. data/lib/pubid/tgpp/parser.rb +2 -59
  170. data/lib/pubid/un/identifier.rb +1 -1
  171. data/lib/pubid/un/parser.rb +1 -18
  172. data/lib/pubid/version.rb +1 -1
  173. data/lib/pubid/w3c/parser.rb +2 -27
  174. data/lib/pubid/xsf/identifier.rb +10 -6
  175. data/lib/pubid/xsf/parser.rb +3 -31
  176. data/lib/pubid/xsf/renderer.rb +2 -4
  177. data/lib/pubid.rb +8 -9
  178. metadata +6 -23
  179. data/lib/pubid/ieee/aiee/parser.rb +0 -130
  180. data/lib/pubid/ieee/ire/parser.rb +0 -109
  181. data/lib/pubid/ieee/nesc/parser.rb +0 -155
  182. data/lib/pubid/iho/parser.rb +0 -68
  183. data/lib/pubid/parser/common_parse_methods.rb +0 -13
  184. data/lib/pubid/parser/common_parse_rules.rb +0 -56
  185. data/lib/pubid/parser/grammar.rb +0 -96
@@ -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