MediaWiki:Skin/Projekt:Adventure2/parser/raw: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) (AZ: Die Seite wurde neu angelegt.) |
J* (Diskussion | Beiträge) |
||
Zeile 8: | Zeile 8: | ||
Event | Event | ||
− | = S? 'event' S | + | = S? 'event' n:(S Identifier)? CC |
sc:ScopeClause | sc:ScopeClause | ||
tr:TriggerClause | tr:TriggerClause | ||
co:ConditionClause? | co:ConditionClause? | ||
ac:ActionClause? | ac:ActionClause? | ||
− | 'end.' S? { return {name: | + | '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 | ScopeClause | ||
Zeile 28: | Zeile 28: | ||
= t:TriggerPageOp L a:Page R {return t+"."+a;} | = t:TriggerPageOp L a:Page R {return t+"."+a;} | ||
/ t:TriggerIdentOp L a:Identifier 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 | TriggerPageOp | ||
Zeile 38: | Zeile 39: | ||
/ 'activate' | / 'activate' | ||
/ 'click' | / 'click' | ||
+ | |||
+ | TriggerBinaryOp | ||
+ | = 'combine' | ||
+ | / 'apply' | ||
ConditionClause | ConditionClause | ||
Zeile 82: | Zeile 87: | ||
Identifier | Identifier | ||
− | = | + | = i1:[a-zäöü_] i2:[a-zäöü_]* {return i1+i2.join("");} |
Page | Page |
Version vom 7. Juli 2012, 10:34 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(state){return state.cpage == p};} / 'any' L a:ConditionArgs R {return function(state){for(var j=0; j<a.length; j++) if (a[j](state)) return true; return false; }} / 'have' L i:Item R {return function(state){return state.citems.indexOf(i) > -1};} 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(action){a2.util.goto(p)};} / f:'add' L i:Item R {return function(action){a2.util.add(i)};} / f:'remove' L i:Item R {return function(action){a2.util.remove(i)};} / f:'print' L s:String R {return function(action){a2.util.print(s)};} / f:'die' L s:String R {return function(action){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("");}