PHP 8.2.31
Preview: cross_reference.rb Size: 5.81 KB
//proc/thread-self/root/opt/alt/ruby20/lib64/ruby/2.0.0/rdoc/cross_reference.rb

##
# RDoc::CrossReference is a reusable way to create cross references for names.

class RDoc::CrossReference

  ##
  # Regular expression to match class references
  #
  # 1. There can be a '\\' in front of text to suppress the cross-reference
  # 2. There can be a '::' in front of class names to reference from the
  #    top-level namespace.
  # 3. The method can be followed by parenthesis (not recommended)

  CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'

  ##
  # Regular expression to match method references.
  #
  # See CLASS_REGEXP_STR

  METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===)(?:\([\w.+*/=<>-]*\))?'

  ##
  # Regular expressions matching text that should potentially have
  # cross-reference links generated are passed to add_special.  Note that
  # these expressions are meant to pick up text for which cross-references
  # have been suppressed, since the suppression characters are removed by the
  # code that is triggered.

  CROSSREF_REGEXP = /(?:^|\s)
                     (
                      (?:
                       # A::B::C.meth
                       #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}

                       # Stand-alone method (preceded by a #)
                       | \\?\##{METHOD_REGEXP_STR}

                       # Stand-alone method (preceded by ::)
                       | ::#{METHOD_REGEXP_STR}

                       # A::B::C
                       # The stuff after CLASS_REGEXP_STR is a
                       # nasty hack.  CLASS_REGEXP_STR unfortunately matches
                       # words like dog and cat (these are legal "class"
                       # names in Fortran 95).  When a word is flagged as a
                       # potential cross-reference, limitations in the markup
                       # engine suppress other processing, such as typesetting.
                       # This is particularly noticeable for contractions.
                       # In order that words like "can't" not
                       # be flagged as potential cross-references, only
                       # flag potential class cross-references if the character
                       # after the cross-reference is a space, sentence
                       # punctuation, tag start character, or attribute
                       # marker.
                       | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)

                       # Things that look like filenames
                       # The key thing is that there must be at least
                       # one special character (period, slash, or
                       # underscore).
                       | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+

                       # Things that have markup suppressed
                       # Don't process things like '\<' in \<tt>, though.
                       # TODO: including < is a hack, not very satisfying.
                       | \\[^\s<]
                      )

                      # labels for headings
                      (?:@[\w+%-]+(?:\.[\w|%-]+)?)?
                     )/x

  ##
  # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.

  ALL_CROSSREF_REGEXP = /
                     (?:^|\s)
                     (
                      (?:
                       # A::B::C.meth
                       #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}

                       # Stand-alone method
                       | \\?#{METHOD_REGEXP_STR}

                       # A::B::C
                       | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)

                       # Things that look like filenames
                       | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+

                       # Things that have markup suppressed
                       | \\[^\s<]
                      )

                      # labels for headings
                      (?:@[\w+%-]+)?
                     )/x

  ##
  # Hash of references that have been looked-up to their replacements

  attr_accessor :seen

  ##
  # Allows cross-references to be created based on the given +context+
  # (RDoc::Context).

  def initialize context
    @context = context
    @store   = context.store

    @seen = {}
  end

  ##
  # Returns a reference to +name+.
  #
  # If the reference is found and +name+ is not documented +text+ will be
  # returned.  If +name+ is escaped +name+ is returned.  If +name+ is not
  # found +text+ is returned.

  def resolve name, text
    return @seen[name] if @seen.include? name

    if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
      type = $2
      type = '' if type == '.'  # will find either #method or ::method
      method = "#{type}#{$3}"
      container = @context.find_symbol_module($1)
    elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
      type = $1
      type = '' if type == '.'
      method = "#{type}#{$2}"
      container = @context
    else
      container = nil
    end

    if container then
      ref = container.find_local_symbol method

      unless ref || RDoc::TopLevel === container then
        ref = container.find_ancestor_local_symbol method
      end
    end

    ref = case name
          when /^\\(#{CLASS_REGEXP_STR})$/o then
            @context.find_symbol $1
          else
            @context.find_symbol name
          end unless ref

    # Try a page name
    ref = @store.page name if not ref and name =~ /^\w+$/

    ref = nil if RDoc::Alias === ref # external alias, can't link to it

    out = if name == '\\' then
            name
          elsif name =~ /^\\/ then
            # we remove the \ only in front of what we know:
            # other backslashes are treated later, only outside of <tt>
            ref ? $' : name
          elsif ref then
            if ref.display? then
              ref
            else
              text
            end
          else
            text
          end

    @seen[name] = out

    out
  end

end

Directory Contents

Dirs: 8 × Files: 44

Name Size Perms Modified Actions
context DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
generator DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
markdown DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
markup DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
parser DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
rd DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
ri DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
stats DIR
- drwxr-xr-x 2024-03-03 22:43:41
Edit Download
2.09 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
142 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
5.90 KB lrw-r--r-- 2013-01-23 01:02:24
Edit Download
3.73 KB lrw-r--r-- 2013-01-23 01:02:24
Edit Download
19.15 KB lrw-r--r-- 2013-01-23 01:02:24
Edit Download
7.71 KB lrw-r--r-- 2013-01-23 01:02:24
Edit Download
121 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
5.39 KB lrw-r--r-- 2012-11-27 08:54:03
Edit Download
3.34 KB lrw-r--r-- 2012-11-27 08:54:03
Edit Download
28.26 KB lrw-r--r-- 2012-12-06 06:20:50
Edit Download
5.81 KB lrw-r--r-- 2013-01-04 06:16:13
Edit Download
2.74 KB lrw-r--r-- 2012-12-18 08:24:57
Edit Download
794 B lrw-r--r-- 2011-05-15 11:55:52
Edit Download
370 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
2.53 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
1.72 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
114 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
2.61 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
2.58 KB lrw-r--r-- 2011-06-29 21:17:31
Edit Download
380.09 KB lrw-r--r-- 2012-12-01 03:58:39
Edit Download
28.31 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
99 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
8.57 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
2.06 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
1.36 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
28.49 KB lrw-r--r-- 2012-12-11 07:44:56
Edit Download
7.83 KB lrw-r--r-- 2013-01-04 06:16:13
Edit Download
3.54 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
13.25 KB lrw-r--r-- 2012-12-13 07:58:47
Edit Download
935 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
315 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
4.91 KB lrw-r--r-- 2012-12-14 05:16:56
Edit Download
27.23 KB lrw-r--r-- 2012-12-18 07:31:36
Edit Download
11.21 KB lrw-r--r-- 2012-12-18 07:31:36
Edit Download
10.83 KB lrw-r--r-- 2013-02-05 08:24:20
Edit Download
330 B lrw-r--r-- 2012-11-27 04:28:14
Edit Download
9.78 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
22.32 KB lrw-r--r-- 2013-01-25 00:15:08
Edit Download
7.66 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
3.46 KB lrw-r--r-- 2012-11-29 23:34:29
Edit Download
7.59 KB lrw-r--r-- 2015-01-30 07:13:13
Edit Download
2.46 KB lrw-r--r-- 2012-11-27 04:28:14
Edit Download
5.70 KB lrw-r--r-- 2013-01-04 06:16:13
Edit Download
5.40 KB lrw-r--r-- 2013-01-23 01:02:24
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).