Hello Terrence Brannon,Hi Tom,
I just maintain the FAQ. I don't answer all questions about P::RD. Here are two resources:This is an email with a question about Parse::RecDescent. I send to you because your name was mentioned on the faq page as being the author of it. I hope I am right in doing so. If not, please accept my apologies.
The Parse::RecDescent Mailing List http://lists.perl.org/showlist.cgi?name=recdescent
Perlmonks.org: www.perlmonks.org
I have forwarded your email to the former so you might want to join quickly in case someone answers
soon.
I am completely out of touch with practical use of P::RD these days.
Now, the question is: How can I match a single newline in the middle of a rule?
(By the way, I have read these items in the faq list, "NEWLINE PROCESSING", "Parsing Windows Init", (.ini) Files", "As end of line", but I feel my questions does not get answered there).
This example (form "the man(1) of descent page") works: Command: LineRange 'c' LineRange LeftLine(s) "---\n" RightLine(s) { print "$item[3]c$item[1]\n"; print map {s/>/</; $_} @{$item[6]}; print $item[5]; print map {s/</>/; $_} @{$item[4]};}
But this doesn't: Command: LineRange 'c' LineRange LeftLine(s) "\n" RightLine(s) # <-- single newline, without dashes { print "$item[3]c$item[1]\n"; print map {s/>/</; $_} @{$item[6]}; print $item[5]; print map {s/</>/; $_} @{$item[4]};}
Why not? I tried changing it to '\n' and /\n/, and making a new rule newline: "\n" | '\n' \ /\n/ all of which to no avail...
Also, I tried this:
### begin listing ###
use strict; use Parse::RecDescent;
my $grammar = q { AdressenGramm: ValidLine(s)
ValidLine: <skip: qr/[ \t]*/> word newline word { print "Found $item[1], $item[3]\n"; } word: /\w+/ newline: /\n/ };
my $parser1 = new Parse::RecDescent($grammar);
my $text = "word1\nword2";
my $result1 = $parser1->AdressenGramm($text) or warn "Bad input1\n";
### end listing ###
which has this as output: Found \s*,
which was somehow not quite what I expected...
What I really want to have is a rule like this:
SeveralLines: Word "\n" Word "\n" Word { print "found: $item[1], $item[2], $item[3]"; }
Word: /[A-Za-z]+/
which would print found: abc, def, ghi for the input "abc\ndef\nghi";
I hope to have been both elaborate and brief enough...
Thanks!
Kind regards,
Tom