# File lib/Getopt/DelimScanner.rb, line 726
    def matchTagged( prefix, ldel, rdel, failmode, bad, ignore )
        failmode = failmode.to_s.intern if failmode
        startPos = self.pointer
        debugMsg 2, "matchTagged starting at pos = %d: prefix = %s, "\
                 "ldel = %s, rdel = %s, failmode = %s, bad = %s, ignore = %s",
                 startPos, prefix.inspect, ldel.inspect, rdel.inspect,
                 failmode.inspect, bad.inspect, ignore.inspect

        rdelspec = ''
        openTagPos, textPos, paraPos, closeTagPos, endPos = ([nil] * 5)
        match = nil

        # Look for the prefix

        raise MatchFailure, "Did not find prefix: /#{prefix.inspect}/" unless
            self.skip( prefix )

        openTagPos = self.pointer
        debugMsg 3, "Found prefix. Pointer now at offset %d" % self.pointer

        # Look for the opening delimiter

        unless (( match = self.scan(ldel) ))
            raise MatchFailure, "Did not find opening tag %s at offset %d" % 
                [ ldel.inspect, self.pointer ]
        end

        textPos = self.pointer
        debugMsg 3, "Found left delimiter '%s': offset now %d" % [ match, textPos ]

        # Make a right delim out of the tag we found if none was specified

        if rdel.nil?
            rdelspec = makeClosingTag( match )
            debugMsg 3, "Generated right-delimiting tag: %s" % rdelspec.inspect
        else
            # Make the regexp-related globals from the match

            rdelspec = rdel.gsub( /(\A|[^\\])\$([1-9])/, '\1self[\2]' ).interpolate( binding )
            debugMsg 3, "Right delimiter (after interpolation) is: %s" % rdelspec.inspect
        end

        # Process until we reach the end of the string or find a closing tag

        while self.rest? && closeTagPos.nil?

            # Skip backslashed characters

            if (( self.skip( /^\\./ ) ))
                debugMsg 4, "Skipping backslashed literal at offset %d" % self.pointer
                next

            # Match paragraphs-break for fail == :para

            elsif (( matchlength = self.skip( /^(\n[ \t]*\n)/ ) ))
                paraPos ||= self.pointer - matchlength
                debugMsg 4, "Found paragraph position at offset %d" % paraPos
                
            # Match closing tag

            elsif (( matchlength = self.skip( rdelspec ) ))
                closeTagPos = self.pointer - matchlength
                debugMsg 3, "Found closing tag at offset %d" % closeTagPos

            # If we're ignoring anything, try to match and move beyond it

            elsif ignore && !ignore.empty? && self.skip(ignore)
                debugMsg 3, "Skipping ignored text '%s' at offset %d" %
                    [ self.matched, self.pointer - self.matched_size ]
                next

            # If there's a "bad" pattern, try to match it, shorting the

            # outer loop if it matches in para or max mode, or failing with

            # a match error if not.

            elsif bad && !bad.empty? && self.match?( bad )
                if failmode == :para || failmode == :max
                    break
                else
                    raise MatchFailure, "Found invalid nested tag '%s' at offset %d" %
                        [ match, self.pointer ]
                end

            # If there's another opening tag, make a recursive call to

            # ourselves to move the cursor beyond it

            elsif (( match = self.scan( ldel ) ))
                tag = match
                self.unscan

                unless self.matchTagged( prefix, ldel, rdel, failmode, bad, ignore )
                    break if failmode == :para || failmode == :max

                    raise MatchFailure, "Found unbalanced nested tag '%s' at offset %d" %
                        [ tag, self.pointer ]
                end

            else 
                self.pointer += 1
                debugMsg 5, "Advanced scan pointer to offset %d" % self.pointer
            end
        end

        # If the closing hasn't been found, then it's a "short" match, which is

        # okay if the failmode indicates we don't care. Otherwise, it's an error.

        unless closeTagPos
            debugMsg 3, "No close tag position found. "
            
            if failmode == :max || failmode == :para
                closeTagPos = self.pointer - 1
                debugMsg 4, "Failmode %s tolerates no closing tag. Close tag position set to %d" %
                    [ failmode.inspect, closeTagPos ]

                # Sync the scan pointer and the paragraph marker if it's set.

                if failmode == :para && paraPos
                    self.pointer = paraPos + 1
                end
            else
                raise MatchFailure, "No closing tag found."
            end
        end

        rval = {
            :match  => self.string[ openTagPos .. (self.pointer - 1) ],
            :prefix => self.string[ startPos, (openTagPos-startPos) ],
            :suffix => self.string[ self.pointer..-1 ],
        }
        debugMsg 1, "matchTagged succeeded: %s" % rval.inspect
        return rval
    end