Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Parsing balanced parentheses

by I0 (Priest)
on Jul 24, 2006 at 04:53 UTC ( #563188=note: print w/ replies, xml ) Need Help??


in reply to Parsing balanced parentheses

use strict; use warnings; use Data::Dumper; my $contents = qq( create item "xxx" { remove entry "}x{" add entry "yy" "xxx" { item1=xxxx, item2=xxxx, } add diffenent entry "}}xxx" { item1=xxx, item2=xxxx, item3=xxx add subitem { item1=xxx, item2=xxx, item3=xxx } add subitem { item1=xxx, item2=xxx, } } another type { item1=xxx } with "{{xxx" } ); (my $re=$contents)=~s/(({)|(})|"(\\.|[^"\\])*"|.)/@{[')','']}[!$3]\Q$1 +\E@{['(','']}[!$2]/gs; print Dumper(@$=eval{$contents=~/$re/}); die $@ if $@; $re=join"|",map{"\Q$_\E"}@$; print Dumper extract($contents); sub extract{ my $c=shift; my @r; while( $c =~ /(\S.*?)\s*(?:{($re)} *(.*)|$)/mg ){ my($h,$b,$t)=($1,$2,$3); push @r,$b?[$h,extract($b),$t||()]:$h; } return @r?[@r]:$c; }


Comment on Re: Parsing balanced parentheses
Download Code
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 06, 2007 at 16:59 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 13, 2007 at 14:29 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 13, 2007 at 15:50 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 13, 2007 at 21:02 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 14, 2007 at 16:51 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 15, 2007 at 11:51 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 15, 2007 at 18:34 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 15, 2007 at 18:36 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 16, 2007 at 13:22 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 16, 2007 at 13:24 UTC
Reaped: Re^2: Parsing balanced parentheses
by NodeReaper (Curate) on Mar 22, 2007 at 08:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://563188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-07-22 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (113 votes), past polls