Hi!
I am writing a script to parse IDL file and to generate graphviz file from it. I encountered following problem, which I isolated below:
Regexp tries to find 'module <module_name> { content };' text globally (//g) and if found, content is parsed recursively to create nested 'subgraph {}' sequences. Code below hangs. And if I remove innemost parens - it works good. Can anyone enlighten me what can be wrong? I am using this regexp (nested parens) for more than year in several scripts and it works (uhm, worked) perfectly since now.
With 'use warnings;' it prints 'Use of uninitialized value in pattern match (m//)', but it doesn't help me in any way to understand the problem.
Thank for any help.
#!perl $_=join"",<DATA>; sub parse { my ($text) = @_; $nw++; my $parens = qr{(?:[^{}]+?|\{(??{$parens})\})*}x; while($text =~ /module (\w+) \{ ($parens) \};?/gx) { ($name, $content)=($1, $2); # print "[$&]"; print ' 'x$nw, "subgraph $name\n"; print ' 'x$nw, "{\n"; parse($content); print ' 'x$nw, "}\n"; } $nw--; } print "digraph G\n{\n"; parse($_); print "}\n"; __DATA__ module abc { module def { module ghi { }; }; };
In reply to balanced parens regexp hangs - solved by grizzley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |