Hello,
I am trying to learn RecDescent. I found an example in the archive of this
mailing list that was close to what I want to do. The subject line of the
thread was:
Line contination characters
Damian gave the solution I am studying. I have attached it at the bottom. I
don't understand the section between the {{ }}. For example:
{ {command => $item[-1]} }
>From tests, I know that $item[-1] matches the line (or multiline} command or
comment. What I don't understand is the:
command => $item[-1]
Is this an array that stores all the commands/comments? If yes, how do I
access this variable. I tried:
print "@command \n";
and
print "$command \n";
but both gave errors.
I would appreciate it if someone would email me a tutorial that explains
this.
Thanks,
jr
Here is Damian's solution.
-----------cut-----------cut-----------cut-----------cut-----------cut------
----
use Parse::RecDescent;
my @lines = << 'EOINST';
// COMMAND ARG1-VALUE,ARG2-VALUE, +
ARG3-VALUE,ARG4-VALUE, +
EVEN-MORE-ARGS
// ANOTHERCOMMAND
* and a comment
* or two
EOINST
my $parse = Parse::RecDescent->new(join '', <DATA>) or die "Bad Grammar!";
use Data::Dumper 'Dumper';
print Dumper [
$parse->Instructions("@lines") or die "NOT parsable!!\n"
];
__DATA__
Instructions: command(s)
command: multiline_command
| singleline_command
| comment
singleline_command:
'//' /.*/
{ {command => $item[-1]} }
multiline_command:
'//' /(.*?[+][ \t]*\n)+.*/
{ $item[-1] =~ s/[+][ \t]*\n//g; {command => $item[-1]} }
comment:
'*' /.*/
{ {comment => $item[-1]} }