Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Answer: How do I match/extract a function from a JavaScript file?

by erroneousBollock (Curate)
on Sep 30, 2007 at 17:43 UTC ( #641796=note: print w/ replies, xml ) Need Help??


in reply to Re: How do I match/extract a function from a JavaScript file?
in thread How do I match/extract a function from a JavaScript file?

sub _extract { my ($funct,$Jscript) = @_; my ($round,$curly); $round = qr!\(([^()]*|(??{$round}))*\)!; $curly = qr!\{([^{}]*|(??{$curly}))*\}!; if ($Jscript =~ m!($funct\s*$round\s*$curly)!ms) { print "Matched :\n",$1; } }
err, I can't see where you've matched the function keyword or the function operator anywhere in your code. That would seem to be a prerequisite to parsing out functions from ECMAScript source.

foo (a, b, c) { if (c) { a++; } else { b--; } print "hi"; } fum (d, e, f, g, h) { if (d) { e++; } else { f = g + h; } print "ho"; }
That's not valid EMCAScript.

-David.


Comment on Re: Answer: How do I match/extract a function from a JavaScript file?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-07-26 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls