.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Text::Balanced 3"
.TH Text::Balanced 3 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
Text::Balanced \- Extract delimited text sequences from strings.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 8
\& use Text::Balanced qw (
\& extract_delimited
\& extract_bracketed
\& extract_quotelike
\& extract_codeblock
\& extract_variable
\& extract_tagged
\& extract_multiple
.Ve
.PP
.Vb 3
\& gen_delimited_pat
\& gen_extract_tagged
\& );
.Ve
.PP
.Vb 2
\& # Extract the initial substring of $text that is delimited by
\& # two (unescaped) instances of the first character in $delim.
.Ve
.PP
.Vb 1
\& ($extracted, $remainder) = extract_delimited($text,$delim);
.Ve
.PP
.Vb 3
\& # Extract the initial substring of $text that is bracketed
\& # with a delimiter(s) specified by $delim (where the string
\& # in $delim contains one or more of '(){}[]<>').
.Ve
.PP
.Vb 1
\& ($extracted, $remainder) = extract_bracketed($text,$delim);
.Ve
.PP
.Vb 2
\& # Extract the initial substring of $text that is bounded by
\& # an HTML/XML tag.
.Ve
.PP
.Vb 1
\& ($extracted, $remainder) = extract_tagged($text);
.Ve
.PP
.Vb 2
\& # Extract the initial substring of $text that is bounded by
\& # a C<BEGIN>...C<END> pair. Don't allow nested C<BEGIN> tags
.Ve
.PP
.Vb 2
\& ($extracted, $remainder) =
\& extract_tagged($text,"BEGIN","END",undef,{bad=>["BEGIN"]});
.Ve
.PP
.Vb 2
\& # Extract the initial substring of $text that represents a
\& # Perl "quote or quote-like operation"
.Ve
.PP
.Vb 1
\& ($extracted, $remainder) = extract_quotelike($text);
.Ve
.PP
.Vb 3
\& # Extract the initial substring of $text that represents a block
\& # of Perl code, bracketed by any of character(s) specified by $delim
\& # (where the string $delim contains one or more of '(){}[]<>').
.Ve
.PP
.Vb 1
\& ($extracted, $remainder) = extract_codeblock($text,$delim);
.Ve
.PP
.Vb 3
\& # Extract the initial substrings of $text that would be extracted by
\& # one or more sequential applications of the specified functions
\& # or regular expressions
.Ve
.PP
.Vb 7
\& @extracted = extract_multiple($text,
\& [ \e&extract_bracketed,
\& \e&extract_quotelike,
\& \e&some_other_extractor_sub,
\& qr/[xyz]*/,
\& 'literal',
\& ]);
.Ve
.PP
# Create a string representing an optimized pattern (a la Friedl)
# that matches a substring delimited by any of the specified characters
# (in this case: any type of quote or a slash)
.PP
.Vb 1
\& $patstring = gen_delimited_pat(q{'"`/});
.Ve
.PP
# Generate a reference to an anonymous sub that is just like extract_tagged
# but pre-compiled and optimized for a specific pair of tags, and consequently
# much faster (i.e. 3 times faster). It uses qr// for better performance on
# repeated calls, so it only works under Perl 5.005 or later.
.PP
.Vb 1
\& $extract_head = gen_extract_tagged('<HEAD>','</HEAD>');
.Ve
.PP
.Vb 1
\& ($extracted, $remainder) = $extract_head->($text);
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The various \f(CW\*(C`extract_...\*(C'\fR subroutines may be used to extract a
delimited string (possibly after skipping a specified prefix string).
The search for the string always begins at the current \f(CW\*(C`pos\*(C'\fR
location of the string's variable (or at index zero, if no \f(CW\*(C`pos\*(C'\fR
position is defined).
.Sh "General behaviour in list contexts"
.IX Subsection "General behaviour in list contexts"
In a list context, all the subroutines return a list, the first three
elements of which are always:
.IP "[0]" 4
.IX Item "[0]"
The extracted string, including the specified delimiters.
If the extraction fails an empty string is returned.
.IP "[1]" 4
.IX Item "[1]"
The remainder of the input string (i.e. the characters after the
extracted string). On failure, the entire string is returned.
.IP "[2]" 4
.IX Item "[2]"
The skipped prefix (i.e. the characters before the extracted string).
On failure, the empty string is returned.
.PP
Note that in a list context, the contents of the original input text (the first
argument) are not modified in any way.
.PP
However, if the input text was passed in a variable, that variable's
\&\f(CW\*(C`pos\*(C'\fR value is updated to point at the first character after the
extracted text. That means that in a list context the various
subroutines can be used much like regular expressions. For example:
.PP
.Vb 4
\& while ( $next = (extract_quotelike($text))[0] )
\& {
\& # process next quote-like (in $next)
\& }
.Ve
.Sh "General behaviour in scalar and void contexts"
.IX Subsection "General behaviour in scalar and void contexts"
In a scalar context, the extracted string is returned, having first been
removed from the input text. Thus, the following code also processes
each quote-like operation, but actually removes them from \f(CW$text:\fR
.PP
.Vb 4
\& while ( $next = extract_quotelike($text) )
\& {
\& # process next quote-like (in $next)
\& }
.Ve
.PP
Note that if the input text is a read-only string (i.e. a literal),
no attempt is made to remove the extracted text.
.PP
In a void context the behaviour of the extraction subroutines is
exactly the same as in a scalar context, except (of course) that the
extracted substring is not returned.
.Sh "A note about prefixes"
.IX Subsection "A note about prefixes"
Prefix patterns are matched without any trailing modifiers (\f(CW\*(C`/gimsox\*(C'\fR etc.)
This can bite you if you're expecting a prefix specification like
\&'.*?(?=<H1>)' to skip everything up to the first <H1> tag. Such a prefix
pattern will only succeed if the <H1> tag is on the current line, since
\&. normally doesn't match newlines.
.PP
To overcome this limitation, you need to turn on /s matching within
the prefix pattern, using the \f(CW\*(C`(?s)\*(C'\fR directive: '(?s).*?(?=<H1>)'
.ie n .Sh """extract_delimited"""
.el .Sh "\f(CWextract_delimited\fP"
.IX Subsection "extract_delimited"
The \f(CW\*(C`extract_delimited\*(C'\fR function formalizes the common idiom
of extracting a single-character-delimited substring from the start of
a string. For example, to extract a single-quote delimited string, the
following code is typically used:
.PP
.Vb 2
\& ($remainder = $text) =~ s/\eA('(\e\e.|[^'])*')//s;
\& $extracted = $1;
.Ve
.PP
but with \f(CW\*(C`extract_delimited\*(C'\fR it can be simplified to:
.PP
.Vb 1
\& ($extracted,$remainder) = extract_delimited($text, "'");
.Ve
.PP
\&\f(CW\*(C`extract_delimited\*(C'\fR takes up to four scalars (the input text, the
delimiters, a prefix pattern to be skipped, and any escape characters)
and extracts the initial substring of the text that
is appropriately delimited. If the delimiter string has multiple
characters, the first one encountered in the text is taken to delimit
the substring.
The third argument specifies a prefix pattern that is to be skipped
(but must be present!) before the substring is extracted.
The final argument specifies the escape character to be used for each
delimiter.
.PP
All arguments are optional. If the escape characters are not specified,
every delimiter is escaped with a backslash (\f(CW\*(C`\e\*(C'\fR).
If the prefix is not specified, the
pattern \f(CW'\es*'\fR \- optional whitespace \- is used. If the delimiter set
is also not specified, the set \f(CW\*(C`/["'`]/\*(C'\fR is used. If the text to be processed
is not specified either, \f(CW$_\fR is used.
.PP
In list context, \f(CW\*(C`extract_delimited\*(C'\fR returns an array of three
elements, the extracted substring (\fIincluding the surrounding
delimiters\fR), the remainder of the text, and the skipped prefix (if
any). If a suitable delimited substring is not found, the first
element of the array is the empty string, the second is the complete
original text, and the prefix returned in the third element is an
empty string.
.PP
In a scalar context, just the extracted substring is returned. In
a void context, the extracted substring (and any prefix) are simply
removed from the beginning of the first argument.
.PP
Examples:
.PP
.Vb 1
\& # Remove a single-quoted substring from the very beginning of $text:
.Ve
.PP
.Vb 1
\& $substring = extract_delimited($text, "'", '');
.Ve
.PP
.Vb 3
\& # Remove a single-quoted Pascalish substring (i.e. one in which
\& # doubling the quote character escapes it) from the very
\& # beginning of $text:
.Ve
.PP
.Vb 1
\& $substring = extract_delimited($text, "'", '', "'");
.Ve
.PP
.Vb 3
\& # Extract a single- or double- quoted substring from the
\& # beginning of $text, optionally after some whitespace
\& # (note the list context to protect $text from modification):
.Ve
.PP
.Vb 1
\& ($substring) = extract_delimited $text, q{"'};
.Ve
.PP
.Vb 1
\& # Delete the substring delimited by the first '/' in $text:
.Ve
.PP
.Vb 1
\& $text = join '', (extract_delimited($text,'/','[^/]*')[2,1];
.Ve
.PP
Note that this last example is \fInot\fR the same as deleting the first
quote-like pattern. For instance, if \f(CW$text\fR contained the string:
.PP
.Vb 1
\& "if ('./cmd' =~ m/$UNIXCMD/s) { $cmd = $1; }"
.Ve
.PP
then after the deletion it would contain:
.PP
.Vb 1
\& "if ('.$UNIXCMD/s) { $cmd = $1; }"
.Ve
.PP
not:
.PP
.Vb 1
\& "if ('./cmd' =~ ms) { $cmd = $1; }"
.Ve
.PP
See \*(L"extract_quotelike\*(R" for a (partial) solution to this problem.
.ie n .Sh """extract_bracketed"""
.el .Sh "\f(CWextract_bracketed\fP"
.IX Subsection "extract_bracketed"
Like \f(CW"extract_delimited"\fR, the \f(CW\*(C`extract_bracketed\*(C'\fR function takes
up to three optional scalar arguments: a string to extract from, a delimiter
specifier, and a prefix pattern. As before, a missing prefix defaults to
optional whitespace and a missing text defaults to \f(CW$_\fR. However, a missing
delimiter specifier defaults to \f(CW'{}()[]<>'\fR (see below).
.PP
\&\f(CW\*(C`extract_bracketed\*(C'\fR extracts a balanced-bracket-delimited
substring (using any one (or more) of the user-specified delimiter
brackets: '(..)', '{..}', '[..]', or '<..>'). Optionally it will also
respect quoted unbalanced brackets (see below).
.PP
A \*(L"delimiter bracket\*(R" is a bracket in list of delimiters passed as
\&\f(CW\*(C`extract_bracketed\*(C'\fR's second argument. Delimiter brackets are
specified by giving either the left or right (or both!) versions
of the required bracket(s). Note that the order in which
two or more delimiter brackets are specified is not significant.
.PP
A \*(L"balanced\-bracket\-delimited substring\*(R" is a substring bounded by
matched brackets, such that any other (left or right) delimiter
bracket \fIwithin\fR the substring is also matched by an opposite
(right or left) delimiter bracket \fIat the same level of nesting\fR. Any
type of bracket not in the delimiter list is treated as an ordinary
character.
.PP
In other words, each type of bracket specified as a delimiter must be
balanced and correctly nested within the substring, and any other kind of
(\*(L"non\-delimiter\*(R") bracket in the substring is ignored.
.PP
For example, given the string:
.PP
.Vb 1
\& $text = "{ an '[irregularly :-(] {} parenthesized >:-)' string }";
.Ve
.PP
then a call to \f(CW\*(C`extract_bracketed\*(C'\fR in a list context:
.PP
.Vb 1
\& @result = extract_bracketed( $text, '{}' );
.Ve
.PP
would return:
.PP
.Vb 1
\& ( "{ an '[irregularly :-(] {} parenthesized >:-)' string }" , "" , "" )
.Ve
.PP
since both sets of \f(CW'{..}'\fR brackets are properly nested and evenly balanced.
(In a scalar context just the first element of the array would be returned. In
a void context, \f(CW$text\fR would be replaced by an empty string.)
.PP
Likewise the call in:
.PP
.Vb 1
\& @result = extract_bracketed( $text, '{[' );
.Ve
.PP
would return the same result, since all sets of both types of specified
delimiter brackets are correctly nested and balanced.
.PP
However, the call in:
.PP
.Vb 1
\& @result = extract_bracketed( $text, '{([<' );
.Ve
.PP
would fail, returning:
.PP
.Vb 1
\& ( undef , "{ an '[irregularly :-(] {} parenthesized >:-)' string }" );
.Ve
.PP
because the embedded pairs of \f(CW'(..)'\fRs and \f(CW'[..]'\fRs are \*(L"cross\-nested\*(R" and
the embedded \f(CW'>'\fR is unbalanced. (In a scalar context, this call would
return an empty string. In a void context, \f(CW$text\fR would be unchanged.)
.PP
Note that the embedded single-quotes in the string don't help in this
case, since they have not been specified as acceptable delimiters and are
therefore treated as non-delimiter characters (and ignored).
.PP
However, if a particular species of quote character is included in the
delimiter specification, then that type of quote will be correctly handled.
for example, if \f(CW$text\fR is:
.PP
.Vb 1
\& $text = '<A HREF=">>>>">link</A>';
.Ve
.PP
then
.PP
.Vb 1
\& @result = extract_bracketed( $text, '<">' );
.Ve
.PP
returns:
.PP
.Vb 1
\& ( '<A HREF=">>>>">', 'link</A>', "" )
.Ve
.PP
as expected. Without the specification of \f(CW\*(C`"\*(C'\fR as an embedded quoter:
.PP
.Vb 1
\& @result = extract_bracketed( $text, '<>' );
.Ve
.PP
the result would be:
.PP
.Vb 1
\& ( '<A HREF=">', '>>>">link</A>', "" )
.Ve
.PP
In addition to the quote delimiters \f(CW\*(C`'\*(C'\fR, \f(CW\*(C`"\*(C'\fR, and \f(CW\*(C``\*(C'\fR, full Perl quote-like
quoting (i.e. q{string}, qq{string}, etc) can be specified by including the
letter 'q' as a delimiter. Hence:
.PP
.Vb 1
\& @result = extract_bracketed( $text, '<q>' );
.Ve
.PP
would correctly match something like this:
.PP
.Vb 1
\& $text = '<leftop: conj /and/ conj>';
.Ve
.PP
See also: \f(CW"extract_quotelike"\fR and \f(CW"extract_codeblock"\fR.
.ie n .Sh """extract_tagged"""
.el .Sh "\f(CWextract_tagged\fP"
.IX Subsection "extract_tagged"
\&\f(CW\*(C`extract_tagged\*(C'\fR extracts and segments text between (balanced)
specified tags.
.PP
The subroutine takes up to five optional arguments:
.IP "1." 4
A string to be processed (\f(CW$_\fR if the string is omitted or \f(CW\*(C`undef\*(C'\fR)
.IP "2." 4
A string specifying a pattern to be matched as the opening tag.
If the pattern string is omitted (or \f(CW\*(C`undef\*(C'\fR) then a pattern
that matches any standard \s-1HTML/XML\s0 tag is used.
.IP "3." 4
A string specifying a pattern to be matched at the closing tag.
If the pattern string is omitted (or \f(CW\*(C`undef\*(C'\fR) then the closing
tag is constructed by inserting a \f(CW\*(C`/\*(C'\fR after any leading bracket
characters in the actual opening tag that was matched (\fInot\fR the pattern
that matched the tag). For example, if the opening tag pattern
is specified as \f(CW'{{\ew+}}'\fR and actually matched the opening tag
\&\f(CW"{{DATA}}"\fR, then the constructed closing tag would be \f(CW"{{/DATA}}"\fR.
.IP "4." 4
A string specifying a pattern to be matched as a prefix (which is to be
skipped). If omitted, optional whitespace is skipped.
.IP "5." 4
A hash reference containing various parsing options (see below)
.PP
The various options that can be specified are:
.ie n .IP """reject => $listref""" 4
.el .IP "\f(CWreject => $listref\fR" 4
.IX Item "reject => $listref"
The list reference contains one or more strings specifying patterns
that must \fInot\fR appear within the tagged text.
.Sp
For example, to extract
an \s-1HTML\s0 link (which should not contain nested links) use:
.Sp
.Vb 1
\& extract_tagged($text, '<A>', '</A>', undef, {reject => ['<A>']} );
.Ve
.ie n .IP """ignore => $listref""" 4
.el .IP "\f(CWignore => $listref\fR" 4
.IX Item "ignore => $listref"
The list reference contains one or more strings specifying patterns
that are \fInot\fR be be treated as nested tags within the tagged text
(even if they would match the start tag pattern).
.Sp
For example, to extract an arbitrary \s-1XML\s0 tag, but ignore \*(L"empty\*(R" elements:
.Sp
.Vb 1
\& extract_tagged($text, undef, undef, undef, {ignore => ['<[^>]*/>']} );
.Ve
.Sp
(also see \*(L"gen_delimited_pat\*(R" below).
.ie n .IP """fail => $str""" 4
.el .IP "\f(CWfail => $str\fR" 4
.IX Item "fail => $str"
The \f(CW\*(C`fail\*(C'\fR option indicates the action to be taken if a matching end
tag is not encountered (i.e. before the end of the string or some
\&\f(CW\*(C`reject\*(C'\fR pattern matches). By default, a failure to match a closing
tag causes \f(CW\*(C`extract_tagged\*(C'\fR to immediately fail.
.Sp
However, if the string value associated with <reject> is \*(L"\s-1MAX\s0\*(R", then
\&\f(CW\*(C`extract_tagged\*(C'\fR returns the complete text up to the point of failure.
If the string is \*(L"\s-1PARA\s0\*(R", \f(CW\*(C`extract_tagged\*(C'\fR returns only the first paragraph
after the tag (up to the first line that is either empty or contains
only whitespace characters).
If the string is "", the default behaviour (i.e. failure) is reinstated.
.Sp
For example, suppose the start tag \*(L"/para\*(R" introduces a paragraph, which then
continues until the next \*(L"/endpara\*(R" tag or until another \*(L"/para\*(R" tag is
encountered:
.Sp
.Vb 1
\& $text = "/para line 1\en\enline 3\en/para line 4";
.Ve
.Sp
.Vb 2
\& extract_tagged($text, '/para', '/endpara', undef,
\& {reject => '/para', fail => MAX );
.Ve
.Sp
.Vb 1
\& # EXTRACTED: "/para line 1\en\enline 3\en"
.Ve
.Sp
Suppose instead, that if no matching \*(L"/endpara\*(R" tag is found, the \*(L"/para\*(R"
tag refers only to the immediately following paragraph:
.Sp
.Vb 1
\& $text = "/para line 1\en\enline 3\en/para line 4";
.Ve
.Sp
.Vb 2
\& extract_tagged($text, '/para', '/endpara', undef,
\& {reject => '/para', fail => MAX );
.Ve
.Sp
.Vb 1
\& # EXTRACTED: "/para line 1\en"
.Ve
.Sp
Note that the specified \f(CW\*(C`fail\*(C'\fR behaviour applies to nested tags as well.
.PP
On success in a list context, an array of 6 elements is returned. The elements are:
.IP "[0]" 4
.IX Item "[0]"
the extracted tagged substring (including the outermost tags),
.IP "[1]" 4
.IX Item "[1]"
the remainder of the input text,
.IP "[2]" 4
.IX Item "[2]"
the prefix substring (if any),
.IP "[3]" 4
.IX Item "[3]"
the opening tag
.IP "[4]" 4
.IX Item "[4]"
the text between the opening and closing tags
.IP "[5]" 4
.IX Item "[5]"
the closing tag (or "" if no closing tag was found)
.PP
On failure, all of these values (except the remaining text) are \f(CW\*(C`undef\*(C'\fR.
.PP
In a scalar context, \f(CW\*(C`extract_tagged\*(C'\fR returns just the complete
substring that matched a tagged text (including the start and end
tags). \f(CW\*(C`undef\*(C'\fR is returned on failure. In addition, the original input
text has the returned substring (and any prefix) removed from it.
.PP
In a void context, the input text just has the matched substring (and
any specified prefix) removed.
.ie n .Sh """gen_extract_tagged"""
.el .Sh "\f(CWgen_extract_tagged\fP"
.IX Subsection "gen_extract_tagged"
(Note: This subroutine is only available under Perl5.005)
.PP
\&\f(CW\*(C`gen_extract_tagged\*(C'\fR generates a new anonymous subroutine which
extracts text between (balanced) specified tags. In other words,
it generates a function identical in function to \f(CW\*(C`extract_tagged\*(C'\fR.
.PP
The difference between \f(CW\*(C`extract_tagged\*(C'\fR and the anonymous
subroutines generated by
\&\f(CW\*(C`gen_extract_tagged\*(C'\fR, is that those generated subroutines:
.IP "\(bu" 4
do not have to reparse tag specification or parsing options every time
they are called (whereas \f(CW\*(C`extract_tagged\*(C'\fR has to effectively rebuild
its tag parser on every call);
.IP "\(bu" 4
make use of the new qr// construct to pre-compile the regexes they use
(whereas \f(CW\*(C`extract_tagged\*(C'\fR uses standard string variable interpolation
to create tag-matching patterns).
.PP
The subroutine takes up to four optional arguments (the same set as
\&\f(CW\*(C`extract_tagged\*(C'\fR except for the string to be processed). It returns
a reference to a subroutine which in turn takes a single argument (the text to
be extracted from).
.PP
In other words, the implementation of \f(CW\*(C`extract_tagged\*(C'\fR is exactly
equivalent to:
.PP
.Vb 6
\& sub extract_tagged
\& {
\& my $text = shift;
\& $extractor = gen_extract_tagged(@_);
\& return $extractor->($text);
\& }
.Ve
.PP
(although \f(CW\*(C`extract_tagged\*(C'\fR is not currently implemented that way, in order
to preserve pre\-5.005 compatibility).
.PP
Using \f(CW\*(C`gen_extract_tagged\*(C'\fR to create extraction functions for specific tags
is a good idea if those functions are going to be called more than once, since
their performance is typically twice as good as the more general-purpose
\&\f(CW\*(C`extract_tagged\*(C'\fR.
.ie n .Sh """extract_quotelike"""
.el .Sh "\f(CWextract_quotelike\fP"
.IX Subsection "extract_quotelike"
\&\f(CW\*(C`extract_quotelike\*(C'\fR attempts to recognize, extract, and segment any
one of the various Perl quotes and quotelike operators (see
\&\fIperlop\fR\|(3)) Nested backslashed delimiters, embedded balanced bracket
delimiters (for the quotelike operators), and trailing modifiers are
all caught. For example, in:
.PP
.Vb 1
\& extract_quotelike 'q # an octothorpe: \e# (not the end of the q!) #'
.Ve
.PP
.Vb 1
\& extract_quotelike ' "You said, \e"Use sed\e"." '
.Ve
.PP
.Vb 1
\& extract_quotelike ' s{([A-Z]{1,8}\e.[A-Z]{3})} /\eL$1\eE/; '
.Ve
.PP
.Vb 1
\& extract_quotelike ' tr/\e\e\e/\e\e\e\e/\e\e\e//ds; '
.Ve
.PP
the full Perl quotelike operations are all extracted correctly.
.PP
Note too that, when using the /x modifier on a regex, any comment
containing the current pattern delimiter will cause the regex to be
immediately terminated. In other words:
.PP
.Vb 5
\& 'm /
\& (?i) # CASE INSENSITIVE
\& [a-z_] # LEADING ALPHABETIC/UNDERSCORE
\& [a-z0-9]* # FOLLOWED BY ANY NUMBER OF ALPHANUMERICS
\& /x'
.Ve
.PP
will be extracted as if it were:
.PP
.Vb 3
\& 'm /
\& (?i) # CASE INSENSITIVE
\& [a-z_] # LEADING ALPHABETIC/'
.Ve
.PP
This behaviour is identical to that of the actual compiler.
.PP
\&\f(CW\*(C`extract_quotelike\*(C'\fR takes two arguments: the text to be processed and
a prefix to be matched at the very beginning of the text. If no prefix
is specified, optional whitespace is the default. If no text is given,
\&\f(CW$_\fR is used.
.PP
In a list context, an array of 11 elements is returned. The elements are:
.IP "[0]" 4
.IX Item "[0]"
the extracted quotelike substring (including trailing modifiers),
.IP "[1]" 4
.IX Item "[1]"
the remainder of the input text,
.IP "[2]" 4
.IX Item "[2]"
the prefix substring (if any),
.IP "[3]" 4
.IX Item "[3]"
the name of the quotelike operator (if any),
.IP "[4]" 4
.IX Item "[4]"
the left delimiter of the first block of the operation,
.IP "[5]" 4
.IX Item "[5]"
the text of the first block of the operation
(that is, the contents of
a quote, the regex of a match or substitution or the target list of a
translation),
.IP "[6]" 4
.IX Item "[6]"
the right delimiter of the first block of the operation,
.IP "[7]" 4
.IX Item "[7]"
the left delimiter of the second block of the operation
(that is, if it is an \f(CW\*(C`s\*(C'\fR, \f(CW\*(C`tr\*(C'\fR, or \f(CW\*(C`y\*(C'\fR),
.IP "[8]" 4
.IX Item "[8]"
the text of the second block of the operation
(that is, the replacement of a substitution or the translation list
of a translation),
.IP "[9]" 4
.IX Item "[9]"
the right delimiter of the second block of the operation (if any),
.IP "[10]" 4
.IX Item "[10]"
the trailing modifiers on the operation (if any).
.PP
For each of the fields marked \*(L"(if any)\*(R" the default value on success is
an empty string.
On failure, all of these values (except the remaining text) are \f(CW\*(C`undef\*(C'\fR.
.PP
In a scalar context, \f(CW\*(C`extract_quotelike\*(C'\fR returns just the complete substring
that matched a quotelike operation (or \f(CW\*(C`undef\*(C'\fR on failure). In a scalar or
void context, the input text has the same substring (and any specified
prefix) removed.
.PP
Examples:
.PP
.Vb 1
\& # Remove the first quotelike literal that appears in text
.Ve
.PP
.Vb 1
\& $quotelike = extract_quotelike($text,'.*?');
.Ve
.PP
.Vb 2
\& # Replace one or more leading whitespace-separated quotelike
\& # literals in $_ with "<QLL>"
.Ve
.PP
.Vb 1
\& do { $_ = join '<QLL>', (extract_quotelike)[2,1] } until $@;
.Ve
.PP
.Vb 1
\& # Isolate the search pattern in a quotelike operation from $text
.Ve
.PP
.Vb 9
\& ($op,$pat) = (extract_quotelike $text)[3,5];
\& if ($op =~ /[ms]/)
\& {
\& print "search pattern: $pat\en";
\& }
\& else
\& {
\& print "$op is not a pattern matching operation\en";
\& }
.Ve
.ie n .Sh """extract_quotelike"" and ""here documents"""
.el .Sh "\f(CWextract_quotelike\fP and ``here documents''"
.IX Subsection "extract_quotelike and here documents"
\&\f(CW\*(C`extract_quotelike\*(C'\fR can successfully extract \*(L"here documents\*(R" from an input
string, but with an important caveat in list contexts.
.PP
Unlike other types of quote-like literals, a here document is rarely
a contiguous substring. For example, a typical piece of code using
here document might look like this:
.PP
.Vb 4
\& <<'EOMSG' || die;
\& This is the message.
\& EOMSG
\& exit;
.Ve
.PP
Given this as an input string in a scalar context, \f(CW\*(C`extract_quotelike\*(C'\fR
would correctly return the string \*(L"<<'\s-1EOMSG\s0'\enThis is the message.\enEOMSG\*(R",
leaving the string \*(L" || die;\enexit;\*(R" in the original variable. In other words,
the two separate pieces of the here document are successfully extracted and
concatenated.
.PP
In a list context, \f(CW\*(C`extract_quotelike\*(C'\fR would return the list
.IP "[0]" 4
.IX Item "[0]"
\&\*(L"<<'\s-1EOMSG\s0'\enThis is the message.\enEOMSG\en\*(R" (i.e. the full extracted here document,
including fore and aft delimiters),
.IP "[1]" 4
.IX Item "[1]"
\&\*(L" || die;\enexit;\*(R" (i.e. the remainder of the input text, concatenated),
.IP "[2]" 4
.IX Item "[2]"
"" (i.e. the prefix substring \*(-- trivial in this case),
.IP "[3]" 4
.IX Item "[3]"
\&\*(L"<<\*(R" (i.e. the \*(L"name\*(R" of the quotelike operator)
.IP "[4]" 4
.IX Item "[4]"
\&\*(L"'\s-1EOMSG\s0'\*(R" (i.e. the left delimiter of the here document, including any quotes),
.IP "[5]" 4
.IX Item "[5]"
\&\*(L"This is the message.\en\*(R" (i.e. the text of the here document),
.IP "[6]" 4
.IX Item "[6]"
\&\*(L"\s-1EOMSG\s0\*(R" (i.e. the right delimiter of the here document),
.IP "[7..10]" 4
.IX Item "[7..10]"
"" (a here document has no second left delimiter, second text, second right
delimiter, or trailing modifiers).
.PP
However, the matching position of the input variable would be set to
\&\*(L"exit;\*(R" (i.e. \fIafter\fR the closing delimiter of the here document),
which would cause the earlier \*(L" || die;\enexit;\*(R" to be skipped in any
sequence of code fragment extractions.
.PP
To avoid this problem, when it encounters a here document while
extracting from a modifiable string, \f(CW\*(C`extract_quotelike\*(C'\fR silently
rearranges the string to an equivalent piece of Perl:
.PP
.Vb 5
\& <<'EOMSG'
\& This is the message.
\& EOMSG
\& || die;
\& exit;
.Ve
.PP
in which the here document \fIis\fR contiguous. It still leaves the
matching position after the here document, but now the rest of the line
on which the here document starts is not skipped.
.PP
To prevent <extract_quotelike> from mucking about with the input in this way
(this is the only case where a list-context \f(CW\*(C`extract_quotelike\*(C'\fR does so),
you can pass the input variable as an interpolated literal:
.PP
.Vb 1
\& $quotelike = extract_quotelike("$var");
.Ve
.ie n .Sh """extract_codeblock"""
.el .Sh "\f(CWextract_codeblock\fP"
.IX Subsection "extract_codeblock"
\&\f(CW\*(C`extract_codeblock\*(C'\fR attempts to recognize and extract a balanced
bracket delimited substring that may contain unbalanced brackets
inside Perl quotes or quotelike operations. That is, \f(CW\*(C`extract_codeblock\*(C'\fR
is like a combination of \f(CW"extract_bracketed"\fR and
\&\f(CW"extract_quotelike"\fR.
.PP
\&\f(CW\*(C`extract_codeblock\*(C'\fR takes the same initial three parameters as \f(CW\*(C`extract_bracketed\*(C'\fR:
a text to process, a set of delimiter brackets to look for, and a prefix to
match first. It also takes an optional fourth parameter, which allows the
outermost delimiter brackets to be specified separately (see below).
.PP
Omitting the first argument (input text) means process \f(CW$_\fR instead.
Omitting the second argument (delimiter brackets) indicates that only \f(CW'{'\fR is to be used.
Omitting the third argument (prefix argument) implies optional whitespace at the start.
Omitting the fourth argument (outermost delimiter brackets) indicates that the
value of the second argument is to be used for the outermost delimiters.
.PP
Once the prefix an the outermost opening delimiter bracket have been
recognized, code blocks are extracted by stepping through the input text and
trying the following alternatives in sequence:
.IP "1." 4
Try and match a closing delimiter bracket. If the bracket was the same
species as the last opening bracket, return the substring to that
point. If the bracket was mismatched, return an error.
.IP "2." 4
Try to match a quote or quotelike operator. If found, call
\&\f(CW\*(C`extract_quotelike\*(C'\fR to eat it. If \f(CW\*(C`extract_quotelike\*(C'\fR fails, return
the error it returned. Otherwise go back to step 1.
.IP "3." 4
Try to match an opening delimiter bracket. If found, call
\&\f(CW\*(C`extract_codeblock\*(C'\fR recursively to eat the embedded block. If the
recursive call fails, return an error. Otherwise, go back to step 1.
.IP "4." 4
Unconditionally match a bareword or any other single character, and
then go back to step 1.
.PP
Examples:
.PP
.Vb 1
\& # Find a while loop in the text
.Ve
.PP
.Vb 4
\& if ($text =~ s/.*?while\es*\e{/{/)
\& {
\& $loop = "while " . extract_codeblock($text);
\& }
.Ve
.PP
.Vb 2
\& # Remove the first round-bracketed list (which may include
\& # round- or curly-bracketed code blocks or quotelike operators)
.Ve
.PP
.Vb 1
\& extract_codeblock $text, "(){}", '[^(]*';
.Ve
.PP
The ability to specify a different outermost delimiter bracket is useful
in some circumstances. For example, in the Parse::RecDescent module,
parser actions which are to be performed only on a successful parse
are specified using a \f(CW\*(C`<defer:...>\*(C'\fR directive. For example:
.PP
.Vb 2
\& sentence: subject verb object
\& <defer: {$::theVerb = $item{verb}} >
.Ve
.PP
Parse::RecDescent uses \f(CW\*(C`extract_codeblock($text, '{}<>')\*(C'\fR to extract the code
within the \f(CW\*(C`<defer:...>\*(C'\fR directive, but there's a problem.
.PP
A deferred action like this:
.PP
.Vb 1
\& <defer: {if ($count>10) {$count--}} >
.Ve
.PP
will be incorrectly parsed as:
.PP
.Vb 1
\& <defer: {if ($count>
.Ve
.PP
because the \*(L"less than\*(R" operator is interpreted as a closing delimiter.
.PP
But, by extracting the directive using
\&\f(CW\*(C`extract_codeblock($text,\ '{}',\ undef,\ '<>')\*(C'\fR
the '>' character is only treated as a delimited at the outermost
level of the code block, so the directive is parsed correctly.
.ie n .Sh """extract_multiple"""
.el .Sh "\f(CWextract_multiple\fP"
.IX Subsection "extract_multiple"
The \f(CW\*(C`extract_multiple\*(C'\fR subroutine takes a string to be processed and a
list of extractors (subroutines or regular expressions) to apply to that string.
.PP
In an array context \f(CW\*(C`extract_multiple\*(C'\fR returns an array of substrings
of the original string, as extracted by the specified extractors.
In a scalar context, \f(CW\*(C`extract_multiple\*(C'\fR returns the first
substring successfully extracted from the original string. In both
scalar and void contexts the original string has the first successfully
extracted substring removed from it. In all contexts
\&\f(CW\*(C`extract_multiple\*(C'\fR starts at the current \f(CW\*(C`pos\*(C'\fR of the string, and
sets that \f(CW\*(C`pos\*(C'\fR appropriately after it matches.
.PP
Hence, the aim of a call to \f(CW\*(C`extract_multiple\*(C'\fR in a list context
is to split the processed string into as many non-overlapping fields as
possible, by repeatedly applying each of the specified extractors
to the remainder of the string. Thus \f(CW\*(C`extract_multiple\*(C'\fR is
a generalized form of Perl's \f(CW\*(C`split\*(C'\fR subroutine.
.PP
The subroutine takes up to four optional arguments:
.IP "1." 4
A string to be processed (\f(CW$_\fR if the string is omitted or \f(CW\*(C`undef\*(C'\fR)
.IP "2." 4
A reference to a list of subroutine references and/or qr// objects and/or
literal strings and/or hash references, specifying the extractors
to be used to split the string. If this argument is omitted (or
\&\f(CW\*(C`undef\*(C'\fR) the list:
.Sp
.Vb 5
\& [
\& sub { extract_variable($_[0], '') },
\& sub { extract_quotelike($_[0],'') },
\& sub { extract_codeblock($_[0],'{}','') },
\& ]
.Ve
.Sp
is used.
.IP "3." 4
A number specifying the maximum number of fields to return. If this
argument is omitted (or \f(CW\*(C`undef\*(C'\fR), split continues as long as possible.
.Sp
If the third argument is \fIN\fR, then extraction continues until \fIN\fR fields
have been successfully extracted, or until the string has been completely
processed.
.Sp
Note that in scalar and void contexts the value of this argument is
automatically reset to 1 (under \f(CW\*(C`\-w\*(C'\fR, a warning is issued if the argument
has to be reset).
.IP "4." 4
A value indicating whether unmatched substrings (see below) within the
text should be skipped or returned as fields. If the value is true,
such substrings are skipped. Otherwise, they are returned.
.PP
The extraction process works by applying each extractor in
sequence to the text string.
.PP
If the extractor is a subroutine it is called in a list context and is
expected to return a list of a single element, namely the extracted
text. It may optionally also return two further arguments: a string
representing the text left after extraction (like $' for a pattern
match), and a string representing any prefix skipped before the
extraction (like $` in a pattern match). Note that this is designed
to facilitate the use of other Text::Balanced subroutines with
\&\f(CW\*(C`extract_multiple\*(C'\fR. Note too that the value returned by an extractor
subroutine need not bear any relationship to the corresponding substring
of the original text (see examples below).
.PP
If the extractor is a precompiled regular expression or a string,
it is matched against the text in a scalar context with a leading
\&'\eG' and the gc modifiers enabled. The extracted value is either
\&\f(CW$1\fR if that variable is defined after the match, or else the
complete match (i.e. $&).
.PP
If the extractor is a hash reference, it must contain exactly one element.
The value of that element is one of the
above extractor types (subroutine reference, regular expression, or string).
The key of that element is the name of a class into which the successful
return value of the extractor will be blessed.
.PP
If an extractor returns a defined value, that value is immediately
treated as the next extracted field and pushed onto the list of fields.
If the extractor was specified in a hash reference, the field is also
blessed into the appropriate class,
.PP
If the extractor fails to match (in the case of a regex extractor), or returns an empty list or an undefined value (in the case of a subroutine extractor), it is
assumed to have failed to extract.
If none of the extractor subroutines succeeds, then one
character is extracted from the start of the text and the extraction
subroutines reapplied. Characters which are thus removed are accumulated and
eventually become the next field (unless the fourth argument is true, in which
case they are discarded).
.PP
For example, the following extracts substrings that are valid Perl variables:
.PP
.Vb 3
\& @fields = extract_multiple($text,
\& [ sub { extract_variable($_[0]) } ],
\& undef, 1);
.Ve
.PP
This example separates a text into fields which are quote delimited,
curly bracketed, and anything else. The delimited and bracketed
parts are also blessed to identify them (the \*(L"anything else\*(R" is unblessed):
.PP
.Vb 5
\& @fields = extract_multiple($text,
\& [
\& { Delim => sub { extract_delimited($_[0],q{'"}) } },
\& { Brack => sub { extract_bracketed($_[0],'{}') } },
\& ]);
.Ve
.PP
This call extracts the next single substring that is a valid Perl quotelike
operator (and removes it from \f(CW$text\fR):
.PP
.Vb 4
\& $quotelike = extract_multiple($text,
\& [
\& sub { extract_quotelike($_[0]) },
\& ], undef, 1);
.Ve
.PP
Finally, here is yet another way to do comma-separated value parsing:
.PP
.Vb 6
\& @fields = extract_multiple($csv_text,
\& [
\& sub { extract_delimited($_[0],q{'"}) },
\& qr/([^,]+)(.*)/,
\& ],
\& undef,1);
.Ve
.PP
The list in the second argument means:
\&\fI\*(L"Try and extract a ' or \*(R" delimited string, otherwise extract anything up to a comma..."\fR.
The undef third argument means:
\&\fI\*(L"...as many times as possible...\*(R"\fR,
and the true value in the fourth argument means
\&\fI\*(L"...discarding anything else that appears (i.e. the commas)\*(R"\fR.
.PP
If you wanted the commas preserved as separate fields (i.e. like split
does if your split pattern has capturing parentheses), you would
just make the last parameter undefined (or remove it).
.ie n .Sh """gen_delimited_pat"""
.el .Sh "\f(CWgen_delimited_pat\fP"
.IX Subsection "gen_delimited_pat"
The \f(CW\*(C`gen_delimited_pat\*(C'\fR subroutine takes a single (string) argument and
> builds a Friedl-style optimized regex that matches a string delimited
by any one of the characters in the single argument. For example:
.PP
.Vb 1
\& gen_delimited_pat(q{'"})
.Ve
.PP
returns the regex:
.PP
.Vb 1
\& (?:\e"(?:\e\e\e"|(?!\e").)*\e"|\e'(?:\e\e\e'|(?!\e').)*\e')
.Ve
.PP
Note that the specified delimiters are automatically quotemeta'd.
.PP
A typical use of \f(CW\*(C`gen_delimited_pat\*(C'\fR would be to build special purpose tags
for \f(CW\*(C`extract_tagged\*(C'\fR. For example, to properly ignore \*(L"empty\*(R" \s-1XML\s0 elements
(which might contain quoted strings):
.PP
.Vb 1
\& my $empty_tag = '<(' . gen_delimited_pat(q{'"}) . '|.)+/>';
.Ve
.PP
.Vb 1
\& extract_tagged($text, undef, undef, undef, {ignore => [$empty_tag]} );
.Ve
.PP
\&\f(CW\*(C`gen_delimited_pat\*(C'\fR may also be called with an optional second argument,
which specifies the \*(L"escape\*(R" character(s) to be used for each delimiter.
For example to match a Pascal-style string (where ' is the delimiter
and '' is a literal ' within the string):
.PP
.Vb 1
\& gen_delimited_pat(q{'},q{'});
.Ve
.PP
Different escape characters can be specified for different delimiters.
For example, to specify that '/' is the escape for single quotes
and '%' is the escape for double quotes:
.PP
.Vb 1
\& gen_delimited_pat(q{'"},q{/%});
.Ve
.PP
If more delimiters than escape chars are specified, the last escape char
is used for the remaining delimiters.
If no escape char is specified for a given specified delimiter, '\e' is used.
.PP
Note that
\&\f(CW\*(C`gen_delimited_pat\*(C'\fR was previously called
\&\f(CW\*(C`delimited_pat\*(C'\fR. That name may still be used, but is now deprecated.
.SH "DIAGNOSTICS"
.IX Header "DIAGNOSTICS"
In a list context, all the functions return \f(CW\*(C`(undef,$original_text)\*(C'\fR
on failure. In a scalar context, failure is indicated by returning \f(CW\*(C`undef\*(C'\fR
(in this case the input text is not modified in any way).
.PP
In addition, on failure in \fIany\fR context, the \f(CW$@\fR variable is set.
Accessing \f(CW\*(C`$@\->{error}\*(C'\fR returns one of the error diagnostics listed
below.
Accessing \f(CW\*(C`$@\->{pos}\*(C'\fR returns the offset into the original string at
which the error was detected (although not necessarily where it occurred!)
Printing \f(CW$@\fR directly produces the error message, with the offset appended.
On success, the \f(CW$@\fR variable is guaranteed to be \f(CW\*(C`undef\*(C'\fR.
.PP
The available diagnostics are:
.ie n .IP """Did not find a suitable bracket: ""%s""""" 4
.el .IP "\f(CWDid not find a suitable bracket: ``%s''\fR" 4
.IX Item "Did not find a suitable bracket: ""%s"""
The delimiter provided to \f(CW\*(C`extract_bracketed\*(C'\fR was not one of
\&\f(CW'()[]<>{}'\fR.
.ie n .IP """Did not find prefix: /%s/""" 4
.el .IP "\f(CWDid not find prefix: /%s/\fR" 4
.IX Item "Did not find prefix: /%s/"
A non-optional prefix was specified but wasn't found at the start of the text.
.ie n .IP """Did not find opening bracket after prefix: ""%s""""" 4
.el .IP "\f(CWDid not find opening bracket after prefix: ``%s''\fR" 4
.IX Item "Did not find opening bracket after prefix: ""%s"""
\&\f(CW\*(C`extract_bracketed\*(C'\fR or \f(CW\*(C`extract_codeblock\*(C'\fR was expecting a
particular kind of bracket at the start of the text, and didn't find it.
.ie n .IP """No quotelike operator found after prefix: ""%s""""" 4
.el .IP "\f(CWNo quotelike operator found after prefix: ``%s''\fR" 4
.IX Item "No quotelike operator found after prefix: ""%s"""
\&\f(CW\*(C`extract_quotelike\*(C'\fR didn't find one of the quotelike operators \f(CW\*(C`q\*(C'\fR,
\&\f(CW\*(C`qq\*(C'\fR, \f(CW\*(C`qw\*(C'\fR, \f(CW\*(C`qx\*(C'\fR, \f(CW\*(C`s\*(C'\fR, \f(CW\*(C`tr\*(C'\fR or \f(CW\*(C`y\*(C'\fR at the start of the substring
it was extracting.
.ie n .IP """Unmatched closing bracket: ""%c""""" 4
.el .IP "\f(CWUnmatched closing bracket: ``%c''\fR" 4
.IX Item "Unmatched closing bracket: ""%c"""
\&\f(CW\*(C`extract_bracketed\*(C'\fR, \f(CW\*(C`extract_quotelike\*(C'\fR or \f(CW\*(C`extract_codeblock\*(C'\fR encountered
a closing bracket where none was expected.
.ie n .IP """Unmatched opening bracket(s): ""%s""""" 4
.el .IP "\f(CWUnmatched opening bracket(s): ``%s''\fR" 4
.IX Item "Unmatched opening bracket(s): ""%s"""
\&\f(CW\*(C`extract_bracketed\*(C'\fR, \f(CW\*(C`extract_quotelike\*(C'\fR or \f(CW\*(C`extract_codeblock\*(C'\fR ran
out of characters in the text before closing one or more levels of nested
brackets.
.ie n .IP """Unmatched embedded quote (%s)""" 4
.el .IP "\f(CWUnmatched embedded quote (%s)\fR" 4
.IX Item "Unmatched embedded quote (%s)"
\&\f(CW\*(C`extract_bracketed\*(C'\fR attempted to match an embedded quoted substring, but
failed to find a closing quote to match it.
.ie n .IP """Did not find closing delimiter to match '%s'""" 4
.el .IP "\f(CWDid not find closing delimiter to match '%s'\fR" 4
.IX Item "Did not find closing delimiter to match '%s'"
\&\f(CW\*(C`extract_quotelike\*(C'\fR was unable to find a closing delimiter to match the
one that opened the quote-like operation.
.ie n .IP """Mismatched closing bracket: expected ""%c"" but found ""%s""""" 4
.el .IP "\f(CWMismatched closing bracket: expected ``%c'' but found ``%s''\fR" 4
.IX Item "Mismatched closing bracket: expected ""%c"" but found ""%s"""
\&\f(CW\*(C`extract_bracketed\*(C'\fR, \f(CW\*(C`extract_quotelike\*(C'\fR or \f(CW\*(C`extract_codeblock\*(C'\fR found
a valid bracket delimiter, but it was the wrong species. This usually
indicates a nesting error, but may indicate incorrect quoting or escaping.
.ie n .IP """No block delimiter found after quotelike ""%s""""" 4
.el .IP "\f(CWNo block delimiter found after quotelike ``%s''\fR" 4
.IX Item "No block delimiter found after quotelike ""%s"""
\&\f(CW\*(C`extract_quotelike\*(C'\fR or \f(CW\*(C`extract_codeblock\*(C'\fR found one of the
quotelike operators \f(CW\*(C`q\*(C'\fR, \f(CW\*(C`qq\*(C'\fR, \f(CW\*(C`qw\*(C'\fR, \f(CW\*(C`qx\*(C'\fR, \f(CW\*(C`s\*(C'\fR, \f(CW\*(C`tr\*(C'\fR or \f(CW\*(C`y\*(C'\fR
without a suitable block after it.
.ie n .IP """Did not find leading dereferencer""" 4
.el .IP "\f(CWDid not find leading dereferencer\fR" 4
.IX Item "Did not find leading dereferencer"
\&\f(CW\*(C`extract_variable\*(C'\fR was expecting one of '$', '@', or '%' at the start of
a variable, but didn't find any of them.
.ie n .IP """Bad identifier after dereferencer""" 4
.el .IP "\f(CWBad identifier after dereferencer\fR" 4
.IX Item "Bad identifier after dereferencer"
\&\f(CW\*(C`extract_variable\*(C'\fR found a '$', '@', or '%' indicating a variable, but that
character was not followed by a legal Perl identifier.
.ie n .IP """Did not find expected opening bracket at %s""" 4
.el .IP "\f(CWDid not find expected opening bracket at %s\fR" 4
.IX Item "Did not find expected opening bracket at %s"
\&\f(CW\*(C`extract_codeblock\*(C'\fR failed to find any of the outermost opening brackets
that were specified.
.ie n .IP """Improperly nested codeblock at %s""" 4
.el .IP "\f(CWImproperly nested codeblock at %s\fR" 4
.IX Item "Improperly nested codeblock at %s"
A nested code block was found that started with a delimiter that was specified
as being only to be used as an outermost bracket.
.ie n .IP """Missing second block for quotelike ""%s""""" 4
.el .IP "\f(CWMissing second block for quotelike ``%s''\fR" 4
.IX Item "Missing second block for quotelike ""%s"""
\&\f(CW\*(C`extract_codeblock\*(C'\fR or \f(CW\*(C`extract_quotelike\*(C'\fR found one of the
quotelike operators \f(CW\*(C`s\*(C'\fR, \f(CW\*(C`tr\*(C'\fR or \f(CW\*(C`y\*(C'\fR followed by only one block.
.ie n .IP """No match found for opening bracket""" 4
.el .IP "\f(CWNo match found for opening bracket\fR" 4
.IX Item "No match found for opening bracket"
\&\f(CW\*(C`extract_codeblock\*(C'\fR failed to find a closing bracket to match the outermost
opening bracket.
.ie n .IP """Did not find opening tag: /%s/""" 4
.el .IP "\f(CWDid not find opening tag: /%s/\fR" 4
.IX Item "Did not find opening tag: /%s/"
\&\f(CW\*(C`extract_tagged\*(C'\fR did not find a suitable opening tag (after any specified
prefix was removed).
.ie n .IP """Unable to construct closing tag to match: /%s/""" 4
.el .IP "\f(CWUnable to construct closing tag to match: /%s/\fR" 4
.IX Item "Unable to construct closing tag to match: /%s/"
\&\f(CW\*(C`extract_tagged\*(C'\fR matched the specified opening tag and tried to
modify the matched text to produce a matching closing tag (because
none was specified). It failed to generate the closing tag, almost
certainly because the opening tag did not start with a
bracket of some kind.
.ie n .IP """Found invalid nested tag: %s""" 4
.el .IP "\f(CWFound invalid nested tag: %s\fR" 4
.IX Item "Found invalid nested tag: %s"
\&\f(CW\*(C`extract_tagged\*(C'\fR found a nested tag that appeared in the \*(L"reject\*(R" list
(and the failure mode was not \*(L"\s-1MAX\s0\*(R" or \*(L"\s-1PARA\s0\*(R").
.ie n .IP """Found unbalanced nested tag: %s""" 4
.el .IP "\f(CWFound unbalanced nested tag: %s\fR" 4
.IX Item "Found unbalanced nested tag: %s"
\&\f(CW\*(C`extract_tagged\*(C'\fR found a nested opening tag that was not matched by a
corresponding nested closing tag (and the failure mode was not \*(L"\s-1MAX\s0\*(R" or \*(L"\s-1PARA\s0\*(R").
.ie n .IP """Did not find closing tag""" 4
.el .IP "\f(CWDid not find closing tag\fR" 4
.IX Item "Did not find closing tag"
\&\f(CW\*(C`extract_tagged\*(C'\fR reached the end of the text without finding a closing tag
to match the original opening tag (and the failure mode was not
\&\*(L"\s-1MAX\s0\*(R" or \*(L"\s-1PARA\s0\*(R").
.SH "AUTHOR"
.IX Header "AUTHOR"
Damian Conway (damian@conway.org)
.SH "BUGS AND IRRITATIONS"
.IX Header "BUGS AND IRRITATIONS"
There are undoubtedly serious bugs lurking somewhere in this code, if
only because parts of it give the impression of understanding a great deal
more about Perl than they really do.
.PP
Bug reports and other feedback are most welcome.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
.Vb 3
\& Copyright (c) 1997-2001, Damian Conway. All Rights Reserved.
\& This module is free software. It may be used, redistributed
\& and/or modified under the same terms as Perl itself.
.Ve
|