I've looked and looked and tried it myself many times but I'm failing miserebly. Here is a problem. Say I have a line of JS code that looks like this:
var someVar = myValue; object.subobject.function(with, some = obj.func(a, b[2][1]), arguments); return true;
I'm developing code hints that should show the definition of the function that I keep in a separate file. To get the definition I need to get the name of the function - in this case just the word function
I already have the code that splits the line into two parts: Left (left of the caret) and Right (right of the caret). They I plan to parse those with RegEx and combine them to get the full function call.
If the caret is anywhere before the word function i should get nothing. If it is anywhere after the ) after the word arguments i should get nothing. if the caret is anywhere within those boudaries I sould get the word function - that is the end result I'm after.
However... since I'm splitting the text into left and right parts (needed in case there are more valid function calls in one like and the other function call is not a parameter within some other function call) here are potential Left and Right parts (top and bottom before the //or) of the string being processed (always just one line) by RegEx:
var someVar = myValue; object.subob
ject.function(with, some = obj.func(a, b[2][1]), arguments); return true;
// or
var someVar = myValue; object.subobject.function(with, some = obj.fu
nc(a, b[2][1]), arguments); return true;
// or
var someVar = myValue; object.subobject.funct
ion(with, some = obj.func(a, b[2][1]), arguments); return true;
// and so on
In the two last cases, after the RegEx is done i should have the Left and Right to be equal function(with, some = obj.fu and nc(a, b[2][1]), arguments), or funct and ion(with, some = obj.func(a, b[2][1]), arguments)
Then my plan is to combine the Left and Right to produce function(with, some = obj.func(a, b[2][1]), arguments) which I will then check with another RegEx to see if it's a valid function call, and if it is process it with another to get the word before the (.
I could really use some assistance for developing the RegEx for Left and Right... the rest I have already made. I'm developing this in AutoHotkey to process JavaScript code. Don't even ask me why...