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"; } }
In reply to Parsing C Functions.. by jmmistrot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |