Actions
- Actions look like standard Perl blocks.
- Inside the actions, Parse::RecDescent will supply
several variables for us:
- @item:
This is a list with the return values of all the matched
items in the current production. $item[0] is
the name of the current rule.
Compare the use of $1, $2 in a
yacc grammar.
- %item:
This provides named access to the items that are already
matched in the current production. Items are named after the
subrules they match; other items have a number as key, the
number that corresponds with the number in the
@items array.
- $return. If an assignment to
$return is made in a production and
the production succeeds, $return is returned
instead of the value of the last item.
Compare the use of $$ in a yacc grammar.
- $text. The remaining of the unparsed text.
You may assign to this - if the production fails, any changes
to $text don't propagate out - but they do if the
production succeeds.
- $thisline, $prevline, $thiscolumn, $prevcolumn,
$thisoffset, $prevoffset:
these variables give information on where in the text the
parser is. This can be useful for error messages.
- $thisparser. A reference to the
current parser object. For deep magic, assign to this
variable and switch to a different parser for the remainer
of the current rule...
- $thisrule, $thisprod.
References to objects representing the current rule and
current production.
If you need scribble space in these variables, use
$this...->{local}.
- And more...
- Startup actions are performed before attempting to match the
first rule. Startup actions are found in the grammar before
the definition of the first rule. Typical usuage is to initialize
variables.
[Prev]
[Next]
[Index]