pubid 2.0.58 → 2.0.60

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +6 -0
  3. data/data/parg/ieee.json +1 -1
  4. data/lib/pubid/bsi/CLAUDE.md +2 -0
  5. data/lib/pubid/bsi/identifiers/consolidated_identifier.rb +3 -0
  6. data/lib/pubid/bsi/pubid_urn_schema.rb +3 -0
  7. data/lib/pubid/bsi/urn.adoc +1 -1
  8. data/lib/pubid/bsi_pfs/identifiers/consolidated_identifier.rb +4 -0
  9. data/lib/pubid/bsi_pfs/pubid_urn_schema.rb +3 -0
  10. data/lib/pubid/bsi_pfs/urn.adoc +4 -1
  11. data/lib/pubid/builder/base.rb +5 -0
  12. data/lib/pubid/cen_cenelec/CLAUDE.md +2 -0
  13. data/lib/pubid/cen_cenelec/identifiers/consolidated_identifier.rb +4 -0
  14. data/lib/pubid/cen_cenelec/pubid_urn_schema.rb +3 -0
  15. data/lib/pubid/cen_cenelec/urn.adoc +1 -1
  16. data/lib/pubid/cen_pfs/identifiers/consolidated_identifier.rb +4 -0
  17. data/lib/pubid/cen_pfs/pubid_urn_schema.rb +3 -0
  18. data/lib/pubid/cen_pfs/urn.adoc +4 -1
  19. data/lib/pubid/components/relation.rb +290 -0
  20. data/lib/pubid/components.rb +1 -0
  21. data/lib/pubid/errors.rb +12 -1
  22. data/lib/pubid/identifier.rb +66 -0
  23. data/lib/pubid/iec/CLAUDE.md +2 -0
  24. data/lib/pubid/iec/identifier.rb +3 -0
  25. data/lib/pubid/iec/identifiers/consolidated_identifier.rb +4 -0
  26. data/lib/pubid/iec/pubid_urn_schema.rb +3 -0
  27. data/lib/pubid/iec/urn.adoc +3 -1
  28. data/lib/pubid/ieee/CLAUDE.md +6 -0
  29. data/lib/pubid/ieee/builder.rb +83 -7
  30. data/lib/pubid/ieee/identifiers/adopted_standard.rb +9 -0
  31. data/lib/pubid/ieee/identifiers/base.rb +6 -0
  32. data/lib/pubid/ieee/identifiers/corrigendum.rb +5 -1
  33. data/lib/pubid/ieee/identifiers/dual_published.rb +9 -0
  34. data/lib/pubid/ieee/identifiers/joint_development.rb +12 -0
  35. data/lib/pubid/ieee/parser.rb +6 -2
  36. data/lib/pubid/ieee/pubid_urn_schema.rb +4 -0
  37. data/lib/pubid/ieee/renderer.rb +2 -0
  38. data/lib/pubid/ieee/urn.adoc +6 -1
  39. data/lib/pubid/iso/CLAUDE.md +2 -0
  40. data/lib/pubid/iso/identifier.rb +3 -0
  41. data/lib/pubid/iso/identifiers/amendment.rb +12 -0
  42. data/lib/pubid/iso/pubid_urn_schema.rb +2 -0
  43. data/lib/pubid/iso/urn.adoc +6 -2
  44. data/lib/pubid/pubid_urn/decoder.rb +46 -0
  45. data/lib/pubid/pubid_urn/encoder.rb +43 -0
  46. data/lib/pubid/pubid_urn/schema.rb +4 -2
  47. data/lib/pubid/version.rb +1 -1
  48. data/lib/pubid.rb +245 -3
  49. metadata +3 -2
data/lib/pubid.rb CHANGED
@@ -491,6 +491,37 @@ module Pubid
491
491
  # A longest-match-first order matters because prefixes nest: "ISO/IEC 2131"
492
492
  # must not be handed to the flavor that merely owns "ISO".
493
493
  #
