Skip to content

Commit

Permalink
[php mode] Another attempt at handling ?> inside comments correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Feb 21, 2012
1 parent 921d4e9 commit 0c90f00
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
4 changes: 2 additions & 2 deletions mode/clike/clike.js
Expand Up @@ -59,7 +59,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
escaped = !escaped && next == "\\";
}
if (end || !(escaped || multiLineStrings))
state.tokenize = tokenBase;
state.tokenize = null;
return "string";
};
}
Expand All @@ -68,7 +68,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
state.tokenize = null;
break;
}
maybeEnd = (ch == "*");
Expand Down
34 changes: 5 additions & 29 deletions mode/php/php.js
Expand Up @@ -11,17 +11,6 @@
return "string";
}
}
function tokenComment(stream, state) {
while (!stream.eol()) {
if (stream.match("?>", false)) break;
if (stream.match("*/")) {
state.tokenize = null;
break;
}
stream.next();
}
return "comment";
}
var phpConfig = {
name: "clike",
keywords: keywords("abstract and array as break case catch cfunction class clone const continue declare " +
Expand All @@ -48,20 +37,6 @@
"#": function(stream, state) {
stream.skipToEnd();
return "comment";
},
"/": function(stream, state) {
if (stream.eat("*")) {
state.tokenize = tokenComment;
return tokenComment(stream, state);
}
if (stream.eat("/")) {
var ch;
while (ch = stream.next()) {
if (stream.match("?>", false)) break;
}
return "comment";
}
return false;
}
}
};
Expand All @@ -73,9 +48,10 @@
var phpMode = CodeMirror.getMode(config, phpConfig);

function dispatch(stream, state) { // TODO open PHP inside text/css
var isPHP = state.mode == "php";
if (stream.sol() && state.pending != '"') state.pending = null;
if (state.curMode == htmlMode) {
if (stream.match("<?")) {
if (stream.match(/^<\?\w*/)) {
state.curMode = phpMode;
state.curState = state.php;
state.curClose = "?>";
Expand Down Expand Up @@ -112,14 +88,14 @@
}
}
return style;
} else if (stream.match(state.curClose, state.mode == "php")) {
} else if ((!isPHP || state.php.tokenize == null) &&
stream.match(state.curClose, isPHP)) {
state.curMode = htmlMode;
state.curState = state.html;
state.curClose = null;
var isPHP = state.mode == "php";
state.mode = "html";
if (isPHP) return "meta";
return dispatch(stream, state);
else return dispatch(stream, state);
} else {
return state.curMode.token(stream, state.curState);
}
Expand Down
3 changes: 2 additions & 1 deletion mode/xml/index.html
Expand Up @@ -25,7 +25,8 @@ <h1>CodeMirror: XML mode</h1>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: {name: "xml", alignCDATA: true},
lineNumbers: true
lineNumbers: true,
onChange: function() { editor.save(); }
});
</script>
<p>The XML mode supports two configuration parameters:</p>
Expand Down

0 comments on commit 0c90f00

Please sign in to comment.