private static SaveableData parseFunction
(String name, String value, DataRepository r, String prefix)
throws MalformedValueException {
SaveableData result = null;
Perl5Util perl = PerlPool.get();
try {
String isSimpleFunction = "m\n^" + simpleFunction + "$\n";
String containsSimpleFunction = "m\n" + simpleFunction + "\n";
String expression = value.substring(1); // remove initial "!"
expression = perl.substitute("s/\\[\\(/" + FB + "/g", expression);
expression = perl.substitute("s/\\)\\]/" + FE + "/g", expression);
String pre, func, post, tempname;
while (! perl.match(isSimpleFunction, expression)) {
try {
if (!perl.match(containsSimpleFunction, expression))
throw new MalformedValueException
("mismatched parentheses");
} catch (Perl5Util.RegexpException e) {
throw new MalformedValueException(e.toString());
}
pre = perl.preMatch();
func = perl.group(1);
post = perl.postMatch();
tempname = getAnonymousFunctionName();
//r.makeUniqueName(r.anonymousPrefix + "_Function");
try {
parseSimpleFunc(tempname, func, null, r, prefix);
} catch (MalformedValueException e) {
r.removeValue(tempname);
throw e;//new MalformedValueException();
}
expression = pre + tempname + post;
}
expression = perl.group(1);
result = parseSimpleFunc(name, expression, value, r, prefix);
} finally {
PerlPool.release(perl);
}
return result;