NAME
Parse::RandGen::Production - Conditions for rule to match (and the action to take if it does)
DESCRIPTION
A Production defines a set of Conditions that must be satisfied for a Rule to match input text. The Production consists of an ordered list of Conditions (subrules, literals, and regexps) that must sequentially match for the Production to match.
A rule matches if any one of its Productions match the input text. In BNF notation, the relationship of Rules and Productions is:
rule1: production1
| production2
| production3
For example:
perlFuncCall: /&?/ identifier '(' argument(s?) ')'
| scalar '->' identifier '(' argument(s?) ')'
The two Productions in this example could respectively match:
"func()", "func(x, y)", or "&func(x)"
"$obj->member()"
The first Production in this example is a list of:
Parse::RandGen::Production->new(
cond => qr/&?/, # Regexp Condition - 0 or 1 '&' characters
cond => "indentifier", # Subrule Condition - exactly 1 "identifier" rule
cond => q{'('}, # Literal Condition - single '(' character
cond => "argument(s?)", # Subrule Condition - 0 or more "argument" rules
cond => ')', # Literal Condition - single ')' character
);
Be aware of the greediness of the underlying parsing mechanism. If a production consists of subsequent conditions, such that the earlier ones can satisfy later ones, then they must be combined into one condition represented by a regular expression. Regular expressions can manage the greediness of their matching in order to get the desired effect.
identifier: /\w*/ /\d/ # The second condition can be met by the first
METHODS
- new
-
Creates a new Production. The arguments are all named pairs. The only required pair is "cond" => condition. The Production can be named with the "name" argument (accessed by the name() accessor).
Any unknown named arguments are treated as user-defined fields. They are stored in the Condition hash ($cond->{}).
Parse::RandGen::Production->new( name => 'request', cond => q{'Request:'}, cond => qr/(\s*\w+\s*[,$]+)/ );
- rule
-
Returns the Parse::RandGen::Rule object that this Production belongs to.
- grammar
-
Returns the Parse::RandGen::Grammar object that this Production belongs to (returns rule()->grammar()).
- check
-
Checks the Production to verify that all subrules can be found in the RandGen.
- conditions
-
Returns a list with the Production's Conditions.
SEE ALSO
Parse::RandGen, Parse::RandGen::Rule, and Parse::RandGen::Condition
AUTHORS
Jeff Dutton