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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.