MediaWiki:Skin/Projekt:Adventure2/parser/raw: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) (jetzt aber) |
J* (Diskussion | Beiträge) (Virtual Triggers) |
||
Zeile 29: | Zeile 29: | ||
TriggerFunction | TriggerFunction | ||
− | = t: | + | = t:TriggerPageOrVirtOp L a:(Page/PageVirtual) R {return t+"."+a;} |
− | / t: | + | / t:TriggerItemOrVirtOp L a:(Item/ItemVirtual) R {return t+"."+a;} |
− | / t: | + | / t:"click" L a:Identifier R {return t+"."+a;} |
+ | / t:"combine" L a:(Item/ItemVirtual) C b:(Item/ItemVirtual) R {return [t,a,b].join(".")} | ||
+ | / t:"apply" L a:(Item/ItemVirtual) C b:Identifier R {return [t,a,b].join(".")} | ||
− | + | TriggerPageOrVirtOp | |
= 'enter' | = 'enter' | ||
/ 'leave' | / 'leave' | ||
− | + | ||
− | + | TriggerItemOrVirtOp | |
= 'add' | = 'add' | ||
/ 'remove' | / 'remove' | ||
/ 'activate' | / 'activate' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
ConditionClause | ConditionClause |
Version vom 17. Juli 2012, 21:45 Uhr
/* * A2 event syntax parser using pegjs * http://pegjs.majda.cz/online */ start = S? d:Declaration* {return d;}
Declaration = EventDec / PageDec / ItemDec
/* EVENTS */
EventDec = S? 'event' n:(S Identifier)? CC tr:TriggerClause co:ConditionClause? ac:ActionClause? End S? { return ["event", {name:n?n[1]:":anonymous:", trigger:tr, condition:(co?co:function(){return true;}), action:(ac?ac:function(){return true;})}]; } 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:TriggerPageOrVirtOp L a:(Page/PageVirtual) R {return t+"."+a;} / t:TriggerItemOrVirtOp L a:(Item/ItemVirtual) R {return t+"."+a;} / t:"click" L a:Identifier R {return t+"."+a;} / t:"combine" L a:(Item/ItemVirtual) C b:(Item/ItemVirtual) R {return [t,a,b].join(".")} / t:"apply" L a:(Item/ItemVirtual) C b:Identifier R {return [t,a,b].join(".")} TriggerPageOrVirtOp = 'enter' / 'leave'
TriggerItemOrVirtOp = 'add' / 'remove' / 'activate' 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]};} / 'page' L v:PageVirtual R {return function(){return !!a2.hasVirtual(v);};} / 'have' L v:ItemVirtual R {return function(){return !!a2.hasVirtual(v);};} 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)};}
/* PAGES AND ITEMS */
PageDec = "page" CC pv:PageVirtualClause? End {return ["page", {virt:pv}];}
PageVirtualClause = "provides" S v:PageVirtualList CC {return v;}
PageVirtualList = v:PageVirtual C vl:PageVirtualList {vl.push(v); return vl;} / v:PageVirtual {return [v];}
ItemDec = "item" CC t:TitleClause? iv:ItemVirtualClause? End {return ["item", {virt:iv, title:t}];}
TitleClause = "title" S s:String CC {return s;}
ItemVirtualClause = "provides" S v:ItemVirtualList CC {return v;}
ItemVirtualList = v:ItemVirtual C vl:ItemVirtualList {vl.push(v); return vl;} / v:ItemVirtual {return [v];}
/* UTILITIES */ L = S? '(' S? R = S? ')' S? C = S? ',' S? CC = S? ';' S? Identifier = i1:[a-zäöü_] i2:[a-zäöü_]* {return i1+i2.join("");} PageVirtual = p:"@" i:Identifier {return p+i;}
ItemVirtual = p:":" i:Identifier {return p+i;}
Page = p:[0-9]+ {return p.join("");} Item = Identifier S = [ \t\n]* "/*" ([^*] / [*][^/] )* "*/" S? / [ \t\n]* "//" [^\n]* [\n] S? / [ \t\n]+ String = "'" s:SingleStringChar* "'" { return s.join("");} / '"' s:DoubleStringChar* '"' { return s.join("");}
SingleStringChar = EscapeSequence / [^']
DoubleStringChar = EscapeSequence / [^"]
EscapeSequence = "\\n" {return "\n";} / "\\\"" {return '"';} / "\\\'" {return "'";}
End = "end" S? "." S?