I have specific built in functions where admins can execute through a website. For simplicity let’s pretend there are only 2 functions which are:
1) func1 "requires 2 paramters"
2) func2 "requires 3 paramters"
so I have a textbox where users can enter stuff like: I use ‘;’ to separate the parameters
func1 x; y; // func1(x,y) is more understandable. func1 takes two parameters
or
func2 1; 2+2; 4; // note that func2 takes 3 parameters...
or even more complicated nested functions such as;
func2 x; func1 a; b; ; z ; // for example in this example 1st parameter = x
2nd parameter = func1 a; b; // note this is a function
3rd parameter = z
with the help of jquery I can take advantage of it’s intellecence/autocomplete functions to make sure I type the name of the functions correctly.
now here is where I am stuck
I will like to inform to the user if he is missing to pass parameters on each function.
for example if the user types:
func2 x; y;
then I will like to inform him that func2 is missing a parameter.
I know that will be eassy the problem is if the user types something like:
func2 x; func1 a; b; ; z ;
I have managed to solve this with c#. It is very eassy. the way I do it is by start looking for functions from right to left. so if I do so the first function that I will find is func1 right? then I will more right until I find two ;’s if I replace that then I will have: func2 x; <temp> ; z ; note I replaced func1 a; b; with then I can continue doing the same thing and I will then find func2 and select until the 3rd ;’s
the problem is that if I create a regular expresion I don’t know how to start looking from right to left. If I were to start looking from left to right like it is the default then func2 will have it’s first paramter = x, it’s second paramter = func1 a, and it’s 3rd parameter = b. and that is not the case. If on the other hand I start doing the same thing from right to left everything works out.
So the hard part is going right to left? Use split regex and then reverse
Example of function with incorrect number of parameters: http://jsfiddle.net/tHcYM/1/