Class DelimScanner
In: lib/Getopt/DelimScanner.rb
Parent: Object

A derivative of StringScanner that can scan for delimited constructs in addition to regular expressions.

Methods

Included Modules

Default

Classes and Modules

Module DelimScanner::Default
Class DelimScanner::DelimiterError
Class DelimScanner::MatchFailure

Constants

Version = /([\d\.]+)/.match( %q{$Revision: 1.2 $} )[1]   Class constants
Rcsid = %q$Id: DelimScanner.rb,v 1.2 2003/01/12 20:56:51 deveiant Exp $
XmlName = '[a-zA-Z_:][a-zA-Z0-9:.-]*'   Pattern to match a valid XML name
NeedCastingDelegators = :scan, :skip, :match?, :check, :scan_until, :skip_until, :exist?, :check_until   A list of delegated methods that need casting.

Attributes

debugLevel  [RW]  Debugging level
matchError  [RW]  The last match error encountered by the scanner

Public Class methods

Define delegating methods that cast their argument to a Regexp from a String. This allows the scanner’s scanning methods to be called with Strings in addition to Regexps. This was mostly stolen from forwardable.rb.

Create a new DelimScanner object for the specified string. If dup is true, a duplicate of the target string will be used instead of the one given. The target string will be frozen after the scanner is created.

Public Instance methods

Match using the scanBracketed method, but only return the match or nil.

Match using the scanCodeblock method, but only return the match or nil.

Match using the scanDelimited method, but only return the match or nil.

Match using the scanQuotelike method, but only return the match or nil.

Match using the scanTagged method, but only return the match or nil.

Match using the scanVariable method, but only return the match or nil.

Returns true if the scanner has encountered a match error.

Starting at the scan pointer, try to match a substring delimited by balanced delimiters of the type specified, after skipping the specified prefix. On a successful match, this method advances the scan pointer and returns a Hash with the following key/value pairs:

:match
The text of the match, including the delimiting brackets.
:prefix
The matched prefix, if any.

On failure, returns nil.

Starting from the scan pointer, and skipping the specified prefix, try to to recognize and match a balanced bracket-, do/end-, or begin/end-delimited substring that may contain unbalanced delimiters inside quotes or quotelike operations.

Starting at the scan pointer, try to match a substring delimited by the specified delimiters, skipping the specified prefix and any character escaped by the specified escape character/s. If matched, advances the scan pointer and returns a Hash with the following key/value pairs on success:

:match
The text of the match, including delimiters.
:prefix
The matched prefix, if any.

If the match fails, returns nil.

Starting from the scan pointer, try to match any one of the various Ruby quotes and quotelike operators after skipping the specified prefix. Nested backslashed delimiters, embedded balanced bracket delimiters (for the quotelike operators), and trailing modifiers are all caught. If matchRawRegex is true, inline regexen (eg., /pattern/) are matched as well. Advances the scan pointer and returns a Hash with the following key/value pairs on success:

:match
The entire text of the match.
:prefix
The matched prefix, if any.
:quoteOp
The name of the quotelike operator (if any) (eg., ’%Q’, ’%r’, etc).
:leftDelim
The left delimiter of the first block of the operation.
:delimText
The text of the first block of the operation.
:rightDelim
The right delimiter of the first block of the operation.
:modifiers
The trailing modifiers on the operation (if any).

On failure, returns nil.

Extracts and segments text from the scan pointer forward that occurs between (balanced) specified tags, after skipping the specified prefix. If the opentag argument is nil, a pattern which will match any standard HTML/XML tag will be used. If the closetag argument is nil, a pattern is created which prepends a / character to the matched opening tag, after any bracketing characters. The options argument is a Hash of one or more options which govern the matching operation. They are described in more detail in the Description section of ‘lib/DelimScanner.rb’. On a successful match, this method advances the scan pointer and returns an

:match
The text of the match, including the delimiting tags.
:prefix
The matched prefix, if any.

On failure, returns nil.

Starting from the scan pointer, try to match a Ruby variable after skipping the specified prefix.

Starting at the scan pointer, try to match a substring with scanBracketed. On a successful match, this method advances the scan pointer and returns the length of the match, including the delimiters and any prefix that was skipped. On failure, returns nil.

Starting at the scan pointer, try to match a substring with scanCodeblock. On a successful match, this method advances the scan pointer and returns the length of the match, including any delimiters and any prefix that was skipped. On failure, returns nil.

Starting at the scan pointer, try to match a substring delimited by the specified delimiters, skipping the specified prefix and any character escaped by the specified escape character/s. If matched, advances the scan pointer and returns the length of the matched string; if it fails the match, returns nil.

Starting at the scan pointer, try to match a substring with scanQuotelike. On a successful match, this method advances the scan pointer and returns the length of the match, including any delimiters and any prefix that was skipped. On failure, returns nil.

Starting at the scan pointer, try to match a substring with scanTagged. On a successful match, this method advances the scan pointer and returns the length of the match, including any delimiters and any prefix that was skipped. On failure, returns nil.

Starting at the scan pointer, try to match a substring with scanVariable. On a successful match, this method advances the scan pointer and returns the length of the match, including any delimiters and any prefix that was skipped. On failure, returns nil.

Protected Instance methods

Scan the string from the scan pointer forward, skipping the specified prefix and trying to match a string delimited by bracketing delimiters ldel and rdel (Regexp objects), and quoting delimiters qdel (Regexp). If quotelike is true, Ruby quotelike constructs will also be honored.

Starting from the scan pointer, skip the specified prefix, and try to match text inside a Ruby code block construct which must be delimited by the specified outerDelimPairs. It may optionally contain sub-blocks delimited with the given innerDelimPairs.

Starting from the scan pointer, skip the specified prefix, and try to match text inside a Ruby quotelike construct. If matchRawRegex is true, the regex construct /pattern/ is also matched.

Starting from the scan pointer, skip the specified prefix, and try to match text bracketed by the given left and right tag-delimiters (ldel and rdel).

Starting from the scan pointer, skip the specified prefix, and try to match text that is a valid Ruby variable or identifier, …?

Attempt to derive and return the number of scan methods traversed up to this point by examining the call stack.

[Validate]