Until now my parser is able to parse functions with a known parameter number using expressions such as this
<FUNCTION><OPENPAR> son=expression() <COMMA> son1=expression() <CLOSEPAR>
Also, optional parameters can also easily be handled
<FUNCTION><OPENPAR> son=expression() <COMMA> son1=expression() [<COMMA> son2=expression()] <CLOSEPAR>
However, I haven't been able to find documentation regarding the possibility of capturing an unknown number of parameters. My guess is something like this
<FUNCTION><OPENPAR> son=expression() <COMMA> son1=expression() [<COMMA> son2=expression()]+ <CLOSEPAR>
But in this case I don't know how to capture of these multiple parameters should be done.
Any ideas or examples? (or if anyone knows that this is impossible)
Let's say at least one parameter is required. Then, you would need something like:
private X myFunction():
{
X result = new X();
}
{
<FUNCTION>
<OPENPAR>
son=expression() { result.params.add(son); }
( <COMMA> son=expression() { result.params.add(son); } )*
<CLOSEPAR>
{ return result; }
}
To sum up, my approach is to:
If you still need working example, you may find this useful.