The section content is what between section name and section end.DESCRIPTION = { UK BANK; UN BANK; };
#! /usr/local/bin/perl -sw BEGIN { close STDERR and open STDERR, '>./STDERR' or die $!; } use Parse::RecDescent; #use strict; #use warnings; $::RD_TRACE = 1; $::RD_HINT = 1; #============================================ # GRAMMAR DEFINITION HERE #============================================ my $grammar = q{ Para: <skip: qr{ (?> \s | /\* .*? \*/ | //[^\n]* )* }sx> List(s) /\Z/ |{ use Data::Dumper 'Dumper'; print "$_->[0]\n" for @{$thisparser->{errors}}; exit; } List: 'SECTION_START' SECTION_NAME SECTION_CONTENT(s?) SECTION_END |<error> SECTION_NAME: /\w+/ {print "section name is $item[1]\n";} |<error> SECTION_CONTENT: # HOW TO DO IT??? /.*/ ...SECTION_END ...!SECTION_START {print "section content is $item[1]\n";} |<error> SECTION_END: 'SECTION_END' {print "section END is $item[1]\n";} |<error> }; #============================================ # MAIN PROGRAM STARTS HERE #============================================ my $parse = new Parse::RecDescent ($grammar); my $text = do { local $/; <DATA> }; $parse->Para($text); __DATA__ /***********************************/ /* comment1 */ /***********************************/ SECTION_START BANK001 /* be there */ DESCRIPTION = "US BANK"; SECTION_END /********************************/ /* comment2*/ /********************************/ SECTION_START BANK002 /* no DESCRIPTION here!!! */ SECTION_END /************************************/ /* comment3 */ /************************************/ SECTION_START BANK003 //mutiple-line DESCRIPTION DESCRIPTION = { UK BANK; UN BANK; }; SECTION_END
In reply to PRD parser problem: How to deal with mutiple lines by Hanken
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |