I want to determine how many parameters (top level) a function has, given the String representation of the function. As an example:
(1) assertEquals(verify, actual);
(2) assertEquals("message", actual, verify);
(3) assertEquals(account.addMoney(19, Delivery.fast()).toString(), bank.getAccount(person.getCredentials("basic")).tally(), mock.getData().verify());
Answers should be (1) = 2, (2) = 3, (3) = 3. You may assume I have the function name, e.g. regex on assert.
Basically I can count commas, but I need to take into account function parameters for inner function calls. So
function(param1, param2.data(param3, param4, param5.getData(param6, param7));
Of course the nesting can be arbitrary deep.
I think a regex might do the trick, but my experience with them is insufficient to solve this question.
Please note that I have considered using a lever/parser, but this seems a bit overkill for my intentions. I have a set of functions as strings and my target method invocations are assertion methods.