Regularity for parsing list of javascript functions

There is a piece of javascript code in the view:

function funname (p1, p2, p3)
{
...
}

funname2 function (p1, p2, p3)
{
...
}

etc.

It is necessary to allocate separately the function name, parameters and body.
Moreover, we must note that in the body can also be functions explicitly, or circuit, i.e., javascript in all their charms.
The option of counting the braces do not offer. :-)
October 8th 19 at 03:56
3 answers
October 8th 19 at 03:58
Here's a good post on the topic:
blog.stevenlevithan.com/archives/regex-recursion

But remember that sometimes braces can occur in the literals.
I think the only absolute correct solution is to use a parser and not regexes. But in simple cases could ride a way from the article.
Actually, just because of literals and a problem arises with the calculation. - rosendo.Rolfson71 commented on October 8th 19 at 04:01
Well, then, because there is little left, right? It appears that you are trying to write a complete parser for regexps :) Why not use ready? - Magnolia.Haag52 commented on October 8th 19 at 04:04
Not sure what you call ready-made parser? The finished engine type V8, Rhino, etc.?
I think it's a little cumbersome, I have no problem to execute the script.
If you mean something else, then, please, explain. Thanks in advance. - rosendo.Rolfson71 commented on October 8th 19 at 04:07
October 8th 19 at 04:00
Highlight
function — will be always
funcName — might not be (?)
funcParams — they take one piece and then disassemble
The problem is not in the header and in the body of the function. - rosendo.Rolfson71 commented on October 8th 19 at 04:03
Yes, and the elephant that I didn't notice =) I wrote these things not by the regular season and counted the characters (I did the highlighting of rows allocated this way) - Magnolia.Haag52 commented on October 8th 19 at 04:06
Yes, I too think that you have to calculate the given literal - rosendo.Rolfson71 commented on October 8th 19 at 04:09
October 8th 19 at 04:02
Functions can be defined in another way:

var name = function (a1, a2, a3) {};
this.name = function (a1, a2, a3) {};
var klass = {
method1: function (a1, a2, a3) {};
}
function createFunction() {
return function (a1, a2, a3) {};
}

So stupid parser for regexps won't help. Write a smart, contextually. Too lazy to write? Scratched jsLint, there he converts text on the JavaScript AST. Also, I saw somewhere a PHP library for tokenization of JavaScript.

Find more questions by tags Regular expressionsJavaScript