494
+ # Pass 2 is pruned to the flavors the input is not known to be incompatible
495
+ # with (issue #803): a flavor whose grammar cannot accept +string+ is
496
+ # dropped from the walk, and each dropped parser is one fewer failed parse
497
+ # whose record the dispatch would otherwise carry to the end. The prune is
498
+ # a FILTER over the existing order — it drops entries and never adds or
499
+ # reorders one, so every surviving flavor is tried exactly where the full
500
+ # dispatch would have tried it. It applies only when +string+ HAS a
501
+ # declared leading prefix ({candidates_by_prefix} non-empty): a string no
502
+ # prefix owns keeps the full walk, because the corpus showed flavors
503
+ # accepting leading tokens their prefix tables never declared there (BSI
504
+ # committee documents, standalone amendments, CEN/EVS stage prefixes, IALA
505
+ # specification numbers — see {dispatch_candidates}). Within a pruned
506
+ # walk, a flavor is dropped only when both:
507
+ #
508
+ # * it declares prefix tokens AND its grammar accepts unprefixed input
509
+ # under no declared prefix (see {accepts_bare?}) — never dropped, and
510
+ # * none of its declared prefix tokens occurs anywhere in +string+ at a
511
+ # token-start position ({prefix_token_occurs?}) — not only as the
512
+ # leading token: a co-published tail counts ("API 579-2 /ASME …" stays
513
+ # compatible with the asme flavor because ASME occurs after the slash,
514
+ # and "ISO/ASTMTR52905-EB" stays compatible with astm because ASTM
515
+ # occurs there even glued to the type token). Per the dual-perspective
516
+ # law each flavor's prefix list already carries the co-publisher faces
517
+ # ({Pubid::JOINT_PREFIXES}), so the occurrence test over that one list
518
+ # covers the joint forms too.
519
+ #
520
+ # Every flavor the prune keeps was tried anyway, so no accepted/rejected
521
+ # row can move (proven over the full testsuite corpus: 0 digest deltas —
522
+ # see PR #804). Ambiguous prefixes, no-owner strings and bare forms walk
523
+ # the survivors of their own prune, still in the full dispatch order.
524
+ #
494
525
  # @param string [String] a human-readable identifier
495
526
  # @return [Identifier]
496
527
  # @raise [Pubid::Errors::ParseError] when no flavor accepts the string
@@ -502,7 +533,9 @@ module Pubid
502
533
  fallback = nil
503
534
 
504
535
  prefix_owners = candidates_by_prefix(string)
505
- (prefix_owners + other_candidates(prefix_owners)).each do |mod|
536
+ candidates = dispatch_candidates(string, prefix_owners)
537
+
538
+ candidates.each do |mod|
506
539
  # An umbrella flavor (ANSI) also parses the joint prefix of a
507
540
  # co-publisher that has its own flavor; that flavor's parse wins.
508
541
  # Only as a prefix owner: in the exhaustive pass the umbrella is one
@@ -524,7 +557,13 @@ module Pubid
524
557
  # IEEE `csa_identifier`) into visible ones. Catching it one layer up
525
558
  # would hand it straight back its disguise: a real builder bug in any
526
559
  # flavor would read as "this string is not an identifier".
527
- first_error ||= e
560
+ #
561
+ # Only the record is kept, never the error object: the engine chains
562
+ # its own failure as the Ruby cause, and that chain — Source, pools,
563
+ # cause tree — pins the subject for as long as the dispatch lives
564
+ # (issue #803). The message/input/flavor strings and the failure
565
+ # position as an Integer are all the raise at the end needs.
566
+ first_error ||= DispatchFailure.from(e, string)
528
567
  next
529
568
  end
530
569
 
@@ -552,13 +591,79 @@ module Pubid
552
591
  end
553
592
 
554
593
  return fallback if fallback
555
- raise first_error if first_error
594
+ raise first_error.to_parse_error if first_error
556
595
 
557
596
  raise Pubid::Errors::ParseError,
558
597
  "no registered flavor could parse #{string.inspect}"
