|
Posted by DJ Stunks on May 3, 2006, 6:04 pm
Please log in for more thread options
DJ Stunks wrote:
> FangQ wrote:
> > is there a simple way using regular expression to find nested tags?
> >
> > for example, the string is:
> >
> > {{ this is part A of the document
> > {{ this is part A1 }}
> > }}
Allow me to just reply to myself here... :P
I repaired my crummy grammar and posting technique (who would have
thought __END__ would end up in __DATA__?). My grammar now parses and
is shown below (getting there!), now I need to concentrate on getting
the output hash right.
Also, I'm not able to have a { or } in the part_text, which I expect
would be a problem in the real world.... I don't know how to
incorporate Text::Balanced here though....
I'll keep working on it.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Parse::RecDescent;
my $grammar = <<'EO_GRAMMAR';
<autotree>
document : part(s)
part : '{{' part_id part_text part(s?) '}}'
part_id : '{' /[^}]+/ '}'
part_text : /[^{}]+/
EO_GRAMMAR
my $parser = Parse::RecDescent->new($grammar)
or die "Could not parse grammar: $@";
my $document = do {local $/; <DATA>};
my $doc_ref = $parser->document($document)
or die "Invalid document";
print Dumper $doc_ref;
__DATA__
{{ this is part A of the document
{{ this is part A1 }}
}}
-jp
|