Page 1 of 1

extract method arguments

Posted: Mon Jan 15, 2007 1:49 pm
by eriko
Hi

I have a string in the following format

function(arg1,arg2,arg3)

the arguments are simple [\w\d]+ but i cant find a simple way to extract them because of the comma

Any clues?

Posted: Mon Jan 15, 2007 1:55 pm
by feyd

Posted: Tue Jan 16, 2007 4:06 am
by eriko
That is not enough since an argument can be another function thus explode splits the string in a bad way.

func(func(A,B), B)

with explode

func(A
B)
B

i want

func(A,B)
B

Posted: Tue Jan 16, 2007 2:54 pm
by feyd
Unfortunately regular expressions don't handle recursion well. No matter what you will have to analyze the output.

Posted: Wed Jan 17, 2007 9:18 am
by Mordred
You have to build a tokenizer for your language, parsing recursive syntax trees with regular expressions won't do, as feyd pointed out.
What are you trying to accomplish, isn't there an easier way to do it? If you need a "scripting" language, why not use PHP itself?