559
598
  end
560
599
  private_class_method :parse_by_prefix
561
600
 
601
+ # One failed flavor parse of the dispatch loop, stripped to the fields the
602
+ # eventual raise needs: the message, input and flavor strings plus the
603
+ # engine's failure position as an Integer (issue #803). The error object is
604
+ # NOT retained — Ruby chains the engine's own failure (a
605
+ # +Parsanol::ParseFailed+) as the raised error's cause, and that chain holds
606
+ # the {Parsanol::Source} with the subject string, a scanner, a regex cache
607
+ # and the engine's slice and position pools; the plateau campaign measured
608
+ # millions of such failures alive across long compiles. The engine-side
609
+ # half of the same fix is parsanol-ruby#123 (position as an Integer, cause
610
+ # chain cut); this record is the dispatcher half.
611
+ #
612
+ # The +parse_failure_cause+ of the reconstructed error stays nil, as it
613
+ # already is for every raise site on this path (the PARG backend passes
614
+ # nil; the synthetic flavor failures pass nil), and the error is built
615
+ # outside any rescue, so no engine error is attached as its cause.
616
+ DispatchFailure = Struct.new(:message, :input, :flavor, :position) do
617
+ # The error raised when the dispatch ends with no flavor able to parse
618
+ # the input. Carries only strings and the Integer position.
619
+ # @return [Errors::ParseError]
620
+ def to_parse_error
621
+ Errors::ParseError.new(message, nil, input: input, flavor: flavor,
622
+ position: position)
623
+ end
624
+
625
+ # The record of one failed candidate parse. +input+ prefers the error's
626
+ # own +input+ — what the flavor actually fed its grammar, which a
627
+ # preprocessing flavor may spell differently from the string the
628
+ # dispatch was asked about — so the raised error reports the same input
629
+ # it always did.
630
+ # @param error [Errors::ParseError]
631
+ # @param string [String]
632
+ # @return [DispatchFailure]
633
+ def self.from(error, string)
634
+ new(error.message, error.input || string, error.flavor,
635
+ engine_position(error))
636
+ end
637
+
638
+ # The engine's failure position, walked off the Ruby cause chain the
639
+ # engine error carries ({Parsanol::ParseFailed#parse_failure_cause} holds
640
+ # an Integer position). A synthetic failure without an engine cause has
641
+ # none.
642
+ # @param error [Errors::ParseError]
643
+ # @return [Integer, nil]
644
+ def self.engine_position(error)
645
+ cause = error.cause
646
+ until cause.nil?
647
+ position = cause_position(cause)
648
+ return position if position
649
+
650
+ cause = cause.cause
651
+ end
652
+ nil
653
+ end
654
+
655
+ # @param cause [Exception, nil] one link of the engine error chain
656
+ # @return [Integer, nil]
657
+ def self.cause_position(cause)
658
+ return unless cause.respond_to?(:parse_failure_cause)
659
+
660
+ failure = cause.parse_failure_cause
661
+ position = failure.position if failure.respond_to?(:position)
662
+ position if position.is_a?(Integer)
663
+ end
664
+ end
665
+ private_constant :DispatchFailure
666
+
562
667
  # Flavor modules that own a prefix +string+ starts with, longest prefix
563
668
  # first. Deduplicated by module identity, so an alias registration is not
564
669
  # tried twice.
@@ -599,11 +704,65 @@ module Pubid
599
704
  end
600
705
  private_class_method :other_candidates
601
706
 
