jmmistrot has asked for the wisdom of the Perl Monks concerning the following question:
So I think I have the regex to parse the function signature: /\s*((?:\S+\s+){0,3})(?:(\S+)\(\s*((?:\S+\s+\S+)*)\s*\))\s*/ I want to remove each complete function from the file as I go so that I can come back for a second pass to grab all globally scoped variables in the C code. My problem is advancing the file keeping track of nesting to know when I have left the function. As you may be aware there is no rule the requires the C code function definition or its scoping delimiters "{" and "}" to be on one line. I consider myself an intermediate regex acolyte and am sure that there is an easy way to do this but I have yet to stumble upon it. It seems to me I am unable to use a replace to slurp up the function cause I don't know the depth of the delimiter nesting. I cant come up with an expression to handle arbitrary cases in a replace anyway... I have tried removing all newlines, running through the file that way.. I can successfully grab the function signature but have yet to figure out a way to know when I have passed by the end of the function. Any "perls" of wisdom greatly appreciated.. Your humble student, -jmmfloat myFunction(float myfunc_arg0, float myfunc_arg1 ) { if(myfunc_arg0>1){ print "arg0 action\n"; } elsif(myfunc_arg1){ print "arg1 action\n"; } else{ print "take no action\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing C Functions..
by chromatic (Archbishop) on Apr 27, 2008 at 19:55 UTC | |
|
Re: Parsing C Functions..
by Your Mother (Archbishop) on Apr 27, 2008 at 19:56 UTC | |
by Starky (Chaplain) on Apr 28, 2008 at 11:59 UTC | |
by dcd (Scribe) on Apr 29, 2008 at 03:42 UTC | |
|
Re: Parsing C Functions..
by pc88mxer (Vicar) on Apr 27, 2008 at 20:02 UTC | |
|
Re: Parsing C Functions.. (tokens)
by tye (Sage) on Apr 28, 2008 at 04:55 UTC | |
|
Re: Parsing C Functions..
by pc88mxer (Vicar) on Apr 27, 2008 at 20:39 UTC | |
|
Re: Parsing C Functions..
by jmmistrot (Sexton) on Apr 27, 2008 at 20:17 UTC | |
|
Re: Parsing C Functions..
by syphilis (Archbishop) on Apr 27, 2008 at 23:41 UTC |