/*
Copyright (c) 2008-2009 Yahoo! Inc.  All rights reserved.
The copyrights embodied in the content of this file are licensed by
Yahoo! Inc. under the BSD (revised) open source license

@author Vlad Dan Dascalescu <dandv@yahoo-inc.com>
*/
if(!Array.prototype.indexOf)Array.prototype.indexOf=function(s,m){var t=this.length,e=Number(m)||0;e=e<0?Math.ceil(e):Math.floor(e);if(e<0)e+=t;for(;e<t;e++)if(e in this&&this[e]===s)return e;return-1};
var PHPParser=Editor.Parser=function(){function s(e,o,l,b,h,g){this.indented=e;this.column=o;this.type=l;if(b!=null)this.align=b;this.prev=h;this.info=g}function m(e){return function(o){var l=o&&o.charAt(0),b=e.type,h=l==b;return b=="form"&&l=="{"?e.indented:b=="stat"||b=="form"?e.indented+indentUnit:e.info=="switch"&&!h?e.indented+(/^(?:case|default)\b/.test(o)?indentUnit:2*indentUnit):e.align?e.column-(h?1:0):e.indented+(h?0:indentUnit)}}var t={atom:true,number:true,variable:true,string:true};return{make:function(e,
o){function l(a){for(var j=a.length-1;j>=0;j--)v.push(a[j])}function b(){l(arguments);C=true}function h(){l(arguments);C=false}function g(a,j){var q=function(){p=new s(D,B,a,null,p,j)};q.lex=true;return q}function d(){if(p.prev)p=p.prev}function k(a){return function(j){j.type==a?b():b(arguments.callee)}}function c(a,j){return function(q){var r;r=q.type;r=typeof a=="string"?(r==a)-1:a.indexOf(r);if(r>=0)j&&typeof j[r]=="function"?h(j[r]):b();else{if(!y)y=q.style;y+=" syntax-error";b(arguments.callee)}}}
function w(){return h(i,w)}function i(a){a=a.type;if(a=="keyword a")b(g("form"),f,E,i,d);else if(a=="keyword b")b(g("form"),E,i,d);else if(a=="{")b(g("}"),z,d);else if(a=="function")u();else if(a=="class")H();else if(a=="foreach")b(g("form"),c("("),g(")"),f,c("as"),c("variable"),k(")"),E,d,i,d);else if(a=="for")b(g("form"),c("("),g(")"),f,c(";"),f,c(";"),f,c(")"),E,d,i,d);else if(a=="modifier")b(c(["modifier","variable","function","abstract"],[null,A(c("variable")),u,I]));else if(a=="abstract")b(c(["modifier",
"function","class"],[I,u,H]));else if(a=="switch")b(g("form"),c("("),f,c(")"),g("}","switch"),c([":","{"]),z,d,d);else if(a=="case")b(f,c(":"));else if(a=="default")b(c(":"));else if(a=="catch")b(g("form"),c("("),c("t_string"),c("variable"),c(")"),i,d);else if(a=="const")b(c("t_string"));else a=="namespace"?b(J,c(";")):h(g("stat"),f,c(";"),d)}function f(a){a=a.type;if(t.hasOwnProperty(a))b(n);else if(a=="<<<")b(c("string"),n);else if(a=="t_string")b(x,n);else if(a=="keyword c"||a=="operator")b(f);
else if(a=="function")b(c("("),g(")"),A(F),c(")"),O,d,c("{"),g("}"),z,d);else a=="("&&b(g(")"),A(f),c(")"),d,n)}function n(a){var j=a.type;if(j=="operator")a.content=="?"?b(f,c(":"),f):b(f);else if(j=="(")b(g(")"),f,A(f),c(")"),d,n);else j=="["&&b(g("]"),f,c("]"),n,d)}function x(a){a.type=="t_double_colon"?b(c(["t_string","variable"]),n):h(f)}function u(){b(c("t_string"),c("("),g(")"),A(F),c(")"),d,z)}function O(a){a.type=="namespace"?b(c("("),A(F),c(")")):h(f)}function H(){b(c("t_string"),k("{"),
g("}"),z,d)}function I(a){a.type=="function"?u():b(c(["function"],[u]))}function A(a){function j(q){q.type==","&&b(a,j)}return function(){h(a,j)}}function z(a){a.type=="}"?b():h(i,z)}function P(a){a.content=="array"&&b(c("("),c(")"))}function K(a){a.content=="="&&b(c(["t_string","string","number","atom"],[P,null,null]))}function L(a){if(a.type=="variable")b(K);else a.content=="&"&&b(c("variable"),K)}function F(a){a.type=="t_string"?b(L):L(a)}function Q(a){a.type=="t_double_colon"&&b(J)}function J(){h(c("t_string"),
Q)}function E(a){a.content==":"&&b(M,d)}function M(a){a.type=="altsyntaxend"?b(c(";")):h(i,M)}var G=tokenizePHP(e),v=[w],p=new s((o||0)-indentUnit,0,"block",false),B=0,D=0,C,y,N={next:function(){for(;v[v.length-1].lex;)v.pop()();var a=G.next();if(a.type=="whitespace"&&B==0)D=a.value.length;B+=a.value.length;if(a.content=="\n"){D=B=0;if(!("align"in p))p.align=false;a.indentation=m(p)}if(a.type=="whitespace"||a.type=="comment"||a.type=="string_not_terminated")return a;if(!("align"in p))p.align=true;
for(;;){C=y=false;v.pop()(a);if(C){if(y)a.style=y;return a}}return 1},copy:function(){var a=p,j=v.concat([]),q=G.state;return function(r){p=a;v=j.concat([]);B=D=0;G=tokenizePHP(r,q);return N}}};d.lex=true;return N},electricChars:"{}:"}}();var PHPHTMLMixedParser=Editor.Parser=function(){var s=["<?php"];if(!(PHPParser&&CSSParser&&JSParser&&XMLParser))throw Error("PHP, CSS, JS, and XML parsers must be loaded for PHP+HTML mixed mode to work.");XMLParser.configure({useHTMLKludges:true});return{make:function(m){function t(){var k=o.next();if(k.content=="<")b=true;else if(k.style=="xml-tagname"&&b===true)b=k.content.toLowerCase();else if(k.style=="xml-attname")h=k.content;else if(k.type=="xml-processing")for(var c=0;c<s.length;c++){if(s[c]==
k.content){d.next=e(PHPParser,"?>");break}}else if(k.style=="xml-attribute"&&k.content=='"php"'&&b=="script"&&h=="language")b="script/php";else if(k.content==">"){if(b=="script/php")d.next=e(PHPParser,"<\/script>");else if(b=="script")d.next=e(JSParser,"<\/script");else if(b=="style")d.next=e(CSSParser,"</style");h=null;b=false}return k}function e(k,c){var w=o.indentation();l=k==PHPParser&&g?g(m):k.make(m,w+indentUnit);return function(){if(m.lookAhead(c,false,false,true)){if(k==PHPParser)g=l.copy();
l=null;d.next=t;return t()}var i=l.next(),f=i.value.lastIndexOf("<"),n=Math.min(i.value.length-f,c.length);if(f!=-1&&i.value.slice(f,f+n).toLowerCase()==c.slice(0,n)&&m.lookAhead(c.slice(n),false,false,true)){m.push(i.value.slice(f));i.value=i.value.slice(0,f)}if(i.indentation){var x=i.indentation;i.indentation=function(u){return u=="</"?w:x(u)}}return i}}var o=XMLParser.make(m),l=null,b=false,h=null,g=null,d={next:t,copy:function(){var k=o.copy(),c=l&&l.copy(),w=d.next,i=b,f=h,n=g;return function(x){m=
x;o=k(x);l=c&&c(x);g=n;d.next=w;b=i;h=f;return d}}};return d},electricChars:"{}/:",configure:function(m){if(m.opening!=null)s=m.opening}}}();