PPR
view release on metacpan or search on metacpan
(?>(?&PerlParenthesesList)) (?>(?&PerlOWS))
(?&PerlBlock)
)*+
(?:
(?>(?&PerlOWS))
(?>(?&PerlPodSequence))
else \b (?>(?&PerlOWS))
(?&PerlBlock)
)?+
| # Loops...
(?>
for(?:each)?+ \b
(?>(?&PerlOWS))
(?:
(?> # Explicitly aliased iterator variable...
(?> \\ (?>(?&PerlOWS)) (?> my | our | state )
| (?> my | our | state ) (?>(?&PerlOWS)) \\
)
(?>(?&PerlOWS))
(?> (?&PerlVariableScalar)
| (?&PerlVariableArray)
| (?&PerlVariableHash)
)
|
# List of scalar iterator variables...
my (?>(?&PerlOWS))
\( (?>(?&PerlOWS))
(?>(?&PerlVariableScalar)) (?>(?&PerlOWS))
(?: , (?>(?&PerlOWS))
(?>(?&PerlVariableScalar)) (?>(?&PerlOWS))
)*+
(?: , (?>(?&PerlOWS)) )?+
\)
|
# Implicitly aliased iterator variable...
(?> (?: my | our | state ) (?>(?&PerlOWS)) )?+
(?&PerlVariableScalar)
)?+
(?>(?&PerlOWS))
(?> (?&PerlParenthesesList) | (?&PerlQuotelikeQW) )
|
(?&PPR_three_part_list)
)
|
(?> while | until) \b (?>(?&PerlOWS))
(?&PerlParenthesesList)
)
(?>(?&PerlOWS))
(?>(?&PerlBlock))
(?:
(?>(?&PerlOWS)) continue
(?>(?&PerlOWS)) (?&PerlBlock)
)?+
| # Phasers...
(?> BEGIN | END | CHECK | INIT | UNITCHECK | ADJUST ) \b (?>(?&PerlOWS))
(?&PerlBlock)
| # Try/catch/finallys...
(?>(?&PerlTryCatchFinallyBlock))
| # Defers...
defer (?>(?&PerlOWS))
(?&PerlBlock)
| # Switches...
(?> given | when ) \b (?>(?&PerlOWS))
(?>(?&PerlParenthesesList)) (?>(?&PerlOWS))
(?&PerlBlock)
|
default (?>(?&PerlOWS))
(?&PerlBlock)
)
) # End of rule (?<PerlControlBlock>)
(?<PerlFormat>
format
(?: (?>(?&PerlNWS)) (?&PerlQualifiedIdentifier) )?+
(?>(?&PerlOWS)) = [^\n]*+
(?&PPR_newline_and_heredoc)
(?:
(?! \. \n )
[^\n\$\@]*+
(?:
(?>
(?= \$ (?! \s ) ) (?&PerlScalarAccessNoSpace)
|
(?= \@ (?! \s ) ) (?&PerlArrayAccessNoSpace)
)
[^\n\$\@]*+
)*+
(?&PPR_newline_and_heredoc)
)*+
\. (?&PerlEndOfLine)
) # End of rule (?<PerlFormat>)
(?<PerlStatementModifier>
(?> if | for(?:each)?+ | while | unless | until | when )
\b
(?>(?&PerlOWS))
(?&PerlExpression)
) # End of rule (?<PerlStatementModifier>)
(?<PerlBlock>
\{ (?>(?&PerlStatementSequence)) \}
) # End of rule (?<PerlBlock>)
(?<PerlCall>
(?>
[&] (?>(?&PerlOWS))
(?> (?&PerlBlock)
| (?&PerlVariableScalar)
| (?&PerlQualifiedIdentifier)
) (?>(?&PerlOWS))
(?:
\( (?>(?&PerlOWS))
"internal-use-only" rules have names that start with C<PPR_>...
=head3 C<< (?&PerlDocument) >>
Matches a valid Perl document, including leading or trailing
whitespace, comments, and any final C<__DATA__> or C<__END__> section.
This rule is context-free, so it can be embedded in a larger regex.
For example, to match an embedded chunk of Perl code, delimited by
C<<<< <<< >>>>...C<<<< >>> >>>>:
$src = m{ <<< (?&PerlDocument) >>> $PPR::GRAMMAR }x;
=head3 C<< (?&PerlEntireDocument) >>
Matches an entire valid Perl document, including leading or trailing
whitespace, comments, and any final C<__DATA__> or C<__END__> section.
This rule is I<not> context-free. It has an internal C<\A> at the beginning
and C<\Z> at the end, so a regex containing C<(?&PerlEntireDocument)>
will only match if:
=over
=item (a)
the C<(?&PerlEntireDocument)> is the sole top-level element of the regex
(or, at least the sole element of a single top-level C<|>-branch of the regex),
=item B<I<and>>
=item (b)
the entire string being matched contains only a single valid Perl document.
=back
In general, if you want to check that a string consists entirely of
a single valid sequence of Perl code, use:
$str =~ m{ (?&PerlEntireDocument) $PPR::GRAMMAR }
If you want to check that a string I<contains> at least one valid sequence
of Perl code at some point, possibly embedded in other text, use:
$str =~ m{ (?&PerlDocument) $PPR::GRAMMAR }
=head3 C<< (?&PerlStatementSequence) >>
Matches zero-or-more valid Perl statements, separated by optional
POD sequences.
=head3 C<< (?&PerlStatement) >>
Matches a single valid Perl statement, including: control structures;
C<BEGIN>, C<CHECK>, C<UNITCHECK>, C<INIT>, C<END>, C<DESTROY>, or
C<AUTOLOAD> blocks; variable declarations, C<use> statements, etc.
=head3 C<< (?&PerlExpression) >>
Matches a single valid Perl expression involving operators of any
precedence, but not any kind of block (i.e. not control structures,
C<BEGIN> blocks, etc.) nor any trailing statement modifier (e.g.
not a postfix C<if>, C<while>, or C<for>).
=head3 C<< (?&PerlLowPrecedenceNotExpression) >>
Matches an expression at the precedence of the C<not> operator.
That is, a single valid Perl expression that involves operators above
the precedence of C<and>.
=head3 C<< (?&PerlAssignment) >>
Matches an assignment expression.
That is, a single valid Perl expression involving operators above the
precedence of comma (C<,> or C<< => >>).
=head3 C<< (?&PerlConditionalExpression) >> or C<< (?&PerlScalarExpression) >>
Matches a conditional expression that uses the C<?>...C<:> ternary operator.
That is, a single valid Perl expression involving operators above the
precedence of assignment.
The alterative name comes from the fact that anything matching this rule
is what most people think of as a single element of a comma-separated list.
=head3 C<< (?&PerlBinaryExpression) >>
Matches an expression that uses any high-precedence binary operators.
That is, a single valid Perl expression involving operators above the
precedence of the ternary operator.
=head3 C<< (?&PerlPrefixPostfixTerm) >>
Matches a term with optional prefix and/or postfix unary operators
and/or a trailing sequence of C<< -> >> dereferences.
That is, a single valid Perl expression involving operators above the
precedence of exponentiation (C<**>).
=head3 C<< (?&PerlTerm) >>
Matches a simple high-precedence term within a Perl expression.
That is: a subroutine or builtin function call; a variable declaration;
a variable or typeglob lookup; an anonymous array, hash, or subroutine
constructor; a quotelike or numeric literal; a regex match; a
substitution; a transliteration; a C<do> or C<eval> block; or any other
expression in surrounding parentheses.
( run in 1.639 second using v1.01-cache-2.11-cpan-39bf76dae61 )