16
keywords: keywords("abstract and array as break case catch cfunction class clone const continue declare " +
17
"default do else elseif enddeclare endfor endforeach endif endswitch endwhile extends " +
18
"final for foreach function global goto if implements interface instanceof namespace " +
19
"new or private protected public static switch throw try use var while xor return" +
20
"die echo empty exit eval include include_once isset list require require_once print unset"),
16
keywords: keywords("abstract and array as break case catch class clone const continue declare default " +
17
"do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
18
"for foreach function global goto if implements interface instanceof namespace " +
19
"new or private protected public static switch throw trait try use var while xor " +
20
"die echo empty exit eval include include_once isset list require require_once return " +
21
"print unset __halt_compiler self static parent"),
21
22
blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
22
23
atoms: keywords("true false null TRUE FALSE NULL"),
23
24
multiLineStrings: true,
48
56
var phpMode = CodeMirror.getMode(config, phpConfig);
50
58
function dispatch(stream, state) { // TODO open PHP inside text/css
59
var isPHP = state.mode == "php";
60
if (stream.sol() && state.pending != '"') state.pending = null;
51
61
if (state.curMode == htmlMode) {
52
var style = htmlMode.token(stream, state.curState);
53
if (style == "meta" && /^<\?/.test(stream.current())) {
62
if (stream.match(/^<\?\w*/)) {
54
63
state.curMode = phpMode;
55
64
state.curState = state.php;
56
state.curClose = /^\?>/;
59
else if (style == "tag" && stream.current() == ">" && state.curState.context) {
65
state.curClose = "?>";
69
if (state.pending == '"') {
70
while (!stream.eol() && stream.next() != '"') {}
72
} else if (state.pending && stream.pos < state.pending.end) {
73
stream.pos = state.pending.end;
74
var style = state.pending.style;
76
var style = htmlMode.token(stream, state.curState);
79
var cur = stream.current(), openPHP = cur.search(/<\?/);
81
if (style == "string" && /\"$/.test(cur) && !/\?>/.test(cur)) state.pending = '"';
82
else state.pending = {end: stream.pos, style: style};
83
stream.backUp(cur.length - openPHP);
84
} else if (style == "tag" && stream.current() == ">" && state.curState.context) {
60
85
if (/^script$/i.test(state.curState.context.tagName)) {
61
86
state.curMode = jsMode;
62
87
state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
63
88
state.curClose = /^<\/\s*script\s*>/i;
64
state.mode = 'javascript';
89
state.mode = "javascript";
66
91
else if (/^style$/i.test(state.curState.context.tagName)) {
67
92
state.curMode = cssMode;
68
93
state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
69
state.curClose = /^<\/\s*style\s*>/i;
94
state.curClose = /^<\/\s*style\s*>/i;
75
else if (stream.match(state.curClose, false)) {
99
} else if ((!isPHP || state.php.tokenize == null) &&
100
stream.match(state.curClose, isPHP)) {
76
101
state.curMode = htmlMode;
77
102
state.curState = state.html;
78
103
state.curClose = null;
80
return dispatch(stream, state);
105
if (isPHP) return "meta";
106
else return dispatch(stream, state);
108
return state.curMode.token(stream, state.curState);
82
else return state.curMode.token(stream, state.curState);
87
114
var html = htmlMode.startState();
88
115
return {html: html,
89
116
php: phpMode.startState(),
90
curMode: parserConfig.startOpen ? phpMode : htmlMode,
91
curState: parserConfig.startOpen ? phpMode.startState() : html,
92
curClose: parserConfig.startOpen ? /^\?>/ : null,
93
mode: parserConfig.startOpen ? 'php' : 'html'}
117
curMode: parserConfig.startOpen ? phpMode : htmlMode,
118
curState: parserConfig.startOpen ? phpMode.startState() : html,
119
curClose: parserConfig.startOpen ? /^\?>/ : null,
120
mode: parserConfig.startOpen ? "php" : "html",
96
124
copyState: function(state) {
99
127
if (state.curState == html) cur = htmlNew;
100
128
else if (state.curState == php) cur = phpNew;
101
129
else cur = CodeMirror.copyState(state.curMode, state.curState);
102
return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur, curClose: state.curClose};
130
return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
131
curClose: state.curClose, mode: state.mode,
132
pending: state.pending};