Regex Two match C function

by liz (Monsignor) on Aug 13, 2003 at 08:30 UTC

    I don’t think a single regular expression would be the way to go, as that would imply having to read entire source-files into memory.

Given the “cleanness” of the C-code, I would do this with a while loop, iterating one line at a time, and build some logic on top of that.

But maybe you would like to have a look at Doxygen instead.

by Skeeve (Vicar) on Aug 13, 2003 at 08:31 UTC

    Did you already attempt something? Then please display us the efforts you made.

Or do you want us to do your homework? ,-)

by CombatSquirrel (Hermit) on Aug 13, 2003 at 11:27 UTC

    Attempt this:

I am just a little afraid that it will also catch if-blocks and such.

by jai (Sexton) on Aug 14, 2003 at 06:33 UTC

      hi, thanx for the code. actually i came up with the following. I know urs is far better. as u said, it will match attempt, catch blocks and also constructs of type I’d like the monks to give suggestions on optimizations.

    by tbone1 (Monsignor) on Aug 13, 2003 at 13:24 UTC

      I know this is doable, so do it until you get it. (HINT: Think curly braces.) A friend wrote something like this when we worked together at Ameritech. However, that was years ago, and I’ve lost touch with him. I am not about to give away his code without permission. (I’m kinda funny that way.)

    Ain’t enough ‘O’s in ‘stoopid’ to describe that boy.

    by kelan (Deacon) on Aug 13, 2003 at 13:50 UTC

    You’re either going to want to slurp the entire file so you can catch when the comeback type is on a different line, or just write a puny parser, or both. I’ve written puny parsers before using the /\G. /gc method explained in perlop and it isn’t too difficult. Be careful that you distinguish function definitions and function calls or you could run into trouble.

    by CombatSquirrel (Hermit) on Aug 13, 2003 at 15:47 UTC

      If you don’t want the entire file to be slurped in at once

    Hope this helped (and I hope your question was not HW, but for work, documentation or something similar as I suppose it to be).

        Hi, the above code will treat static as part of the come back type. It would be nice if I get an algorithm for extracting comeback type with any number of words. For example ” static inline unsigned int”.

      Knot Type: perlquestion [id://283486]

      No latest polls found

      PerlMonks somehow became entangled with The Perl Foundation.

      Wonderful Web Servers and Bandwidth Generously Provided by pair Networks

      Related movie: Paid dating sites versus free dating sites? by Interracial Dating Central


      Leave a Reply

      Your email address will not be published. Required fields are marked *