/*
Copyright 2012, KISSY UI Library v1.31
MIT Licensed
build time: Dec 20 22:27
*/
KISSY.add("kison/grammar",function(f,l,e,d,c,b,a,g){function h(w){var b=0,a;for(a in w)b++;return b}function t(b,a){for(var c=0;c<a.length;c++)if(b.equals(a[c]))return c;return-1}function m(){m.superclass.constructor.apply(this,arguments)}function p(b){var a=this,c=a.lexer,o,j,i=a.table,d=i.gotos,i=i.action,s=a.productions,g=[null],n=[0];for(c.resetInput(b);;){b=n[n.length-1];o||(o=c.lex());if(!o)return!1;j=i[b]&&i[b][o];if(!j){var u=[];i[b]&&f.each(i[b],function(b,c){u.push(a.lexer.mapReverseSymbol(c))});
c.showDebugInfo();u.join(", ");return!1}switch(j[k.TYPE_INDEX]){case k.SHIFT_TYPE:n.push(o);g.push(c.text);n.push(j[k.TO_INDEX]);o=null;break;case k.REDUCE_TYPE:var e=s[j[k.PRODUCTION_INDEX]],b=e.symbol||e[0];j=e.action||e[2];var h=(e.rhs||e[1]).length,m,e=g[g.length-h];a.$$=e;for(e=0;e<h;e++)a["$"+(h-e)]=g[g.length-1-e];j&&(m=j.call(a));e=void 0!==m?m:a.$$;h&&(n=n.slice(0,-2*h),g=g.slice(0,-1*h));n.push(b);g.push(e);n.push(d[n[n.length-2]][n[n.length-1]]);break;case k.ACCEPT_TYPE:return e}}}var k=
{SHIFT_TYPE:1,REDUCE_TYPE:2,ACCEPT_TYPE:0,TYPE_INDEX:0,PRODUCTION_INDEX:1,TO_INDEX:2},q=e.serializeObject,v=f.mix,r=a.STATIC.END_TAG;f.extend(m,l,{build:function(){var b=this.lexer,a=this.get("productions");a.unshift({symbol:"$START",rhs:[a[0].symbol]});f.each(a,function(c,o){c.symbol=b.mapSymbol(c.symbol);var j=c.rhs;f.each(j,function(a,c){j[c]=b.mapSymbol(a)});a[o]=new g(c)});this.buildTerminals();this.buildNonTerminals();this.buildNullAble();this.buildFirsts();this.buildItemSet();this.buildLalrItemSets();
this.buildTable()},buildTerminals:function(){var b=this.get("lexer"),a=b&&b.rules,c=this.get("terminals");c[b.mapSymbol(r)]=1;f.each(a,function(b){(b=b.token||b[0])&&(c[b]=1)})},buildNonTerminals:function(){var a=this.get("terminals"),c=this.get("nonTerminals"),d=this.get("productions");f.each(d,function(o){var j=o.get("symbol"),i=c[j];i||(i=c[j]=new b({symbol:j}));i.get("productions").push(o);f.each(o.get("handles"),function(i){!a[i]&&!c[i]&&(c[i]=new b({symbol:i}))})})},buildNullAble:function(){for(var b=
this,a,c,o,j,i,d,g,e=b.get("nonTerminals"),n=!0;n;)for(j in n=!1,f.each(b.get("productions"),function(f){if(!f.get("nullAble")){c=f.get("rhs");for(o=a=0;i=c[a];++a)b.isNullAble(i)&&o++;o===a&&f.set("nullAble",n=!0)}}),e)if(!e[j].get("nullAble")){g=e[j].get("productions");for(a=0;d=g[a];a++)if(d.get("nullAble")){e[j].set("nullAble",n=!0);break}}},isNullAble:function(b){var a=this.get("nonTerminals");if(b instanceof Array){for(var a=0,c;c=b[a];++a)if(!this.isNullAble(c))return!1;return!0}return a[b]?
a[b].get("nullAble"):!1},findFirst:function(b){var a={},c,f,j=this.get("nonTerminals");if(b instanceof Array){for(f=0;(c=b[f])&&!(j[c]?v(a,j[c].get("firsts")):a[c]=1,!this.isNullAble(c));++f);return a}return j[b]?j[b].get("firsts"):[b]},buildFirsts:function(){var b=this,a;b.get("productions");for(var c=b.get("nonTerminals"),d=!0,j,i;d;)for(j in d=!1,f.each(b.get("productions"),function(a){var c=b.findFirst(a.get("rhs"));h(c)!==h(a.get("firsts"))&&(a.set("firsts",c),d=!0)}),c)a=c[j],i={},f.each(a.get("productions"),
function(a){v(i,a.get("firsts"))}),h(i)!==h(a.get("firsts"))&&(a.set("firsts",i),d=!0)},closure:function(a){for(var b=this,c=a.get("items"),g=b.get("productions"),j=1;j;)j=!1,f.each(c,function(c){var e=c.get("dotPosition"),s=c.get("production").get("rhs"),h=s[e],c=c.get("lookAhead"),n={};f.each(c,function(a,c){var i=s.slice(e+1);i.push(c);f.mix(n,b.findFirst(i))});f.each(g,function(b){if(b.get("symbol")==h){var b=new d({production:b}),c=a.findItemIndex(b,!0);-1!=c?(b=a.getItemAt(c),j=j||!!b.addLookAhead(n)):
(b.addLookAhead(n),a.addItem(b),j=!0)}})});return a},gotos:function(b,a){var g=new c,e=b.get("items");f.each(e,function(b){var c=b.get("production"),f=b.get("dotPosition");c.get("rhs")[f]==a&&(c=new d({production:c,dotPosition:f+1}),f=g.findItemIndex(c,!0),-1!=f?(c=g.getItemAt(f),c.addLookAhead(b.get("lookAhead"))):(c.addLookAhead(b.get("lookAhead")),g.addItem(c)))});return this.closure(g)},findItemSetIndex:function(b){var a=this.get("itemSets"),c;for(c=0;c<a.length;c++)if(a[c].equals(b))return c;
return-1},buildItemSet:function(){var b=this,a=b.lexer,g=b.get("itemSets"),e={},j=b.get("productions");e[a.mapSymbol(r)]=1;e=b.closure(new c({items:[new d({production:j[0],lookAhead:e})]}));g.push(e);var i=!0,h=f.merge(b.get("terminals"),b.get("nonTerminals"));for(delete h[a.mapSymbol(r)];i;)i=!1,a=g.concat(),f.each(a,function(a){f.each(h,function(c,f){a.__cache||(a.__cache={});if(!a.__cache[f]){var d=b.gotos(a,f);a.__cache[f]=1;if(0!=d.size()){var e=b.findItemSetIndex(d);-1<e?d=g[e]:(g.push(d),i=
!0);a.get("gotos")[f]=d;d.addReverseGoto(f,a)}}})})},buildLalrItemSets:function(){var b=this.get("itemSets"),a,c,d,g;for(a=0;a<b.length;a++){d=b[a];for(c=a+1;c<b.length;c++)if(g=b[c],d.equals(g,!0)){for(var i=0;i<d.get("items").length;i++)d.get("items")[i].addLookAhead(g.get("items")[i].get("lookAhead"));var e=d.get("gotos");f.each(g.get("gotos"),function(b,a){e[a]=b;b.addReverseGoto(a,d)});f.each(g.get("reverseGotos"),function(b,a){f.each(b,function(b){b.get("gotos")[a]=d;d.addReverseGoto(a,b)})});
b.splice(c--,1)}}},buildTable:function(){var b=this.lexer,a=this.get("table"),c=this.get("itemSets"),d=this.get("productions"),g={},i={},e,h,m;a.gotos=g;a.action=i;e=this.get("nonTerminals");for(h=0;h<c.length;h++)a=c[h],f.each(a.get("gotos"),function(b,a){e[a]?(g[h]=g[h]||{},g[h][a]=t(b,c)):(i[h]=i[h]||{},m=i[h][a]=[],m[k.TYPE_INDEX]=k.SHIFT_TYPE,m[k.PRODUCTION_INDEX]=0,m[k.TO_INDEX]=t(b,c))}),f.each(a.get("items"),function(a){var c=a.get("production");a.get("dotPosition")==c.get("rhs").length&&
(c.get("symbol")==b.mapSymbol("$START")?a.get("lookAhead")[b.mapSymbol(r)]&&(i[h]=i[h]||{},m=i[h][b.mapSymbol(r)]=[],m[k.TYPE_INDEX]=k.ACCEPT_TYPE,m[k.TO_INDEX]=m[k.PRODUCTION_INDEX]=0):(i[h]=i[h]||{},f.each(a.get("lookAhead"),function(a,b){m=i[h][b]=[];m[k.TYPE_INDEX]=k.REDUCE_TYPE;m[k.TO_INDEX]=0;m[k.PRODUCTION_INDEX]=f.indexOf(c,d)})))})},visualizeTable:function(){var a=this.get("table"),b=a.gotos,a=a.action,c=this.get("productions"),d=[];f.each(this.get("itemSets"),function(a,b){d.push(Array(70).join("*")+
" itemSet : "+b);d.push(a.toString());d.push("")});d.push("");d.push(Array(70).join("*")+" table : ");f.each(a,function(a,b){f.each(a,function(a,f){var g,e=a[k.TYPE_INDEX];e==k.ACCEPT_TYPE?g="acc":e==k.REDUCE_TYPE?(g=c[a[k.PRODUCTION_INDEX]],g="r, "+g.get("symbol")+"="+g.get("rhs").join(" ")):e==k.SHIFT_TYPE&&(g="s, "+a[k.TO_INDEX]);d.push("action["+b+"]["+f+"] = "+g)})});d.push("");f.each(b,function(a,b){f.each(a,function(a,c){d.push("goto["+b+"]["+c+"] = "+a)})});return d},genCode:function(a){var a=
a||{},b=this.get("table"),c=this.get("lexer"),d=c.genCode(a);this.build();var g=[];f.each(this.get("productions"),function(a){var b=a.get("action"),a=[a.get("symbol"),a.get("rhs")];b&&a.push(b);g.push(a)});var e=[];e.push("/* Generated by kison from KISSY */");e.push("var parser = {},S = KISSY,GrammarConst = "+q(k)+";");e.push(d);e.push("parser.lexer = lexer;");a.compressSymbol&&e.push("lexer.symbolMap = "+q(c.symbolMap)+";");e.push("parser.productions = "+q(g)+";");e.push("parser.table = "+q(b)+
";");e.push("parser.parse = "+p.toString()+";");e.push("return parser;");return e.join("\n")}},{ATTRS:{table:{value:{}},itemSets:{value:[]},productions:{value:[]},nonTerminals:{value:{}},lexer:{setter:function(b){b instanceof a||(b=new a(b));return this.lexer=b}},terminals:{value:{}}}});return m},{requires:"base,./utils,./item,./item-set,./non-terminal,./lexer,./production".split(",")});
KISSY.add("kison/item-set",function(f,l){function e(){e.superclass.constructor.apply(this,arguments)}f.extend(e,l,{addItem:function(d){for(var c=this.get("items"),b=0;b<c.length&&!(c[b].get("production").toString()>d.get("production").toString());b++);c.splice(b,0,d)},size:function(){return this.get("items").length},findItemIndex:function(d,c){for(var b=this.get("items"),a=0;a<b.length;a++)if(b[a].equals(d,c))return a;return-1},getItemAt:function(d){return this.get("items")[d]},equals:function(d,
c){var b=this.get("items"),a,g=d.get("items");if(b.length!=g.length)return!1;for(a=0;a<b.length;a++)if(!b[a].equals(g[a],c))return!1;return!0},toString:function(){var d=[];f.each(this.get("items"),function(c){d.push(c.toString())});return d.join("\n")},addReverseGoto:function(d,c){var b=this.get("reverseGotos");b[d]=b[d]||[];b[d].push(c)}},{ATTRS:{items:{value:[]},gotos:{value:{}},reverseGotos:{value:{}}}});return e},{requires:["base"]});
KISSY.add("kison/item",function(f,l){function e(){e.superclass.constructor.apply(this,arguments)}f.extend(e,l,{equals:function(d,c){return!d.get("production").equals(this.get("production"))||d.get("dotPosition")!=this.get("dotPosition")||!c&&!f.equals(this.get("lookAhead"),d.get("lookAhead"))?!1:!0},toString:function(d){return this.get("production").toString(this.get("dotPosition"))+(d?"":","+f.keys(this.get("lookAhead")).join("/"))},addLookAhead:function(d){var c=this.get("lookAhead"),b=0;f.each(d,
function(a,d){c[d]||(b=c[d]=1)});return b}},{ATTRS:{production:{},dotPosition:{value:0},lookAhead:{value:{}}}});return e},{requires:["base"]});KISSY.add("kison",function(f,l,e,d,c){var b={};b.Grammar=l;b.Production=e;b.Lexer=d;b.Utils=c;return!f.trim("")?(alert("kison can only use uncompressed version!"),null):b},{requires:["kison/grammar","kison/production","kison/lexer","kison/utils"]});
KISSY.add("kison/lexer",function(f,l){var e=l.serializeObject,d=function(c){this.rules=[];f.mix(this,c);this.resetInput(this.input)};d.STATIC={INITIAL:"I",DEBUG_CONTEXT_LIMIT:20,END_TAG:"$EOF"};d.prototype={resetInput:function(c){f.mix(this,{input:c,matched:"",stateStack:[d.STATIC.INITIAL],match:"",text:"",firstLine:1,lineNumber:1,lastLine:1,firstColumn:1,lastColumn:1})},genCode:function(c){var b=d.STATIC,a=this,g=c.compressSymbol,h=c.compressLexerState,c=[],l;a.symbolId=a.stateId=0;g&&(a.symbolMap=
{},a.mapSymbol(b.END_TAG));h&&(l=a.stateMap={});c.push("var Lexer = "+d.toString()+";");c.push("Lexer.prototype= "+e(d.prototype,/genCode/)+";");c.push("Lexer.STATIC= "+e(b)+";");b=e({rules:a.rules},h||g?function(b){if(b&&b.regexp){var c=b.state,d=b.action,g=b.token||0;g&&(g=a.mapSymbol(g));b=[g,b.regexp,d||0];h&&c&&(c=f.map(c,function(b){return a.mapState(b)}));c&&b.push(c);return b}}:0);c.push("var lexer = new Lexer("+b+");");if(h||g)a.rules=eval("("+b+")").rules,h&&c.push("lexer.stateMap = "+e(l)+
";");return c.join("\n")},getCurrentRules:function(){var c=this.stateStack[this.stateStack.length-1],b=[],c=this.mapState(c);f.each(this.rules,function(a){var g=a.state||a[3];g?f.inArray(c,g)&&b.push(a):c==d.STATIC.INITIAL&&b.push(a)});return b},pushState:function(c){this.stateStack.push(c)},popState:function(){return this.stateStack.pop()},getStateStack:function(){return this.stateStack},showDebugInfo:function(){var c=d.STATIC.DEBUG_CONTEXT_LIMIT,b=this.matched,a=this.match,g=this.input,b=b.slice(0,
b.length-a.length),b=(b.length>c?"...":"")+b.slice(-c).replace(/\n/," "),a=a+g,a=a.slice(0,c)+(a.length>c?"...":"");return b+a+"\n"+Array(b.length+1).join("-")+"^"},mapSymbol:function(c){var b=this.symbolMap;return!b?c:b[c]||(b[c]=++this.symbolId)},mapReverseSymbol:function(c){var b=this.symbolMap,a,d=this.reverseSymbolMap;if(!d&&b)for(a in d=this.reverseSymbolMap={},b)d[b[a]]=a;return d?d[c]:c},mapState:function(c){var b=this.stateMap;return!b?c:b[c]||(b[c]=++this.stateId)},lex:function(){var c=
this.input,b,a,g,e=this.getCurrentRules();this.match=this.text="";if(!f.trim(c))return this.mapSymbol(d.STATIC.END_TAG);for(b=0;b<e.length;b++){a=e[b];var l=a.token||a[0];g=a.action||a[2]||void 0;if(a=c.match(a.regexp||a[1])){if(b=a[0].match(/\n.*/g))this.lineNumber+=b.length;f.mix(this,{firstLine:this.lastLine,lastLine:this.lineNumber+1,firstColumn:this.lastColumn,lastColumn:b?b[b.length-1].length-1:this.lastColumn+a[0].length});b=this.match=a[0];this.matches=a;this.text=b;this.matched+=b;g=g&&g.call(this);
g=void 0==g?l:this.mapSymbol(g);this.input=c=c.slice(b.length);return g?g:this.lex()}}}};return d},{requires:["./utils"]});KISSY.add("kison/non-terminal",function(f,l){function e(){e.superclass.constructor.apply(this,arguments)}f.extend(e,l,{},{ATTRS:{productions:{value:[]},firsts:{value:{}},symbol:{},nullAble:{value:!1}}});return e},{requires:["base"]});
KISSY.add("kison/production",function(f,l){function e(){e.superclass.constructor.apply(this,arguments)}f.extend(e,l,{equals:function(d){return!f.equals(d.get("rhs"),this.get("rhs"))?!1:d.get("symbol")==this.get("symbol")},toString:function(d){var c="",b=this.get("rhs");f.each(b,function(a,b){b==d&&(c+=".");c+=a});d==b.length&&(c+=".");return this.get("symbol")+"=>"+c}},{ATTRS:{firsts:{value:{}},follows:{value:[]},symbol:{},rhs:{value:[]},nullAble:{value:!1},action:{}}});return e},{requires:["base"]});
KISSY.add("kison/utils",function(f){var l=/"/g,e=/'/g,d;return{escapeString:d=function(c,b){var a=e;'"'==b?a=l:b="'";return c.replace(/\\/g,"\\\\").replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(a,"\\"+b)},serializeObject:function b(a,e){var h;if(e&&f.isFunction(e)&&!1===(h=e(a)))return!1;void 0!==h&&(a=h);h=[];if("string"==typeof a)return"'"+d(a)+"'";if(f.isNumber(a))return a+"";if(f.isRegExp(a))return"/"+a.source+"/"+(a.global?"g":"")+(a.ignoreCase?"i":"")+(a.multiline?"m":
"");if(f.isArray(a)){h.push("[");var l=[];f.each(a,function(a){a=b(a,e);!1!==a&&l.push(a)});h.push(l.join(", "));h.push("]");return h.join("")}if(f.isObject(a)){h=["{"];var m=1,p;for(p in a){var k=a[p];if(!e||!f.isRegExp(e)||!p.match(e))if(k=b(k,e),!1!==k){var q="'"+d(p)+"'";h.push((m?"":",")+q+": "+k);m=0}}h.push("}");return h.join("\n")}return a+""}}});