707
+ # The dispatch order for +string+ — prefix owners first, then every other
708
+ # flavor — filtered down to the flavors +string+ is not known to be
709
+ # incompatible with ({flavor_compatible?}). A filter: the survivors keep
710
+ # the exact original order (issue #803).
711
+ #
712
+ # The prune applies only when +string+ HAS a declared leading prefix. A
713
+ # string no prefix owns keeps the full walk: the testsuite corpus showed
714
+ # flavors accepting leading tokens their own {PrefixesSupport} table never
715
+ # declared there (BSI committee documents "14/30300822 DC", standalone
716
+ # amendments "AMD 11015", CEN stage prefixes "FprEN 16114:2011", EVS
717
+ # "prEVS-EN 100:2026", CSA "CAN3-A451.1-M86", IALA "S-201") — where no
718
+ # declared prefix occurs, the prefix data bounds nothing and every parser
719
+ # has to run.
720
+ #
721
+ # @param string [String] a human-readable identifier
722
+ # @param prefix_owners [Array<Module>] see {candidates_by_prefix}
723
+ # @return [Array<Module>]
724
+ # @api private
725
+ def self.dispatch_candidates(string, prefix_owners)
726
+ if prefix_owners.empty?
727
+ return prefix_owners + other_candidates(prefix_owners)
728
+ end
729
+
730
+ lowered = string.downcase
731
+ (prefix_owners + other_candidates(prefix_owners))
732
+ .select { |mod| flavor_compatible?(mod, lowered) }
733
+ end
734
+ private_class_method :dispatch_candidates
735
+
602
736
  # A meaningless string no real identifier scheme should claim. Used to find
603
737
  # the flavors whose grammar accepts anything.
604
738
  ROUTING_PROBE = "zzqx-nonsense-9714"
605
739
  private_constant :ROUTING_PROBE
606
740
 
741
+ # Unprefixed probe shapes for {accepts_bare?}: the bare (publisher-less)
742
+ # forms a grammar can accept, one representative per observed shape family.
743
+ # Measured acceptance over the registered flavors:
744
+ #
745
+ # * "123" — a bare number (astm, iec, ieee, iso, nist, iana, adobe)
746
+ # * "1234-56" — a bare dash-number (ogc)
747
+ # * "abc" — a bare slug (adobe, iana)
748
+ # * "TR 123" — a bare series token + number (ashrae, gb, iec, iso)
749
+ # * "978-1-56619-909-4" — a valid bare ISBN-13 (isbn)
750
+ # * "10.1234/foo" — a bare DOI (doi, doi_pfs)
751
+ # * "AB/CD" — a bare slash-delimited designation (un, whose grammar
752
+ # takes any two-token slash shape far outside its own UN prefix)
753
+ # * "TS 1.1" — a bare series token + dotted version (tgpp, whose TS/TR
754
+ # series designations need no 3GPP prefix)
755
+ #
756
+ # A flavor that parses ANY of these accepts unprefixed input, so the
757
+ # dispatch prune (issue #803) may never drop it — its grammar does not
758
+ # require a leading prefix, and a string carrying none of its prefixes can
759
+ # still be its identifier. Measured like {accepts_anything?}: probed, not
760
+ # listed, so a grammar that gains or loses the property is classified
761
+ # without anyone editing a constant.
762
+ BARE_FORM_PROBES = ["123", "1234-56", "abc", "TR 123", "978-1-56619-909-4",
763
+ "10.1234/foo", "AB/CD", "TS 1.1"].freeze
764
+ private_constant :BARE_FORM_PROBES
765
+
607
766
  # True when +mod+'s grammar accepts an arbitrary slug.
608
767
  #
609
768
  # `adobe` and `iana` do, by design — their identifiers genuinely are free
@@ -632,6 +791,89 @@ module Pubid
632
791
  end
633
792
  private_class_method :accepts_anything?
634
793
 
