1 function jsonT(self, rules) {
5 for (var rule in rules)
6 if (rule.substr(0,4) != "self")
7 rules["self."+rule] = rules[rule];
10 apply: function(expr) {
11 var trf = function(s){ return s.replace(/{([A-Za-z0-9_\$\.\[\]\'@\(\)]+)}/g,
12 function($0,$1){return T.processArg($1, expr);})},
13 x = expr.replace(/\[[0-9]+\]/g, "[*]"), res;
15 if (typeof(rules[x]) == "string")
17 else if (typeof(rules[x]) == "function")
18 res = trf(rules[x](eval(expr)).toString());
24 processArg: function(arg, parentExpr) {
25 var expand = function(a,e){return (e=a.replace(/^\$/,e)).substr(0,4)!="self" ? ("self."+e) : e; },
28 if (arg.charAt(0) == "@")
29 res = eval(arg.replace(/@([A-za-z0-9_]+)\(([A-Za-z0-9_\$\.\[\]\']+)\)/,
30 function($0,$1,$2){return "rules['self."+$1+"']("+expand($2,parentExpr)+")";}));
32 res = T.apply(expand(arg, parentExpr));
34 res = T.eval(parentExpr);
38 eval: function(expr) {
39 var v = eval(expr), res = "";
40 if (typeof(v) != "undefined") {
41 if (v instanceof Array) {
42 for (var i=0; i<v.length; i++)
43 if (typeof(v[i]) != "undefined")
44 res += T.apply(expr+"["+i+"]");
46 else if (typeof(v) == "object") {
48 if (typeof(v[m]) != "undefined")
49 res += T.apply(expr+"."+m);
57 return T.init().apply("self");