php.js 3.24 KB
!function(){function e(e){for(var t={},r=e.split(" "),n=0;n<r.length;++n)t[r[n]]=!0;return t}function t(e){return function(t,r){return t.match(e)?r.tokenize=null:t.skipToEnd(),"string"}}var r={name:"clike",keywords:e("abstract and array as break case catch class clone const continue declare default do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final for foreach function global goto if implements interface instanceof namespace new or private protected public static switch throw trait try use var while xor die echo empty exit eval include include_once isset list require require_once return print unset __halt_compiler self static parent"),blockKeywords:e("catch do else elseif for foreach if switch try while"),atoms:e("true false null TRUE FALSE NULL"),multiLineStrings:!0,hooks:{$:function(e,t){return e.eatWhile(/[\w\$_]/),"variable-2"},"<":function(e,r){return!!e.match(/<</)&&(e.eatWhile(/[\w\.]/),r.tokenize=t(e.current().slice(3)),r.tokenize(e,r))},"#":function(e,t){for(;!e.eol()&&!e.match("?>",!1);)e.next();return"comment"},"/":function(e,t){if(e.eat("/")){for(;!e.eol()&&!e.match("?>",!1);)e.next();return"comment"}return!1}}};CodeMirror.defineMode("php",function(e,t){function n(e,t){var r="php"==t.mode;if(e.sol()&&'"'!=t.pending&&(t.pending=null),t.curMode==o){if(e.match(/^<\?\w*/))return t.curMode=i,t.curState=t.php,t.curClose="?>",t.mode="php","meta";if('"'==t.pending){for(;!e.eol()&&'"'!=e.next(););var s="string"}else if(t.pending&&e.pos<t.pending.end){e.pos=t.pending.end;var s=t.pending.style}else var s=o.token(e,t.curState);t.pending=null;var u=e.current(),d=u.search(/<\?/);return d!=-1?("string"==s&&/\"$/.test(u)&&!/\?>/.test(u)?t.pending='"':t.pending={end:e.pos,style:s},e.backUp(u.length-d)):"tag"==s&&">"==e.current()&&t.curState.context&&(/^script$/i.test(t.curState.context.tagName)?(t.curMode=c,t.curState=c.startState(o.indent(t.curState,"")),t.curClose=/^<\/\s*script\s*>/i,t.mode="javascript"):/^style$/i.test(t.curState.context.tagName)&&(t.curMode=a,t.curState=a.startState(o.indent(t.curState,"")),t.curClose=/^<\/\s*style\s*>/i,t.mode="css")),s}return r&&null!=t.php.tokenize||!e.match(t.curClose,r)?t.curMode.token(e,t.curState):(t.curMode=o,t.curState=t.html,t.curClose=null,t.mode="html",r?"meta":n(e,t))}var o=CodeMirror.getMode(e,{name:"xml",htmlMode:!0}),c=CodeMirror.getMode(e,"javascript"),a=CodeMirror.getMode(e,"css"),i=CodeMirror.getMode(e,r);return{startState:function(){var e=o.startState();return{html:e,php:i.startState(),curMode:t.startOpen?i:o,curState:t.startOpen?i.startState():e,curClose:t.startOpen?/^\?>/:null,mode:t.startOpen?"php":"html",pending:null}},copyState:function(e){var t,r=e.html,n=CodeMirror.copyState(o,r),c=e.php,a=CodeMirror.copyState(i,c);return t=e.curState==r?n:e.curState==c?a:CodeMirror.copyState(e.curMode,e.curState),{html:n,php:a,curMode:e.curMode,curState:t,curClose:e.curClose,mode:e.mode,pending:e.pending}},token:n,indent:function(e,t){return e.curMode!=i&&/^\s*<\//.test(t)||e.curMode==i&&/^\?>/.test(t)?o.indent(e.html,t):e.curMode.indent(e.curState,t)},electricChars:"/{}:"}},"xml","clike","javascript","css"),CodeMirror.defineMIME("application/x-httpd-php","php"),CodeMirror.defineMIME("application/x-httpd-php-open",{name:"php",startOpen:!0}),CodeMirror.defineMIME("text/x-php",r)}();