Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Regex to pull out string within parenthesis that could contain parenthesis

by sundialsvc4 (Abbot)
on Jul 09, 2018 at 19:55 UTC ( #1218187=note: print w/replies, xml ) Need Help??


in reply to Regex to pull out string within parenthesis that could contain parenthesis

Another possibility to consider is Parse::RecDescent or something along those lines – a true parser.   You can write your grammar so that it looks for function declarations and ignores everything else, and now the solution is truly generalized.   When, inevitably, a programmer did something that your current crop of regular-expressions didn’t recognize (if you caught it), you would find yourself maybe going through more-and-more calisthenics.   Whereas a parser avoids all that.

I have personal experience with this.   In a past life, I concocted a system that parsed a mess of SAS® source-files, Korn(!) shell scripts, and Tivoli job-files, to construct a data-flow picture of what this old application was actually doing.   Parse::RecDescent frankly astounded me with its ability to do so much of the job “with speed, grace, and style.”   I had prior experience with other parsers based on Bison and Yacc (which are also supported through Perl ...), but this was considerably more flexible, allowing me to write grammars to zero-in on what I needed out of the files without having to create a grammar for all of its irrelevant-to-me twists and turns.

As the system I was building became more visible, its requirements expanded several times.   But, thanks to the parser and my experience with it at that time, I was able to accommodate those new requests without major re-design.   That positively sold me on it, hence my suggestion.

  • Comment on Re: Regex to pull out string within parenthesis that could contain parenthesis

Replies are listed 'Best First'.
Re^2: Regex to pull out string within parenthesis that could contain parenthesis
by AnomalousMonk (Bishop) on Jul 09, 2018 at 21:17 UTC
    Another possibility to consider is Parse::RecDescent or something along those lines – a true parser. ... When ... your current crop of regular-expressions didn’t recognize [something], you would find yourself maybe going through more-and-more calisthenics. Whereas a parser avoids all that.

    I tend to agree that a real parser is a better, certainly a more general and scalable, solution than a regex approach.

    I have personal experience with this. ... I concocted a system that parsed a mess of [stuff] ... Parse::RecDescent frankly astounded me ... I had prior experience with other parsers ..., but this was considerably more flexible, allowing me to write grammars ...

    The OPed problem definition is pretty limited and seems fairly well defined. Would you care to supply an SASE | SSCCE (update: I don't know why I thought a Self-Addressed Stamped Envelope would be helpful here :) for a parser approach that would address this problem? I think such an example would certainly add to the discussion.


    Give a man a fish:  <%-{-{-{-<

      A reply falls below the community's threshold of quality. You may see it by logging in.
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2019-12-15 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?