I am trying to make use questions like this one to devise a regexp that will match and give a function name and all parameters in a very simplified Python-like syntax like the following:
mycall(x, y, hello)
with the desired results:
- function name:
mycall - parameter 0:
x - parameter 1:
y - parameter 2:
hello
Of course it should also match noparams(), and any number of parameters. As for my simplifications, I just need parameters names, I don't allow default parameters or something different from a list of comma separated names.
My tries with variants of "(\\s*)([A-Za-z0-9_])+\\(\\)" just to match a function name string with spaces at the beginning are failing, with this code:
std::regex fnregexp(s);
std::smatch pieces_match;
if (std::regex_match(q, pieces_match, fnregexp))
{
std::cout << ">>>> '" << q << "'" << std::endl;
for (size_t i = 0; i < pieces_match.size(); ++i)
{
std::ssub_match sub_match = pieces_match[i];
std::string piece = sub_match.str();
std::cout << " submatch " << i << ": '" << piece << "'" << std::endl;
}
}
I have the following output for " hello()":
>>>> ' hello()'
submatch 0: ' hello()'
submatch 1: ' '
submatch 2: 'o'
With this very basic syntax, is it possible to find name of the function and its parameters?
Cheers!
def foo(param):in Python or calls to that function?def.\w+. First match would be the function name, each other match would be the arguments