Difference between revisions of "User:Zocky"

From Culture.si
Line 1: Line 1:
{{#data:grid
+
{
|country = Event.Country
+
function OP(h,t,opc,valc) {
|year = date_part('year',Event.Start)
+
    if (!t.length) return h;
|events = count(Event.#)
+
    opc = opc || 1;
|#groupby = year, country
+
        valc = valc || 3;
|#orderby = year, country
+
        var ret =  [h];
|#limit = 1000
+
        t.forEach(function(n) {
}}
+
        ret.push(n[opc]);
 
+
        ret.push(n[valc]);
 
+
        })
{{#data:grid
+
        return ret;
|category = Event.Tag
+
    }
|year = date_part('year',Event.Start)
+
    function EVAL(nodes,ctx) {
|events = count(Event.#)
+
        if (!Array.isArray(nodes)) return nodes;
|#groupby = year, category
+
    var acc = EVAL(nodes[0],ctx);
|#orderby = year, category
+
        for (var i = 1; i<nodes.length;) {
|#limit = 1000
+
        var op = nodes[i++];
}}
+
            console.log(acc,op);
 +
            switch (op) {
 +
            case '+': acc+=EVAL(nodes[i++],ctx); break;
 +
            case '-': acc-=EVAL(nodes[i++],ctx); break;
 +
            case '*': acc*=EVAL(nodes[i++],ctx); break;
 +
            case '/': acc/=EVAL(nodes[i++],ctx); break;
 +
            case '%': acc%=EVAL(nodes[i++],ctx); break;
 +
            case '$': acc=ctx[acc]; break;
 +
            case '=': acc = ctx[acc] = EVAL(nodes[i++],ctx);; break;
 +
            case ';':
 +
            case ',': acc=EVAL(nodes[i++],ctx); break;
 +
           
 +
            }
 +
        }
 +
        return acc;
 +
    }
 +
}
 +
program = e:statements { return [EVAL(e,{a:3}),!e];}
 +
statements = h:statement t:(_ ';' _ statement)* ';'? { return OP(h,t)}
 +
statement = assign/expr
 +
assign = n:ident _ "=" _ e:expr { return [n,'=',e] }
 +
expr = addsub
 +
addsub = h:muldiv t:( _ [+-] _ muldiv)* { return OP(h,t)}
 +
muldiv = h:atom t:( _ [*/%] _ atom)* { return OP(h,t)}
 +
atom = path/number/brackets
 +
brackets = _ "(" _ e:expr _ ")" _ { return e}
 +
path = h:head t:( _ [.] _ key)* { return OP(h,t)}
 +
head = i:ident { return [i,'$']; }/brackets
 +
key = ident/digits/brackets
 +
number = n:$( d:digits ('.' digits)? ([Ee] digits)?) { return Number(n);}
 +
digits = [0-9]+
 +
ident = $([A-Z_]i [A-Z0-9_]i*)
 +
_ = [ \n\r\t]*
 +
__ = [ \n\r\t]+

Revision as of 01:46, 23 August 2016

{ function OP(h,t,opc,valc) {

   	if (!t.length) return h;
   	opc = opc || 1;
       valc = valc || 3;
       var ret =  [h];
       t.forEach(function(n) {
       	ret.push(n[opc]);
       	ret.push(n[valc]);
       })
       return ret;
   }
   function EVAL(nodes,ctx) {
       if (!Array.isArray(nodes)) return nodes;
   	var acc = EVAL(nodes[0],ctx);
       for (var i = 1; i<nodes.length;) {
       	var op = nodes[i++];
           console.log(acc,op);
           switch (op) {
           case '+': acc+=EVAL(nodes[i++],ctx); break;
           case '-': acc-=EVAL(nodes[i++],ctx); break;
           case '*': acc*=EVAL(nodes[i++],ctx); break;
           case '/': acc/=EVAL(nodes[i++],ctx); break;
           case '%': acc%=EVAL(nodes[i++],ctx); break;
           case '$': acc=ctx[acc]; break;
           case '=': acc = ctx[acc] = EVAL(nodes[i++],ctx);; break;
           case ';':
           case ',': acc=EVAL(nodes[i++],ctx); break;
           	
           }
       }
       return acc;
   }

} program = e:statements { return [EVAL(e,{a:3}),!e];} statements = h:statement t:(_ ';' _ statement)* ';'? { return OP(h,t)} statement = assign/expr assign = n:ident _ "=" _ e:expr { return [n,'=',e] } expr = addsub addsub = h:muldiv t:( _ [+-] _ muldiv)* { return OP(h,t)} muldiv = h:atom t:( _ [*/%] _ atom)* { return OP(h,t)} atom = path/number/brackets brackets = _ "(" _ e:expr _ ")" _ { return e} path = h:head t:( _ [.] _ key)* { return OP(h,t)} head = i:ident { return [i,'$']; }/brackets key = ident/digits/brackets number = n:$( d:digits ('.' digits)? ([Ee] digits)?) { return Number(n);} digits = [0-9]+ ident = $([A-Z_]i [A-Z0-9_]i*) _ = [ \n\r\t]* __ = [ \n\r\t]+