Farabi
view release on metacpan or search on metacpan
lib/Farabi/files/public/assets/codemirror/mode/php/php.js view on Meta::CPAN
};
}
function stringWithEscapes(stream, state) {
var escaped = false, next, end = false;
if (stream.current() == '"') return "string";
// "Complex" syntax
if (stream.match("${", false) || stream.match("{$", false)) {
state.tokenize = null;
return "string";
}
// Simple syntax
if (stream.match(/\$[a-zA-Z_][a-zA-Z0-9_]*/)) {
// After the variable name there may appear array or object operator.
if (stream.match("[", false)) {
// Match array operator
state.tokenize = matchSequence([
[["[", null]],
[[/\d[\w\.]*/, "number"],
[/\$[a-zA-Z_][a-zA-Z0-9_]*/, "variable-2"],
[/[\w\$]+/, "variable"]],
[["]", null]]
]);
}
if (stream.match(/\-\>\w/, false)) {
// Match object operator
state.tokenize = matchSequence([
[["->", null]],
[[/[\w]+/, "variable"]]
]);
}
return "variable-2";
}
// Normal string
while (
!stream.eol() &&
(!stream.match("{$", false)) &&
(!stream.match(/(\$[a-zA-Z_][a-zA-Z0-9_]*|\$\{)/, false) || escaped)
) {
next = stream.next();
if (!escaped && next == '"') { end = true; break; }
escaped = !escaped && next == "\\";
}
if (end) {
state.tokenize = null;
state.phpEncapsStack.pop();
}
return "string";
}
var phpKeywords = "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 yield insteadof finally";
var phpAtoms = "true false null TRUE FALSE NULL __CLASS__ __DIR__ __FILE__ __LINE__ __METHOD__ __FUNCTION__ __NAMESPACE__ __TRAIT__";
var phpBuiltin = "func_num_args func_get_arg func_get_args strlen strcmp strncmp strcasecmp strncasecmp each error_reporting define defined trigger_error user_error set_error_handler restore_error_handler get_declared_classes get_loaded_extensions ...
CodeMirror.registerHelper("hintWords", "php", [phpKeywords, phpAtoms, phpBuiltin].join(" ").split(" "));
CodeMirror.registerHelper("wordChars", "php", /[\\w$]/);
var phpConfig = {
name: "clike",
helperType: "php",
keywords: keywords(phpKeywords),
blockKeywords: keywords("catch do else elseif for foreach if switch try while finally"),
atoms: keywords(phpAtoms),
builtin: keywords(phpBuiltin),
multiLineStrings: true,
hooks: {
"$": function(stream) {
stream.eatWhile(/[\w\$_]/);
return "variable-2";
},
"<": function(stream, state) {
if (stream.match(/<</)) {
stream.eatWhile(/[\w\.]/);
state.tokenize = heredoc(stream.current().slice(3));
return state.tokenize(stream, state);
}
return false;
},
"#": function(stream) {
while (!stream.eol() && !stream.match("?>", false)) stream.next();
return "comment";
},
"/": function(stream) {
if (stream.eat("/")) {
while (!stream.eol() && !stream.match("?>", false)) stream.next();
return "comment";
}
return false;
},
'"': function(stream, state) {
if (!state.phpEncapsStack)
state.phpEncapsStack = [];
state.phpEncapsStack.push(0);
state.tokenize = stringWithEscapes;
return state.tokenize(stream, state);
},
"{": function(_stream, state) {
if (state.phpEncapsStack && state.phpEncapsStack.length > 0)
state.phpEncapsStack[state.phpEncapsStack.length - 1]++;
return false;
},
"}": function(_stream, state) {
if (state.phpEncapsStack && state.phpEncapsStack.length > 0)
if (--state.phpEncapsStack[state.phpEncapsStack.length - 1] == 0)
state.tokenize = stringWithEscapes;
return false;
}
}
};
CodeMirror.defineMode("php", function(config, parserConfig) {
var htmlMode = CodeMirror.getMode(config, "text/html");
var phpMode = CodeMirror.getMode(config, phpConfig);
( run in 0.806 second using v1.01-cache-2.11-cpan-d8267643d1d )