in reply to Parsing C Source File Functions.
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 rowTo 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.
But there's many other ways (Super Search for threads on passing parameters) to do it, including mucking directly with @_sub foo { my $self = shift; my $p = {@_}; my $name = $p->{name} or die; my $value = $p->{value} || 123; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing C Source File Functions.
by Ace128 (Hermit) on Oct 21, 2006 at 16:20 UTC |