Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Parsing C Source File Functions.

by davidrw (Prior)
on Oct 21, 2006 at 16:07 UTC ( [id://579771]=note: print w/replies, xml ) Need Help??


in reply to Parsing C Source File Functions.

i think the inner block would be much clearer and short as something like this (note also that $a and $b should be avoided because of their use by sort):
foreach (@FILE_ARRAY){ next unless /^(?:([0-9_a-zA-Z*]+) +)?(?:([0-9_a-zA-Z*]+) +)?(?:([0-9 +_a-zA-Z*]+) +)?([0-9_a-zA-Z*]+)\((.+?)\)/; my ($args, @definition) = map { defined($_)?$_:'' } $5, $1, $2, $3, +$3; print join(" ", @definition) . " ARGS: $args\n"; }

This only works with parsing one row
To workaround this, you need to slurp in either the whole file, or maybe just one function (maybe defined by /^}$/ ?? not going to be 100%) at a time.. Then your regex can use the /s modifier and span multiple lines and you'll want to change all the spaces in the regex to \s+

Later Im gonna add for parsing Perl scripts aswell, but that is alot easier.
easier? really? There is PPI, but there's set way to pass parameters into a function ... e.g.
sub foo { my $self = shift; my $p = {@_}; my $name = $p->{name} or die; my $value = $p->{value} || 123; }
But there's many other ways (Super Search for threads on passing parameters) to do it, including mucking directly with @_

Replies are listed 'Best First'.
Re^2: Parsing C Source File Functions.
by Ace128 (Hermit) on Oct 21, 2006 at 16:20 UTC
    Forgot to mention that for the Perl part I may not care about the arguments the same way... unless using this PPI is smart and I can get some interesting data from it which I can use with the ND. :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-23 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found