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: \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 | SECTION_NAME: /\w+/ {print "section name is $item[1]\n";} | SECTION_CONTENT: # HOW TO DO IT??? /.*/ ...SECTION_END ...!SECTION_START {print "section content is $item[1]\n";} | SECTION_END: 'SECTION_END' {print "section END is $item[1]\n";} | }; #============================================ # MAIN PROGRAM STARTS HERE #============================================ my $parse = new Parse::RecDescent ($grammar); my $text = do { local $/; }; $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