.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .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. \*(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- .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" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" 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 "PPIx::Regexp 3pm" .TH PPIx::Regexp 3pm "2019-04-03" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" PPIx::Regexp \- Represent a regular expression of some sort .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 5 \& use PPIx::Regexp; \& use PPIx::Regexp::Dumper; \& my $re = PPIx::Regexp\->new( \*(Aqqr{foo}smx\*(Aq ); \& PPIx::Regexp::Dumper\->new( $re ) \& \->print(); .Ve .SH "INHERITANCE" .IX Header "INHERITANCE" \&\f(CW\*(C`PPIx::Regexp\*(C'\fR is a PPIx::Regexp::Node. .PP \&\f(CW\*(C`PPIx::Regexp\*(C'\fR has no descendants. .SH "DESCRIPTION" .IX Header "DESCRIPTION" The purpose of the \fIPPIx-Regexp\fR package is to parse regular expressions in a manner similar to the way the \s-1PPI\s0 package parses Perl. This class forms the root of the parse tree, playing a role similar to PPI::Document. .PP This package shares with \s-1PPI\s0 the property of being round-trip safe. That is, .PP .Vb 3 \& my $expr = \*(Aqs/ ( \ed+ ) ( \eD+ ) /$2$1/smxg\*(Aq; \& my $re = PPIx::Regexp\->new( $expr ); \& print $re\->content() eq $expr ? "yes\en" : "no\en" .Ve .PP should print 'yes' for any valid regular expression. .PP Navigation is similar to that provided by \s-1PPI\s0. That is to say, things like \f(CW\*(C`children\*(C'\fR, \f(CW\*(C`find_first\*(C'\fR, \f(CW\*(C`snext_sibling\*(C'\fR and so on all work pretty much the same way as in \s-1PPI\s0. .PP The class hierarchy is also similar to \s-1PPI\s0. Except for some utility classes (the dumper, the lexer, and the tokenizer) all classes are descended from PPIx::Regexp::Element, which provides basic navigation. Tokens are descended from PPIx::Regexp::Token, which provides content. All containers are descended from PPIx::Regexp::Node, which provides for children, and all structure elements are descended from PPIx::Regexp::Structure, which provides beginning and ending delimiters, and a type. .PP There are two features of \s-1PPI\s0 that this package does not provide \&\- mutability and operator overloading. There are no plans for serious mutability, though something like \s-1PPI\s0's \f(CW\*(C`prune\*(C'\fR functionality might be considered. Similarly there are no plans for operator overloading, which appears to the author to represent a performance hit for little tangible gain. .SH "NOTICE" .IX Header "NOTICE" The use of this class to parse non-regexp quote-like strings was an experiment that I consider failed. Therefore this use is \fBdeprecated\fR in favor of PPIx::QuoteLike. As of version 0.058_01, the first use of the \f(CW\*(C`parse\*(C'\fR argument to \fBnew()\fR resulted in a warning. As of version 0.062_01, all uses of the \f(CW\*(C`parse\*(C'\fR argument resulted in a warning. After another six months, the \f(CW\*(C`parse\*(C'\fR argument will become fatal. .PP The author will attempt to preserve the documented interface, but if the interface needs to change to correct some egregiously bad design or implementation decision, then it will change. Any incompatible changes will go through a deprecation cycle. .PP The goal of this package is to parse well-formed regular expressions correctly. A secondary goal is not to blow up on ill-formed regular expressions. The correct identification and characterization of ill-formed regular expressions is \fBnot\fR a goal of this package, nor is the consistent parsing of ill-formed regular expressions from release to release. .PP This policy attempts to track features in development releases as well as public releases. However, features added in a development release and then removed before the next production release \fBwill not\fR be tracked, and any functionality relating to such features \fBwill be removed\fR. The issue here is the potential re-use (with different semantics) of syntax that did not make it into the production release. .PP From time to time the Perl regular expression engine changes in ways that change the parse of a given regular expression. When these changes occur, \f(CW\*(C`PPIx::Regexp\*(C'\fR will be changed to produce the more modern parse. Known examples of this include: .ie n .IP "$( no longer interpolates as of Perl 5.005, per ""perl5005delta""." 4 .el .IP "\f(CW$(\fR no longer interpolates as of Perl 5.005, per \f(CWperl5005delta\fR." 4 .IX Item "$( no longer interpolates as of Perl 5.005, per perl5005delta." Newer Perls seem to parse this as \f(CW\*(C`qr{$}\*(C'\fR (i.e. and end-of-string or newline assertion) followed by an open parenthesis, and that is what \&\f(CW\*(C`PPIx::Regexp\*(C'\fR does. .ie n .IP "$) and $| also seem to parse as the ""$"" assertion" 4 .el .IP "\f(CW$)\fR and \f(CW$|\fR also seem to parse as the \f(CW$\fR assertion" 4 .IX Item "$) and $| also seem to parse as the $ assertion" followed by the relevant meta-character, though I have no documentation reference for this. .ie n .IP """@+"" and ""@\-"" no longer interpolate as of Perl 5.9.4" 4 .el .IP "\f(CW@+\fR and \f(CW@\-\fR no longer interpolate as of Perl 5.9.4" 4 .IX Item "@+ and @- no longer interpolate as of Perl 5.9.4" per \f(CW\*(C`perl594delta\*(C'\fR. Subsequent Perls treat \f(CW\*(C`@+\*(C'\fR as a quantified literal and \f(CW\*(C`@\-\*(C'\fR as two literals, and that is what \f(CW\*(C`PPIx::Regexp\*(C'\fR does. Note that subscripted references to these arrays \fBdo\fR interpolate, and are so parsed by \f(CW\*(C`PPIx::Regexp\*(C'\fR. .IP "Only space and horizontal tab are whitespace as of Perl 5.23.4" 4 .IX Item "Only space and horizontal tab are whitespace as of Perl 5.23.4" when inside a bracketed character class inside an extended bracketed character class, per \f(CW\*(C`perl5234delta\*(C'\fR. Formerly any white space character parsed as whitespace. This change in \f(CW\*(C`PPIx::Regexp\*(C'\fR will be reverted if the change in Perl does not make it into Perl 5.24.0. .IP "Unescaped literal left curly brackets" 4 .IX Item "Unescaped literal left curly brackets" These are being removed in positions where quantifiers are legal, so that they can be used for new functionality. Some of them are gone in 5.25.1, others will be removed in a future version of Perl. In situations where they have been removed, \&\fBperl_version_removed()\fR will return the version in which they were removed. When the new functionality appears, the parse produced by this software will reflect the new functionality. .Sp \&\fB\s-1NOTE\s0\fR that the situation with a literal left curly after a literal character is complicated. It was made an error in Perl 5.25.1, and remained so through all 5.26 releases, but became a warning again in 5.27.1 due to its use in \s-1GNU\s0 Autoconf. Whether it will ever become illegal again is not clear to me based on the contents of \&\fIperl5271delta\fR. At the moment \&\fBperl_version_removed()\fR returns \f(CW\*(C`undef\*(C'\fR, but obviously that is not the whole story, and methods \&\fBaccepts_perl()\fR and \&\fBrequirements_for_perl()\fR were introduced to deal with this complication. .ie n .IP """\eo{...}""" 4 .el .IP "\f(CW\eo{...}\fR" 4 .IX Item "o{...}" is parsed as the octal equivalent of \f(CW\*(C`\ex{...}\*(C'\fR. This is its meaning as of perl 5.13.2. Before 5.13.2 it was simply literal \f(CW\*(Aqo\*(Aq\fR and so on. .PP There are very probably other examples of this. When they come to light they will be documented as producing the modern parse, and the code modified to produce this parse if necessary. .SH "METHODS" .IX Header "METHODS" This class provides the following public methods. Methods not documented here are private, and unsupported in the sense that the author reserves the right to change or remove them without notice. .SS "new" .IX Subsection "new" .Vb 1 \& my $re = PPIx::Regexp\->new(\*(Aq/foo/\*(Aq); .Ve .PP This method instantiates a \f(CW\*(C`PPIx::Regexp\*(C'\fR object from a string, a PPI::Token::QuoteLike::Regexp, a PPI::Token::Regexp::Match, or a PPI::Token::Regexp::Substitute. Honestly, any PPI::Element will work, but only the three Regexp classes mentioned previously are likely to do anything useful. .PP Whatever form the argument takes, it is assumed to consist entirely of a valid match, substitution, or \f(CW\*(C`qr<>\*(C'\fR string. .PP Optionally you can pass one or more name/value pairs after the regular expression. The possible options are: .IP "default_modifiers array_reference" 4 .IX Item "default_modifiers array_reference" This option specifies a reference to an array of default modifiers to apply to the regular expression being parsed. Each modifier is specified as a string. Any actual modifiers found supersede the defaults. .Sp When applying the defaults, \f(CW\*(Aq?\*(Aq\fR and \f(CW\*(Aq/\*(Aq\fR are completely ignored, and \f(CW\*(Aq^\*(Aq\fR is ignored unless it occurs at the beginning of the modifier. The first dash (\f(CW\*(Aq\-\*(Aq\fR) causes subsequent modifiers to be negated. .Sp So, for example, if you wish to produce a \f(CW\*(C`PPIx::Regexp\*(C'\fR object representing the regular expression in .Sp .Vb 5 \& use re \*(Aq/smx\*(Aq; \& { \& no re \*(Aq/x\*(Aq; \& m/ foo /; \& } .Ve .Sp you would (after some help from \s-1PPI\s0 in finding the relevant statements), do something like .Sp .Vb 2 \& my $re = PPIx::Regexp\->new( \*(Aqm/ foo /\*(Aq, \& default_modifiers => [ \*(Aq/smx\*(Aq, \*(Aq\-/x\*(Aq ] ); .Ve .IP "encoding name" 4 .IX Item "encoding name" This option specifies the encoding of the regular expression. This is passed to the tokenizer, which will \f(CW\*(C`decode\*(C'\fR the regular expression string before it tokenizes it. For example: .Sp .Vb 3 \& my $re = PPIx::Regexp\->new( \*(Aq/foo/\*(Aq, \& encoding => \*(Aqiso\-8859\-1\*(Aq, \& ); .Ve .IP "parse parse_type" 4 .IX Item "parse parse_type" This option specifies what kind of parse is to be done. Possible values are \f(CW\*(Aqregex\*(Aq\fR, \f(CW\*(Aqstring\*(Aq\fR, or \f(CW\*(Aqguess\*(Aq\fR. Any value but \f(CW\*(Aqregex\*(Aq\fR is experimental. .Sp As it turns out, I consider parsing non-regexp quote-like things with this class to be a failed experiment, and the relevant functionality is being deprecated and removed in favor of PPIx::QuoteLike. See above for details. .Sp If \f(CW\*(Aqregex\*(Aq\fR is specified, the first argument is expected to be a valid regex, and parsed as though it were. .Sp If \f(CW\*(Aqstring\*(Aq\fR is specified, the first argument is expected to be a valid string literal and parsed as such. The return is still a \&\f(CW\*(C`PPIx::Regexp\*(C'\fR object, but the \&\fBregular_expression()\fR and \fBmodifier()\fR methods return nothing, and the \fBreplacement()\fR method returns the content of the string. .Sp If \f(CW\*(Aqguess\*(Aq\fR is specified, this method will try to guess what the first argument is. If the first argument is a PPI::Element, the guess will reflect the \s-1PPI\s0 parse. But the guess can be wrong if the first argument is a string representing an unusually-delimited regex. For example, \f(CW\*(Aqguess\*(Aq\fR will parse \f(CW"foo"\fR as a string, but Perl will parse it as a regex if preceded by a regex binding operator (e.g. \f(CW\*(C`$x =~ "foo"\*(C'\fR), as shown by .Sp .Vb 1 \& perl \-MO=Deparse \-e \*(Aq$x =~ "foo"\*(Aq .Ve .Sp which prints .Sp .Vb 1 \& $x =~ /foo/u .Ve .Sp under Perl 5.22.0. .Sp The default is \f(CW\*(Aqregex\*(Aq\fR. .IP "postderef boolean" 4 .IX Item "postderef boolean" This option is passed on to the tokenizer, where it specifies whether postfix dereferences are recognized in interpolations and code. This experimental feature was introduced in Perl 5.19.5. .Sp The default is the value of \&\f(CW$PPIx::Regexp::Tokenizer::DEFAULT_POSTDEREF\fR, which is true. When originally introduced this was false, but was documented as becoming true when and if postfix dereferencing became mainstream. The intent to mainstream was announced with Perl 5.23.1, and became official (so to speak) with Perl 5.24.0, so the default became true with PPIx::Regexp 0.049_01. .Sp Note that if \s-1PPI\s0 starts unconditionally recognizing postfix dereferences, this argument will immediately become ignored, and will be put through a deprecation cycle and removed. .IP "strict boolean" 4 .IX Item "strict boolean" This option is passed on to the tokenizer and lexer, where it specifies whether the parse should assume \f(CW\*(C`use re \*(Aqstrict\*(Aq\*(C'\fR is in effect. .Sp The \f(CW\*(Aqstrict\*(Aq\fR pragma was introduced in Perl 5.22, and its documentation says that it is experimental, and that there is no commitment to backward compatibility. The same applies to the parse produced when this option is asserted. Also, the usual caveat applies: if \f(CW\*(C`use re \*(Aqstrict\*(Aq\*(C'\fR ends up being retracted, this option and all related functionality will be also. .Sp Given the nature of \f(CW\*(C`use re \*(Aqstrict\*(Aq\*(C'\fR, you should expect that if you assert this option, regular expressions that previously parsed without error might no longer do so. If an element ends up being declared an error because this option is set, its \f(CW\*(C`perl_version_introduced()\*(C'\fR will be the Perl version at which \f(CW\*(C`use re \*(Aqstrict\*(Aq\*(C'\fR started rejecting these elements. .Sp The default is false. .IP "trace number" 4 .IX Item "trace number" If greater than zero, this option causes trace output from the parse. The author reserves the right to change or eliminate this without notice. .PP Passing optional input other than the above is not an error, but neither is it supported. .SS "new_from_cache" .IX Subsection "new_from_cache" This static method wraps \*(L"new\*(R" in a caching mechanism. Only one object will be generated for a given PPI::Element, no matter how many times this method is called. Calls after the first for a given PPI::Element simply return the same \f(CW\*(C`PPIx::Regexp\*(C'\fR object. .PP When the \f(CW\*(C`PPIx::Regexp\*(C'\fR object is returned from cache, the values of the optional arguments are ignored. .PP Calls to this method with the regular expression in a string rather than a PPI::Element will not be cached. .PP \&\fBCaveat:\fR This method is provided for code like Perl::Critic which might instantiate the same object multiple times. The cache will persist until \*(L"flush_cache\*(R" is called. .SS "flush_cache" .IX Subsection "flush_cache" .Vb 2 \& $re\->flush_cache(); # Remove $re from cache \& PPIx::Regexp\->flush_cache(); # Empty the cache .Ve .PP This method flushes the cache used by \*(L"new_from_cache\*(R". If called as a static method with no arguments, the entire cache is emptied. Otherwise any objects specified are removed from the cache. .SS "capture_names" .IX Subsection "capture_names" .Vb 3 \& foreach my $name ( $re\->capture_names() ) { \& print "Capture name \*(Aq$name\*(Aq\en"; \& } .Ve .PP This convenience method returns the capture names found in the regular expression. .PP This method is equivalent to .PP .Vb 1 \& $self\->regular_expression()\->capture_names(); .Ve .PP except that if \f(CW\*(C`$self\->regular_expression()\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR (meaning that something went terribly wrong with the parse) this method will simply return. .SS "delimiters" .IX Subsection "delimiters" .Vb 2 \& print join("\et", PPIx::Regexp\->new(\*(Aqs/foo/bar/\*(Aq)\->delimiters()); \& # prints \*(Aq// //\*(Aq .Ve .PP When called in list context, this method returns either one or two strings, depending on whether the parsed expression has a replacement string. In the case of non-bracketed substitutions, the start delimiter of the replacement string is considered to be the same as its finish delimiter, as illustrated by the above example. .PP When called in scalar context, you get the delimiters of the regular expression; that is, element 0 of the array that is returned in list context. .PP Optionally, you can pass an index value and the corresponding delimiters will be returned; index 0 represents the regular expression's delimiters, and index 1 represents the replacement string's delimiters, which may be undef. For example, .PP .Vb 2 \& print PPIx::Regexp\->new(\*(Aqs{foo}\*(Aq)\->delimiters(1); \& # prints \*(Aq<>\*(Aq .Ve .PP If the object was not initialized with a valid regexp of some sort, the results of this method are undefined. .SS "errstr" .IX Subsection "errstr" This static method returns the error string from the most recent attempt to instantiate a \f(CW\*(C`PPIx::Regexp\*(C'\fR. It will be \f(CW\*(C`undef\*(C'\fR if the most recent attempt succeeded. .SS "extract_regexps" .IX Subsection "extract_regexps" .Vb 3 \& my $doc = PPI::Document\->new( $path ); \& $doc\->index_locations(); \& my @res = PPIx::Regexp\->extract_regexps( $doc ) .Ve .PP This convenience (well, sort-of) static method takes as its argument a PPI::Document object and returns \f(CW\*(C`PPIx::Regexp\*(C'\fR objects corresponding to all regular expressions found in it, in the order in which they occur in the document. You will need to keep a reference to the original PPI::Document object if you wish to be able to recover the original PPI::Element objects via the PPIx::Regexp::Element \&\fBsource()\fR method. .SS "failures" .IX Subsection "failures" .Vb 1 \& print "There were ", $re\->failures(), " parse failures\en"; .Ve .PP This method returns the number of parse failures. This is a count of the number of unknown tokens plus the number of unterminated structures plus the number of unmatched right brackets of any sort. .SS "max_capture_number" .IX Subsection "max_capture_number" .Vb 2 \& print "Highest used capture number ", \& $re\->max_capture_number(), "\en"; .Ve .PP This convenience method returns the highest capture number used by the regular expression. If there are no captures, the return will be 0. .PP This method is equivalent to .PP .Vb 1 \& $self\->regular_expression()\->max_capture_number(); .Ve .PP except that if \f(CW\*(C`$self\->regular_expression()\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR (meaning that something went terribly wrong with the parse) this method will too. .SS "modifier" .IX Subsection "modifier" .Vb 3 \& my $re = PPIx::Regexp\->new( \*(Aqs/(foo)/${1}bar/smx\*(Aq ); \& print $re\->modifier()\->content(), "\en"; \& # prints \*(Aqsmx\*(Aq. .Ve .PP This method retrieves the modifier of the object. This comes from the end of the initializing string or object and will be a PPIx::Regexp::Token::Modifier. .PP \&\fBNote\fR that this object represents the actual modifiers present on the regexp, and does not take into account any that may have been applied by default (i.e. via the \f(CW\*(C`default_modifiers\*(C'\fR argument to \f(CW\*(C`new()\*(C'\fR). For something that takes account of default modifiers, see \&\fBmodifier_asserted()\fR, below. .PP In the event of a parse failure, there may not be a modifier present, in which case nothing is returned. .SS "modifier_asserted" .IX Subsection "modifier_asserted" .Vb 4 \& my $re = PPIx::Regexp\->new( \*(Aq/ . /\*(Aq, \& default_modifiers => [ \*(Aqsmx\*(Aq ] ); \& print $re\->modifier_asserted( \*(Aqx\*(Aq ) ? "yes\en" : "no\en"; \& # prints \*(Aqyes\*(Aq. .Ve .PP This method returns true if the given modifier is asserted for the regexp, whether explicitly or by the modifiers passed in the \&\f(CW\*(C`default_modifiers\*(C'\fR argument. .PP Starting with version 0.036_01, if the argument is a single-character modifier followed by an asterisk (intended as a wild card character), the return is the number of times that modifier appears. In this case an exception will be thrown if you specify a multi-character modifier (e.g. \f(CW\*(Aqee*\*(Aq\fR), or if you specify one of the match semantics modifiers (e.g. \f(CW\*(Aqa*\*(Aq\fR). .SS "regular_expression" .IX Subsection "regular_expression" .Vb 3 \& my $re = PPIx::Regexp\->new( \*(Aqs/(foo)/${1}bar/smx\*(Aq ); \& print $re\->regular_expression()\->content(), "\en"; \& # prints \*(Aq/(foo)/\*(Aq. .Ve .PP This method returns that portion of the object which actually represents a regular expression. .SS "replacement" .IX Subsection "replacement" .Vb 3 \& my $re = PPIx::Regexp\->new( \*(Aqs/(foo)/${1}bar/smx\*(Aq ); \& print $re\->replacement()\->content(), "\en"; \& # prints \*(Aq${1}bar/\*(Aq. .Ve .PP This method returns that portion of the object which represents the replacement string. This will be \f(CW\*(C`undef\*(C'\fR unless the regular expression actually has a replacement string. Delimiters will be included, but there will be no beginning delimiter unless the regular expression was bracketed. .SS "source" .IX Subsection "source" .Vb 1 \& my $source = $re\->source(); .Ve .PP This method returns the object or string that was used to instantiate the object. .SS "type" .IX Subsection "type" .Vb 3 \& my $re = PPIx::Regexp\->new( \*(Aqs/(foo)/${1}bar/smx\*(Aq ); \& print $re\->type()\->content(), "\en"; \& # prints \*(Aqs\*(Aq. .Ve .PP This method retrieves the type of the object. This comes from the beginning of the initializing string or object, and will be a PPIx::Regexp::Token::Structure whose \f(CW\*(C`content\*(C'\fR is one of 's', \&'m', 'qr', or ''. .SH "RESTRICTIONS" .IX Header "RESTRICTIONS" By the nature of this module, it is never going to get everything right. Many of the known problem areas involve interpolations one way or another. .SS "Ambiguous Syntax" .IX Subsection "Ambiguous Syntax" Perl's regular expressions contain cases where the syntax is ambiguous. A particularly egregious example is an interpolation followed by square or curly brackets, for example \f(CW$foo[...]\fR. There is nothing in the syntax to say whether the programmer wanted to interpolate an element of array \f(CW@foo\fR, or whether he wanted to interpolate scalar \f(CW$foo\fR, and then follow that interpolation by a character class. .PP The \fIperlop\fR documentation notes that in this case what Perl does is to guess. That is, it employs various heuristics on the code to try to figure out what the programmer wanted. These heuristics are documented as being undocumented (!) and subject to change without notice. As an example of the problems even \fIperl\fR faces in parsing Perl, see . .PP Given this situation, this module's chances of duplicating every Perl version's interpretation of every regular expression are pretty much nil. What it does now is to assume that square brackets containing \fBonly\fR an integer or an interpolation represent a subscript; otherwise they represent a character class. Similarly, curly brackets containing \&\fBonly\fR a bareword or an interpolation are a subscript; otherwise they represent a quantifier. .SS "Changes in Syntax" .IX Subsection "Changes in Syntax" Sometimes the introduction of new syntax changes the way a regular expression is parsed. For example, the \f(CW\*(C`\ev\*(C'\fR character class was introduced in Perl 5.9.5. But it did not represent a syntax error prior to that version of Perl, it was simply parsed as \f(CW\*(C`v\*(C'\fR. So .PP .Vb 1 \& $ perl \-le \*(Aqprint "v" =~ m/\ev/ ? "yes" : "no"\*(Aq .Ve .PP prints \*(L"yes\*(R" under Perl 5.8.9, but \*(L"no\*(R" under 5.10.0. \f(CW\*(C`PPIx::Regexp\*(C'\fR generally assumes the more modern parse in cases like this. .SS "Equivocation" .IX Subsection "Equivocation" Very occasionally, a construction will be removed and then added back \*(-- and then, conceivably, removed again. In this case, the plan is for \&\fBperl_version_introduced()\fR to return the earliest version in which the construction appeared, and \&\fBperl_version_removed()\fR to return the version after the last version in which it appeared (whether production or development), or \f(CW\*(C`undef\*(C'\fR if it is in the highest-numbered Perl. .PP The constructions involved in this are: .PP \fIUn-escaped literal left curly after literal\fR .IX Subsection "Un-escaped literal left curly after literal" .PP That is, something like \f(CW\*(C`qr\*(C'\fR. .PP This was made an error in \f(CW5.25.1\fR, and it was an error in \f(CW5.26.0\fR. But it became a warning again in \f(CW5.27.1\fR. The \fIperl5271delta\fR says it was re-instated because the changes broke \s-1GNU\s0 Autoconf, and the warning message says it will be removed in Perl \f(CW5.30\fR. .PP Accordingly, \&\fBperl_version_introduced()\fR returns \f(CW5.0\fR. At the moment \&\fBperl_version_removed()\fR returns \&\f(CW\*(Aq5.025001\*(Aq\fR. But if it is present with or without warning in \f(CW5.28\fR, \&\fBperl_version_removed()\fR will become \&\f(CW\*(C`undef\*(C'\fR. If you need finer resolution than this, see PPIx::Regexp::Element methods l<\fBaccepts_perl()\fR|ppix::regexp::element/accepts_perl> and l<\fBrequirements_for_perl()\fR|ppix::regexp::element/requirements_for_perl> .SS "Static Parsing" .IX Subsection "Static Parsing" It is well known that Perl can not be statically parsed. That is, you can not completely parse a piece of Perl code without executing that same code. .PP Nevertheless, this class is trying to statically parse regular expressions. The main problem with this is that there is no way to know what is being interpolated into the regular expression by an interpolated variable. This is a problem because the interpolated value can change the interpretation of adjacent elements. .PP This module deals with this by making assumptions about what is in an interpolated variable. These assumptions will not be enumerated here, but in general the principal is to assume the interpolated value does not change the interpretation of the regular expression. For example, .PP .Vb 2 \& my $foo = \*(Aqa\-z]\*(Aq; \& my $re = qr{[$foo}; .Ve .PP is fine with the Perl interpreter, but will confuse the dickens out of this module. Similarly and more usefully, something like .PP .Vb 2 \& my $mods = \*(Aqi\*(Aq; \& my $re = qr{(?$mods:foo)}; .Ve .PP or maybe .PP .Vb 2 \& my $mods = \*(Aqi\*(Aq; \& my $re = qr{(?$mods)$foo}; .Ve .PP probably sets a modifier of some sort, and that is how this module interprets it. If the interpolation is \fBnot\fR about modifiers, this module will get it wrong. Another such semi-benign example is .PP .Vb 2 \& my $foo = $] >= 5.010 ? \*(Aq?\*(Aq : \*(Aq\*(Aq; \& my $re = qr{($foo\ew+)}; .Ve .PP which will parse, but this module will never realize that it might be looking at a named capture. .SS "Non-Standard Syntax" .IX Subsection "Non-Standard Syntax" There are modules out there that alter the syntax of Perl. If the syntax of a regular expression is altered, this module has no way to understand that it has been altered, much less to adapt to the alteration. The following modules are known to cause problems: .PP Acme::PerlML, which renders Perl as \s-1XML.\s0 .PP Data::PostfixDeref, which causes Perl to interpret suffixed empty brackets as dereferencing the thing they suffix. .PP Filter::Trigraph, which recognizes \s-1ANSI C\s0 trigraphs, allowing Perl to be written in the \s-1ISO 646\s0 character set. .PP Perl6::Pugs. Enough said. .PP Perl6::Rules, which back-ports some of the Perl 6 regular expression syntax to Perl 5. .PP Regexp::Extended, which extends regular expressions in various ways, some of which seem to conflict with Perl 5.010. .SH "SEE ALSO" .IX Header "SEE ALSO" Regexp::Parsertron, which uses Marpa::R2 to parse the regexp, and Tree for navigation. Unlike \f(CW\*(C`PPIx::Regexp|PPIx::Regexp\*(C'\fR, Regexp::Parsertron supports modification of the parse tree. .PP Regexp::Parser, which parses a bare regular expression (without enclosing \f(CW\*(C`qr{}\*(C'\fR, \f(CW\*(C`m//\*(C'\fR, or whatever) and uses a different navigation model. After a long hiatus, this module has been adopted, and is again supported. .SH "SUPPORT" .IX Header "SUPPORT" Support is by the author. Please file bug reports at , or in electronic mail to the author. .SH "AUTHOR" .IX Header "AUTHOR" Thomas R. Wyant, \s-1III\s0 \fIwyant at cpan dot org\fR .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2009\-2019 by Thomas R. Wyant, \s-1III\s0 .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory \s-1LICENSES.\s0 .PP This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.