Problem Formulation
I have to extract arguments from function calls with NodeJS.
For example:
`foo0()` => [""]
`foo1(1)` => ["1"]
`foo2(1, "HelloThere")` => ["1", ""HelloThere""]
`foo3(foo1(1), foo2(foo1(1), 2), 3)` => ["foo(1)", "foo2(foo1(1), 2)", 3]
`foo4(
// 123456
foo1(1),
abcdef,
foo2(1, 2) + foo3(1+2, 333, "Hello"),
"nRandom,((,,,Dummy )),, ,, ,Stringn"
)` => ["// 123456n foo1(1)", "abcdef", "foo2(1, 2) + foo3(1+2, 333, "Hello")", ""nRandom,((,,,Dummy )),, ,, ,Stringn"n"]
Attempts
First I have starts with a naive attempt:
>> `foo2(1, "HelloThere")`.split(/s?,s/g)
Array [ "foo2(1", '"HelloThere")' ]
then just take foo2(
and )
beforehand.
But obviously it would not work on more complicated cases:
>> `foo3(foo1(1), foo2(foo1(1), 2), 3)`
Array(4) [ "foo3(foo1(1)", "foo2(foo1(1)", "2)", "3)" ]
After some researches, I found a way to match balanced parentheses
But I am not sure how to use it to separate arguments.
Many thanks for the help.