794
+ # True when +mod+ is a possible reader of +lowered_string+ — the dispatch
795
+ # prune (issue #803) drops a flavor only when this answers false, and the
796
+ # answer is built so a kept flavor is never a wrong keep: the two escape
797
+ # hatches ({accepts_bare?}, any prefix occurrence anywhere) each err
798
+ # toward keeping.
799
+ #
800
+ # @param mod [Module] a flavor module
801
+ # @param lowered_string [String] the input, downcased once by the caller
802
+ # @return [Boolean]
803
+ # @api private
804
+ def self.flavor_compatible?(mod, lowered_string)
805
+ return true if accepts_bare?(mod)
806
+
807
+ mod.prefixes.any? do |prefix|
808
+ prefix_token_occurs?(lowered_string, prefix.downcase)
809
+ end
810
+ end
811
+ private_class_method :flavor_compatible?
812
+
813
+ # True when +lowered_prefix+ occurs in +lowered_string+ at a token-start
814
+ # position: preceded by the start of the string or by a non-alphanumeric
815
+ # character — the leading half of the {prefix_match?} boundary rule,
816
+ # applied at every position instead of only the first.
817
+ #
818
+ # The trailing half is deliberately NOT applied: a flavor's prefix may be
819
+ # glued to what follows it in a form its grammar accepts
820
+ # ("ISO/ASTMTR52905-EB" carries ASTM directly against the TR type token),
821
+ # so requiring a trailing boundary would drop exactly the flavor that
822
+ # parses the string.
823
+ #
824
+ # @param lowered_string [String]
825
+ # @param lowered_prefix [String]
826
+ # @return [Boolean]
827
+ # @api private
828
+ def self.prefix_token_occurs?(lowered_string, lowered_prefix)
829
+ index = -1
830
+ while (index = lowered_string.index(lowered_prefix, index + 1))
831
+ return true if index.zero?
832
+
833
+ boundary = lowered_string[index - 1]
834
+ return true unless /[a-z0-9]/.match?(boundary)
835
+ end
836
+ false
837
+ end
838
+ private_class_method :prefix_token_occurs?
839
+
840
+ # True when +mod+'s grammar accepts an unprefixed input — a bare form none
841
+ # of its prefixes leads. astm reads "123" as "ASTM 123", iec reads "CIE" as
842
+ # "IEC CIE", isbn reads a bare ISBN, doi reads a bare "10.…": such a flavor
843
+ # owns strings that carry no prefix token of its at all, so the dispatch
844
+ # prune (issue #803) may never drop it from the walk.
845
+ #
846
+ # Detected by probing ({BARE_FORM_PROBES}) rather than by a hardcoded list,
847
+ # like {accepts_anything?}: one probe round per flavor, memoised, so a
848
+ # grammar that gains or loses the property is classified without anyone
849
+ # remembering to edit a constant.
850
+ #
851
+ # @param mod [Module] a flavor module
852
+ # @return [Boolean]
853
+ # @api private
854
+ def self.accepts_bare?(mod)
855
+ @accepts_bare ||= {}
856
+ return @accepts_bare[mod] if @accepts_bare.key?(mod)
857
+
858
+ @accepts_bare[mod] = BARE_FORM_PROBES.any? { |p| parses_probe?(mod, p) }
859
+ end
860
+ private_class_method :accepts_bare?
861
+
862
+ # One probe parse of the bare-acceptance calibration: true when +mod+'s
863
+ # grammar accepts +probe+.
864
+ #
865
+ # @param mod [Module] a flavor module
866
+ # @param probe [String] a {BARE_FORM_PROBES} shape
867
+ # @return [Boolean]
868
+ # @api private
869
+ def self.parses_probe?(mod, probe)
870
+ mod.parse(probe)
871
+ true
872
+ rescue StandardError, Pubid::Errors::ParseError
873
+ false
874
+ end
875
+ private_class_method :parses_probe?
876
+
635
877
  # Prefix => flavor modules, longest prefix first, built once.
636
878
  #
637
879
  # {prefix_flavors} rebuilds its index on every call, iterating every
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.58
4
+ version: 2.0.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-27 00:00:00.000000000 Z
11
+ date: 2026-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model
@@ -512,6 +512,7 @@ files:
512
512
  - lib/pubid/components/language.rb
513
513
  - lib/pubid/components/locality.rb
514
514
  - lib/pubid/components/publisher.rb
515
+ - lib/pubid/components/relation.rb
515
516
  - lib/pubid/components/relationship.rb
516
517
  - lib/pubid/components/stage.rb
517
518
  - lib/pubid/components/supplement.rb