MediaWiki:Skin/Projekt:Adventure2/parser/raw: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) |
J* (Diskussion | Beiträge) |
||
Zeile 48: | Zeile 48: | ||
ConditionFunction | ConditionFunction | ||
− | = 'page' L p:Page R {return function( | + | = 'page' L p:Page R {return function(){return a2.cpage == p};} |
− | / 'any' L a:ConditionArgs R {return function( | + | / 'any' L a:ConditionArgs R {return function(){for(var j=0; j<a.length; j++) if (a[j]()) return true; return false; }} |
− | / 'have' L i:Item R {return function( | + | / 'all' L a:ConditionArgs R {return function(){for(var j=0; j<a.length; j++) if (!a[j]()) return false; return true; }} |
+ | / 'not' L f:ConditionFunction R {return function(){ return !f()};} | ||
+ | / 'have' L i:Item R {return function(){return !!a2.items[i]};} | ||
ConditionArgs | ConditionArgs | ||
Zeile 64: | Zeile 66: | ||
ActionFunction | ActionFunction | ||
− | = f:'goto' L p:Page R {return function( | + | = f:'goto' L p:Page R {return function(){a2.util.goto(p)};} |
− | / f:'add' L i:Item R {return function( | + | / f:'add' L i:Item R {return function(){a2.util.add(i)};} |
− | / f:'remove' L i:Item R {return function( | + | / f:'remove' L i:Item R {return function(){a2.util.remove(i)};} |
− | / f:'print' L s:String R {return function( | + | / f:'print' L s:String R {return function(){a2.util.print(s)};} |
− | / f:'die' L s:String R {return function( | + | / f:'die' L s:String R {return function(){a2.util.die(s)};} |
L | L |
Version vom 7. Juli 2012, 12:30 Uhr
/* * A2 event syntax parser using pegjs * http://pegjs.majda.cz/online */ start = Event Event = S? 'event' n:(S Identifier)? CC sc:ScopeClause tr:TriggerClause co:ConditionClause? ac:ActionClause? 'end.' S? { return {name:n?n[1]:"<anonymous>", scope:sc, trigger:tr, condition:(co?co:function(){return true;}), action:(ac?ac:function(){return true;})}; } ScopeClause = 'in' S sc:Scope CC {return sc;} TriggerClause = 'on' S S? tr:TriggerFunctions CC {return tr;} TriggerFunctions = t:TriggerFunction C o:TriggerFunctions {o.push(t); return o;} / t:TriggerFunction {return [t];} TriggerFunction = t:TriggerPageOp L a:Page R {return t+"."+a;} / t:TriggerIdentOp L a:Identifier R {return t+"."+a;} / t:TriggerBinaryOp L a:Identifier C b:Identifier R {return [t,a,b].join(".")} TriggerPageOp = 'enter' / 'leave' TriggerIdentOp = 'add' / 'remove' / 'activate' / 'click'
TriggerBinaryOp = 'combine' / 'apply' ConditionClause = 'if' S co:ConditionFunction CC {return co;} ConditionFunction = 'page' L p:Page R {return function(){return a2.cpage == p};} / 'any' L a:ConditionArgs R {return function(){for(var j=0; j<a.length; j++) if (a[j]()) return true; return false; }} / 'all' L a:ConditionArgs R {return function(){for(var j=0; j<a.length; j++) if (!a[j]()) return false; return true; }} / 'not' L f:ConditionFunction R {return function(){ return !f()};} / 'have' L i:Item R {return function(){return !!a2.items[i]};} ConditionArgs = f:ConditionFunction C a:ConditionArgs {a.push(f); return a;} / f:ConditionFunction {return [f];} ActionClause = 'do' S ac:ActionFunctions CC {return ac;} ActionFunctions = f:ActionFunction C a:ActionFunctions {return function(action){a(); f();};} / ActionFunction ActionFunction = f:'goto' L p:Page R {return function(){a2.util.goto(p)};} / f:'add' L i:Item R {return function(){a2.util.add(i)};} / f:'remove' L i:Item R {return function(){a2.util.remove(i)};} / f:'print' L s:String R {return function(){a2.util.print(s)};} / f:'die' L s:String R {return function(){a2.util.die(s)};} L = S? '(' S? R = S? ')' S? C = S? ',' S? CC = S? ';' S? Scope = s:'page' S p:Page {return [s,p]; } / s:'item' S i:Item {return [s,i]; } Identifier = i1:[a-zäöü_] i2:[a-zäöü_]* {return i1+i2.join("");} Page = p:[0-9]+ {return p.join("");} Item = Identifier S = [ \t\n]+ String = "'" s:[^']* "'" { return s.join("");} / '"' s:[^"]* '"' { return s.join("");}