玛氪宕·梦魔(Markdown Memo),使用Markdown的云端备忘录,百度IFE的RIA启航班的不合格的作业,才……才没有什么阴谋呢!
源gitee链接https://gitee.com/arathi/MarkdownMemo?_from=gitee_search
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
10773 lines
413 KiB
10773 lines
413 KiB
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.modeInfo = [
|
|
{name: "APL", mime: "text/apl", mode: "apl", ext: ["dyalog", "apl"]},
|
|
{name: "Asterisk", mime: "text/x-asterisk", mode: "asterisk", file: /^extensions\.conf$/i},
|
|
{name: "C", mime: "text/x-csrc", mode: "clike", ext: ["c", "h"]},
|
|
{name: "C++", mime: "text/x-c++src", mode: "clike", ext: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"], alias: ["cpp"]},
|
|
{name: "Cobol", mime: "text/x-cobol", mode: "cobol", ext: ["cob", "cpy"]},
|
|
{name: "C#", mime: "text/x-csharp", mode: "clike", ext: ["cs"], alias: ["csharp"]},
|
|
{name: "Clojure", mime: "text/x-clojure", mode: "clojure", ext: ["clj"]},
|
|
{name: "CoffeeScript", mime: "text/x-coffeescript", mode: "coffeescript", ext: ["coffee"], alias: ["coffee", "coffee-script"]},
|
|
{name: "Common Lisp", mime: "text/x-common-lisp", mode: "commonlisp", ext: ["cl", "lisp", "el"], alias: ["lisp"]},
|
|
{name: "Cypher", mime: "application/x-cypher-query", mode: "cypher", ext: ["cyp", "cypher"]},
|
|
{name: "Cython", mime: "text/x-cython", mode: "python", ext: ["pyx", "pxd", "pxi"]},
|
|
{name: "CSS", mime: "text/css", mode: "css", ext: ["css"]},
|
|
{name: "CQL", mime: "text/x-cassandra", mode: "sql", ext: ["cql"]},
|
|
{name: "D", mime: "text/x-d", mode: "d", ext: ["d"]},
|
|
{name: "Dart", mimes: ["application/dart", "text/x-dart"], mode: "dart", ext: ["dart"]},
|
|
{name: "diff", mime: "text/x-diff", mode: "diff", ext: ["diff", "patch"]},
|
|
{name: "Django", mime: "text/x-django", mode: "django"},
|
|
{name: "Dockerfile", mime: "text/x-dockerfile", mode: "dockerfile", file: /^Dockerfile$/},
|
|
{name: "DTD", mime: "application/xml-dtd", mode: "dtd", ext: ["dtd"]},
|
|
{name: "Dylan", mime: "text/x-dylan", mode: "dylan", ext: ["dylan", "dyl", "intr"]},
|
|
{name: "EBNF", mime: "text/x-ebnf", mode: "ebnf"},
|
|
{name: "ECL", mime: "text/x-ecl", mode: "ecl", ext: ["ecl"]},
|
|
{name: "Eiffel", mime: "text/x-eiffel", mode: "eiffel", ext: ["e"]},
|
|
{name: "Embedded Javascript", mime: "application/x-ejs", mode: "htmlembedded", ext: ["ejs"]},
|
|
{name: "Embedded Ruby", mime: "application/x-erb", mode: "htmlembedded", ext: ["erb"]},
|
|
{name: "Erlang", mime: "text/x-erlang", mode: "erlang", ext: ["erl"]},
|
|
{name: "Forth", mime: "text/x-forth", mode: "forth", ext: ["forth", "fth", "4th"]},
|
|
{name: "Fortran", mime: "text/x-fortran", mode: "fortran", ext: ["f", "for", "f77", "f90"]},
|
|
{name: "F#", mime: "text/x-fsharp", mode: "mllike", ext: ["fs"], alias: ["fsharp"]},
|
|
{name: "Gas", mime: "text/x-gas", mode: "gas", ext: ["s"]},
|
|
{name: "Gherkin", mime: "text/x-feature", mode: "gherkin", ext: ["feature"]},
|
|
{name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm", file: /^(readme|contributing|history).md$/i},
|
|
{name: "Go", mime: "text/x-go", mode: "go", ext: ["go"]},
|
|
{name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy"]},
|
|
{name: "HAML", mime: "text/x-haml", mode: "haml", ext: ["haml"]},
|
|
{name: "Haskell", mime: "text/x-haskell", mode: "haskell", ext: ["hs"]},
|
|
{name: "Haxe", mime: "text/x-haxe", mode: "haxe", ext: ["hx"]},
|
|
{name: "HXML", mime: "text/x-hxml", mode: "haxe", ext: ["hxml"]},
|
|
{name: "ASP.NET", mime: "application/x-aspx", mode: "htmlembedded", ext: ["aspx"], alias: ["asp", "aspx"]},
|
|
{name: "HTML", mime: "text/html", mode: "htmlmixed", ext: ["html", "htm"], alias: ["xhtml"]},
|
|
{name: "HTTP", mime: "message/http", mode: "http"},
|
|
{name: "IDL", mime: "text/x-idl", mode: "idl", ext: ["pro"]},
|
|
{name: "Jade", mime: "text/x-jade", mode: "jade", ext: ["jade"]},
|
|
{name: "Java", mime: "text/x-java", mode: "clike", ext: ["java"]},
|
|
{name: "Java Server Pages", mime: "application/x-jsp", mode: "htmlembedded", ext: ["jsp"], alias: ["jsp"]},
|
|
{name: "JavaScript", mimes: ["text/javascript", "text/ecmascript", "application/javascript", "application/x-javascript", "application/ecmascript"],
|
|
mode: "javascript", ext: ["js"], alias: ["ecmascript", "js", "node"]},
|
|
{name: "JSON", mimes: ["application/json", "application/x-json"], mode: "javascript", ext: ["json", "map"], alias: ["json5"]},
|
|
{name: "JSON-LD", mime: "application/ld+json", mode: "javascript", ext: ["jsonld"], alias: ["jsonld"]},
|
|
{name: "Jinja2", mime: "null", mode: "jinja2"},
|
|
{name: "Julia", mime: "text/x-julia", mode: "julia", ext: ["jl"]},
|
|
{name: "Kotlin", mime: "text/x-kotlin", mode: "kotlin", ext: ["kt"]},
|
|
{name: "LESS", mime: "text/x-less", mode: "css", ext: ["less"]},
|
|
{name: "LiveScript", mime: "text/x-livescript", mode: "livescript", ext: ["ls"], alias: ["ls"]},
|
|
{name: "Lua", mime: "text/x-lua", mode: "lua", ext: ["lua"]},
|
|
{name: "Markdown", mime: "text/x-markdown", mode: "markdown", ext: ["markdown", "md", "mkd"]},
|
|
{name: "mIRC", mime: "text/mirc", mode: "mirc"},
|
|
{name: "MariaDB SQL", mime: "text/x-mariadb", mode: "sql"},
|
|
{name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]},
|
|
{name: "MS SQL", mime: "text/x-mssql", mode: "sql"},
|
|
{name: "MySQL", mime: "text/x-mysql", mode: "sql"},
|
|
{name: "Nginx", mime: "text/x-nginx-conf", mode: "nginx", file: /nginx.*\.conf$/i},
|
|
{name: "NTriples", mime: "text/n-triples", mode: "ntriples", ext: ["nt"]},
|
|
{name: "Objective C", mime: "text/x-objectivec", mode: "clike", ext: ["m", "mm"]},
|
|
{name: "OCaml", mime: "text/x-ocaml", mode: "mllike", ext: ["ml", "mli", "mll", "mly"]},
|
|
{name: "Octave", mime: "text/x-octave", mode: "octave", ext: ["m"]},
|
|
{name: "Pascal", mime: "text/x-pascal", mode: "pascal", ext: ["p", "pas"]},
|
|
{name: "PEG.js", mime: "null", mode: "pegjs", ext: ["jsonld"]},
|
|
{name: "Perl", mime: "text/x-perl", mode: "perl", ext: ["pl", "pm"]},
|
|
{name: "PHP", mime: "application/x-httpd-php", mode: "php", ext: ["php", "php3", "php4", "php5", "phtml"]},
|
|
{name: "Pig", mime: "text/x-pig", mode: "pig", ext: ["pig"]},
|
|
{name: "Plain Text", mime: "text/plain", mode: "null", ext: ["txt", "text", "conf", "def", "list", "log"]},
|
|
{name: "PLSQL", mime: "text/x-plsql", mode: "sql", ext: ["pls"]},
|
|
{name: "Properties files", mime: "text/x-properties", mode: "properties", ext: ["properties", "ini", "in"], alias: ["ini", "properties"]},
|
|
{name: "Python", mime: "text/x-python", mode: "python", ext: ["py", "pyw"]},
|
|
{name: "Puppet", mime: "text/x-puppet", mode: "puppet", ext: ["pp"]},
|
|
{name: "Q", mime: "text/x-q", mode: "q", ext: ["q"]},
|
|
{name: "R", mime: "text/x-rsrc", mode: "r", ext: ["r"], alias: ["rscript"]},
|
|
{name: "reStructuredText", mime: "text/x-rst", mode: "rst", ext: ["rst"], alias: ["rst"]},
|
|
{name: "RPM Changes", mime: "text/x-rpm-changes", mode: "rpm"},
|
|
{name: "RPM Spec", mime: "text/x-rpm-spec", mode: "rpm", ext: ["spec"]},
|
|
{name: "Ruby", mime: "text/x-ruby", mode: "ruby", ext: ["rb"], alias: ["jruby", "macruby", "rake", "rb", "rbx"]},
|
|
{name: "Rust", mime: "text/x-rustsrc", mode: "rust", ext: ["rs"]},
|
|
{name: "Sass", mime: "text/x-sass", mode: "sass", ext: ["sass"]},
|
|
{name: "Scala", mime: "text/x-scala", mode: "clike", ext: ["scala"]},
|
|
{name: "Scheme", mime: "text/x-scheme", mode: "scheme", ext: ["scm", "ss"]},
|
|
{name: "SCSS", mime: "text/x-scss", mode: "css", ext: ["scss"]},
|
|
{name: "Shell", mime: "text/x-sh", mode: "shell", ext: ["sh", "ksh", "bash"], alias: ["bash", "sh", "zsh"]},
|
|
{name: "Sieve", mime: "application/sieve", mode: "sieve", ext: ["siv", "sieve"]},
|
|
{name: "Slim", mimes: ["text/x-slim", "application/x-slim"], mode: "slim", ext: ["slim"]},
|
|
{name: "Smalltalk", mime: "text/x-stsrc", mode: "smalltalk", ext: ["st"]},
|
|
{name: "Smarty", mime: "text/x-smarty", mode: "smarty", ext: ["tpl"]},
|
|
{name: "SmartyMixed", mime: "text/x-smarty", mode: "smartymixed"},
|
|
{name: "Solr", mime: "text/x-solr", mode: "solr"},
|
|
{name: "Soy", mime: "text/x-soy", mode: "soy", ext: ["soy"], alias: ["closure template"]},
|
|
{name: "SPARQL", mime: "application/sparql-query", mode: "sparql", ext: ["rq", "sparql"], alias: ["sparul"]},
|
|
{name: "Spreadsheet", mime: "text/x-spreadsheet", mode: "spreadsheet", alias: ["excel", "formula"]},
|
|
{name: "SQL", mime: "text/x-sql", mode: "sql", ext: ["sql"]},
|
|
{name: "MariaDB", mime: "text/x-mariadb", mode: "sql"},
|
|
{name: "sTeX", mime: "text/x-stex", mode: "stex"},
|
|
{name: "LaTeX", mime: "text/x-latex", mode: "stex", ext: ["text", "ltx"], alias: ["tex"]},
|
|
{name: "SystemVerilog", mime: "text/x-systemverilog", mode: "verilog", ext: ["v"]},
|
|
{name: "Tcl", mime: "text/x-tcl", mode: "tcl", ext: ["tcl"]},
|
|
{name: "Textile", mime: "text/x-textile", mode: "textile", ext: ["textile"]},
|
|
{name: "TiddlyWiki ", mime: "text/x-tiddlywiki", mode: "tiddlywiki"},
|
|
{name: "Tiki wiki", mime: "text/tiki", mode: "tiki"},
|
|
{name: "TOML", mime: "text/x-toml", mode: "toml", ext: ["toml"]},
|
|
{name: "Tornado", mime: "text/x-tornado", mode: "tornado"},
|
|
{name: "Turtle", mime: "text/turtle", mode: "turtle", ext: ["ttl"]},
|
|
{name: "TypeScript", mime: "application/typescript", mode: "javascript", ext: ["ts"], alias: ["ts"]},
|
|
{name: "VB.NET", mime: "text/x-vb", mode: "vb", ext: ["vb"]},
|
|
{name: "VBScript", mime: "text/vbscript", mode: "vbscript", ext: ["vbs"]},
|
|
{name: "Velocity", mime: "text/velocity", mode: "velocity", ext: ["vtl"]},
|
|
{name: "Verilog", mime: "text/x-verilog", mode: "verilog", ext: ["v"]},
|
|
{name: "XML", mimes: ["application/xml", "text/xml"], mode: "xml", ext: ["xml", "xsl", "xsd"], alias: ["rss", "wsdl", "xsd"]},
|
|
{name: "XQuery", mime: "application/xquery", mode: "xquery", ext: ["xy", "xquery"]},
|
|
{name: "YAML", mime: "text/x-yaml", mode: "yaml", ext: ["yaml"], alias: ["yml"]},
|
|
{name: "Z80", mime: "text/x-z80", mode: "z80", ext: ["z80"]}
|
|
];
|
|
// Ensure all modes have a mime property for backwards compatibility
|
|
for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
|
|
var info = CodeMirror.modeInfo[i];
|
|
if (info.mimes) info.mime = info.mimes[0];
|
|
}
|
|
|
|
CodeMirror.findModeByMIME = function(mime) {
|
|
mime = mime.toLowerCase();
|
|
for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
|
|
var info = CodeMirror.modeInfo[i];
|
|
if (info.mime == mime) return info;
|
|
if (info.mimes) for (var j = 0; j < info.mimes.length; j++)
|
|
if (info.mimes[j] == mime) return info;
|
|
}
|
|
};
|
|
|
|
CodeMirror.findModeByExtension = function(ext) {
|
|
for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
|
|
var info = CodeMirror.modeInfo[i];
|
|
if (info.ext) for (var j = 0; j < info.ext.length; j++)
|
|
if (info.ext[j] == ext) return info;
|
|
}
|
|
};
|
|
|
|
CodeMirror.findModeByFileName = function(filename) {
|
|
for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
|
|
var info = CodeMirror.modeInfo[i];
|
|
if (info.file && info.file.test(filename)) return info;
|
|
}
|
|
var dot = filename.lastIndexOf(".");
|
|
var ext = dot > -1 && filename.substring(dot + 1, filename.length);
|
|
if (ext) return CodeMirror.findModeByExtension(ext);
|
|
};
|
|
|
|
CodeMirror.findModeByName = function(name) {
|
|
name = name.toLowerCase();
|
|
for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
|
|
var info = CodeMirror.modeInfo[i];
|
|
if (info.name.toLowerCase() == name) return info;
|
|
if (info.alias) for (var j = 0; j < info.alias.length; j++)
|
|
if (info.alias[j].toLowerCase() == name) return info;
|
|
}
|
|
};
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
|
|
|
|
var indentUnit = config.indentUnit,
|
|
tokenHooks = parserConfig.tokenHooks,
|
|
documentTypes = parserConfig.documentTypes || {},
|
|
mediaTypes = parserConfig.mediaTypes || {},
|
|
mediaFeatures = parserConfig.mediaFeatures || {},
|
|
propertyKeywords = parserConfig.propertyKeywords || {},
|
|
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
|
|
fontProperties = parserConfig.fontProperties || {},
|
|
counterDescriptors = parserConfig.counterDescriptors || {},
|
|
colorKeywords = parserConfig.colorKeywords || {},
|
|
valueKeywords = parserConfig.valueKeywords || {},
|
|
allowNested = parserConfig.allowNested;
|
|
|
|
var type, override;
|
|
function ret(style, tp) { type = tp; return style; }
|
|
|
|
// Tokenizers
|
|
|
|
function tokenBase(stream, state) {
|
|
var ch = stream.next();
|
|
if (tokenHooks[ch]) {
|
|
var result = tokenHooks[ch](stream, state);
|
|
if (result !== false) return result;
|
|
}
|
|
if (ch == "@") {
|
|
stream.eatWhile(/[\w\\\-]/);
|
|
return ret("def", stream.current());
|
|
} else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
|
|
return ret(null, "compare");
|
|
} else if (ch == "\"" || ch == "'") {
|
|
state.tokenize = tokenString(ch);
|
|
return state.tokenize(stream, state);
|
|
} else if (ch == "#") {
|
|
stream.eatWhile(/[\w\\\-]/);
|
|
return ret("atom", "hash");
|
|
} else if (ch == "!") {
|
|
stream.match(/^\s*\w*/);
|
|
return ret("keyword", "important");
|
|
} else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
|
|
stream.eatWhile(/[\w.%]/);
|
|
return ret("number", "unit");
|
|
} else if (ch === "-") {
|
|
if (/[\d.]/.test(stream.peek())) {
|
|
stream.eatWhile(/[\w.%]/);
|
|
return ret("number", "unit");
|
|
} else if (stream.match(/^-[\w\\\-]+/)) {
|
|
stream.eatWhile(/[\w\\\-]/);
|
|
if (stream.match(/^\s*:/, false))
|
|
return ret("variable-2", "variable-definition");
|
|
return ret("variable-2", "variable");
|
|
} else if (stream.match(/^\w+-/)) {
|
|
return ret("meta", "meta");
|
|
}
|
|
} else if (/[,+>*\/]/.test(ch)) {
|
|
return ret(null, "select-op");
|
|
} else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
|
|
return ret("qualifier", "qualifier");
|
|
} else if (/[:;{}\[\]\(\)]/.test(ch)) {
|
|
return ret(null, ch);
|
|
} else if ((ch == "u" && stream.match(/rl(-prefix)?\(/)) ||
|
|
(ch == "d" && stream.match("omain(")) ||
|
|
(ch == "r" && stream.match("egexp("))) {
|
|
stream.backUp(1);
|
|
state.tokenize = tokenParenthesized;
|
|
return ret("property", "word");
|
|
} else if (/[\w\\\-]/.test(ch)) {
|
|
stream.eatWhile(/[\w\\\-]/);
|
|
return ret("property", "word");
|
|
} else {
|
|
return ret(null, null);
|
|
}
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (ch == quote && !escaped) {
|
|
if (quote == ")") stream.backUp(1);
|
|
break;
|
|
}
|
|
escaped = !escaped && ch == "\\";
|
|
}
|
|
if (ch == quote || !escaped && quote != ")") state.tokenize = null;
|
|
return ret("string", "string");
|
|
};
|
|
}
|
|
|
|
function tokenParenthesized(stream, state) {
|
|
stream.next(); // Must be '('
|
|
if (!stream.match(/\s*[\"\')]/, false))
|
|
state.tokenize = tokenString(")");
|
|
else
|
|
state.tokenize = null;
|
|
return ret(null, "(");
|
|
}
|
|
|
|
// Context management
|
|
|
|
function Context(type, indent, prev) {
|
|
this.type = type;
|
|
this.indent = indent;
|
|
this.prev = prev;
|
|
}
|
|
|
|
function pushContext(state, stream, type) {
|
|
state.context = new Context(type, stream.indentation() + indentUnit, state.context);
|
|
return type;
|
|
}
|
|
|
|
function popContext(state) {
|
|
state.context = state.context.prev;
|
|
return state.context.type;
|
|
}
|
|
|
|
function pass(type, stream, state) {
|
|
return states[state.context.type](type, stream, state);
|
|
}
|
|
function popAndPass(type, stream, state, n) {
|
|
for (var i = n || 1; i > 0; i--)
|
|
state.context = state.context.prev;
|
|
return pass(type, stream, state);
|
|
}
|
|
|
|
// Parser
|
|
|
|
function wordAsValue(stream) {
|
|
var word = stream.current().toLowerCase();
|
|
if (valueKeywords.hasOwnProperty(word))
|
|
override = "atom";
|
|
else if (colorKeywords.hasOwnProperty(word))
|
|
override = "keyword";
|
|
else
|
|
override = "variable";
|
|
}
|
|
|
|
var states = {};
|
|
|
|
states.top = function(type, stream, state) {
|
|
if (type == "{") {
|
|
return pushContext(state, stream, "block");
|
|
} else if (type == "}" && state.context.prev) {
|
|
return popContext(state);
|
|
} else if (/@(media|supports|(-moz-)?document)/.test(type)) {
|
|
return pushContext(state, stream, "atBlock");
|
|
} else if (/@(font-face|counter-style)/.test(type)) {
|
|
state.stateArg = type;
|
|
return "restricted_atBlock_before";
|
|
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
|
|
return "keyframes";
|
|
} else if (type && type.charAt(0) == "@") {
|
|
return pushContext(state, stream, "at");
|
|
} else if (type == "hash") {
|
|
override = "builtin";
|
|
} else if (type == "word") {
|
|
override = "tag";
|
|
} else if (type == "variable-definition") {
|
|
return "maybeprop";
|
|
} else if (type == "interpolation") {
|
|
return pushContext(state, stream, "interpolation");
|
|
} else if (type == ":") {
|
|
return "pseudo";
|
|
} else if (allowNested && type == "(") {
|
|
return pushContext(state, stream, "parens");
|
|
}
|
|
return state.context.type;
|
|
};
|
|
|
|
states.block = function(type, stream, state) {
|
|
if (type == "word") {
|
|
var word = stream.current().toLowerCase();
|
|
if (propertyKeywords.hasOwnProperty(word)) {
|
|
override = "property";
|
|
return "maybeprop";
|
|
} else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
|
|
override = "string-2";
|
|
return "maybeprop";
|
|
} else if (allowNested) {
|
|
override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag";
|
|
return "block";
|
|
} else {
|
|
override += " error";
|
|
return "maybeprop";
|
|
}
|
|
} else if (type == "meta") {
|
|
return "block";
|
|
} else if (!allowNested && (type == "hash" || type == "qualifier")) {
|
|
override = "error";
|
|
return "block";
|
|
} else {
|
|
return states.top(type, stream, state);
|
|
}
|
|
};
|
|
|
|
states.maybeprop = function(type, stream, state) {
|
|
if (type == ":") return pushContext(state, stream, "prop");
|
|
return pass(type, stream, state);
|
|
};
|
|
|
|
states.prop = function(type, stream, state) {
|
|
if (type == ";") return popContext(state);
|
|
if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
|
|
if (type == "}" || type == "{") return popAndPass(type, stream, state);
|
|
if (type == "(") return pushContext(state, stream, "parens");
|
|
|
|
if (type == "hash" && !/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) {
|
|
override += " error";
|
|
} else if (type == "word") {
|
|
wordAsValue(stream);
|
|
} else if (type == "interpolation") {
|
|
return pushContext(state, stream, "interpolation");
|
|
}
|
|
return "prop";
|
|
};
|
|
|
|
states.propBlock = function(type, _stream, state) {
|
|
if (type == "}") return popContext(state);
|
|
if (type == "word") { override = "property"; return "maybeprop"; }
|
|
return state.context.type;
|
|
};
|
|
|
|
states.parens = function(type, stream, state) {
|
|
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
|
if (type == ")") return popContext(state);
|
|
if (type == "(") return pushContext(state, stream, "parens");
|
|
if (type == "word") wordAsValue(stream);
|
|
return "parens";
|
|
};
|
|
|
|
states.pseudo = function(type, stream, state) {
|
|
if (type == "word") {
|
|
override = "variable-3";
|
|
return state.context.type;
|
|
}
|
|
return pass(type, stream, state);
|
|
};
|
|
|
|
states.atBlock = function(type, stream, state) {
|
|
if (type == "(") return pushContext(state, stream, "atBlock_parens");
|
|
if (type == "}") return popAndPass(type, stream, state);
|
|
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
|
|
|
|
if (type == "word") {
|
|
var word = stream.current().toLowerCase();
|
|
if (word == "only" || word == "not" || word == "and" || word == "or")
|
|
override = "keyword";
|
|
else if (documentTypes.hasOwnProperty(word))
|
|
override = "tag";
|
|
else if (mediaTypes.hasOwnProperty(word))
|
|
override = "attribute";
|
|
else if (mediaFeatures.hasOwnProperty(word))
|
|
override = "property";
|
|
else if (propertyKeywords.hasOwnProperty(word))
|
|
override = "property";
|
|
else if (nonStandardPropertyKeywords.hasOwnProperty(word))
|
|
override = "string-2";
|
|
else if (valueKeywords.hasOwnProperty(word))
|
|
override = "atom";
|
|
else
|
|
override = "error";
|
|
}
|
|
return state.context.type;
|
|
};
|
|
|
|
states.atBlock_parens = function(type, stream, state) {
|
|
if (type == ")") return popContext(state);
|
|
if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
|
|
return states.atBlock(type, stream, state);
|
|
};
|
|
|
|
states.restricted_atBlock_before = function(type, stream, state) {
|
|
if (type == "{")
|
|
return pushContext(state, stream, "restricted_atBlock");
|
|
if (type == "word" && state.stateArg == "@counter-style") {
|
|
override = "variable";
|
|
return "restricted_atBlock_before";
|
|
}
|
|
return pass(type, stream, state);
|
|
};
|
|
|
|
states.restricted_atBlock = function(type, stream, state) {
|
|
if (type == "}") {
|
|
state.stateArg = null;
|
|
return popContext(state);
|
|
}
|
|
if (type == "word") {
|
|
if ((state.stateArg == "@font-face" && !fontProperties.hasOwnProperty(stream.current().toLowerCase())) ||
|
|
(state.stateArg == "@counter-style" && !counterDescriptors.hasOwnProperty(stream.current().toLowerCase())))
|
|
override = "error";
|
|
else
|
|
override = "property";
|
|
return "maybeprop";
|
|
}
|
|
return "restricted_atBlock";
|
|
};
|
|
|
|
states.keyframes = function(type, stream, state) {
|
|
if (type == "word") { override = "variable"; return "keyframes"; }
|
|
if (type == "{") return pushContext(state, stream, "top");
|
|
return pass(type, stream, state);
|
|
};
|
|
|
|
states.at = function(type, stream, state) {
|
|
if (type == ";") return popContext(state);
|
|
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
|
if (type == "word") override = "tag";
|
|
else if (type == "hash") override = "builtin";
|
|
return "at";
|
|
};
|
|
|
|
states.interpolation = function(type, stream, state) {
|
|
if (type == "}") return popContext(state);
|
|
if (type == "{" || type == ";") return popAndPass(type, stream, state);
|
|
if (type != "variable") override = "error";
|
|
return "interpolation";
|
|
};
|
|
|
|
return {
|
|
startState: function(base) {
|
|
return {tokenize: null,
|
|
state: "top",
|
|
stateArg: null,
|
|
context: new Context("top", base || 0, null)};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (!state.tokenize && stream.eatSpace()) return null;
|
|
var style = (state.tokenize || tokenBase)(stream, state);
|
|
if (style && typeof style == "object") {
|
|
type = style[1];
|
|
style = style[0];
|
|
}
|
|
override = style;
|
|
state.state = states[state.state](type, stream, state);
|
|
return override;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
var cx = state.context, ch = textAfter && textAfter.charAt(0);
|
|
var indent = cx.indent;
|
|
if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
|
|
if (cx.prev &&
|
|
(ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "restricted_atBlock") ||
|
|
ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") ||
|
|
ch == "{" && (cx.type == "at" || cx.type == "atBlock"))) {
|
|
indent = cx.indent - indentUnit;
|
|
cx = cx.prev;
|
|
}
|
|
return indent;
|
|
},
|
|
|
|
electricChars: "}",
|
|
blockCommentStart: "/*",
|
|
blockCommentEnd: "*/",
|
|
fold: "brace"
|
|
};
|
|
});
|
|
|
|
function keySet(array) {
|
|
var keys = {};
|
|
for (var i = 0; i < array.length; ++i) {
|
|
keys[array[i]] = true;
|
|
}
|
|
return keys;
|
|
}
|
|
|
|
var documentTypes_ = [
|
|
"domain", "regexp", "url", "url-prefix"
|
|
], documentTypes = keySet(documentTypes_);
|
|
|
|
var mediaTypes_ = [
|
|
"all", "aural", "braille", "handheld", "print", "projection", "screen",
|
|
"tty", "tv", "embossed"
|
|
], mediaTypes = keySet(mediaTypes_);
|
|
|
|
var mediaFeatures_ = [
|
|
"width", "min-width", "max-width", "height", "min-height", "max-height",
|
|
"device-width", "min-device-width", "max-device-width", "device-height",
|
|
"min-device-height", "max-device-height", "aspect-ratio",
|
|
"min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
|
|
"min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
|
|
"max-color", "color-index", "min-color-index", "max-color-index",
|
|
"monochrome", "min-monochrome", "max-monochrome", "resolution",
|
|
"min-resolution", "max-resolution", "scan", "grid"
|
|
], mediaFeatures = keySet(mediaFeatures_);
|
|
|
|
var propertyKeywords_ = [
|
|
"align-content", "align-items", "align-self", "alignment-adjust",
|
|
"alignment-baseline", "anchor-point", "animation", "animation-delay",
|
|
"animation-direction", "animation-duration", "animation-fill-mode",
|
|
"animation-iteration-count", "animation-name", "animation-play-state",
|
|
"animation-timing-function", "appearance", "azimuth", "backface-visibility",
|
|
"background", "background-attachment", "background-clip", "background-color",
|
|
"background-image", "background-origin", "background-position",
|
|
"background-repeat", "background-size", "baseline-shift", "binding",
|
|
"bleed", "bookmark-label", "bookmark-level", "bookmark-state",
|
|
"bookmark-target", "border", "border-bottom", "border-bottom-color",
|
|
"border-bottom-left-radius", "border-bottom-right-radius",
|
|
"border-bottom-style", "border-bottom-width", "border-collapse",
|
|
"border-color", "border-image", "border-image-outset",
|
|
"border-image-repeat", "border-image-slice", "border-image-source",
|
|
"border-image-width", "border-left", "border-left-color",
|
|
"border-left-style", "border-left-width", "border-radius", "border-right",
|
|
"border-right-color", "border-right-style", "border-right-width",
|
|
"border-spacing", "border-style", "border-top", "border-top-color",
|
|
"border-top-left-radius", "border-top-right-radius", "border-top-style",
|
|
"border-top-width", "border-width", "bottom", "box-decoration-break",
|
|
"box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
|
|
"caption-side", "clear", "clip", "color", "color-profile", "column-count",
|
|
"column-fill", "column-gap", "column-rule", "column-rule-color",
|
|
"column-rule-style", "column-rule-width", "column-span", "column-width",
|
|
"columns", "content", "counter-increment", "counter-reset", "crop", "cue",
|
|
"cue-after", "cue-before", "cursor", "direction", "display",
|
|
"dominant-baseline", "drop-initial-after-adjust",
|
|
"drop-initial-after-align", "drop-initial-before-adjust",
|
|
"drop-initial-before-align", "drop-initial-size", "drop-initial-value",
|
|
"elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
|
|
"flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
|
|
"float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
|
|
"font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
|
|
"font-stretch", "font-style", "font-synthesis", "font-variant",
|
|
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
|
|
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
|
|
"font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
|
|
"grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
|
|
"grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
|
|
"grid-template", "grid-template-areas", "grid-template-columns",
|
|
"grid-template-rows", "hanging-punctuation", "height", "hyphens",
|
|
"icon", "image-orientation", "image-rendering", "image-resolution",
|
|
"inline-box-align", "justify-content", "left", "letter-spacing",
|
|
"line-break", "line-height", "line-stacking", "line-stacking-ruby",
|
|
"line-stacking-shift", "line-stacking-strategy", "list-style",
|
|
"list-style-image", "list-style-position", "list-style-type", "margin",
|
|
"margin-bottom", "margin-left", "margin-right", "margin-top",
|
|
"marker-offset", "marks", "marquee-direction", "marquee-loop",
|
|
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
|
|
"max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
|
|
"nav-left", "nav-right", "nav-up", "object-fit", "object-position",
|
|
"opacity", "order", "orphans", "outline",
|
|
"outline-color", "outline-offset", "outline-style", "outline-width",
|
|
"overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
|
|
"padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
|
|
"page", "page-break-after", "page-break-before", "page-break-inside",
|
|
"page-policy", "pause", "pause-after", "pause-before", "perspective",
|
|
"perspective-origin", "pitch", "pitch-range", "play-during", "position",
|
|
"presentation-level", "punctuation-trim", "quotes", "region-break-after",
|
|
"region-break-before", "region-break-inside", "region-fragment",
|
|
"rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
|
|
"right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
|
|
"ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
|
|
"shape-outside", "size", "speak", "speak-as", "speak-header",
|
|
"speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
|
|
"tab-size", "table-layout", "target", "target-name", "target-new",
|
|
"target-position", "text-align", "text-align-last", "text-decoration",
|
|
"text-decoration-color", "text-decoration-line", "text-decoration-skip",
|
|
"text-decoration-style", "text-emphasis", "text-emphasis-color",
|
|
"text-emphasis-position", "text-emphasis-style", "text-height",
|
|
"text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
|
|
"text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
|
|
"text-wrap", "top", "transform", "transform-origin", "transform-style",
|
|
"transition", "transition-delay", "transition-duration",
|
|
"transition-property", "transition-timing-function", "unicode-bidi",
|
|
"vertical-align", "visibility", "voice-balance", "voice-duration",
|
|
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
|
|
"voice-volume", "volume", "white-space", "widows", "width", "word-break",
|
|
"word-spacing", "word-wrap", "z-index",
|
|
// SVG-specific
|
|
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
|
|
"flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
|
|
"color-interpolation", "color-interpolation-filters",
|
|
"color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
|
|
"marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
|
|
"stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
|
|
"stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
|
|
"baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
|
|
"glyph-orientation-vertical", "text-anchor", "writing-mode"
|
|
], propertyKeywords = keySet(propertyKeywords_);
|
|
|
|
var nonStandardPropertyKeywords_ = [
|
|
"scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
|
|
"scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
|
|
"scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
|
|
"searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
|
|
"searchfield-results-decoration", "zoom"
|
|
], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
|
|
|
|
var fontProperties_ = [
|
|
"font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
|
|
"font-stretch", "font-weight", "font-style"
|
|
], fontProperties = keySet(fontProperties_);
|
|
|
|
var counterDescriptors_ = [
|
|
"additive-symbols", "fallback", "negative", "pad", "prefix", "range",
|
|
"speak-as", "suffix", "symbols", "system"
|
|
], counterDescriptors = keySet(counterDescriptors_);
|
|
|
|
var colorKeywords_ = [
|
|
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
|
|
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
|
|
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
|
|
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
|
|
"darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
|
|
"darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
|
|
"darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
|
|
"deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
|
|
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
|
|
"gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
|
|
"hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
|
|
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
|
|
"lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
|
|
"lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
|
|
"lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
|
|
"maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
|
|
"mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
|
|
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
|
|
"navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
|
|
"orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
|
|
"papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
|
|
"purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",
|
|
"salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
|
|
"slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
|
|
"teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
|
|
"whitesmoke", "yellow", "yellowgreen"
|
|
], colorKeywords = keySet(colorKeywords_);
|
|
|
|
var valueKeywords_ = [
|
|
"above", "absolute", "activeborder", "additive", "activecaption", "afar",
|
|
"after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate",
|
|
"always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
|
|
"arabic-indic", "armenian", "asterisks", "attr", "auto", "avoid", "avoid-column", "avoid-page",
|
|
"avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
|
|
"bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
|
|
"both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel",
|
|
"buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "cambodian",
|
|
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
|
|
"cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch",
|
|
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
|
|
"col-resize", "collapse", "column", "compact", "condensed", "contain", "content",
|
|
"content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
|
|
"cross", "crosshair", "currentcolor", "cursive", "cyclic", "dashed", "decimal",
|
|
"decimal-leading-zero", "default", "default-button", "destination-atop",
|
|
"destination-in", "destination-out", "destination-over", "devanagari",
|
|
"disc", "discard", "disclosure-closed", "disclosure-open", "document",
|
|
"dot-dash", "dot-dot-dash",
|
|
"dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
|
|
"element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
|
|
"ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
|
|
"ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
|
|
"ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
|
|
"ethiopic-halehame-gez", "ethiopic-halehame-om-et",
|
|
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
|
|
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
|
|
"ethiopic-numeric", "ew-resize", "expanded", "extends", "extra-condensed",
|
|
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "footnotes",
|
|
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
|
|
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
|
|
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
|
|
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
|
|
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
|
|
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
|
|
"inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert",
|
|
"italic", "japanese-formal", "japanese-informal", "justify", "kannada",
|
|
"katakana", "katakana-iroha", "keep-all", "khmer",
|
|
"korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal",
|
|
"landscape", "lao", "large", "larger", "left", "level", "lighter",
|
|
"line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem",
|
|
"local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
|
|
"lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
|
|
"lower-roman", "lowercase", "ltr", "malayalam", "match", "matrix", "matrix3d",
|
|
"media-controls-background", "media-current-time-display",
|
|
"media-fullscreen-button", "media-mute-button", "media-play-button",
|
|
"media-return-to-realtime-button", "media-rewind-button",
|
|
"media-seek-back-button", "media-seek-forward-button", "media-slider",
|
|
"media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
|
|
"media-volume-slider-container", "media-volume-sliderthumb", "medium",
|
|
"menu", "menulist", "menulist-button", "menulist-text",
|
|
"menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
|
|
"mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
|
|
"narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
|
|
"no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
|
|
"ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
|
|
"optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
|
|
"outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
|
|
"painted", "page", "paused", "persian", "perspective", "plus-darker", "plus-lighter",
|
|
"pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d",
|
|
"progress", "push-button", "radial-gradient", "radio", "read-only",
|
|
"read-write", "read-write-plaintext-only", "rectangle", "region",
|
|
"relative", "repeat", "repeating-linear-gradient",
|
|
"repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse",
|
|
"rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY",
|
|
"rotateZ", "round", "row-resize", "rtl", "run-in", "running",
|
|
"s-resize", "sans-serif", "scale", "scale3d", "scaleX", "scaleY", "scaleZ",
|
|
"scroll", "scrollbar", "se-resize", "searchfield",
|
|
"searchfield-cancel-button", "searchfield-decoration",
|
|
"searchfield-results-button", "searchfield-results-decoration",
|
|
"semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
|
|
"simp-chinese-formal", "simp-chinese-informal", "single",
|
|
"skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal",
|
|
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
|
|
"small", "small-caps", "small-caption", "smaller", "solid", "somali",
|
|
"source-atop", "source-in", "source-out", "source-over", "space", "spell-out", "square",
|
|
"square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
|
|
"subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "table",
|
|
"table-caption", "table-cell", "table-column", "table-column-group",
|
|
"table-footer-group", "table-header-group", "table-row", "table-row-group",
|
|
"tamil",
|
|
"telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
|
|
"thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
|
|
"threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
|
|
"tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
|
|
"trad-chinese-formal", "trad-chinese-informal",
|
|
"translate", "translate3d", "translateX", "translateY", "translateZ",
|
|
"transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
|
|
"upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
|
|
"upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
|
|
"var", "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
|
|
"visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
|
|
"window", "windowframe", "windowtext", "words", "x-large", "x-small", "xor",
|
|
"xx-large", "xx-small"
|
|
], valueKeywords = keySet(valueKeywords_);
|
|
|
|
var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(propertyKeywords_)
|
|
.concat(nonStandardPropertyKeywords_).concat(colorKeywords_).concat(valueKeywords_);
|
|
CodeMirror.registerHelper("hintWords", "css", allWords);
|
|
|
|
function tokenCComment(stream, state) {
|
|
var maybeEnd = false, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (maybeEnd && ch == "/") {
|
|
state.tokenize = null;
|
|
break;
|
|
}
|
|
maybeEnd = (ch == "*");
|
|
}
|
|
return ["comment", "comment"];
|
|
}
|
|
|
|
function tokenSGMLComment(stream, state) {
|
|
if (stream.skipTo("-->")) {
|
|
stream.match("-->");
|
|
state.tokenize = null;
|
|
} else {
|
|
stream.skipToEnd();
|
|
}
|
|
return ["comment", "comment"];
|
|
}
|
|
|
|
CodeMirror.defineMIME("text/css", {
|
|
documentTypes: documentTypes,
|
|
mediaTypes: mediaTypes,
|
|
mediaFeatures: mediaFeatures,
|
|
propertyKeywords: propertyKeywords,
|
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
|
fontProperties: fontProperties,
|
|
counterDescriptors: counterDescriptors,
|
|
colorKeywords: colorKeywords,
|
|
valueKeywords: valueKeywords,
|
|
tokenHooks: {
|
|
"<": function(stream, state) {
|
|
if (!stream.match("!--")) return false;
|
|
state.tokenize = tokenSGMLComment;
|
|
return tokenSGMLComment(stream, state);
|
|
},
|
|
"/": function(stream, state) {
|
|
if (!stream.eat("*")) return false;
|
|
state.tokenize = tokenCComment;
|
|
return tokenCComment(stream, state);
|
|
}
|
|
},
|
|
name: "css"
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-scss", {
|
|
mediaTypes: mediaTypes,
|
|
mediaFeatures: mediaFeatures,
|
|
propertyKeywords: propertyKeywords,
|
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
|
colorKeywords: colorKeywords,
|
|
valueKeywords: valueKeywords,
|
|
fontProperties: fontProperties,
|
|
allowNested: true,
|
|
tokenHooks: {
|
|
"/": function(stream, state) {
|
|
if (stream.eat("/")) {
|
|
stream.skipToEnd();
|
|
return ["comment", "comment"];
|
|
} else if (stream.eat("*")) {
|
|
state.tokenize = tokenCComment;
|
|
return tokenCComment(stream, state);
|
|
} else {
|
|
return ["operator", "operator"];
|
|
}
|
|
},
|
|
":": function(stream) {
|
|
if (stream.match(/\s*\{/))
|
|
return [null, "{"];
|
|
return false;
|
|
},
|
|
"$": function(stream) {
|
|
stream.match(/^[\w-]+/);
|
|
if (stream.match(/^\s*:/, false))
|
|
return ["variable-2", "variable-definition"];
|
|
return ["variable-2", "variable"];
|
|
},
|
|
"#": function(stream) {
|
|
if (!stream.eat("{")) return false;
|
|
return [null, "interpolation"];
|
|
}
|
|
},
|
|
name: "css",
|
|
helperType: "scss"
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-less", {
|
|
mediaTypes: mediaTypes,
|
|
mediaFeatures: mediaFeatures,
|
|
propertyKeywords: propertyKeywords,
|
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
|
colorKeywords: colorKeywords,
|
|
valueKeywords: valueKeywords,
|
|
fontProperties: fontProperties,
|
|
allowNested: true,
|
|
tokenHooks: {
|
|
"/": function(stream, state) {
|
|
if (stream.eat("/")) {
|
|
stream.skipToEnd();
|
|
return ["comment", "comment"];
|
|
} else if (stream.eat("*")) {
|
|
state.tokenize = tokenCComment;
|
|
return tokenCComment(stream, state);
|
|
} else {
|
|
return ["operator", "operator"];
|
|
}
|
|
},
|
|
"@": function(stream) {
|
|
if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/, false)) return false;
|
|
stream.eatWhile(/[\w\\\-]/);
|
|
if (stream.match(/^\s*:/, false))
|
|
return ["variable-2", "variable-definition"];
|
|
return ["variable-2", "variable"];
|
|
},
|
|
"&": function() {
|
|
return ["atom", "atom"];
|
|
}
|
|
},
|
|
name: "css",
|
|
helperType: "less"
|
|
});
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("sass", function(config) {
|
|
function tokenRegexp(words) {
|
|
return new RegExp("^" + words.join("|"));
|
|
}
|
|
|
|
var keywords = ["true", "false", "null", "auto"];
|
|
var keywordsRegexp = new RegExp("^" + keywords.join("|"));
|
|
|
|
var operators = ["\\(", "\\)", "=", ">", "<", "==", ">=", "<=", "\\+", "-",
|
|
"\\!=", "/", "\\*", "%", "and", "or", "not", ";","\\{","\\}",":"];
|
|
var opRegexp = tokenRegexp(operators);
|
|
|
|
var pseudoElementsRegexp = /^::?[a-zA-Z_][\w\-]*/;
|
|
|
|
function urlTokens(stream, state) {
|
|
var ch = stream.peek();
|
|
|
|
if (ch === ")") {
|
|
stream.next();
|
|
state.tokenizer = tokenBase;
|
|
return "operator";
|
|
} else if (ch === "(") {
|
|
stream.next();
|
|
stream.eatSpace();
|
|
|
|
return "operator";
|
|
} else if (ch === "'" || ch === '"') {
|
|
state.tokenizer = buildStringTokenizer(stream.next());
|
|
return "string";
|
|
} else {
|
|
state.tokenizer = buildStringTokenizer(")", false);
|
|
return "string";
|
|
}
|
|
}
|
|
function comment(indentation, multiLine) {
|
|
return function(stream, state) {
|
|
if (stream.sol() && stream.indentation() <= indentation) {
|
|
state.tokenizer = tokenBase;
|
|
return tokenBase(stream, state);
|
|
}
|
|
|
|
if (multiLine && stream.skipTo("*/")) {
|
|
stream.next();
|
|
stream.next();
|
|
state.tokenizer = tokenBase;
|
|
} else {
|
|
stream.skipToEnd();
|
|
}
|
|
|
|
return "comment";
|
|
};
|
|
}
|
|
|
|
function buildStringTokenizer(quote, greedy) {
|
|
if (greedy == null) { greedy = true; }
|
|
|
|
function stringTokenizer(stream, state) {
|
|
var nextChar = stream.next();
|
|
var peekChar = stream.peek();
|
|
var previousChar = stream.string.charAt(stream.pos-2);
|
|
|
|
var endingString = ((nextChar !== "\\" && peekChar === quote) || (nextChar === quote && previousChar !== "\\"));
|
|
|
|
if (endingString) {
|
|
if (nextChar !== quote && greedy) { stream.next(); }
|
|
state.tokenizer = tokenBase;
|
|
return "string";
|
|
} else if (nextChar === "#" && peekChar === "{") {
|
|
state.tokenizer = buildInterpolationTokenizer(stringTokenizer);
|
|
stream.next();
|
|
return "operator";
|
|
} else {
|
|
return "string";
|
|
}
|
|
}
|
|
|
|
return stringTokenizer;
|
|
}
|
|
|
|
function buildInterpolationTokenizer(currentTokenizer) {
|
|
return function(stream, state) {
|
|
if (stream.peek() === "}") {
|
|
stream.next();
|
|
state.tokenizer = currentTokenizer;
|
|
return "operator";
|
|
} else {
|
|
return tokenBase(stream, state);
|
|
}
|
|
};
|
|
}
|
|
|
|
function indent(state) {
|
|
if (state.indentCount == 0) {
|
|
state.indentCount++;
|
|
var lastScopeOffset = state.scopes[0].offset;
|
|
var currentOffset = lastScopeOffset + config.indentUnit;
|
|
state.scopes.unshift({ offset:currentOffset });
|
|
}
|
|
}
|
|
|
|
function dedent(state) {
|
|
if (state.scopes.length == 1) return;
|
|
|
|
state.scopes.shift();
|
|
}
|
|
|
|
function tokenBase(stream, state) {
|
|
var ch = stream.peek();
|
|
|
|
// Comment
|
|
if (stream.match("/*")) {
|
|
state.tokenizer = comment(stream.indentation(), true);
|
|
return state.tokenizer(stream, state);
|
|
}
|
|
if (stream.match("//")) {
|
|
state.tokenizer = comment(stream.indentation(), false);
|
|
return state.tokenizer(stream, state);
|
|
}
|
|
|
|
// Interpolation
|
|
if (stream.match("#{")) {
|
|
state.tokenizer = buildInterpolationTokenizer(tokenBase);
|
|
return "operator";
|
|
}
|
|
|
|
// Strings
|
|
if (ch === '"' || ch === "'") {
|
|
stream.next();
|
|
state.tokenizer = buildStringTokenizer(ch);
|
|
return "string";
|
|
}
|
|
|
|
if(!state.cursorHalf){// state.cursorHalf === 0
|
|
// first half i.e. before : for key-value pairs
|
|
// including selectors
|
|
|
|
if (ch === ".") {
|
|
stream.next();
|
|
if (stream.match(/^[\w-]+/)) {
|
|
indent(state);
|
|
return "atom";
|
|
} else if (stream.peek() === "#") {
|
|
indent(state);
|
|
return "atom";
|
|
}
|
|
}
|
|
|
|
if (ch === "#") {
|
|
stream.next();
|
|
// ID selectors
|
|
if (stream.match(/^[\w-]+/)) {
|
|
indent(state);
|
|
return "atom";
|
|
}
|
|
if (stream.peek() === "#") {
|
|
indent(state);
|
|
return "atom";
|
|
}
|
|
}
|
|
|
|
// Variables
|
|
if (ch === "$") {
|
|
stream.next();
|
|
stream.eatWhile(/[\w-]/);
|
|
return "variable-2";
|
|
}
|
|
|
|
// Numbers
|
|
if (stream.match(/^-?[0-9\.]+/))
|
|
return "number";
|
|
|
|
// Units
|
|
if (stream.match(/^(px|em|in)\b/))
|
|
return "unit";
|
|
|
|
if (stream.match(keywordsRegexp))
|
|
return "keyword";
|
|
|
|
if (stream.match(/^url/) && stream.peek() === "(") {
|
|
state.tokenizer = urlTokens;
|
|
return "atom";
|
|
}
|
|
|
|
if (ch === "=") {
|
|
// Match shortcut mixin definition
|
|
if (stream.match(/^=[\w-]+/)) {
|
|
indent(state);
|
|
return "meta";
|
|
}
|
|
}
|
|
|
|
if (ch === "+") {
|
|
// Match shortcut mixin definition
|
|
if (stream.match(/^\+[\w-]+/)){
|
|
return "variable-3";
|
|
}
|
|
}
|
|
|
|
if(ch === "@"){
|
|
if(stream.match(/@extend/)){
|
|
if(!stream.match(/\s*[\w]/))
|
|
dedent(state);
|
|
}
|
|
}
|
|
|
|
|
|
// Indent Directives
|
|
if (stream.match(/^@(else if|if|media|else|for|each|while|mixin|function)/)) {
|
|
indent(state);
|
|
return "meta";
|
|
}
|
|
|
|
// Other Directives
|
|
if (ch === "@") {
|
|
stream.next();
|
|
stream.eatWhile(/[\w-]/);
|
|
return "meta";
|
|
}
|
|
|
|
if (stream.eatWhile(/[\w-]/)){
|
|
if(stream.match(/ *: *[\w-\+\$#!\("']/,false)){
|
|
return "propery";
|
|
}
|
|
else if(stream.match(/ *:/,false)){
|
|
indent(state);
|
|
state.cursorHalf = 1;
|
|
return "atom";
|
|
}
|
|
else if(stream.match(/ *,/,false)){
|
|
return "atom";
|
|
}
|
|
else{
|
|
indent(state);
|
|
return "atom";
|
|
}
|
|
}
|
|
|
|
if(ch === ":"){
|
|
if (stream.match(pseudoElementsRegexp)){ // could be a pseudo-element
|
|
return "keyword";
|
|
}
|
|
stream.next();
|
|
state.cursorHalf=1;
|
|
return "operator";
|
|
}
|
|
|
|
} // cursorHalf===0 ends here
|
|
else{
|
|
|
|
if (ch === "#") {
|
|
stream.next();
|
|
// Hex numbers
|
|
if (stream.match(/[0-9a-fA-F]{6}|[0-9a-fA-F]{3}/)){
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "number";
|
|
}
|
|
}
|
|
|
|
// Numbers
|
|
if (stream.match(/^-?[0-9\.]+/)){
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "number";
|
|
}
|
|
|
|
// Units
|
|
if (stream.match(/^(px|em|in)\b/)){
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "unit";
|
|
}
|
|
|
|
if (stream.match(keywordsRegexp)){
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "keyword";
|
|
}
|
|
|
|
if (stream.match(/^url/) && stream.peek() === "(") {
|
|
state.tokenizer = urlTokens;
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "atom";
|
|
}
|
|
|
|
// Variables
|
|
if (ch === "$") {
|
|
stream.next();
|
|
stream.eatWhile(/[\w-]/);
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "variable-3";
|
|
}
|
|
|
|
// bang character for !important, !default, etc.
|
|
if (ch === "!") {
|
|
stream.next();
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return stream.match(/^[\w]+/) ? "keyword": "operator";
|
|
}
|
|
|
|
if (stream.match(opRegexp)){
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "operator";
|
|
}
|
|
|
|
// attributes
|
|
if (stream.eatWhile(/[\w-]/)) {
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
}
|
|
return "attribute";
|
|
}
|
|
|
|
//stream.eatSpace();
|
|
if(!stream.peek()){
|
|
state.cursorHalf = 0;
|
|
return null;
|
|
}
|
|
|
|
} // else ends here
|
|
|
|
if (stream.match(opRegexp))
|
|
return "operator";
|
|
|
|
// If we haven't returned by now, we move 1 character
|
|
// and return an error
|
|
stream.next();
|
|
return null;
|
|
}
|
|
|
|
function tokenLexer(stream, state) {
|
|
if (stream.sol()) state.indentCount = 0;
|
|
var style = state.tokenizer(stream, state);
|
|
var current = stream.current();
|
|
|
|
if (current === "@return" || current === "}"){
|
|
dedent(state);
|
|
}
|
|
|
|
if (style !== null) {
|
|
var startOfToken = stream.pos - current.length;
|
|
|
|
var withCurrentIndent = startOfToken + (config.indentUnit * state.indentCount);
|
|
|
|
var newScopes = [];
|
|
|
|
for (var i = 0; i < state.scopes.length; i++) {
|
|
var scope = state.scopes[i];
|
|
|
|
if (scope.offset <= withCurrentIndent)
|
|
newScopes.push(scope);
|
|
}
|
|
|
|
state.scopes = newScopes;
|
|
}
|
|
|
|
|
|
return style;
|
|
}
|
|
|
|
return {
|
|
startState: function() {
|
|
return {
|
|
tokenizer: tokenBase,
|
|
scopes: [{offset: 0, type: "sass"}],
|
|
indentCount: 0,
|
|
cursorHalf: 0, // cursor half tells us if cursor lies after (1)
|
|
// or before (0) colon (well... more or less)
|
|
definedVars: [],
|
|
definedMixins: []
|
|
};
|
|
},
|
|
token: function(stream, state) {
|
|
var style = tokenLexer(stream, state);
|
|
|
|
state.lastToken = { style: style, content: stream.current() };
|
|
|
|
return style;
|
|
},
|
|
|
|
indent: function(state) {
|
|
return state.scopes[0].offset;
|
|
}
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-sass", "sass");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode('shell', function() {
|
|
|
|
var words = {};
|
|
function define(style, string) {
|
|
var split = string.split(' ');
|
|
for(var i = 0; i < split.length; i++) {
|
|
words[split[i]] = style;
|
|
}
|
|
};
|
|
|
|
// Atoms
|
|
define('atom', 'true false');
|
|
|
|
// Keywords
|
|
define('keyword', 'if then do else elif while until for in esac fi fin ' +
|
|
'fil done exit set unset export function');
|
|
|
|
// Commands
|
|
define('builtin', 'ab awk bash beep cat cc cd chown chmod chroot clear cp ' +
|
|
'curl cut diff echo find gawk gcc get git grep kill killall ln ls make ' +
|
|
'mkdir openssl mv nc node npm ping ps restart rm rmdir sed service sh ' +
|
|
'shopt shred source sort sleep ssh start stop su sudo tee telnet top ' +
|
|
'touch vi vim wall wc wget who write yes zsh');
|
|
|
|
function tokenBase(stream, state) {
|
|
if (stream.eatSpace()) return null;
|
|
|
|
var sol = stream.sol();
|
|
var ch = stream.next();
|
|
|
|
if (ch === '\\') {
|
|
stream.next();
|
|
return null;
|
|
}
|
|
if (ch === '\'' || ch === '"' || ch === '`') {
|
|
state.tokens.unshift(tokenString(ch));
|
|
return tokenize(stream, state);
|
|
}
|
|
if (ch === '#') {
|
|
if (sol && stream.eat('!')) {
|
|
stream.skipToEnd();
|
|
return 'meta'; // 'comment'?
|
|
}
|
|
stream.skipToEnd();
|
|
return 'comment';
|
|
}
|
|
if (ch === '$') {
|
|
state.tokens.unshift(tokenDollar);
|
|
return tokenize(stream, state);
|
|
}
|
|
if (ch === '+' || ch === '=') {
|
|
return 'operator';
|
|
}
|
|
if (ch === '-') {
|
|
stream.eat('-');
|
|
stream.eatWhile(/\w/);
|
|
return 'attribute';
|
|
}
|
|
if (/\d/.test(ch)) {
|
|
stream.eatWhile(/\d/);
|
|
if(stream.eol() || !/\w/.test(stream.peek())) {
|
|
return 'number';
|
|
}
|
|
}
|
|
stream.eatWhile(/[\w-]/);
|
|
var cur = stream.current();
|
|
if (stream.peek() === '=' && /\w+/.test(cur)) return 'def';
|
|
return words.hasOwnProperty(cur) ? words[cur] : null;
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
var next, end = false, escaped = false;
|
|
while ((next = stream.next()) != null) {
|
|
if (next === quote && !escaped) {
|
|
end = true;
|
|
break;
|
|
}
|
|
if (next === '$' && !escaped && quote !== '\'') {
|
|
escaped = true;
|
|
stream.backUp(1);
|
|
state.tokens.unshift(tokenDollar);
|
|
break;
|
|
}
|
|
escaped = !escaped && next === '\\';
|
|
}
|
|
if (end || !escaped) {
|
|
state.tokens.shift();
|
|
}
|
|
return (quote === '`' || quote === ')' ? 'quote' : 'string');
|
|
};
|
|
};
|
|
|
|
var tokenDollar = function(stream, state) {
|
|
if (state.tokens.length > 1) stream.eat('$');
|
|
var ch = stream.next(), hungry = /\w/;
|
|
if (ch === '{') hungry = /[^}]/;
|
|
if (ch === '(') {
|
|
state.tokens[0] = tokenString(')');
|
|
return tokenize(stream, state);
|
|
}
|
|
if (!/\d/.test(ch)) {
|
|
stream.eatWhile(hungry);
|
|
stream.eat('}');
|
|
}
|
|
state.tokens.shift();
|
|
return 'def';
|
|
};
|
|
|
|
function tokenize(stream, state) {
|
|
return (state.tokens[0] || tokenBase) (stream, state);
|
|
};
|
|
|
|
return {
|
|
startState: function() {return {tokens:[]};},
|
|
token: function(stream, state) {
|
|
return tokenize(stream, state);
|
|
},
|
|
lineComment: '#',
|
|
fold: "brace"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME('text/x-sh', 'shell');
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("sql", function(config, parserConfig) {
|
|
"use strict";
|
|
|
|
var client = parserConfig.client || {},
|
|
atoms = parserConfig.atoms || {"false": true, "true": true, "null": true},
|
|
builtin = parserConfig.builtin || {},
|
|
keywords = parserConfig.keywords || {},
|
|
operatorChars = parserConfig.operatorChars || /^[*+\-%<>!=&|~^]/,
|
|
support = parserConfig.support || {},
|
|
hooks = parserConfig.hooks || {},
|
|
dateSQL = parserConfig.dateSQL || {"date" : true, "time" : true, "timestamp" : true};
|
|
|
|
function tokenBase(stream, state) {
|
|
var ch = stream.next();
|
|
|
|
// call hooks from the mime type
|
|
if (hooks[ch]) {
|
|
var result = hooks[ch](stream, state);
|
|
if (result !== false) return result;
|
|
}
|
|
|
|
if (support.hexNumber == true &&
|
|
((ch == "0" && stream.match(/^[xX][0-9a-fA-F]+/))
|
|
|| (ch == "x" || ch == "X") && stream.match(/^'[0-9a-fA-F]+'/))) {
|
|
// hex
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/hexadecimal-literals.html
|
|
return "number";
|
|
} else if (support.binaryNumber == true &&
|
|
(((ch == "b" || ch == "B") && stream.match(/^'[01]+'/))
|
|
|| (ch == "0" && stream.match(/^b[01]+/)))) {
|
|
// bitstring
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/bit-field-literals.html
|
|
return "number";
|
|
} else if (ch.charCodeAt(0) > 47 && ch.charCodeAt(0) < 58) {
|
|
// numbers
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/number-literals.html
|
|
stream.match(/^[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/);
|
|
support.decimallessFloat == true && stream.eat('.');
|
|
return "number";
|
|
} else if (ch == "?" && (stream.eatSpace() || stream.eol() || stream.eat(";"))) {
|
|
// placeholders
|
|
return "variable-3";
|
|
} else if (ch == "'" || (ch == '"' && support.doubleQuote)) {
|
|
// strings
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html
|
|
state.tokenize = tokenLiteral(ch);
|
|
return state.tokenize(stream, state);
|
|
} else if ((((support.nCharCast == true && (ch == "n" || ch == "N"))
|
|
|| (support.charsetCast == true && ch == "_" && stream.match(/[a-z][a-z0-9]*/i)))
|
|
&& (stream.peek() == "'" || stream.peek() == '"'))) {
|
|
// charset casting: _utf8'str', N'str', n'str'
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html
|
|
return "keyword";
|
|
} else if (/^[\(\),\;\[\]]/.test(ch)) {
|
|
// no highlightning
|
|
return null;
|
|
} else if (support.commentSlashSlash && ch == "/" && stream.eat("/")) {
|
|
// 1-line comment
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
} else if ((support.commentHash && ch == "#")
|
|
|| (ch == "-" && stream.eat("-") && (!support.commentSpaceRequired || stream.eat(" ")))) {
|
|
// 1-line comments
|
|
// ref: https://kb.askmonty.org/en/comment-syntax/
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
} else if (ch == "/" && stream.eat("*")) {
|
|
// multi-line comments
|
|
// ref: https://kb.askmonty.org/en/comment-syntax/
|
|
state.tokenize = tokenComment;
|
|
return state.tokenize(stream, state);
|
|
} else if (ch == ".") {
|
|
// .1 for 0.1
|
|
if (support.zerolessFloat == true && stream.match(/^(?:\d+(?:e[+-]?\d+)?)/i)) {
|
|
return "number";
|
|
}
|
|
// .table_name (ODBC)
|
|
// // ref: http://dev.mysql.com/doc/refman/5.6/en/identifier-qualifiers.html
|
|
if (support.ODBCdotTable == true && stream.match(/^[a-zA-Z_]+/)) {
|
|
return "variable-2";
|
|
}
|
|
} else if (operatorChars.test(ch)) {
|
|
// operators
|
|
stream.eatWhile(operatorChars);
|
|
return null;
|
|
} else if (ch == '{' &&
|
|
(stream.match(/^( )*(d|D|t|T|ts|TS)( )*'[^']*'( )*}/) || stream.match(/^( )*(d|D|t|T|ts|TS)( )*"[^"]*"( )*}/))) {
|
|
// dates (weird ODBC syntax)
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html
|
|
return "number";
|
|
} else {
|
|
stream.eatWhile(/^[_\w\d]/);
|
|
var word = stream.current().toLowerCase();
|
|
// dates (standard SQL syntax)
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html
|
|
if (dateSQL.hasOwnProperty(word) && (stream.match(/^( )+'[^']*'/) || stream.match(/^( )+"[^"]*"/)))
|
|
return "number";
|
|
if (atoms.hasOwnProperty(word)) return "atom";
|
|
if (builtin.hasOwnProperty(word)) return "builtin";
|
|
if (keywords.hasOwnProperty(word)) return "keyword";
|
|
if (client.hasOwnProperty(word)) return "string-2";
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// 'string', with char specified in quote escaped by '\'
|
|
function tokenLiteral(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (ch == quote && !escaped) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
escaped = !escaped && ch == "\\";
|
|
}
|
|
return "string";
|
|
};
|
|
}
|
|
function tokenComment(stream, state) {
|
|
while (true) {
|
|
if (stream.skipTo("*")) {
|
|
stream.next();
|
|
if (stream.eat("/")) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
} else {
|
|
stream.skipToEnd();
|
|
break;
|
|
}
|
|
}
|
|
return "comment";
|
|
}
|
|
|
|
function pushContext(stream, state, type) {
|
|
state.context = {
|
|
prev: state.context,
|
|
indent: stream.indentation(),
|
|
col: stream.column(),
|
|
type: type
|
|
};
|
|
}
|
|
|
|
function popContext(state) {
|
|
state.indent = state.context.indent;
|
|
state.context = state.context.prev;
|
|
}
|
|
|
|
return {
|
|
startState: function() {
|
|
return {tokenize: tokenBase, context: null};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.sol()) {
|
|
if (state.context && state.context.align == null)
|
|
state.context.align = false;
|
|
}
|
|
if (stream.eatSpace()) return null;
|
|
|
|
var style = state.tokenize(stream, state);
|
|
if (style == "comment") return style;
|
|
|
|
if (state.context && state.context.align == null)
|
|
state.context.align = true;
|
|
|
|
var tok = stream.current();
|
|
if (tok == "(")
|
|
pushContext(stream, state, ")");
|
|
else if (tok == "[")
|
|
pushContext(stream, state, "]");
|
|
else if (state.context && state.context.type == tok)
|
|
popContext(state);
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
var cx = state.context;
|
|
if (!cx) return CodeMirror.Pass;
|
|
var closing = textAfter.charAt(0) == cx.type;
|
|
if (cx.align) return cx.col + (closing ? 0 : 1);
|
|
else return cx.indent + (closing ? 0 : config.indentUnit);
|
|
},
|
|
|
|
blockCommentStart: "/*",
|
|
blockCommentEnd: "*/",
|
|
lineComment: support.commentSlashSlash ? "//" : support.commentHash ? "#" : null
|
|
};
|
|
});
|
|
|
|
(function() {
|
|
"use strict";
|
|
|
|
// `identifier`
|
|
function hookIdentifier(stream) {
|
|
// MySQL/MariaDB identifiers
|
|
// ref: http://dev.mysql.com/doc/refman/5.6/en/identifier-qualifiers.html
|
|
var ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (ch == "`" && !stream.eat("`")) return "variable-2";
|
|
}
|
|
stream.backUp(stream.current().length - 1);
|
|
return stream.eatWhile(/\w/) ? "variable-2" : null;
|
|
}
|
|
|
|
// variable token
|
|
function hookVar(stream) {
|
|
// variables
|
|
// @@prefix.varName @varName
|
|
// varName can be quoted with ` or ' or "
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/user-variables.html
|
|
if (stream.eat("@")) {
|
|
stream.match(/^session\./);
|
|
stream.match(/^local\./);
|
|
stream.match(/^global\./);
|
|
}
|
|
|
|
if (stream.eat("'")) {
|
|
stream.match(/^.*'/);
|
|
return "variable-2";
|
|
} else if (stream.eat('"')) {
|
|
stream.match(/^.*"/);
|
|
return "variable-2";
|
|
} else if (stream.eat("`")) {
|
|
stream.match(/^.*`/);
|
|
return "variable-2";
|
|
} else if (stream.match(/^[0-9a-zA-Z$\.\_]+/)) {
|
|
return "variable-2";
|
|
}
|
|
return null;
|
|
};
|
|
|
|
// short client keyword token
|
|
function hookClient(stream) {
|
|
// \N means NULL
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/null-values.html
|
|
if (stream.eat("N")) {
|
|
return "atom";
|
|
}
|
|
// \g, etc
|
|
// ref: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html
|
|
return stream.match(/^[a-zA-Z.#!?]/) ? "variable-2" : null;
|
|
}
|
|
|
|
// these keywords are used by all SQL dialects (however, a mode can still overwrite it)
|
|
var sqlKeywords = "alter and as asc between by count create delete desc distinct drop from having in insert into is join like not on or order select set table union update values where ";
|
|
|
|
// turn a space-separated list into an array
|
|
function set(str) {
|
|
var obj = {}, words = str.split(" ");
|
|
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
|
return obj;
|
|
}
|
|
|
|
// A generic SQL Mode. It's not a standard, it just try to support what is generally supported
|
|
CodeMirror.defineMIME("text/x-sql", {
|
|
name: "sql",
|
|
keywords: set(sqlKeywords + "begin"),
|
|
builtin: set("bool boolean bit blob enum long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision real date datetime year unsigned signed decimal numeric"),
|
|
atoms: set("false true null unknown"),
|
|
operatorChars: /^[*+\-%<>!=]/,
|
|
dateSQL: set("date time timestamp"),
|
|
support: set("ODBCdotTable doubleQuote binaryNumber hexNumber")
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-mssql", {
|
|
name: "sql",
|
|
client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"),
|
|
keywords: set(sqlKeywords + "begin trigger proc view index for add constraint key primary foreign collate clustered nonclustered"),
|
|
builtin: set("bigint numeric bit smallint decimal smallmoney int tinyint money float real char varchar text nchar nvarchar ntext binary varbinary image cursor timestamp hierarchyid uniqueidentifier sql_variant xml table "),
|
|
atoms: set("false true null unknown"),
|
|
operatorChars: /^[*+\-%<>!=]/,
|
|
dateSQL: set("date datetimeoffset datetime2 smalldatetime datetime time"),
|
|
hooks: {
|
|
"@": hookVar
|
|
}
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-mysql", {
|
|
name: "sql",
|
|
client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"),
|
|
keywords: set(sqlKeywords + "accessible action add after algorithm all analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance diagnostics directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general get global grant grants group groupby_concat handler hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show signal slave slow smallint snapshot soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"),
|
|
builtin: set("bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"),
|
|
atoms: set("false true null unknown"),
|
|
operatorChars: /^[*+\-%<>!=&|^]/,
|
|
dateSQL: set("date time timestamp"),
|
|
support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber doubleQuote nCharCast charsetCast commentHash commentSpaceRequired"),
|
|
hooks: {
|
|
"@": hookVar,
|
|
"`": hookIdentifier,
|
|
"\\": hookClient
|
|
}
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-mariadb", {
|
|
name: "sql",
|
|
client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"),
|
|
keywords: set(sqlKeywords + "accessible action add after algorithm all always analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance diagnostics directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general generated get global grant grants group groupby_concat handler hard hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password persistent phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show shutdown signal slave slow smallint snapshot soft soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views virtual warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"),
|
|
builtin: set("bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"),
|
|
atoms: set("false true null unknown"),
|
|
operatorChars: /^[*+\-%<>!=&|^]/,
|
|
dateSQL: set("date time timestamp"),
|
|
support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber doubleQuote nCharCast charsetCast commentHash commentSpaceRequired"),
|
|
hooks: {
|
|
"@": hookVar,
|
|
"`": hookIdentifier,
|
|
"\\": hookClient
|
|
}
|
|
});
|
|
|
|
// the query language used by Apache Cassandra is called CQL, but this mime type
|
|
// is called Cassandra to avoid confusion with Contextual Query Language
|
|
CodeMirror.defineMIME("text/x-cassandra", {
|
|
name: "sql",
|
|
client: { },
|
|
keywords: set("use select from using consistency where limit first reversed first and in insert into values using consistency ttl update set delete truncate begin batch apply create keyspace with columnfamily primary key index on drop alter type add any one quorum all local_quorum each_quorum"),
|
|
builtin: set("ascii bigint blob boolean counter decimal double float int text timestamp uuid varchar varint"),
|
|
atoms: set("false true"),
|
|
operatorChars: /^[<>=]/,
|
|
dateSQL: { },
|
|
support: set("commentSlashSlash decimallessFloat"),
|
|
hooks: { }
|
|
});
|
|
|
|
// this is based on Peter Raganitsch's 'plsql' mode
|
|
CodeMirror.defineMIME("text/x-plsql", {
|
|
name: "sql",
|
|
client: set("appinfo arraysize autocommit autoprint autorecovery autotrace blockterminator break btitle cmdsep colsep compatibility compute concat copycommit copytypecheck define describe echo editfile embedded escape exec execute feedback flagger flush heading headsep instance linesize lno loboffset logsource long longchunksize markup native newpage numformat numwidth pagesize pause pno recsep recsepchar release repfooter repheader serveroutput shiftinout show showmode size spool sqlblanklines sqlcase sqlcode sqlcontinue sqlnumber sqlpluscompatibility sqlprefix sqlprompt sqlterminator suffix tab term termout time timing trimout trimspool ttitle underline verify version wrap"),
|
|
keywords: set("abort accept access add all alter and any array arraylen as asc assert assign at attributes audit authorization avg base_table begin between binary_integer body boolean by case cast char char_base check close cluster clusters colauth column comment commit compress connect connected constant constraint crash create current currval cursor data_base database date dba deallocate debugoff debugon decimal declare default definition delay delete desc digits dispose distinct do drop else elseif elsif enable end entry escape exception exception_init exchange exclusive exists exit external fast fetch file for force form from function generic goto grant group having identified if immediate in increment index indexes indicator initial initrans insert interface intersect into is key level library like limited local lock log logging long loop master maxextents maxtrans member minextents minus mislabel mode modify multiset new next no noaudit nocompress nologging noparallel not nowait number_base object of off offline on online only open option or order out package parallel partition pctfree pctincrease pctused pls_integer positive positiven pragma primary prior private privileges procedure public raise range raw read rebuild record ref references refresh release rename replace resource restrict return returning returns reverse revoke rollback row rowid rowlabel rownum rows run savepoint schema segment select separate session set share snapshot some space split sql start statement storage subtype successful synonym tabauth table tables tablespace task terminate then to trigger truncate type union unique unlimited unrecoverable unusable update use using validate value values variable view views when whenever where while with work"),
|
|
builtin: set("abs acos add_months ascii asin atan atan2 average bfile bfilename bigserial bit blob ceil character chartorowid chr clob concat convert cos cosh count dec decode deref dual dump dup_val_on_index empty error exp false float floor found glb greatest hextoraw initcap instr instrb int integer isopen last_day least lenght lenghtb ln lower lpad ltrim lub make_ref max min mlslabel mod months_between natural naturaln nchar nclob new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower nls_sort nls_upper nlssort no_data_found notfound null number numeric nvarchar2 nvl others power rawtohex real reftohex round rowcount rowidtochar rowtype rpad rtrim serial sign signtype sin sinh smallint soundex sqlcode sqlerrm sqrt stddev string substr substrb sum sysdate tan tanh to_char text to_date to_label to_multi_byte to_number to_single_byte translate true trunc uid unlogged upper user userenv varchar varchar2 variance varying vsize xml"),
|
|
operatorChars: /^[*+\-%<>!=~]/,
|
|
dateSQL: set("date time timestamp"),
|
|
support: set("doubleQuote nCharCast zerolessFloat binaryNumber hexNumber")
|
|
});
|
|
|
|
// Created to support specific hive keywords
|
|
CodeMirror.defineMIME("text/x-hive", {
|
|
name: "sql",
|
|
keywords: set("select alter $elem$ $key$ $value$ add after all analyze and archive as asc before between binary both bucket buckets by cascade case cast change cluster clustered clusterstatus collection column columns comment compute concatenate continue create cross cursor data database databases dbproperties deferred delete delimited desc describe directory disable distinct distribute drop else enable end escaped exclusive exists explain export extended external false fetch fields fileformat first format formatted from full function functions grant group having hold_ddltime idxproperties if import in index indexes inpath inputdriver inputformat insert intersect into is items join keys lateral left like limit lines load local location lock locks mapjoin materialized minus msck no_drop nocompress not of offline on option or order out outer outputdriver outputformat overwrite partition partitioned partitions percent plus preserve procedure purge range rcfile read readonly reads rebuild recordreader recordwriter recover reduce regexp rename repair replace restrict revoke right rlike row schema schemas semi sequencefile serde serdeproperties set shared show show_database sort sorted ssl statistics stored streamtable table tables tablesample tblproperties temporary terminated textfile then tmp to touch transform trigger true unarchive undo union uniquejoin unlock update use using utc utc_tmestamp view when where while with"),
|
|
builtin: set("bool boolean long timestamp tinyint smallint bigint int float double date datetime unsigned string array struct map uniontype"),
|
|
atoms: set("false true null unknown"),
|
|
operatorChars: /^[*+\-%<>!=]/,
|
|
dateSQL: set("date timestamp"),
|
|
support: set("ODBCdotTable doubleQuote binaryNumber hexNumber")
|
|
});
|
|
}());
|
|
|
|
});
|
|
|
|
/*
|
|
How Properties of Mime Types are used by SQL Mode
|
|
=================================================
|
|
|
|
keywords:
|
|
A list of keywords you want to be highlighted.
|
|
builtin:
|
|
A list of builtin types you want to be highlighted (if you want types to be of class "builtin" instead of "keyword").
|
|
operatorChars:
|
|
All characters that must be handled as operators.
|
|
client:
|
|
Commands parsed and executed by the client (not the server).
|
|
support:
|
|
A list of supported syntaxes which are not common, but are supported by more than 1 DBMS.
|
|
* ODBCdotTable: .tableName
|
|
* zerolessFloat: .1
|
|
* doubleQuote
|
|
* nCharCast: N'string'
|
|
* charsetCast: _utf8'string'
|
|
* commentHash: use # char for comments
|
|
* commentSlashSlash: use // for comments
|
|
* commentSpaceRequired: require a space after -- for comments
|
|
atoms:
|
|
Keywords that must be highlighted as atoms,. Some DBMS's support more atoms than others:
|
|
UNKNOWN, INFINITY, UNDERFLOW, NaN...
|
|
dateSQL:
|
|
Used for date/time SQL standard syntax, because not all DBMS's support same temporal types.
|
|
*/
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|
var indentUnit = config.indentUnit,
|
|
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
|
|
dontAlignCalls = parserConfig.dontAlignCalls,
|
|
keywords = parserConfig.keywords || {},
|
|
builtin = parserConfig.builtin || {},
|
|
blockKeywords = parserConfig.blockKeywords || {},
|
|
atoms = parserConfig.atoms || {},
|
|
hooks = parserConfig.hooks || {},
|
|
multiLineStrings = parserConfig.multiLineStrings,
|
|
indentStatements = parserConfig.indentStatements !== false;
|
|
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
|
|
|
var curPunc;
|
|
|
|
function tokenBase(stream, state) {
|
|
var ch = stream.next();
|
|
if (hooks[ch]) {
|
|
var result = hooks[ch](stream, state);
|
|
if (result !== false) return result;
|
|
}
|
|
if (ch == '"' || ch == "'") {
|
|
state.tokenize = tokenString(ch);
|
|
return state.tokenize(stream, state);
|
|
}
|
|
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
|
curPunc = ch;
|
|
return null;
|
|
}
|
|
if (/\d/.test(ch)) {
|
|
stream.eatWhile(/[\w\.]/);
|
|
return "number";
|
|
}
|
|
if (ch == "/") {
|
|
if (stream.eat("*")) {
|
|
state.tokenize = tokenComment;
|
|
return tokenComment(stream, state);
|
|
}
|
|
if (stream.eat("/")) {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
}
|
|
if (isOperatorChar.test(ch)) {
|
|
stream.eatWhile(isOperatorChar);
|
|
return "operator";
|
|
}
|
|
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
|
|
var cur = stream.current();
|
|
if (keywords.propertyIsEnumerable(cur)) {
|
|
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
|
return "keyword";
|
|
}
|
|
if (builtin.propertyIsEnumerable(cur)) {
|
|
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
|
return "builtin";
|
|
}
|
|
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
|
return "variable";
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, next, end = false;
|
|
while ((next = stream.next()) != null) {
|
|
if (next == quote && !escaped) {end = true; break;}
|
|
escaped = !escaped && next == "\\";
|
|
}
|
|
if (end || !(escaped || multiLineStrings))
|
|
state.tokenize = null;
|
|
return "string";
|
|
};
|
|
}
|
|
|
|
function tokenComment(stream, state) {
|
|
var maybeEnd = false, ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "/" && maybeEnd) {
|
|
state.tokenize = null;
|
|
break;
|
|
}
|
|
maybeEnd = (ch == "*");
|
|
}
|
|
return "comment";
|
|
}
|
|
|
|
function Context(indented, column, type, align, prev) {
|
|
this.indented = indented;
|
|
this.column = column;
|
|
this.type = type;
|
|
this.align = align;
|
|
this.prev = prev;
|
|
}
|
|
function pushContext(state, col, type) {
|
|
var indent = state.indented;
|
|
if (state.context && state.context.type == "statement")
|
|
indent = state.context.indented;
|
|
return state.context = new Context(indent, col, type, null, state.context);
|
|
}
|
|
function popContext(state) {
|
|
var t = state.context.type;
|
|
if (t == ")" || t == "]" || t == "}")
|
|
state.indented = state.context.indented;
|
|
return state.context = state.context.prev;
|
|
}
|
|
|
|
// Interface
|
|
|
|
return {
|
|
startState: function(basecolumn) {
|
|
return {
|
|
tokenize: null,
|
|
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
|
indented: 0,
|
|
startOfLine: true
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
var ctx = state.context;
|
|
if (stream.sol()) {
|
|
if (ctx.align == null) ctx.align = false;
|
|
state.indented = stream.indentation();
|
|
state.startOfLine = true;
|
|
}
|
|
if (stream.eatSpace()) return null;
|
|
curPunc = null;
|
|
var style = (state.tokenize || tokenBase)(stream, state);
|
|
if (style == "comment" || style == "meta") return style;
|
|
if (ctx.align == null) ctx.align = true;
|
|
|
|
if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
|
|
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
|
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
|
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
|
else if (curPunc == "}") {
|
|
while (ctx.type == "statement") ctx = popContext(state);
|
|
if (ctx.type == "}") ctx = popContext(state);
|
|
while (ctx.type == "statement") ctx = popContext(state);
|
|
}
|
|
else if (curPunc == ctx.type) popContext(state);
|
|
else if (indentStatements &&
|
|
(((ctx.type == "}" || ctx.type == "top") && curPunc != ';') ||
|
|
(ctx.type == "statement" && curPunc == "newstatement")))
|
|
pushContext(state, stream.column(), "statement");
|
|
state.startOfLine = false;
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
|
|
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
|
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
|
var closing = firstChar == ctx.type;
|
|
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
|
|
else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.column + (closing ? 0 : 1);
|
|
else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
|
|
else return ctx.indented + (closing ? 0 : indentUnit);
|
|
},
|
|
|
|
electricChars: "{}",
|
|
blockCommentStart: "/*",
|
|
blockCommentEnd: "*/",
|
|
lineComment: "//",
|
|
fold: "brace"
|
|
};
|
|
});
|
|
|
|
function words(str) {
|
|
var obj = {}, words = str.split(" ");
|
|
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
|
return obj;
|
|
}
|
|
var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
|
|
"double static else struct entry switch extern typedef float union for unsigned " +
|
|
"goto while enum void const signed volatile";
|
|
|
|
function cppHook(stream, state) {
|
|
if (!state.startOfLine) return false;
|
|
for (;;) {
|
|
if (stream.skipTo("\\")) {
|
|
stream.next();
|
|
if (stream.eol()) {
|
|
state.tokenize = cppHook;
|
|
break;
|
|
}
|
|
} else {
|
|
stream.skipToEnd();
|
|
state.tokenize = null;
|
|
break;
|
|
}
|
|
}
|
|
return "meta";
|
|
}
|
|
|
|
function cpp11StringHook(stream, state) {
|
|
stream.backUp(1);
|
|
// Raw strings.
|
|
if (stream.match(/(R|u8R|uR|UR|LR)/)) {
|
|
var match = stream.match(/"([^\s\\()]{0,16})\(/);
|
|
if (!match) {
|
|
return false;
|
|
}
|
|
state.cpp11RawStringDelim = match[1];
|
|
state.tokenize = tokenRawString;
|
|
return tokenRawString(stream, state);
|
|
}
|
|
// Unicode strings/chars.
|
|
if (stream.match(/(u8|u|U|L)/)) {
|
|
if (stream.match(/["']/, /* eat */ false)) {
|
|
return "string";
|
|
}
|
|
return false;
|
|
}
|
|
// Ignore this hook.
|
|
stream.next();
|
|
return false;
|
|
}
|
|
|
|
// C#-style strings where "" escapes a quote.
|
|
function tokenAtString(stream, state) {
|
|
var next;
|
|
while ((next = stream.next()) != null) {
|
|
if (next == '"' && !stream.eat('"')) {
|
|
state.tokenize = null;
|
|
break;
|
|
}
|
|
}
|
|
return "string";
|
|
}
|
|
|
|
// C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where
|
|
// <delim> can be a string up to 16 characters long.
|
|
function tokenRawString(stream, state) {
|
|
// Escape characters that have special regex meanings.
|
|
var delim = state.cpp11RawStringDelim.replace(/[^\w\s]/g, '\\$&');
|
|
var match = stream.match(new RegExp(".*?\\)" + delim + '"'));
|
|
if (match)
|
|
state.tokenize = null;
|
|
else
|
|
stream.skipToEnd();
|
|
return "string";
|
|
}
|
|
|
|
function def(mimes, mode) {
|
|
if (typeof mimes == "string") mimes = [mimes];
|
|
var words = [];
|
|
function add(obj) {
|
|
if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))
|
|
words.push(prop);
|
|
}
|
|
add(mode.keywords);
|
|
add(mode.builtin);
|
|
add(mode.atoms);
|
|
if (words.length) {
|
|
mode.helperType = mimes[0];
|
|
CodeMirror.registerHelper("hintWords", mimes[0], words);
|
|
}
|
|
|
|
for (var i = 0; i < mimes.length; ++i)
|
|
CodeMirror.defineMIME(mimes[i], mode);
|
|
}
|
|
|
|
def(["text/x-csrc", "text/x-c", "text/x-chdr"], {
|
|
name: "clike",
|
|
keywords: words(cKeywords),
|
|
blockKeywords: words("case do else for if switch while struct"),
|
|
atoms: words("null"),
|
|
hooks: {"#": cppHook},
|
|
modeProps: {fold: ["brace", "include"]}
|
|
});
|
|
|
|
def(["text/x-c++src", "text/x-c++hdr"], {
|
|
name: "clike",
|
|
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
|
|
"static_cast typeid catch operator template typename class friend private " +
|
|
"this using const_cast inline public throw virtual delete mutable protected " +
|
|
"wchar_t alignas alignof constexpr decltype nullptr noexcept thread_local final " +
|
|
"static_assert override"),
|
|
blockKeywords: words("catch class do else finally for if struct switch try while"),
|
|
atoms: words("true false null"),
|
|
hooks: {
|
|
"#": cppHook,
|
|
"u": cpp11StringHook,
|
|
"U": cpp11StringHook,
|
|
"L": cpp11StringHook,
|
|
"R": cpp11StringHook
|
|
},
|
|
modeProps: {fold: ["brace", "include"]}
|
|
});
|
|
|
|
def("text/x-java", {
|
|
name: "clike",
|
|
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
|
|
"do double else enum extends final finally float for goto if implements import " +
|
|
"instanceof int interface long native new package private protected public " +
|
|
"return short static strictfp super switch synchronized this throw throws transient " +
|
|
"try void volatile while"),
|
|
blockKeywords: words("catch class do else finally for if switch try while"),
|
|
atoms: words("true false null"),
|
|
hooks: {
|
|
"@": function(stream) {
|
|
stream.eatWhile(/[\w\$_]/);
|
|
return "meta";
|
|
}
|
|
},
|
|
modeProps: {fold: ["brace", "import"]}
|
|
});
|
|
|
|
def("text/x-csharp", {
|
|
name: "clike",
|
|
keywords: words("abstract as base break case catch checked class const continue" +
|
|
" default delegate do else enum event explicit extern finally fixed for" +
|
|
" foreach goto if implicit in interface internal is lock namespace new" +
|
|
" operator out override params private protected public readonly ref return sealed" +
|
|
" sizeof stackalloc static struct switch this throw try typeof unchecked" +
|
|
" unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
|
|
" global group into join let orderby partial remove select set value var yield"),
|
|
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
|
|
builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
|
|
" Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
|
|
" UInt64 bool byte char decimal double short int long object" +
|
|
" sbyte float string ushort uint ulong"),
|
|
atoms: words("true false null"),
|
|
hooks: {
|
|
"@": function(stream, state) {
|
|
if (stream.eat('"')) {
|
|
state.tokenize = tokenAtString;
|
|
return tokenAtString(stream, state);
|
|
}
|
|
stream.eatWhile(/[\w\$_]/);
|
|
return "meta";
|
|
}
|
|
}
|
|
});
|
|
|
|
function tokenTripleString(stream, state) {
|
|
var escaped = false;
|
|
while (!stream.eol()) {
|
|
if (!escaped && stream.match('"""')) {
|
|
state.tokenize = null;
|
|
break;
|
|
}
|
|
escaped = stream.next() == "\\" && !escaped;
|
|
}
|
|
return "string";
|
|
}
|
|
|
|
def("text/x-scala", {
|
|
name: "clike",
|
|
keywords: words(
|
|
|
|
/* scala */
|
|
"abstract case catch class def do else extends false final finally for forSome if " +
|
|
"implicit import lazy match new null object override package private protected return " +
|
|
"sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
|
|
"<% >: # @ " +
|
|
|
|
/* package scala */
|
|
"assert assume require print println printf readLine readBoolean readByte readShort " +
|
|
"readChar readInt readLong readFloat readDouble " +
|
|
|
|
"AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
|
|
"Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
|
|
"Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
|
|
"Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
|
|
"StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
|
|
|
|
/* package java.lang */
|
|
"Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
|
|
"Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
|
|
"Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
|
|
"StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
|
|
),
|
|
multiLineStrings: true,
|
|
blockKeywords: words("catch class do else finally for forSome if match switch try while"),
|
|
atoms: words("true false null"),
|
|
indentStatements: false,
|
|
hooks: {
|
|
"@": function(stream) {
|
|
stream.eatWhile(/[\w\$_]/);
|
|
return "meta";
|
|
},
|
|
'"': function(stream, state) {
|
|
if (!stream.match('""')) return false;
|
|
state.tokenize = tokenTripleString;
|
|
return state.tokenize(stream, state);
|
|
},
|
|
"'": function(stream) {
|
|
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
|
|
return "atom";
|
|
}
|
|
}
|
|
});
|
|
|
|
def(["x-shader/x-vertex", "x-shader/x-fragment"], {
|
|
name: "clike",
|
|
keywords: words("float int bool void " +
|
|
"vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
|
|
"mat2 mat3 mat4 " +
|
|
"sampler1D sampler2D sampler3D samplerCube " +
|
|
"sampler1DShadow sampler2DShadow " +
|
|
"const attribute uniform varying " +
|
|
"break continue discard return " +
|
|
"for while do if else struct " +
|
|
"in out inout"),
|
|
blockKeywords: words("for while do if else struct"),
|
|
builtin: words("radians degrees sin cos tan asin acos atan " +
|
|
"pow exp log exp2 sqrt inversesqrt " +
|
|
"abs sign floor ceil fract mod min max clamp mix step smoothstep " +
|
|
"length distance dot cross normalize ftransform faceforward " +
|
|
"reflect refract matrixCompMult " +
|
|
"lessThan lessThanEqual greaterThan greaterThanEqual " +
|
|
"equal notEqual any all not " +
|
|
"texture1D texture1DProj texture1DLod texture1DProjLod " +
|
|
"texture2D texture2DProj texture2DLod texture2DProjLod " +
|
|
"texture3D texture3DProj texture3DLod texture3DProjLod " +
|
|
"textureCube textureCubeLod " +
|
|
"shadow1D shadow2D shadow1DProj shadow2DProj " +
|
|
"shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
|
|
"dFdx dFdy fwidth " +
|
|
"noise1 noise2 noise3 noise4"),
|
|
atoms: words("true false " +
|
|
"gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
|
|
"gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
|
|
"gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
|
|
"gl_FogCoord gl_PointCoord " +
|
|
"gl_Position gl_PointSize gl_ClipVertex " +
|
|
"gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
|
|
"gl_TexCoord gl_FogFragCoord " +
|
|
"gl_FragCoord gl_FrontFacing " +
|
|
"gl_FragData gl_FragDepth " +
|
|
"gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
|
|
"gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
|
|
"gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
|
|
"gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
|
|
"gl_ProjectionMatrixInverseTranspose " +
|
|
"gl_ModelViewProjectionMatrixInverseTranspose " +
|
|
"gl_TextureMatrixInverseTranspose " +
|
|
"gl_NormalScale gl_DepthRange gl_ClipPlane " +
|
|
"gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
|
|
"gl_FrontLightModelProduct gl_BackLightModelProduct " +
|
|
"gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
|
|
"gl_FogParameters " +
|
|
"gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
|
|
"gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
|
|
"gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
|
|
"gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
|
|
"gl_MaxDrawBuffers"),
|
|
hooks: {"#": cppHook},
|
|
modeProps: {fold: ["brace", "include"]}
|
|
});
|
|
|
|
def("text/x-nesc", {
|
|
name: "clike",
|
|
keywords: words(cKeywords + "as atomic async call command component components configuration event generic " +
|
|
"implementation includes interface module new norace nx_struct nx_union post provides " +
|
|
"signal task uses abstract extends"),
|
|
blockKeywords: words("case do else for if switch while struct"),
|
|
atoms: words("null"),
|
|
hooks: {"#": cppHook},
|
|
modeProps: {fold: ["brace", "include"]}
|
|
});
|
|
|
|
def("text/x-objectivec", {
|
|
name: "clike",
|
|
keywords: words(cKeywords + "inline restrict _Bool _Complex _Imaginery BOOL Class bycopy byref id IMP in " +
|
|
"inout nil oneway out Protocol SEL self super atomic nonatomic retain copy readwrite readonly"),
|
|
atoms: words("YES NO NULL NILL ON OFF"),
|
|
hooks: {
|
|
"@": function(stream) {
|
|
stream.eatWhile(/[\w\$]/);
|
|
return "keyword";
|
|
},
|
|
"#": cppHook
|
|
},
|
|
modeProps: {fold: "brace"}
|
|
});
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), require("../clike/clike"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../htmlmixed/htmlmixed", "../clike/clike"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
function keywords(str) {
|
|
var obj = {}, words = str.split(" ");
|
|
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
|
return obj;
|
|
}
|
|
|
|
// Helper for stringWithEscapes
|
|
function matchSequence(list, end) {
|
|
if (list.length == 0) return stringWithEscapes(end);
|
|
return function (stream, state) {
|
|
var patterns = list[0];
|
|
for (var i = 0; i < patterns.length; i++) if (stream.match(patterns[i][0])) {
|
|
state.tokenize = matchSequence(list.slice(1), end);
|
|
return patterns[i][1];
|
|
}
|
|
state.tokenize = stringWithEscapes(end);
|
|
return "string";
|
|
};
|
|
}
|
|
function stringWithEscapes(closing) {
|
|
return function(stream, state) { return stringWithEscapes_(stream, state, closing); };
|
|
}
|
|
function stringWithEscapes_(stream, state, closing) {
|
|
// "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]]
|
|
], closing);
|
|
}
|
|
if (stream.match(/\-\>\w/, false)) {
|
|
// Match object operator
|
|
state.tokenize = matchSequence([
|
|
[["->", null]],
|
|
[[/[\w]+/, "variable"]]
|
|
], closing);
|
|
}
|
|
return "variable-2";
|
|
}
|
|
|
|
var escaped = false;
|
|
// Normal string
|
|
while (!stream.eol() &&
|
|
(escaped || (!stream.match("{$", false) &&
|
|
!stream.match(/^(\$[a-zA-Z_][a-zA-Z0-9_]*|\$\{)/, false)))) {
|
|
if (!escaped && stream.match(closing)) {
|
|
state.tokenize = null;
|
|
state.tokStack.pop(); state.tokStack.pop();
|
|
break;
|
|
}
|
|
escaped = stream.next() == "\\" && !escaped;
|
|
}
|
|
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 extension_loaded get_extension_funcs debug_backtrace constant bin2hex hex2bin sleep usleep time mktime gmmktime strftime gmstrftime strtotime date gmdate getdate localtime checkdate flush wordwrap htmlspecialchars htmlentities html_entity_decode md5 md5_file crc32 getimagesize image_type_to_mime_type phpinfo phpversion phpcredits strnatcmp strnatcasecmp substr_count strspn strcspn strtok strtoupper strtolower strpos strrpos strrev hebrev hebrevc nl2br basename dirname pathinfo stripslashes stripcslashes strstr stristr strrchr str_shuffle str_word_count strcoll substr substr_replace quotemeta ucfirst ucwords strtr addslashes addcslashes rtrim str_replace str_repeat count_chars chunk_split trim ltrim strip_tags similar_text explode implode setlocale localeconv parse_str str_pad chop strchr sprintf printf vprintf vsprintf sscanf fscanf parse_url urlencode urldecode rawurlencode rawurldecode readlink linkinfo link unlink exec system escapeshellcmd escapeshellarg passthru shell_exec proc_open proc_close rand srand getrandmax mt_rand mt_srand mt_getrandmax base64_decode base64_encode abs ceil floor round is_finite is_nan is_infinite bindec hexdec octdec decbin decoct dechex base_convert number_format fmod ip2long long2ip getenv putenv getopt microtime gettimeofday getrusage uniqid quoted_printable_decode set_time_limit get_cfg_var magic_quotes_runtime set_magic_quotes_runtime get_magic_quotes_gpc get_magic_quotes_runtime import_request_variables error_log serialize unserialize memory_get_usage var_dump var_export debug_zval_dump print_r highlight_file show_source highlight_string ini_get ini_get_all ini_set ini_alter ini_restore get_include_path set_include_path restore_include_path setcookie header headers_sent connection_aborted connection_status ignore_user_abort parse_ini_file is_uploaded_file move_uploaded_file intval floatval doubleval strval gettype settype is_null is_resource is_bool is_long is_float is_int is_integer is_double is_real is_numeric is_string is_array is_object is_scalar ereg ereg_replace eregi eregi_replace split spliti join sql_regcase dl pclose popen readfile rewind rmdir umask fclose feof fgetc fgets fgetss fread fopen fpassthru ftruncate fstat fseek ftell fflush fwrite fputs mkdir rename copy tempnam tmpfile file file_get_contents stream_select stream_context_create stream_context_set_params stream_context_set_option stream_context_get_options stream_filter_prepend stream_filter_append fgetcsv flock get_meta_tags stream_set_write_buffer set_file_buffer set_socket_blocking stream_set_blocking socket_set_blocking stream_get_meta_data stream_register_wrapper stream_wrapper_register stream_set_timeout socket_set_timeout socket_get_status realpath fnmatch fsockopen pfsockopen pack unpack get_browser crypt opendir closedir chdir getcwd rewinddir readdir dir glob fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype file_exists is_writable is_writeable is_readable is_executable is_file is_dir is_link stat lstat chown touch clearstatcache mail ob_start ob_flush ob_clean ob_end_flush ob_end_clean ob_get_flush ob_get_clean ob_get_length ob_get_level ob_get_status ob_get_contents ob_implicit_flush ob_list_handlers ksort krsort natsort natcasesort asort arsort sort rsort usort uasort uksort shuffle array_walk count end prev next reset current key min max in_array array_search extract compact array_fill range array_multisort array_push array_pop array_shift array_unshift array_splice array_slice array_merge array_merge_recursive array_keys array_values array_count_values array_reverse array_reduce array_pad array_flip array_change_key_case array_rand array_unique array_intersect array_intersect_assoc array_diff array_diff_assoc array_sum array_filter array_map array_chunk array_key_exists pos sizeof key_exists assert assert_options version_compare ftok str_rot13 aggregate session_name session_module_name session_save_path session_id session_regenerate_id session_decode session_register session_unregister session_is_registered session_encode session_start session_destroy session_unset session_set_save_handler session_cache_limiter session_cache_expire session_set_cookie_params session_get_cookie_params session_write_close preg_match preg_match_all preg_replace preg_replace_callback preg_split preg_quote preg_grep overload ctype_alnum ctype_alpha ctype_cntrl ctype_digit ctype_lower ctype_graph ctype_print ctype_punct ctype_space ctype_upper ctype_xdigit virtual apache_request_headers apache_note apache_lookup_uri apache_child_terminate apache_setenv apache_response_headers apache_get_version getallheaders mysql_connect mysql_pconnect mysql_close mysql_select_db mysql_create_db mysql_drop_db mysql_query mysql_unbuffered_query mysql_db_query mysql_list_dbs mysql_list_tables mysql_list_fields mysql_list_processes mysql_error mysql_errno mysql_affected_rows mysql_insert_id mysql_result mysql_num_rows mysql_num_fields mysql_fetch_row mysql_fetch_array mysql_fetch_assoc mysql_fetch_object mysql_data_seek mysql_fetch_lengths mysql_fetch_field mysql_field_seek mysql_free_result mysql_field_name mysql_field_table mysql_field_len mysql_field_type mysql_field_flags mysql_escape_string mysql_real_escape_string mysql_stat mysql_thread_id mysql_client_encoding mysql_get_client_info mysql_get_host_info mysql_get_proto_info mysql_get_server_info mysql_info mysql mysql_fieldname mysql_fieldtable mysql_fieldlen mysql_fieldtype mysql_fieldflags mysql_selectdb mysql_createdb mysql_dropdb mysql_freeresult mysql_numfields mysql_numrows mysql_listdbs mysql_listtables mysql_listfields mysql_db_name mysql_dbname mysql_tablename mysql_table_name pg_connect pg_pconnect pg_close pg_connection_status pg_connection_busy pg_connection_reset pg_host pg_dbname pg_port pg_tty pg_options pg_ping pg_query pg_send_query pg_cancel_query pg_fetch_result pg_fetch_row pg_fetch_assoc pg_fetch_array pg_fetch_object pg_fetch_all pg_affected_rows pg_get_result pg_result_seek pg_result_status pg_free_result pg_last_oid pg_num_rows pg_num_fields pg_field_name pg_field_num pg_field_size pg_field_type pg_field_prtlen pg_field_is_null pg_get_notify pg_get_pid pg_result_error pg_last_error pg_last_notice pg_put_line pg_end_copy pg_copy_to pg_copy_from pg_trace pg_untrace pg_lo_create pg_lo_unlink pg_lo_open pg_lo_close pg_lo_read pg_lo_write pg_lo_read_all pg_lo_import pg_lo_export pg_lo_seek pg_lo_tell pg_escape_string pg_escape_bytea pg_unescape_bytea pg_client_encoding pg_set_client_encoding pg_meta_data pg_convert pg_insert pg_update pg_delete pg_select pg_exec pg_getlastoid pg_cmdtuples pg_errormessage pg_numrows pg_numfields pg_fieldname pg_fieldsize pg_fieldtype pg_fieldnum pg_fieldprtlen pg_fieldisnull pg_freeresult pg_result pg_loreadall pg_locreate pg_lounlink pg_loopen pg_loclose pg_loread pg_lowrite pg_loimport pg_loexport http_response_code get_declared_traits getimagesizefromstring socket_import_stream stream_set_chunk_size trait_exists header_register_callback class_uses session_status session_register_shutdown echo print global static exit array empty eval isset unset die include require include_once require_once json_decode json_encode json_last_error json_last_error_msg curl_close curl_copy_handle curl_errno curl_error curl_escape curl_exec curl_file_create curl_getinfo curl_init curl_multi_add_handle curl_multi_close curl_multi_exec curl_multi_getcontent curl_multi_info_read curl_multi_init curl_multi_remove_handle curl_multi_select curl_multi_setopt curl_multi_strerror curl_pause curl_reset curl_setopt_array curl_setopt curl_share_close curl_share_init curl_share_setopt curl_strerror curl_unescape curl_version mysqli_affected_rows mysqli_autocommit mysqli_change_user mysqli_character_set_name mysqli_close mysqli_commit mysqli_connect_errno mysqli_connect_error mysqli_connect mysqli_data_seek mysqli_debug mysqli_dump_debug_info mysqli_errno mysqli_error_list mysqli_error mysqli_fetch_all mysqli_fetch_array mysqli_fetch_assoc mysqli_fetch_field_direct mysqli_fetch_field mysqli_fetch_fields mysqli_fetch_lengths mysqli_fetch_object mysqli_fetch_row mysqli_field_count mysqli_field_seek mysqli_field_tell mysqli_free_result mysqli_get_charset mysqli_get_client_info mysqli_get_client_stats mysqli_get_client_version mysqli_get_connection_stats mysqli_get_host_info mysqli_get_proto_info mysqli_get_server_info mysqli_get_server_version mysqli_info mysqli_init mysqli_insert_id mysqli_kill mysqli_more_results mysqli_multi_query mysqli_next_result mysqli_num_fields mysqli_num_rows mysqli_options mysqli_ping mysqli_prepare mysqli_query mysqli_real_connect mysqli_real_escape_string mysqli_real_query mysqli_reap_async_query mysqli_refresh mysqli_rollback mysqli_select_db mysqli_set_charset mysqli_set_local_infile_default mysqli_set_local_infile_handler mysqli_sqlstate mysqli_ssl_set mysqli_stat mysqli_stmt_init mysqli_store_result mysqli_thread_id mysqli_thread_safe mysqli_use_result mysqli_warning_count";
|
|
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\.]/);
|
|
var delim = stream.current().slice(3);
|
|
if (delim) {
|
|
(state.tokStack || (state.tokStack = [])).push(delim, 0);
|
|
state.tokenize = stringWithEscapes(delim);
|
|
return "string";
|
|
}
|
|
}
|
|
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) {
|
|
(state.tokStack || (state.tokStack = [])).push('"', 0);
|
|
state.tokenize = stringWithEscapes('"');
|
|
return "string";
|
|
},
|
|
"{": function(_stream, state) {
|
|
if (state.tokStack && state.tokStack.length)
|
|
state.tokStack[state.tokStack.length - 1]++;
|
|
return false;
|
|
},
|
|
"}": function(_stream, state) {
|
|
if (state.tokStack && state.tokStack.length > 0 &&
|
|
!--state.tokStack[state.tokStack.length - 1]) {
|
|
state.tokenize = stringWithEscapes(state.tokStack[state.tokStack.length - 2]);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
|
|
CodeMirror.defineMode("php", function(config, parserConfig) {
|
|
var htmlMode = CodeMirror.getMode(config, "text/html");
|
|
var phpMode = CodeMirror.getMode(config, phpConfig);
|
|
|
|
function dispatch(stream, state) {
|
|
var isPHP = state.curMode == phpMode;
|
|
if (stream.sol() && state.pending && state.pending != '"' && state.pending != "'") state.pending = null;
|
|
if (!isPHP) {
|
|
if (stream.match(/^<\?\w*/)) {
|
|
state.curMode = phpMode;
|
|
state.curState = state.php;
|
|
return "meta";
|
|
}
|
|
if (state.pending == '"' || state.pending == "'") {
|
|
while (!stream.eol() && stream.next() != state.pending) {}
|
|
var style = "string";
|
|
} else if (state.pending && stream.pos < state.pending.end) {
|
|
stream.pos = state.pending.end;
|
|
var style = state.pending.style;
|
|
} else {
|
|
var style = htmlMode.token(stream, state.curState);
|
|
}
|
|
if (state.pending) state.pending = null;
|
|
var cur = stream.current(), openPHP = cur.search(/<\?/), m;
|
|
if (openPHP != -1) {
|
|
if (style == "string" && (m = cur.match(/[\'\"]$/)) && !/\?>/.test(cur)) state.pending = m[0];
|
|
else state.pending = {end: stream.pos, style: style};
|
|
stream.backUp(cur.length - openPHP);
|
|
}
|
|
return style;
|
|
} else if (isPHP && state.php.tokenize == null && stream.match("?>")) {
|
|
state.curMode = htmlMode;
|
|
state.curState = state.html;
|
|
return "meta";
|
|
} else {
|
|
return phpMode.token(stream, state.curState);
|
|
}
|
|
}
|
|
|
|
return {
|
|
startState: function() {
|
|
var html = CodeMirror.startState(htmlMode), php = CodeMirror.startState(phpMode);
|
|
return {html: html,
|
|
php: php,
|
|
curMode: parserConfig.startOpen ? phpMode : htmlMode,
|
|
curState: parserConfig.startOpen ? php : html,
|
|
pending: null};
|
|
},
|
|
|
|
copyState: function(state) {
|
|
var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
|
|
php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
|
|
if (state.curMode == htmlMode) cur = htmlNew;
|
|
else cur = phpNew;
|
|
return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
|
|
pending: state.pending};
|
|
},
|
|
|
|
token: dispatch,
|
|
|
|
indent: function(state, textAfter) {
|
|
if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
|
|
(state.curMode == phpMode && /^\?>/.test(textAfter)))
|
|
return htmlMode.indent(state.html, textAfter);
|
|
return state.curMode.indent(state.curState, textAfter);
|
|
},
|
|
|
|
blockCommentStart: "/*",
|
|
blockCommentEnd: "*/",
|
|
lineComment: "//",
|
|
|
|
innerMode: function(state) { return {state: state.curState, mode: state.curMode}; }
|
|
};
|
|
}, "htmlmixed", "clike");
|
|
|
|
CodeMirror.defineMIME("application/x-httpd-php", "php");
|
|
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
|
|
CodeMirror.defineMIME("text/x-php", phpConfig);
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|
var indentUnit = config.indentUnit;
|
|
var multilineTagIndentFactor = parserConfig.multilineTagIndentFactor || 1;
|
|
var multilineTagIndentPastTag = parserConfig.multilineTagIndentPastTag;
|
|
if (multilineTagIndentPastTag == null) multilineTagIndentPastTag = true;
|
|
|
|
var Kludges = parserConfig.htmlMode ? {
|
|
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
|
|
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
|
|
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
|
|
'track': true, 'wbr': true, 'menuitem': true},
|
|
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
|
|
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
|
|
'th': true, 'tr': true},
|
|
contextGrabbers: {
|
|
'dd': {'dd': true, 'dt': true},
|
|
'dt': {'dd': true, 'dt': true},
|
|
'li': {'li': true},
|
|
'option': {'option': true, 'optgroup': true},
|
|
'optgroup': {'optgroup': true},
|
|
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
|
|
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
|
|
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
|
|
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
|
|
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
|
|
'rp': {'rp': true, 'rt': true},
|
|
'rt': {'rp': true, 'rt': true},
|
|
'tbody': {'tbody': true, 'tfoot': true},
|
|
'td': {'td': true, 'th': true},
|
|
'tfoot': {'tbody': true},
|
|
'th': {'td': true, 'th': true},
|
|
'thead': {'tbody': true, 'tfoot': true},
|
|
'tr': {'tr': true}
|
|
},
|
|
doNotIndent: {"pre": true},
|
|
allowUnquoted: true,
|
|
allowMissing: true,
|
|
caseFold: true
|
|
} : {
|
|
autoSelfClosers: {},
|
|
implicitlyClosed: {},
|
|
contextGrabbers: {},
|
|
doNotIndent: {},
|
|
allowUnquoted: false,
|
|
allowMissing: false,
|
|
caseFold: false
|
|
};
|
|
var alignCDATA = parserConfig.alignCDATA;
|
|
|
|
// Return variables for tokenizers
|
|
var type, setStyle;
|
|
|
|
function inText(stream, state) {
|
|
function chain(parser) {
|
|
state.tokenize = parser;
|
|
return parser(stream, state);
|
|
}
|
|
|
|
var ch = stream.next();
|
|
if (ch == "<") {
|
|
if (stream.eat("!")) {
|
|
if (stream.eat("[")) {
|
|
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
|
|
else return null;
|
|
} else if (stream.match("--")) {
|
|
return chain(inBlock("comment", "-->"));
|
|
} else if (stream.match("DOCTYPE", true, true)) {
|
|
stream.eatWhile(/[\w\._\-]/);
|
|
return chain(doctype(1));
|
|
} else {
|
|
return null;
|
|
}
|
|
} else if (stream.eat("?")) {
|
|
stream.eatWhile(/[\w\._\-]/);
|
|
state.tokenize = inBlock("meta", "?>");
|
|
return "meta";
|
|
} else {
|
|
type = stream.eat("/") ? "closeTag" : "openTag";
|
|
state.tokenize = inTag;
|
|
return "tag bracket";
|
|
}
|
|
} else if (ch == "&") {
|
|
var ok;
|
|
if (stream.eat("#")) {
|
|
if (stream.eat("x")) {
|
|
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
|
|
} else {
|
|
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
|
|
}
|
|
} else {
|
|
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
|
|
}
|
|
return ok ? "atom" : "error";
|
|
} else {
|
|
stream.eatWhile(/[^&<]/);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function inTag(stream, state) {
|
|
var ch = stream.next();
|
|
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
|
state.tokenize = inText;
|
|
type = ch == ">" ? "endTag" : "selfcloseTag";
|
|
return "tag bracket";
|
|
} else if (ch == "=") {
|
|
type = "equals";
|
|
return null;
|
|
} else if (ch == "<") {
|
|
state.tokenize = inText;
|
|
state.state = baseState;
|
|
state.tagName = state.tagStart = null;
|
|
var next = state.tokenize(stream, state);
|
|
return next ? next + " tag error" : "tag error";
|
|
} else if (/[\'\"]/.test(ch)) {
|
|
state.tokenize = inAttribute(ch);
|
|
state.stringStartCol = stream.column();
|
|
return state.tokenize(stream, state);
|
|
} else {
|
|
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
|
|
return "word";
|
|
}
|
|
}
|
|
|
|
function inAttribute(quote) {
|
|
var closure = function(stream, state) {
|
|
while (!stream.eol()) {
|
|
if (stream.next() == quote) {
|
|
state.tokenize = inTag;
|
|
break;
|
|
}
|
|
}
|
|
return "string";
|
|
};
|
|
closure.isInAttribute = true;
|
|
return closure;
|
|
}
|
|
|
|
function inBlock(style, terminator) {
|
|
return function(stream, state) {
|
|
while (!stream.eol()) {
|
|
if (stream.match(terminator)) {
|
|
state.tokenize = inText;
|
|
break;
|
|
}
|
|
stream.next();
|
|
}
|
|
return style;
|
|
};
|
|
}
|
|
function doctype(depth) {
|
|
return function(stream, state) {
|
|
var ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (ch == "<") {
|
|
state.tokenize = doctype(depth + 1);
|
|
return state.tokenize(stream, state);
|
|
} else if (ch == ">") {
|
|
if (depth == 1) {
|
|
state.tokenize = inText;
|
|
break;
|
|
} else {
|
|
state.tokenize = doctype(depth - 1);
|
|
return state.tokenize(stream, state);
|
|
}
|
|
}
|
|
}
|
|
return "meta";
|
|
};
|
|
}
|
|
|
|
function Context(state, tagName, startOfLine) {
|
|
this.prev = state.context;
|
|
this.tagName = tagName;
|
|
this.indent = state.indented;
|
|
this.startOfLine = startOfLine;
|
|
if (Kludges.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
|
|
this.noIndent = true;
|
|
}
|
|
function popContext(state) {
|
|
if (state.context) state.context = state.context.prev;
|
|
}
|
|
function maybePopContext(state, nextTagName) {
|
|
var parentTagName;
|
|
while (true) {
|
|
if (!state.context) {
|
|
return;
|
|
}
|
|
parentTagName = state.context.tagName;
|
|
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
|
|
!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
|
|
return;
|
|
}
|
|
popContext(state);
|
|
}
|
|
}
|
|
|
|
function baseState(type, stream, state) {
|
|
if (type == "openTag") {
|
|
state.tagStart = stream.column();
|
|
return tagNameState;
|
|
} else if (type == "closeTag") {
|
|
return closeTagNameState;
|
|
} else {
|
|
return baseState;
|
|
}
|
|
}
|
|
function tagNameState(type, stream, state) {
|
|
if (type == "word") {
|
|
state.tagName = stream.current();
|
|
setStyle = "tag";
|
|
return attrState;
|
|
} else {
|
|
setStyle = "error";
|
|
return tagNameState;
|
|
}
|
|
}
|
|
function closeTagNameState(type, stream, state) {
|
|
if (type == "word") {
|
|
var tagName = stream.current();
|
|
if (state.context && state.context.tagName != tagName &&
|
|
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
|
|
popContext(state);
|
|
if (state.context && state.context.tagName == tagName) {
|
|
setStyle = "tag";
|
|
return closeState;
|
|
} else {
|
|
setStyle = "tag error";
|
|
return closeStateErr;
|
|
}
|
|
} else {
|
|
setStyle = "error";
|
|
return closeStateErr;
|
|
}
|
|
}
|
|
|
|
function closeState(type, _stream, state) {
|
|
if (type != "endTag") {
|
|
setStyle = "error";
|
|
return closeState;
|
|
}
|
|
popContext(state);
|
|
return baseState;
|
|
}
|
|
function closeStateErr(type, stream, state) {
|
|
setStyle = "error";
|
|
return closeState(type, stream, state);
|
|
}
|
|
|
|
function attrState(type, _stream, state) {
|
|
if (type == "word") {
|
|
setStyle = "attribute";
|
|
return attrEqState;
|
|
} else if (type == "endTag" || type == "selfcloseTag") {
|
|
var tagName = state.tagName, tagStart = state.tagStart;
|
|
state.tagName = state.tagStart = null;
|
|
if (type == "selfcloseTag" ||
|
|
Kludges.autoSelfClosers.hasOwnProperty(tagName)) {
|
|
maybePopContext(state, tagName);
|
|
} else {
|
|
maybePopContext(state, tagName);
|
|
state.context = new Context(state, tagName, tagStart == state.indented);
|
|
}
|
|
return baseState;
|
|
}
|
|
setStyle = "error";
|
|
return attrState;
|
|
}
|
|
function attrEqState(type, stream, state) {
|
|
if (type == "equals") return attrValueState;
|
|
if (!Kludges.allowMissing) setStyle = "error";
|
|
return attrState(type, stream, state);
|
|
}
|
|
function attrValueState(type, stream, state) {
|
|
if (type == "string") return attrContinuedState;
|
|
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return attrState;}
|
|
setStyle = "error";
|
|
return attrState(type, stream, state);
|
|
}
|
|
function attrContinuedState(type, stream, state) {
|
|
if (type == "string") return attrContinuedState;
|
|
return attrState(type, stream, state);
|
|
}
|
|
|
|
return {
|
|
startState: function() {
|
|
return {tokenize: inText,
|
|
state: baseState,
|
|
indented: 0,
|
|
tagName: null, tagStart: null,
|
|
context: null};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (!state.tagName && stream.sol())
|
|
state.indented = stream.indentation();
|
|
|
|
if (stream.eatSpace()) return null;
|
|
type = null;
|
|
var style = state.tokenize(stream, state);
|
|
if ((style || type) && style != "comment") {
|
|
setStyle = null;
|
|
state.state = state.state(type || style, stream, state);
|
|
if (setStyle)
|
|
style = setStyle == "error" ? style + " error" : setStyle;
|
|
}
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter, fullLine) {
|
|
var context = state.context;
|
|
// Indent multi-line strings (e.g. css).
|
|
if (state.tokenize.isInAttribute) {
|
|
if (state.tagStart == state.indented)
|
|
return state.stringStartCol + 1;
|
|
else
|
|
return state.indented + indentUnit;
|
|
}
|
|
if (context && context.noIndent) return CodeMirror.Pass;
|
|
if (state.tokenize != inTag && state.tokenize != inText)
|
|
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
|
|
// Indent the starts of attribute names.
|
|
if (state.tagName) {
|
|
if (multilineTagIndentPastTag)
|
|
return state.tagStart + state.tagName.length + 2;
|
|
else
|
|
return state.tagStart + indentUnit * multilineTagIndentFactor;
|
|
}
|
|
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
|
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
|
|
if (tagAfter && tagAfter[1]) { // Closing tag spotted
|
|
while (context) {
|
|
if (context.tagName == tagAfter[2]) {
|
|
context = context.prev;
|
|
break;
|
|
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) {
|
|
context = context.prev;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
} else if (tagAfter) { // Opening tag spotted
|
|
while (context) {
|
|
var grabbers = Kludges.contextGrabbers[context.tagName];
|
|
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
|
|
context = context.prev;
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
while (context && !context.startOfLine)
|
|
context = context.prev;
|
|
if (context) return context.indent + indentUnit;
|
|
else return 0;
|
|
},
|
|
|
|
electricInput: /<\/[\s\w:]+>$/,
|
|
blockCommentStart: "<!--",
|
|
blockCommentEnd: "-->",
|
|
|
|
configuration: parserConfig.htmlMode ? "html" : "xml",
|
|
helperType: parserConfig.htmlMode ? "html" : "xml"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/xml", "xml");
|
|
CodeMirror.defineMIME("application/xml", "xml");
|
|
if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
|
|
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../meta"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../xml/xml", "../meta"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
var htmlFound = CodeMirror.modes.hasOwnProperty("xml");
|
|
var htmlMode = CodeMirror.getMode(cmCfg, htmlFound ? {name: "xml", htmlMode: true} : "text/plain");
|
|
|
|
function getMode(name) {
|
|
if (CodeMirror.findModeByName) {
|
|
var found = CodeMirror.findModeByName(name);
|
|
if (found) name = found.mime || found.mimes[0];
|
|
}
|
|
var mode = CodeMirror.getMode(cmCfg, name);
|
|
return mode.name == "null" ? null : mode;
|
|
}
|
|
|
|
// Should characters that affect highlighting be highlighted separate?
|
|
// Does not include characters that will be output (such as `1.` and `-` for lists)
|
|
if (modeCfg.highlightFormatting === undefined)
|
|
modeCfg.highlightFormatting = false;
|
|
|
|
// Maximum number of nested blockquotes. Set to 0 for infinite nesting.
|
|
// Excess `>` will emit `error` token.
|
|
if (modeCfg.maxBlockquoteDepth === undefined)
|
|
modeCfg.maxBlockquoteDepth = 0;
|
|
|
|
// Should underscores in words open/close em/strong?
|
|
if (modeCfg.underscoresBreakWords === undefined)
|
|
modeCfg.underscoresBreakWords = true;
|
|
|
|
// Turn on fenced code blocks? ("```" to start/end)
|
|
if (modeCfg.fencedCodeBlocks === undefined) modeCfg.fencedCodeBlocks = false;
|
|
|
|
// Turn on task lists? ("- [ ] " and "- [x] ")
|
|
if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
|
|
|
|
// Turn on strikethrough syntax
|
|
if (modeCfg.strikethrough === undefined)
|
|
modeCfg.strikethrough = false;
|
|
|
|
var codeDepth = 0;
|
|
|
|
var header = 'header'
|
|
, code = 'comment'
|
|
, quote = 'quote'
|
|
, list1 = 'variable-2'
|
|
, list2 = 'variable-3'
|
|
, list3 = 'keyword'
|
|
, hr = 'hr'
|
|
, image = 'tag'
|
|
, formatting = 'formatting'
|
|
, linkinline = 'link'
|
|
, linkemail = 'link'
|
|
, linktext = 'link'
|
|
, linkhref = 'string'
|
|
, em = 'em'
|
|
, strong = 'strong'
|
|
, strikethrough = 'strikethrough';
|
|
|
|
var hrRE = /^([*\-=_])(?:\s*\1){2,}\s*$/
|
|
, ulRE = /^[*\-+]\s+/
|
|
, olRE = /^[0-9]+\.\s+/
|
|
, taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE
|
|
, atxHeaderRE = /^#+/
|
|
, setextHeaderRE = /^(?:\={1,}|-{1,})$/
|
|
, textRE = /^[^#!\[\]*_\\<>` "'(~]+/;
|
|
|
|
function switchInline(stream, state, f) {
|
|
state.f = state.inline = f;
|
|
return f(stream, state);
|
|
}
|
|
|
|
function switchBlock(stream, state, f) {
|
|
state.f = state.block = f;
|
|
return f(stream, state);
|
|
}
|
|
|
|
|
|
// Blocks
|
|
|
|
function blankLine(state) {
|
|
// Reset linkTitle state
|
|
state.linkTitle = false;
|
|
// Reset EM state
|
|
state.em = false;
|
|
// Reset STRONG state
|
|
state.strong = false;
|
|
// Reset strikethrough state
|
|
state.strikethrough = false;
|
|
// Reset state.quote
|
|
state.quote = 0;
|
|
if (!htmlFound && state.f == htmlBlock) {
|
|
state.f = inlineNormal;
|
|
state.block = blockNormal;
|
|
}
|
|
// Reset state.trailingSpace
|
|
state.trailingSpace = 0;
|
|
state.trailingSpaceNewLine = false;
|
|
// Mark this line as blank
|
|
state.thisLineHasContent = false;
|
|
return null;
|
|
}
|
|
|
|
function blockNormal(stream, state) {
|
|
|
|
var sol = stream.sol();
|
|
|
|
var prevLineIsList = (state.list !== false);
|
|
if (state.list !== false && state.indentationDiff >= 0) { // Continued list
|
|
if (state.indentationDiff < 4) { // Only adjust indentation if *not* a code block
|
|
state.indentation -= state.indentationDiff;
|
|
}
|
|
state.list = null;
|
|
} else if (state.list !== false && state.indentation > 0) {
|
|
state.list = null;
|
|
state.listDepth = Math.floor(state.indentation / 4);
|
|
} else if (state.list !== false) { // No longer a list
|
|
state.list = false;
|
|
state.listDepth = 0;
|
|
}
|
|
|
|
var match = null;
|
|
if (state.indentationDiff >= 4) {
|
|
state.indentation -= 4;
|
|
stream.skipToEnd();
|
|
return code;
|
|
} else if (stream.eatSpace()) {
|
|
return null;
|
|
} else if (match = stream.match(atxHeaderRE)) {
|
|
state.header = match[0].length <= 6 ? match[0].length : 6;
|
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
|
state.f = state.inline;
|
|
return getType(state);
|
|
} else if (state.prevLineHasContent && (match = stream.match(setextHeaderRE))) {
|
|
state.header = match[0].charAt(0) == '=' ? 1 : 2;
|
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
|
state.f = state.inline;
|
|
return getType(state);
|
|
} else if (stream.eat('>')) {
|
|
state.indentation++;
|
|
state.quote = sol ? 1 : state.quote + 1;
|
|
if (modeCfg.highlightFormatting) state.formatting = "quote";
|
|
stream.eatSpace();
|
|
return getType(state);
|
|
} else if (stream.peek() === '[') {
|
|
return switchInline(stream, state, footnoteLink);
|
|
} else if (stream.match(hrRE, true)) {
|
|
return hr;
|
|
} else if ((!state.prevLineHasContent || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
|
|
var listType = null;
|
|
if (stream.match(ulRE, true)) {
|
|
listType = 'ul';
|
|
} else {
|
|
stream.match(olRE, true);
|
|
listType = 'ol';
|
|
}
|
|
state.indentation += 4;
|
|
state.list = true;
|
|
state.listDepth++;
|
|
if (modeCfg.taskLists && stream.match(taskListRE, false)) {
|
|
state.taskList = true;
|
|
}
|
|
state.f = state.inline;
|
|
if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
|
|
return getType(state);
|
|
} else if (modeCfg.fencedCodeBlocks && stream.match(/^```[ \t]*([\w+#]*)/, true)) {
|
|
// try switching mode
|
|
state.localMode = getMode(RegExp.$1);
|
|
if (state.localMode) state.localState = state.localMode.startState();
|
|
state.f = state.block = local;
|
|
if (modeCfg.highlightFormatting) state.formatting = "code-block";
|
|
state.code = true;
|
|
return getType(state);
|
|
}
|
|
|
|
return switchInline(stream, state, state.inline);
|
|
}
|
|
|
|
function htmlBlock(stream, state) {
|
|
var style = htmlMode.token(stream, state.htmlState);
|
|
if ((htmlFound && state.htmlState.tagStart === null && !state.htmlState.context) ||
|
|
(state.md_inside && stream.current().indexOf(">") > -1)) {
|
|
state.f = inlineNormal;
|
|
state.block = blockNormal;
|
|
state.htmlState = null;
|
|
}
|
|
return style;
|
|
}
|
|
|
|
function local(stream, state) {
|
|
if (stream.sol() && stream.match("```", false)) {
|
|
state.localMode = state.localState = null;
|
|
state.f = state.block = leavingLocal;
|
|
return null;
|
|
} else if (state.localMode) {
|
|
return state.localMode.token(stream, state.localState);
|
|
} else {
|
|
stream.skipToEnd();
|
|
return code;
|
|
}
|
|
}
|
|
|
|
function leavingLocal(stream, state) {
|
|
stream.match("```");
|
|
state.block = blockNormal;
|
|
state.f = inlineNormal;
|
|
if (modeCfg.highlightFormatting) state.formatting = "code-block";
|
|
state.code = true;
|
|
var returnType = getType(state);
|
|
state.code = false;
|
|
return returnType;
|
|
}
|
|
|
|
// Inline
|
|
function getType(state) {
|
|
var styles = [];
|
|
|
|
if (state.formatting) {
|
|
styles.push(formatting);
|
|
|
|
if (typeof state.formatting === "string") state.formatting = [state.formatting];
|
|
|
|
for (var i = 0; i < state.formatting.length; i++) {
|
|
styles.push(formatting + "-" + state.formatting[i]);
|
|
|
|
if (state.formatting[i] === "header") {
|
|
styles.push(formatting + "-" + state.formatting[i] + "-" + state.header);
|
|
}
|
|
|
|
// Add `formatting-quote` and `formatting-quote-#` for blockquotes
|
|
// Add `error` instead if the maximum blockquote nesting depth is passed
|
|
if (state.formatting[i] === "quote") {
|
|
if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
|
|
styles.push(formatting + "-" + state.formatting[i] + "-" + state.quote);
|
|
} else {
|
|
styles.push("error");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (state.taskOpen) {
|
|
styles.push("meta");
|
|
return styles.length ? styles.join(' ') : null;
|
|
}
|
|
if (state.taskClosed) {
|
|
styles.push("property");
|
|
return styles.length ? styles.join(' ') : null;
|
|
}
|
|
|
|
if (state.linkHref) {
|
|
styles.push(linkhref);
|
|
return styles.length ? styles.join(' ') : null;
|
|
}
|
|
|
|
if (state.strong) { styles.push(strong); }
|
|
if (state.em) { styles.push(em); }
|
|
if (state.strikethrough) { styles.push(strikethrough); }
|
|
|
|
if (state.linkText) { styles.push(linktext); }
|
|
|
|
if (state.code) { styles.push(code); }
|
|
|
|
if (state.header) { styles.push(header); styles.push(header + "-" + state.header); }
|
|
|
|
if (state.quote) {
|
|
styles.push(quote);
|
|
|
|
// Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
|
|
if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
|
|
styles.push(quote + "-" + state.quote);
|
|
} else {
|
|
styles.push(quote + "-" + modeCfg.maxBlockquoteDepth);
|
|
}
|
|
}
|
|
|
|
if (state.list !== false) {
|
|
var listMod = (state.listDepth - 1) % 3;
|
|
if (!listMod) {
|
|
styles.push(list1);
|
|
} else if (listMod === 1) {
|
|
styles.push(list2);
|
|
} else {
|
|
styles.push(list3);
|
|
}
|
|
}
|
|
|
|
if (state.trailingSpaceNewLine) {
|
|
styles.push("trailing-space-new-line");
|
|
} else if (state.trailingSpace) {
|
|
styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
|
|
}
|
|
|
|
return styles.length ? styles.join(' ') : null;
|
|
}
|
|
|
|
function handleText(stream, state) {
|
|
if (stream.match(textRE, true)) {
|
|
return getType(state);
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function inlineNormal(stream, state) {
|
|
var style = state.text(stream, state);
|
|
if (typeof style !== 'undefined')
|
|
return style;
|
|
|
|
if (state.list) { // List marker (*, +, -, 1., etc)
|
|
state.list = null;
|
|
return getType(state);
|
|
}
|
|
|
|
if (state.taskList) {
|
|
var taskOpen = stream.match(taskListRE, true)[1] !== "x";
|
|
if (taskOpen) state.taskOpen = true;
|
|
else state.taskClosed = true;
|
|
if (modeCfg.highlightFormatting) state.formatting = "task";
|
|
state.taskList = false;
|
|
return getType(state);
|
|
}
|
|
|
|
state.taskOpen = false;
|
|
state.taskClosed = false;
|
|
|
|
if (state.header && stream.match(/^#+$/, true)) {
|
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
|
return getType(state);
|
|
}
|
|
|
|
// Get sol() value now, before character is consumed
|
|
var sol = stream.sol();
|
|
|
|
var ch = stream.next();
|
|
|
|
if (ch === '\\') {
|
|
stream.next();
|
|
if (modeCfg.highlightFormatting) {
|
|
var type = getType(state);
|
|
return type ? type + " formatting-escape" : "formatting-escape";
|
|
}
|
|
}
|
|
|
|
// Matches link titles present on next line
|
|
if (state.linkTitle) {
|
|
state.linkTitle = false;
|
|
var matchCh = ch;
|
|
if (ch === '(') {
|
|
matchCh = ')';
|
|
}
|
|
matchCh = (matchCh+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
|
var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
|
|
if (stream.match(new RegExp(regex), true)) {
|
|
return linkhref;
|
|
}
|
|
}
|
|
|
|
// If this block is changed, it may need to be updated in GFM mode
|
|
if (ch === '`') {
|
|
var previousFormatting = state.formatting;
|
|
if (modeCfg.highlightFormatting) state.formatting = "code";
|
|
var t = getType(state);
|
|
var before = stream.pos;
|
|
stream.eatWhile('`');
|
|
var difference = 1 + stream.pos - before;
|
|
if (!state.code) {
|
|
codeDepth = difference;
|
|
state.code = true;
|
|
return getType(state);
|
|
} else {
|
|
if (difference === codeDepth) { // Must be exact
|
|
state.code = false;
|
|
return t;
|
|
}
|
|
state.formatting = previousFormatting;
|
|
return getType(state);
|
|
}
|
|
} else if (state.code) {
|
|
return getType(state);
|
|
}
|
|
|
|
if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
|
|
stream.match(/\[[^\]]*\]/);
|
|
state.inline = state.f = linkHref;
|
|
return image;
|
|
}
|
|
|
|
if (ch === '[' && stream.match(/.*\](\(.*\)| ?\[.*\])/, false)) {
|
|
state.linkText = true;
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
return getType(state);
|
|
}
|
|
|
|
if (ch === ']' && state.linkText && stream.match(/\(.*\)| ?\[.*\]/, false)) {
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
var type = getType(state);
|
|
state.linkText = false;
|
|
state.inline = state.f = linkHref;
|
|
return type;
|
|
}
|
|
|
|
if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
|
|
state.f = state.inline = linkInline;
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
var type = getType(state);
|
|
if (type){
|
|
type += " ";
|
|
} else {
|
|
type = "";
|
|
}
|
|
return type + linkinline;
|
|
}
|
|
|
|
if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
|
|
state.f = state.inline = linkInline;
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
var type = getType(state);
|
|
if (type){
|
|
type += " ";
|
|
} else {
|
|
type = "";
|
|
}
|
|
return type + linkemail;
|
|
}
|
|
|
|
if (ch === '<' && stream.match(/^\w/, false)) {
|
|
if (stream.string.indexOf(">") != -1) {
|
|
var atts = stream.string.substring(1,stream.string.indexOf(">"));
|
|
if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) {
|
|
state.md_inside = true;
|
|
}
|
|
}
|
|
stream.backUp(1);
|
|
state.htmlState = CodeMirror.startState(htmlMode);
|
|
return switchBlock(stream, state, htmlBlock);
|
|
}
|
|
|
|
if (ch === '<' && stream.match(/^\/\w*?>/)) {
|
|
state.md_inside = false;
|
|
return "tag";
|
|
}
|
|
|
|
var ignoreUnderscore = false;
|
|
if (!modeCfg.underscoresBreakWords) {
|
|
if (ch === '_' && stream.peek() !== '_' && stream.match(/(\w)/, false)) {
|
|
var prevPos = stream.pos - 2;
|
|
if (prevPos >= 0) {
|
|
var prevCh = stream.string.charAt(prevPos);
|
|
if (prevCh !== '_' && prevCh.match(/(\w)/, false)) {
|
|
ignoreUnderscore = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (ch === '*' || (ch === '_' && !ignoreUnderscore)) {
|
|
if (sol && stream.peek() === ' ') {
|
|
// Do nothing, surrounded by newline and space
|
|
} else if (state.strong === ch && stream.eat(ch)) { // Remove STRONG
|
|
if (modeCfg.highlightFormatting) state.formatting = "strong";
|
|
var t = getType(state);
|
|
state.strong = false;
|
|
return t;
|
|
} else if (!state.strong && stream.eat(ch)) { // Add STRONG
|
|
state.strong = ch;
|
|
if (modeCfg.highlightFormatting) state.formatting = "strong";
|
|
return getType(state);
|
|
} else if (state.em === ch) { // Remove EM
|
|
if (modeCfg.highlightFormatting) state.formatting = "em";
|
|
var t = getType(state);
|
|
state.em = false;
|
|
return t;
|
|
} else if (!state.em) { // Add EM
|
|
state.em = ch;
|
|
if (modeCfg.highlightFormatting) state.formatting = "em";
|
|
return getType(state);
|
|
}
|
|
} else if (ch === ' ') {
|
|
if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
|
|
if (stream.peek() === ' ') { // Surrounded by spaces, ignore
|
|
return getType(state);
|
|
} else { // Not surrounded by spaces, back up pointer
|
|
stream.backUp(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (modeCfg.strikethrough) {
|
|
if (ch === '~' && stream.eatWhile(ch)) {
|
|
if (state.strikethrough) {// Remove strikethrough
|
|
if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
|
|
var t = getType(state);
|
|
state.strikethrough = false;
|
|
return t;
|
|
} else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
|
|
state.strikethrough = true;
|
|
if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
|
|
return getType(state);
|
|
}
|
|
} else if (ch === ' ') {
|
|
if (stream.match(/^~~/, true)) { // Probably surrounded by space
|
|
if (stream.peek() === ' ') { // Surrounded by spaces, ignore
|
|
return getType(state);
|
|
} else { // Not surrounded by spaces, back up pointer
|
|
stream.backUp(2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (ch === ' ') {
|
|
if (stream.match(/ +$/, false)) {
|
|
state.trailingSpace++;
|
|
} else if (state.trailingSpace) {
|
|
state.trailingSpaceNewLine = true;
|
|
}
|
|
}
|
|
|
|
return getType(state);
|
|
}
|
|
|
|
function linkInline(stream, state) {
|
|
var ch = stream.next();
|
|
|
|
if (ch === ">") {
|
|
state.f = state.inline = inlineNormal;
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
var type = getType(state);
|
|
if (type){
|
|
type += " ";
|
|
} else {
|
|
type = "";
|
|
}
|
|
return type + linkinline;
|
|
}
|
|
|
|
stream.match(/^[^>]+/, true);
|
|
|
|
return linkinline;
|
|
}
|
|
|
|
function linkHref(stream, state) {
|
|
// Check if space, and return NULL if so (to avoid marking the space)
|
|
if(stream.eatSpace()){
|
|
return null;
|
|
}
|
|
var ch = stream.next();
|
|
if (ch === '(' || ch === '[') {
|
|
state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");
|
|
if (modeCfg.highlightFormatting) state.formatting = "link-string";
|
|
state.linkHref = true;
|
|
return getType(state);
|
|
}
|
|
return 'error';
|
|
}
|
|
|
|
function getLinkHrefInside(endChar) {
|
|
return function(stream, state) {
|
|
var ch = stream.next();
|
|
|
|
if (ch === endChar) {
|
|
state.f = state.inline = inlineNormal;
|
|
if (modeCfg.highlightFormatting) state.formatting = "link-string";
|
|
var returnState = getType(state);
|
|
state.linkHref = false;
|
|
return returnState;
|
|
}
|
|
|
|
if (stream.match(inlineRE(endChar), true)) {
|
|
stream.backUp(1);
|
|
}
|
|
|
|
state.linkHref = true;
|
|
return getType(state);
|
|
};
|
|
}
|
|
|
|
function footnoteLink(stream, state) {
|
|
if (stream.match(/^[^\]]*\]:/, false)) {
|
|
state.f = footnoteLinkInside;
|
|
stream.next(); // Consume [
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
state.linkText = true;
|
|
return getType(state);
|
|
}
|
|
return switchInline(stream, state, inlineNormal);
|
|
}
|
|
|
|
function footnoteLinkInside(stream, state) {
|
|
if (stream.match(/^\]:/, true)) {
|
|
state.f = state.inline = footnoteUrl;
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
var returnType = getType(state);
|
|
state.linkText = false;
|
|
return returnType;
|
|
}
|
|
|
|
stream.match(/^[^\]]+/, true);
|
|
|
|
return linktext;
|
|
}
|
|
|
|
function footnoteUrl(stream, state) {
|
|
// Check if space, and return NULL if so (to avoid marking the space)
|
|
if(stream.eatSpace()){
|
|
return null;
|
|
}
|
|
// Match URL
|
|
stream.match(/^[^\s]+/, true);
|
|
// Check for link title
|
|
if (stream.peek() === undefined) { // End of line, set flag to check next line
|
|
state.linkTitle = true;
|
|
} else { // More content on line, check if link title
|
|
stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
|
|
}
|
|
state.f = state.inline = inlineNormal;
|
|
return linkhref;
|
|
}
|
|
|
|
var savedInlineRE = [];
|
|
function inlineRE(endChar) {
|
|
if (!savedInlineRE[endChar]) {
|
|
// Escape endChar for RegExp (taken from http://stackoverflow.com/a/494122/526741)
|
|
endChar = (endChar+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
|
// Match any non-endChar, escaped character, as well as the closing
|
|
// endChar.
|
|
savedInlineRE[endChar] = new RegExp('^(?:[^\\\\]|\\\\.)*?(' + endChar + ')');
|
|
}
|
|
return savedInlineRE[endChar];
|
|
}
|
|
|
|
var mode = {
|
|
startState: function() {
|
|
return {
|
|
f: blockNormal,
|
|
|
|
prevLineHasContent: false,
|
|
thisLineHasContent: false,
|
|
|
|
block: blockNormal,
|
|
htmlState: null,
|
|
indentation: 0,
|
|
|
|
inline: inlineNormal,
|
|
text: handleText,
|
|
|
|
formatting: false,
|
|
linkText: false,
|
|
linkHref: false,
|
|
linkTitle: false,
|
|
em: false,
|
|
strong: false,
|
|
header: 0,
|
|
taskList: false,
|
|
list: false,
|
|
listDepth: 0,
|
|
quote: 0,
|
|
trailingSpace: 0,
|
|
trailingSpaceNewLine: false,
|
|
strikethrough: false
|
|
};
|
|
},
|
|
|
|
copyState: function(s) {
|
|
return {
|
|
f: s.f,
|
|
|
|
prevLineHasContent: s.prevLineHasContent,
|
|
thisLineHasContent: s.thisLineHasContent,
|
|
|
|
block: s.block,
|
|
htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
|
|
indentation: s.indentation,
|
|
|
|
localMode: s.localMode,
|
|
localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
|
|
|
|
inline: s.inline,
|
|
text: s.text,
|
|
formatting: false,
|
|
linkTitle: s.linkTitle,
|
|
em: s.em,
|
|
strong: s.strong,
|
|
strikethrough: s.strikethrough,
|
|
header: s.header,
|
|
taskList: s.taskList,
|
|
list: s.list,
|
|
listDepth: s.listDepth,
|
|
quote: s.quote,
|
|
trailingSpace: s.trailingSpace,
|
|
trailingSpaceNewLine: s.trailingSpaceNewLine,
|
|
md_inside: s.md_inside
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
|
|
// Reset state.formatting
|
|
state.formatting = false;
|
|
|
|
if (stream.sol()) {
|
|
var forceBlankLine = !!state.header;
|
|
|
|
// Reset state.header
|
|
state.header = 0;
|
|
|
|
if (stream.match(/^\s*$/, true) || forceBlankLine) {
|
|
state.prevLineHasContent = false;
|
|
blankLine(state);
|
|
return forceBlankLine ? this.token(stream, state) : null;
|
|
} else {
|
|
state.prevLineHasContent = state.thisLineHasContent;
|
|
state.thisLineHasContent = true;
|
|
}
|
|
|
|
// Reset state.taskList
|
|
state.taskList = false;
|
|
|
|
// Reset state.code
|
|
state.code = false;
|
|
|
|
// Reset state.trailingSpace
|
|
state.trailingSpace = 0;
|
|
state.trailingSpaceNewLine = false;
|
|
|
|
state.f = state.block;
|
|
var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length;
|
|
var difference = Math.floor((indentation - state.indentation) / 4) * 4;
|
|
if (difference > 4) difference = 4;
|
|
var adjustedIndentation = state.indentation + difference;
|
|
state.indentationDiff = adjustedIndentation - state.indentation;
|
|
state.indentation = adjustedIndentation;
|
|
if (indentation > 0) return null;
|
|
}
|
|
return state.f(stream, state);
|
|
},
|
|
|
|
innerMode: function(state) {
|
|
if (state.block == htmlBlock) return {state: state.htmlState, mode: htmlMode};
|
|
if (state.localState) return {state: state.localState, mode: state.localMode};
|
|
return {state: state, mode: mode};
|
|
},
|
|
|
|
blankLine: blankLine,
|
|
|
|
getType: getType,
|
|
|
|
fold: "markdown"
|
|
};
|
|
return mode;
|
|
}, "xml");
|
|
|
|
CodeMirror.defineMIME("text/x-markdown", "markdown");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
// TODO actually recognize syntax of TypeScript constructs
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
var indentUnit = config.indentUnit;
|
|
var statementIndent = parserConfig.statementIndent;
|
|
var jsonldMode = parserConfig.jsonld;
|
|
var jsonMode = parserConfig.json || jsonldMode;
|
|
var isTS = parserConfig.typescript;
|
|
var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
|
|
|
|
// Tokenizer
|
|
|
|
var keywords = function(){
|
|
function kw(type) {return {type: type, style: "keyword"};}
|
|
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
|
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
|
|
|
var jsKeywords = {
|
|
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
|
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, "debugger": C,
|
|
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
|
"function": kw("function"), "catch": kw("catch"),
|
|
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
|
"in": operator, "typeof": operator, "instanceof": operator,
|
|
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
|
"this": kw("this"), "module": kw("module"), "class": kw("class"), "super": kw("atom"),
|
|
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C
|
|
};
|
|
|
|
// Extend the 'normal' keywords with the TypeScript language extensions
|
|
if (isTS) {
|
|
var type = {type: "variable", style: "variable-3"};
|
|
var tsKeywords = {
|
|
// object-like things
|
|
"interface": kw("interface"),
|
|
"extends": kw("extends"),
|
|
"constructor": kw("constructor"),
|
|
|
|
// scope modifiers
|
|
"public": kw("public"),
|
|
"private": kw("private"),
|
|
"protected": kw("protected"),
|
|
"static": kw("static"),
|
|
|
|
// types
|
|
"string": type, "number": type, "bool": type, "any": type
|
|
};
|
|
|
|
for (var attr in tsKeywords) {
|
|
jsKeywords[attr] = tsKeywords[attr];
|
|
}
|
|
}
|
|
|
|
return jsKeywords;
|
|
}();
|
|
|
|
var isOperatorChar = /[+\-*&%=<>!?|~^]/;
|
|
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
|
|
|
|
function readRegexp(stream) {
|
|
var escaped = false, next, inSet = false;
|
|
while ((next = stream.next()) != null) {
|
|
if (!escaped) {
|
|
if (next == "/" && !inSet) return;
|
|
if (next == "[") inSet = true;
|
|
else if (inSet && next == "]") inSet = false;
|
|
}
|
|
escaped = !escaped && next == "\\";
|
|
}
|
|
}
|
|
|
|
// Used as scratch variables to communicate multiple values without
|
|
// consing up tons of objects.
|
|
var type, content;
|
|
function ret(tp, style, cont) {
|
|
type = tp; content = cont;
|
|
return style;
|
|
}
|
|
function tokenBase(stream, state) {
|
|
var ch = stream.next();
|
|
if (ch == '"' || ch == "'") {
|
|
state.tokenize = tokenString(ch);
|
|
return state.tokenize(stream, state);
|
|
} else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
|
|
return ret("number", "number");
|
|
} else if (ch == "." && stream.match("..")) {
|
|
return ret("spread", "meta");
|
|
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
|
return ret(ch);
|
|
} else if (ch == "=" && stream.eat(">")) {
|
|
return ret("=>", "operator");
|
|
} else if (ch == "0" && stream.eat(/x/i)) {
|
|
stream.eatWhile(/[\da-f]/i);
|
|
return ret("number", "number");
|
|
} else if (/\d/.test(ch)) {
|
|
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
|
|
return ret("number", "number");
|
|
} else if (ch == "/") {
|
|
if (stream.eat("*")) {
|
|
state.tokenize = tokenComment;
|
|
return tokenComment(stream, state);
|
|
} else if (stream.eat("/")) {
|
|
stream.skipToEnd();
|
|
return ret("comment", "comment");
|
|
} else if (state.lastType == "operator" || state.lastType == "keyword c" ||
|
|
state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) {
|
|
readRegexp(stream);
|
|
stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
|
|
return ret("regexp", "string-2");
|
|
} else {
|
|
stream.eatWhile(isOperatorChar);
|
|
return ret("operator", "operator", stream.current());
|
|
}
|
|
} else if (ch == "`") {
|
|
state.tokenize = tokenQuasi;
|
|
return tokenQuasi(stream, state);
|
|
} else if (ch == "#") {
|
|
stream.skipToEnd();
|
|
return ret("error", "error");
|
|
} else if (isOperatorChar.test(ch)) {
|
|
stream.eatWhile(isOperatorChar);
|
|
return ret("operator", "operator", stream.current());
|
|
} else if (wordRE.test(ch)) {
|
|
stream.eatWhile(wordRE);
|
|
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
|
return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
|
|
ret("variable", "variable", word);
|
|
}
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, next;
|
|
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
|
|
state.tokenize = tokenBase;
|
|
return ret("jsonld-keyword", "meta");
|
|
}
|
|
while ((next = stream.next()) != null) {
|
|
if (next == quote && !escaped) break;
|
|
escaped = !escaped && next == "\\";
|
|
}
|
|
if (!escaped) state.tokenize = tokenBase;
|
|
return ret("string", "string");
|
|
};
|
|
}
|
|
|
|
function tokenComment(stream, state) {
|
|
var maybeEnd = false, ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "/" && maybeEnd) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
maybeEnd = (ch == "*");
|
|
}
|
|
return ret("comment", "comment");
|
|
}
|
|
|
|
function tokenQuasi(stream, state) {
|
|
var escaped = false, next;
|
|
while ((next = stream.next()) != null) {
|
|
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
escaped = !escaped && next == "\\";
|
|
}
|
|
return ret("quasi", "string-2", stream.current());
|
|
}
|
|
|
|
var brackets = "([{}])";
|
|
// This is a crude lookahead trick to try and notice that we're
|
|
// parsing the argument patterns for a fat-arrow function before we
|
|
// actually hit the arrow token. It only works if the arrow is on
|
|
// the same line as the arguments and there's no strange noise
|
|
// (comments) in between. Fallback is to only notice when we hit the
|
|
// arrow, and not declare the arguments as locals for the arrow
|
|
// body.
|
|
function findFatArrow(stream, state) {
|
|
if (state.fatArrowAt) state.fatArrowAt = null;
|
|
var arrow = stream.string.indexOf("=>", stream.start);
|
|
if (arrow < 0) return;
|
|
|
|
var depth = 0, sawSomething = false;
|
|
for (var pos = arrow - 1; pos >= 0; --pos) {
|
|
var ch = stream.string.charAt(pos);
|
|
var bracket = brackets.indexOf(ch);
|
|
if (bracket >= 0 && bracket < 3) {
|
|
if (!depth) { ++pos; break; }
|
|
if (--depth == 0) break;
|
|
} else if (bracket >= 3 && bracket < 6) {
|
|
++depth;
|
|
} else if (wordRE.test(ch)) {
|
|
sawSomething = true;
|
|
} else if (/["'\/]/.test(ch)) {
|
|
return;
|
|
} else if (sawSomething && !depth) {
|
|
++pos;
|
|
break;
|
|
}
|
|
}
|
|
if (sawSomething && !depth) state.fatArrowAt = pos;
|
|
}
|
|
|
|
// Parser
|
|
|
|
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
|
|
|
|
function JSLexical(indented, column, type, align, prev, info) {
|
|
this.indented = indented;
|
|
this.column = column;
|
|
this.type = type;
|
|
this.prev = prev;
|
|
this.info = info;
|
|
if (align != null) this.align = align;
|
|
}
|
|
|
|
function inScope(state, varname) {
|
|
for (var v = state.localVars; v; v = v.next)
|
|
if (v.name == varname) return true;
|
|
for (var cx = state.context; cx; cx = cx.prev) {
|
|
for (var v = cx.vars; v; v = v.next)
|
|
if (v.name == varname) return true;
|
|
}
|
|
}
|
|
|
|
function parseJS(state, style, type, content, stream) {
|
|
var cc = state.cc;
|
|
// Communicate our context to the combinators.
|
|
// (Less wasteful than consing up a hundred closures on every call.)
|
|
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
|
|
|
|
if (!state.lexical.hasOwnProperty("align"))
|
|
state.lexical.align = true;
|
|
|
|
while(true) {
|
|
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
|
if (combinator(type, content)) {
|
|
while(cc.length && cc[cc.length - 1].lex)
|
|
cc.pop()();
|
|
if (cx.marked) return cx.marked;
|
|
if (type == "variable" && inScope(state, content)) return "variable-2";
|
|
return style;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Combinator utils
|
|
|
|
var cx = {state: null, column: null, marked: null, cc: null};
|
|
function pass() {
|
|
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
|
}
|
|
function cont() {
|
|
pass.apply(null, arguments);
|
|
return true;
|
|
}
|
|
function register(varname) {
|
|
function inList(list) {
|
|
for (var v = list; v; v = v.next)
|
|
if (v.name == varname) return true;
|
|
return false;
|
|
}
|
|
var state = cx.state;
|
|
if (state.context) {
|
|
cx.marked = "def";
|
|
if (inList(state.localVars)) return;
|
|
state.localVars = {name: varname, next: state.localVars};
|
|
} else {
|
|
if (inList(state.globalVars)) return;
|
|
if (parserConfig.globalVars)
|
|
state.globalVars = {name: varname, next: state.globalVars};
|
|
}
|
|
}
|
|
|
|
// Combinators
|
|
|
|
var defaultVars = {name: "this", next: {name: "arguments"}};
|
|
function pushcontext() {
|
|
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
|
cx.state.localVars = defaultVars;
|
|
}
|
|
function popcontext() {
|
|
cx.state.localVars = cx.state.context.vars;
|
|
cx.state.context = cx.state.context.prev;
|
|
}
|
|
function pushlex(type, info) {
|
|
var result = function() {
|
|
var state = cx.state, indent = state.indented;
|
|
if (state.lexical.type == "stat") indent = state.lexical.indented;
|
|
else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
|
|
indent = outer.indented;
|
|
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
|
|
};
|
|
result.lex = true;
|
|
return result;
|
|
}
|
|
function poplex() {
|
|
var state = cx.state;
|
|
if (state.lexical.prev) {
|
|
if (state.lexical.type == ")")
|
|
state.indented = state.lexical.indented;
|
|
state.lexical = state.lexical.prev;
|
|
}
|
|
}
|
|
poplex.lex = true;
|
|
|
|
function expect(wanted) {
|
|
function exp(type) {
|
|
if (type == wanted) return cont();
|
|
else if (wanted == ";") return pass();
|
|
else return cont(exp);
|
|
};
|
|
return exp;
|
|
}
|
|
|
|
function statement(type, value) {
|
|
if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
|
|
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
|
|
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
|
if (type == "{") return cont(pushlex("}"), block, poplex);
|
|
if (type == ";") return cont();
|
|
if (type == "if") {
|
|
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
|
cx.state.cc.pop()();
|
|
return cont(pushlex("form"), expression, statement, poplex, maybeelse);
|
|
}
|
|
if (type == "function") return cont(functiondef);
|
|
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
|
|
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
|
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
|
|
block, poplex, poplex);
|
|
if (type == "case") return cont(expression, expect(":"));
|
|
if (type == "default") return cont(expect(":"));
|
|
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
|
statement, poplex, popcontext);
|
|
if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex);
|
|
if (type == "class") return cont(pushlex("form"), className, poplex);
|
|
if (type == "export") return cont(pushlex("form"), afterExport, poplex);
|
|
if (type == "import") return cont(pushlex("form"), afterImport, poplex);
|
|
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
|
}
|
|
function expression(type) {
|
|
return expressionInner(type, false);
|
|
}
|
|
function expressionNoComma(type) {
|
|
return expressionInner(type, true);
|
|
}
|
|
function expressionInner(type, noComma) {
|
|
if (cx.state.fatArrowAt == cx.stream.start) {
|
|
var body = noComma ? arrowBodyNoComma : arrowBody;
|
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
|
|
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
|
|
}
|
|
|
|
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
|
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
|
if (type == "function") return cont(functiondef, maybeop);
|
|
if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
|
|
if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
|
|
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
|
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
|
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
|
if (type == "quasi") { return pass(quasi, maybeop); }
|
|
return cont();
|
|
}
|
|
function maybeexpression(type) {
|
|
if (type.match(/[;\}\)\],]/)) return pass();
|
|
return pass(expression);
|
|
}
|
|
function maybeexpressionNoComma(type) {
|
|
if (type.match(/[;\}\)\],]/)) return pass();
|
|
return pass(expressionNoComma);
|
|
}
|
|
|
|
function maybeoperatorComma(type, value) {
|
|
if (type == ",") return cont(expression);
|
|
return maybeoperatorNoComma(type, value, false);
|
|
}
|
|
function maybeoperatorNoComma(type, value, noComma) {
|
|
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
|
|
var expr = noComma == false ? expression : expressionNoComma;
|
|
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
|
|
if (type == "operator") {
|
|
if (/\+\+|--/.test(value)) return cont(me);
|
|
if (value == "?") return cont(expression, expect(":"), expr);
|
|
return cont(expr);
|
|
}
|
|
if (type == "quasi") { return pass(quasi, me); }
|
|
if (type == ";") return;
|
|
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
|
if (type == ".") return cont(property, me);
|
|
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
|
}
|
|
function quasi(type, value) {
|
|
if (type != "quasi") return pass();
|
|
if (value.slice(value.length - 2) != "${") return cont(quasi);
|
|
return cont(expression, continueQuasi);
|
|
}
|
|
function continueQuasi(type) {
|
|
if (type == "}") {
|
|
cx.marked = "string-2";
|
|
cx.state.tokenize = tokenQuasi;
|
|
return cont(quasi);
|
|
}
|
|
}
|
|
function arrowBody(type) {
|
|
findFatArrow(cx.stream, cx.state);
|
|
return pass(type == "{" ? statement : expression);
|
|
}
|
|
function arrowBodyNoComma(type) {
|
|
findFatArrow(cx.stream, cx.state);
|
|
return pass(type == "{" ? statement : expressionNoComma);
|
|
}
|
|
function maybelabel(type) {
|
|
if (type == ":") return cont(poplex, statement);
|
|
return pass(maybeoperatorComma, expect(";"), poplex);
|
|
}
|
|
function property(type) {
|
|
if (type == "variable") {cx.marked = "property"; return cont();}
|
|
}
|
|
function objprop(type, value) {
|
|
if (type == "variable" || cx.style == "keyword") {
|
|
cx.marked = "property";
|
|
if (value == "get" || value == "set") return cont(getterSetter);
|
|
return cont(afterprop);
|
|
} else if (type == "number" || type == "string") {
|
|
cx.marked = jsonldMode ? "property" : (cx.style + " property");
|
|
return cont(afterprop);
|
|
} else if (type == "jsonld-keyword") {
|
|
return cont(afterprop);
|
|
} else if (type == "[") {
|
|
return cont(expression, expect("]"), afterprop);
|
|
}
|
|
}
|
|
function getterSetter(type) {
|
|
if (type != "variable") return pass(afterprop);
|
|
cx.marked = "property";
|
|
return cont(functiondef);
|
|
}
|
|
function afterprop(type) {
|
|
if (type == ":") return cont(expressionNoComma);
|
|
if (type == "(") return pass(functiondef);
|
|
}
|
|
function commasep(what, end) {
|
|
function proceed(type) {
|
|
if (type == ",") {
|
|
var lex = cx.state.lexical;
|
|
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
|
|
return cont(what, proceed);
|
|
}
|
|
if (type == end) return cont();
|
|
return cont(expect(end));
|
|
}
|
|
return function(type) {
|
|
if (type == end) return cont();
|
|
return pass(what, proceed);
|
|
};
|
|
}
|
|
function contCommasep(what, end, info) {
|
|
for (var i = 3; i < arguments.length; i++)
|
|
cx.cc.push(arguments[i]);
|
|
return cont(pushlex(end, info), commasep(what, end), poplex);
|
|
}
|
|
function block(type) {
|
|
if (type == "}") return cont();
|
|
return pass(statement, block);
|
|
}
|
|
function maybetype(type) {
|
|
if (isTS && type == ":") return cont(typedef);
|
|
}
|
|
function typedef(type) {
|
|
if (type == "variable"){cx.marked = "variable-3"; return cont();}
|
|
}
|
|
function vardef() {
|
|
return pass(pattern, maybetype, maybeAssign, vardefCont);
|
|
}
|
|
function pattern(type, value) {
|
|
if (type == "variable") { register(value); return cont(); }
|
|
if (type == "[") return contCommasep(pattern, "]");
|
|
if (type == "{") return contCommasep(proppattern, "}");
|
|
}
|
|
function proppattern(type, value) {
|
|
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
|
|
register(value);
|
|
return cont(maybeAssign);
|
|
}
|
|
if (type == "variable") cx.marked = "property";
|
|
return cont(expect(":"), pattern, maybeAssign);
|
|
}
|
|
function maybeAssign(_type, value) {
|
|
if (value == "=") return cont(expressionNoComma);
|
|
}
|
|
function vardefCont(type) {
|
|
if (type == ",") return cont(vardef);
|
|
}
|
|
function maybeelse(type, value) {
|
|
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
|
}
|
|
function forspec(type) {
|
|
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
|
|
}
|
|
function forspec1(type) {
|
|
if (type == "var") return cont(vardef, expect(";"), forspec2);
|
|
if (type == ";") return cont(forspec2);
|
|
if (type == "variable") return cont(formaybeinof);
|
|
return pass(expression, expect(";"), forspec2);
|
|
}
|
|
function formaybeinof(_type, value) {
|
|
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
|
return cont(maybeoperatorComma, forspec2);
|
|
}
|
|
function forspec2(type, value) {
|
|
if (type == ";") return cont(forspec3);
|
|
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
|
return pass(expression, expect(";"), forspec3);
|
|
}
|
|
function forspec3(type) {
|
|
if (type != ")") cont(expression);
|
|
}
|
|
function functiondef(type, value) {
|
|
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
|
|
if (type == "variable") {register(value); return cont(functiondef);}
|
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext);
|
|
}
|
|
function funarg(type) {
|
|
if (type == "spread") return cont(funarg);
|
|
return pass(pattern, maybetype);
|
|
}
|
|
function className(type, value) {
|
|
if (type == "variable") {register(value); return cont(classNameAfter);}
|
|
}
|
|
function classNameAfter(type, value) {
|
|
if (value == "extends") return cont(expression, classNameAfter);
|
|
if (type == "{") return cont(pushlex("}"), classBody, poplex);
|
|
}
|
|
function classBody(type, value) {
|
|
if (type == "variable" || cx.style == "keyword") {
|
|
cx.marked = "property";
|
|
if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
|
|
return cont(functiondef, classBody);
|
|
}
|
|
if (value == "*") {
|
|
cx.marked = "keyword";
|
|
return cont(classBody);
|
|
}
|
|
if (type == ";") return cont(classBody);
|
|
if (type == "}") return cont();
|
|
}
|
|
function classGetterSetter(type) {
|
|
if (type != "variable") return pass();
|
|
cx.marked = "property";
|
|
return cont();
|
|
}
|
|
function afterModule(type, value) {
|
|
if (type == "string") return cont(statement);
|
|
if (type == "variable") { register(value); return cont(maybeFrom); }
|
|
}
|
|
function afterExport(_type, value) {
|
|
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
|
|
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
|
|
return pass(statement);
|
|
}
|
|
function afterImport(type) {
|
|
if (type == "string") return cont();
|
|
return pass(importSpec, maybeFrom);
|
|
}
|
|
function importSpec(type, value) {
|
|
if (type == "{") return contCommasep(importSpec, "}");
|
|
if (type == "variable") register(value);
|
|
return cont();
|
|
}
|
|
function maybeFrom(_type, value) {
|
|
if (value == "from") { cx.marked = "keyword"; return cont(expression); }
|
|
}
|
|
function arrayLiteral(type) {
|
|
if (type == "]") return cont();
|
|
return pass(expressionNoComma, maybeArrayComprehension);
|
|
}
|
|
function maybeArrayComprehension(type) {
|
|
if (type == "for") return pass(comprehension, expect("]"));
|
|
if (type == ",") return cont(commasep(maybeexpressionNoComma, "]"));
|
|
return pass(commasep(expressionNoComma, "]"));
|
|
}
|
|
function comprehension(type) {
|
|
if (type == "for") return cont(forspec, comprehension);
|
|
if (type == "if") return cont(expression, comprehension);
|
|
}
|
|
|
|
function isContinuedStatement(state, textAfter) {
|
|
return state.lastType == "operator" || state.lastType == "," ||
|
|
isOperatorChar.test(textAfter.charAt(0)) ||
|
|
/[,.]/.test(textAfter.charAt(0));
|
|
}
|
|
|
|
// Interface
|
|
|
|
return {
|
|
startState: function(basecolumn) {
|
|
var state = {
|
|
tokenize: tokenBase,
|
|
lastType: "sof",
|
|
cc: [],
|
|
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
|
localVars: parserConfig.localVars,
|
|
context: parserConfig.localVars && {vars: parserConfig.localVars},
|
|
indented: 0
|
|
};
|
|
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
|
|
state.globalVars = parserConfig.globalVars;
|
|
return state;
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.sol()) {
|
|
if (!state.lexical.hasOwnProperty("align"))
|
|
state.lexical.align = false;
|
|
state.indented = stream.indentation();
|
|
findFatArrow(stream, state);
|
|
}
|
|
if (state.tokenize != tokenComment && stream.eatSpace()) return null;
|
|
var style = state.tokenize(stream, state);
|
|
if (type == "comment") return style;
|
|
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
|
|
return parseJS(state, style, type, content, stream);
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (state.tokenize == tokenComment) return CodeMirror.Pass;
|
|
if (state.tokenize != tokenBase) return 0;
|
|
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
|
|
// Kludge to prevent 'maybelse' from blocking lexical scope pops
|
|
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
|
|
var c = state.cc[i];
|
|
if (c == poplex) lexical = lexical.prev;
|
|
else if (c != maybeelse) break;
|
|
}
|
|
if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
|
|
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
|
|
lexical = lexical.prev;
|
|
var type = lexical.type, closing = firstChar == type;
|
|
|
|
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
|
|
else if (type == "form" && firstChar == "{") return lexical.indented;
|
|
else if (type == "form") return lexical.indented + indentUnit;
|
|
else if (type == "stat")
|
|
return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
|
|
else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
|
|
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
|
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
|
else return lexical.indented + (closing ? 0 : indentUnit);
|
|
},
|
|
|
|
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
|
|
blockCommentStart: jsonMode ? null : "/*",
|
|
blockCommentEnd: jsonMode ? null : "*/",
|
|
lineComment: jsonMode ? null : "//",
|
|
fold: "brace",
|
|
|
|
helperType: jsonMode ? "json" : "javascript",
|
|
jsonldMode: jsonldMode,
|
|
jsonMode: jsonMode
|
|
};
|
|
});
|
|
|
|
CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
|
|
|
|
CodeMirror.defineMIME("text/javascript", "javascript");
|
|
CodeMirror.defineMIME("text/ecmascript", "javascript");
|
|
CodeMirror.defineMIME("application/javascript", "javascript");
|
|
CodeMirror.defineMIME("application/x-javascript", "javascript");
|
|
CodeMirror.defineMIME("application/ecmascript", "javascript");
|
|
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
|
CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
|
|
CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
|
|
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
|
|
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
|
|
var htmlMode = CodeMirror.getMode(config, {name: "xml",
|
|
htmlMode: true,
|
|
multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
|
|
multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag});
|
|
var cssMode = CodeMirror.getMode(config, "css");
|
|
|
|
var scriptTypes = [], scriptTypesConf = parserConfig && parserConfig.scriptTypes;
|
|
scriptTypes.push({matches: /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i,
|
|
mode: CodeMirror.getMode(config, "javascript")});
|
|
if (scriptTypesConf) for (var i = 0; i < scriptTypesConf.length; ++i) {
|
|
var conf = scriptTypesConf[i];
|
|
scriptTypes.push({matches: conf.matches, mode: conf.mode && CodeMirror.getMode(config, conf.mode)});
|
|
}
|
|
scriptTypes.push({matches: /./,
|
|
mode: CodeMirror.getMode(config, "text/plain")});
|
|
|
|
function html(stream, state) {
|
|
var tagName = state.htmlState.tagName;
|
|
if (tagName) tagName = tagName.toLowerCase();
|
|
var style = htmlMode.token(stream, state.htmlState);
|
|
if (tagName == "script" && /\btag\b/.test(style) && stream.current() == ">") {
|
|
// Script block: mode to change to depends on type attribute
|
|
var scriptType = stream.string.slice(Math.max(0, stream.pos - 100), stream.pos).match(/\btype\s*=\s*("[^"]+"|'[^']+'|\S+)[^<]*$/i);
|
|
scriptType = scriptType ? scriptType[1] : "";
|
|
if (scriptType && /[\"\']/.test(scriptType.charAt(0))) scriptType = scriptType.slice(1, scriptType.length - 1);
|
|
for (var i = 0; i < scriptTypes.length; ++i) {
|
|
var tp = scriptTypes[i];
|
|
if (typeof tp.matches == "string" ? scriptType == tp.matches : tp.matches.test(scriptType)) {
|
|
if (tp.mode) {
|
|
state.token = script;
|
|
state.localMode = tp.mode;
|
|
state.localState = tp.mode.startState && tp.mode.startState(htmlMode.indent(state.htmlState, ""));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
} else if (tagName == "style" && /\btag\b/.test(style) && stream.current() == ">") {
|
|
state.token = css;
|
|
state.localMode = cssMode;
|
|
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
|
|
}
|
|
return style;
|
|
}
|
|
function maybeBackup(stream, pat, style) {
|
|
var cur = stream.current();
|
|
var close = cur.search(pat), m;
|
|
if (close > -1) stream.backUp(cur.length - close);
|
|
else if (m = cur.match(/<\/?$/)) {
|
|
stream.backUp(cur.length);
|
|
if (!stream.match(pat, false)) stream.match(cur);
|
|
}
|
|
return style;
|
|
}
|
|
function script(stream, state) {
|
|
if (stream.match(/^<\/\s*script\s*>/i, false)) {
|
|
state.token = html;
|
|
state.localState = state.localMode = null;
|
|
return null;
|
|
}
|
|
return maybeBackup(stream, /<\/\s*script\s*>/,
|
|
state.localMode.token(stream, state.localState));
|
|
}
|
|
function css(stream, state) {
|
|
if (stream.match(/^<\/\s*style\s*>/i, false)) {
|
|
state.token = html;
|
|
state.localState = state.localMode = null;
|
|
return null;
|
|
}
|
|
return maybeBackup(stream, /<\/\s*style\s*>/,
|
|
cssMode.token(stream, state.localState));
|
|
}
|
|
|
|
return {
|
|
startState: function() {
|
|
var state = htmlMode.startState();
|
|
return {token: html, localMode: null, localState: null, htmlState: state};
|
|
},
|
|
|
|
copyState: function(state) {
|
|
if (state.localState)
|
|
var local = CodeMirror.copyState(state.localMode, state.localState);
|
|
return {token: state.token, localMode: state.localMode, localState: local,
|
|
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
return state.token(stream, state);
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (!state.localMode || /^\s*<\//.test(textAfter))
|
|
return htmlMode.indent(state.htmlState, textAfter);
|
|
else if (state.localMode.indent)
|
|
return state.localMode.indent(state.localState, textAfter);
|
|
else
|
|
return CodeMirror.Pass;
|
|
},
|
|
|
|
innerMode: function(state) {
|
|
return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
|
|
}
|
|
};
|
|
}, "xml", "javascript", "css");
|
|
|
|
CodeMirror.defineMIME("text/html", "htmlmixed");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../markdown/markdown"), require("../../addon/mode/overlay"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../markdown/markdown", "../../addon/mode/overlay"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("gfm", function(config, modeConfig) {
|
|
var codeDepth = 0;
|
|
function blankLine(state) {
|
|
state.code = false;
|
|
return null;
|
|
}
|
|
var gfmOverlay = {
|
|
startState: function() {
|
|
return {
|
|
code: false,
|
|
codeBlock: false,
|
|
ateSpace: false
|
|
};
|
|
},
|
|
copyState: function(s) {
|
|
return {
|
|
code: s.code,
|
|
codeBlock: s.codeBlock,
|
|
ateSpace: s.ateSpace
|
|
};
|
|
},
|
|
token: function(stream, state) {
|
|
state.combineTokens = null;
|
|
|
|
// Hack to prevent formatting override inside code blocks (block and inline)
|
|
if (state.codeBlock) {
|
|
if (stream.match(/^```/)) {
|
|
state.codeBlock = false;
|
|
return null;
|
|
}
|
|
stream.skipToEnd();
|
|
return null;
|
|
}
|
|
if (stream.sol()) {
|
|
state.code = false;
|
|
}
|
|
if (stream.sol() && stream.match(/^```/)) {
|
|
stream.skipToEnd();
|
|
state.codeBlock = true;
|
|
return null;
|
|
}
|
|
// If this block is changed, it may need to be updated in Markdown mode
|
|
if (stream.peek() === '`') {
|
|
stream.next();
|
|
var before = stream.pos;
|
|
stream.eatWhile('`');
|
|
var difference = 1 + stream.pos - before;
|
|
if (!state.code) {
|
|
codeDepth = difference;
|
|
state.code = true;
|
|
} else {
|
|
if (difference === codeDepth) { // Must be exact
|
|
state.code = false;
|
|
}
|
|
}
|
|
return null;
|
|
} else if (state.code) {
|
|
stream.next();
|
|
return null;
|
|
}
|
|
// Check if space. If so, links can be formatted later on
|
|
if (stream.eatSpace()) {
|
|
state.ateSpace = true;
|
|
return null;
|
|
}
|
|
if (stream.sol() || state.ateSpace) {
|
|
state.ateSpace = false;
|
|
if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?:[a-f0-9]{7,40}\b)/)) {
|
|
// User/Project@SHA
|
|
// User@SHA
|
|
// SHA
|
|
state.combineTokens = true;
|
|
return "link";
|
|
} else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
|
|
// User/Project#Num
|
|
// User#Num
|
|
// #Num
|
|
state.combineTokens = true;
|
|
return "link";
|
|
}
|
|
}
|
|
if (stream.match(/^((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i) &&
|
|
stream.string.slice(stream.start - 2, stream.start) != "](") {
|
|
// URLs
|
|
// Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
|
|
// And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
|
|
state.combineTokens = true;
|
|
return "link";
|
|
}
|
|
stream.next();
|
|
return null;
|
|
},
|
|
blankLine: blankLine
|
|
};
|
|
|
|
var markdownConfig = {
|
|
underscoresBreakWords: false,
|
|
taskLists: true,
|
|
fencedCodeBlocks: true,
|
|
strikethrough: true
|
|
};
|
|
for (var attr in modeConfig) {
|
|
markdownConfig[attr] = modeConfig[attr];
|
|
}
|
|
markdownConfig.name = "markdown";
|
|
CodeMirror.defineMIME("gfmBase", markdownConfig);
|
|
return CodeMirror.overlayMode(CodeMirror.getMode(config, "gfmBase"), gfmOverlay);
|
|
}, "markdown");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("http", function() {
|
|
function failFirstLine(stream, state) {
|
|
stream.skipToEnd();
|
|
state.cur = header;
|
|
return "error";
|
|
}
|
|
|
|
function start(stream, state) {
|
|
if (stream.match(/^HTTP\/\d\.\d/)) {
|
|
state.cur = responseStatusCode;
|
|
return "keyword";
|
|
} else if (stream.match(/^[A-Z]+/) && /[ \t]/.test(stream.peek())) {
|
|
state.cur = requestPath;
|
|
return "keyword";
|
|
} else {
|
|
return failFirstLine(stream, state);
|
|
}
|
|
}
|
|
|
|
function responseStatusCode(stream, state) {
|
|
var code = stream.match(/^\d+/);
|
|
if (!code) return failFirstLine(stream, state);
|
|
|
|
state.cur = responseStatusText;
|
|
var status = Number(code[0]);
|
|
if (status >= 100 && status < 200) {
|
|
return "positive informational";
|
|
} else if (status >= 200 && status < 300) {
|
|
return "positive success";
|
|
} else if (status >= 300 && status < 400) {
|
|
return "positive redirect";
|
|
} else if (status >= 400 && status < 500) {
|
|
return "negative client-error";
|
|
} else if (status >= 500 && status < 600) {
|
|
return "negative server-error";
|
|
} else {
|
|
return "error";
|
|
}
|
|
}
|
|
|
|
function responseStatusText(stream, state) {
|
|
stream.skipToEnd();
|
|
state.cur = header;
|
|
return null;
|
|
}
|
|
|
|
function requestPath(stream, state) {
|
|
stream.eatWhile(/\S/);
|
|
state.cur = requestProtocol;
|
|
return "string-2";
|
|
}
|
|
|
|
function requestProtocol(stream, state) {
|
|
if (stream.match(/^HTTP\/\d\.\d$/)) {
|
|
state.cur = header;
|
|
return "keyword";
|
|
} else {
|
|
return failFirstLine(stream, state);
|
|
}
|
|
}
|
|
|
|
function header(stream) {
|
|
if (stream.sol() && !stream.eat(/[ \t]/)) {
|
|
if (stream.match(/^.*?:/)) {
|
|
return "atom";
|
|
} else {
|
|
stream.skipToEnd();
|
|
return "error";
|
|
}
|
|
} else {
|
|
stream.skipToEnd();
|
|
return "string";
|
|
}
|
|
}
|
|
|
|
function body(stream) {
|
|
stream.skipToEnd();
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
token: function(stream, state) {
|
|
var cur = state.cur;
|
|
if (cur != header && cur != body && stream.eatSpace()) return null;
|
|
return cur(stream, state);
|
|
},
|
|
|
|
blankLine: function(state) {
|
|
state.cur = body;
|
|
},
|
|
|
|
startState: function() {
|
|
return {cur: start};
|
|
}
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("message/http", "http");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("go", function(config) {
|
|
var indentUnit = config.indentUnit;
|
|
|
|
var keywords = {
|
|
"break":true, "case":true, "chan":true, "const":true, "continue":true,
|
|
"default":true, "defer":true, "else":true, "fallthrough":true, "for":true,
|
|
"func":true, "go":true, "goto":true, "if":true, "import":true,
|
|
"interface":true, "map":true, "package":true, "range":true, "return":true,
|
|
"select":true, "struct":true, "switch":true, "type":true, "var":true,
|
|
"bool":true, "byte":true, "complex64":true, "complex128":true,
|
|
"float32":true, "float64":true, "int8":true, "int16":true, "int32":true,
|
|
"int64":true, "string":true, "uint8":true, "uint16":true, "uint32":true,
|
|
"uint64":true, "int":true, "uint":true, "uintptr":true
|
|
};
|
|
|
|
var atoms = {
|
|
"true":true, "false":true, "iota":true, "nil":true, "append":true,
|
|
"cap":true, "close":true, "complex":true, "copy":true, "imag":true,
|
|
"len":true, "make":true, "new":true, "panic":true, "print":true,
|
|
"println":true, "real":true, "recover":true
|
|
};
|
|
|
|
var isOperatorChar = /[+\-*&^%:=<>!|\/]/;
|
|
|
|
var curPunc;
|
|
|
|
function tokenBase(stream, state) {
|
|
var ch = stream.next();
|
|
if (ch == '"' || ch == "'" || ch == "`") {
|
|
state.tokenize = tokenString(ch);
|
|
return state.tokenize(stream, state);
|
|
}
|
|
if (/[\d\.]/.test(ch)) {
|
|
if (ch == ".") {
|
|
stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/);
|
|
} else if (ch == "0") {
|
|
stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/);
|
|
} else {
|
|
stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/);
|
|
}
|
|
return "number";
|
|
}
|
|
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
|
curPunc = ch;
|
|
return null;
|
|
}
|
|
if (ch == "/") {
|
|
if (stream.eat("*")) {
|
|
state.tokenize = tokenComment;
|
|
return tokenComment(stream, state);
|
|
}
|
|
if (stream.eat("/")) {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
}
|
|
if (isOperatorChar.test(ch)) {
|
|
stream.eatWhile(isOperatorChar);
|
|
return "operator";
|
|
}
|
|
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
|
|
var cur = stream.current();
|
|
if (keywords.propertyIsEnumerable(cur)) {
|
|
if (cur == "case" || cur == "default") curPunc = "case";
|
|
return "keyword";
|
|
}
|
|
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
|
return "variable";
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, next, end = false;
|
|
while ((next = stream.next()) != null) {
|
|
if (next == quote && !escaped) {end = true; break;}
|
|
escaped = !escaped && next == "\\";
|
|
}
|
|
if (end || !(escaped || quote == "`"))
|
|
state.tokenize = tokenBase;
|
|
return "string";
|
|
};
|
|
}
|
|
|
|
function tokenComment(stream, state) {
|
|
var maybeEnd = false, ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "/" && maybeEnd) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
maybeEnd = (ch == "*");
|
|
}
|
|
return "comment";
|
|
}
|
|
|
|
function Context(indented, column, type, align, prev) {
|
|
this.indented = indented;
|
|
this.column = column;
|
|
this.type = type;
|
|
this.align = align;
|
|
this.prev = prev;
|
|
}
|
|
function pushContext(state, col, type) {
|
|
return state.context = new Context(state.indented, col, type, null, state.context);
|
|
}
|
|
function popContext(state) {
|
|
if (!state.context.prev) return;
|
|
var t = state.context.type;
|
|
if (t == ")" || t == "]" || t == "}")
|
|
state.indented = state.context.indented;
|
|
return state.context = state.context.prev;
|
|
}
|
|
|
|
// Interface
|
|
|
|
return {
|
|
startState: function(basecolumn) {
|
|
return {
|
|
tokenize: null,
|
|
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
|
indented: 0,
|
|
startOfLine: true
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
var ctx = state.context;
|
|
if (stream.sol()) {
|
|
if (ctx.align == null) ctx.align = false;
|
|
state.indented = stream.indentation();
|
|
state.startOfLine = true;
|
|
if (ctx.type == "case") ctx.type = "}";
|
|
}
|
|
if (stream.eatSpace()) return null;
|
|
curPunc = null;
|
|
var style = (state.tokenize || tokenBase)(stream, state);
|
|
if (style == "comment") return style;
|
|
if (ctx.align == null) ctx.align = true;
|
|
|
|
if (curPunc == "{") pushContext(state, stream.column(), "}");
|
|
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
|
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
|
else if (curPunc == "case") ctx.type = "case";
|
|
else if (curPunc == "}" && ctx.type == "}") ctx = popContext(state);
|
|
else if (curPunc == ctx.type) popContext(state);
|
|
state.startOfLine = false;
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
|
|
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
|
if (ctx.type == "case" && /^(?:case|default)\b/.test(textAfter)) {
|
|
state.context.type = "}";
|
|
return ctx.indented;
|
|
}
|
|
var closing = firstChar == ctx.type;
|
|
if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
|
else return ctx.indented + (closing ? 0 : indentUnit);
|
|
},
|
|
|
|
electricChars: "{}):",
|
|
fold: "brace",
|
|
blockCommentStart: "/*",
|
|
blockCommentEnd: "*/",
|
|
lineComment: "//"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-go", "go");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../clike/clike"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../clike/clike"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
var keywords = ("this super static final const abstract class extends external factory " +
|
|
"implements get native operator set typedef with enum throw rethrow " +
|
|
"assert break case continue default in return new deferred async await " +
|
|
"try catch finally do else for if switch while import library export " +
|
|
"part of show hide is").split(" ");
|
|
var blockKeywords = "try catch finally do else for if switch while".split(" ");
|
|
var atoms = "true false null".split(" ");
|
|
var builtins = "void bool num int double dynamic var String".split(" ");
|
|
|
|
function set(words) {
|
|
var obj = {};
|
|
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
|
return obj;
|
|
}
|
|
|
|
CodeMirror.defineMIME("application/dart", {
|
|
name: "clike",
|
|
keywords: set(keywords),
|
|
multiLineStrings: true,
|
|
blockKeywords: set(blockKeywords),
|
|
builtin: set(builtins),
|
|
atoms: set(atoms),
|
|
hooks: {
|
|
"@": function(stream) {
|
|
stream.eatWhile(/[\w\$_]/);
|
|
return "meta";
|
|
}
|
|
}
|
|
});
|
|
|
|
CodeMirror.registerHelper("hintWords", "application/dart", keywords.concat(atoms).concat(builtins));
|
|
|
|
// This is needed to make loading through meta.js work.
|
|
CodeMirror.defineMode("dart", function(conf) {
|
|
return CodeMirror.getMode(conf, "application/dart");
|
|
}, "clike");
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
/**
|
|
* Link to the project's GitHub page:
|
|
* https://github.com/pickhardt/coffeescript-codemirror-mode
|
|
*/
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("coffeescript", function(conf, parserConf) {
|
|
var ERRORCLASS = "error";
|
|
|
|
function wordRegexp(words) {
|
|
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
|
}
|
|
|
|
var operators = /^(?:->|=>|\+[+=]?|-[\-=]?|\*[\*=]?|\/[\/=]?|[=!]=|<[><]?=?|>>?=?|%=?|&=?|\|=?|\^=?|\~|!|\?|(or|and|\|\||&&|\?)=)/;
|
|
var delimiters = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/;
|
|
var identifiers = /^[_A-Za-z$][_A-Za-z$0-9]*/;
|
|
var properties = /^(@|this\.)[_A-Za-z$][_A-Za-z$0-9]*/;
|
|
|
|
var wordOperators = wordRegexp(["and", "or", "not",
|
|
"is", "isnt", "in",
|
|
"instanceof", "typeof"]);
|
|
var indentKeywords = ["for", "while", "loop", "if", "unless", "else",
|
|
"switch", "try", "catch", "finally", "class"];
|
|
var commonKeywords = ["break", "by", "continue", "debugger", "delete",
|
|
"do", "in", "of", "new", "return", "then",
|
|
"this", "@", "throw", "when", "until", "extends"];
|
|
|
|
var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
|
|
|
|
indentKeywords = wordRegexp(indentKeywords);
|
|
|
|
|
|
var stringPrefixes = /^('{3}|\"{3}|['\"])/;
|
|
var regexPrefixes = /^(\/{3}|\/)/;
|
|
var commonConstants = ["Infinity", "NaN", "undefined", "null", "true", "false", "on", "off", "yes", "no"];
|
|
var constants = wordRegexp(commonConstants);
|
|
|
|
// Tokenizers
|
|
function tokenBase(stream, state) {
|
|
// Handle scope changes
|
|
if (stream.sol()) {
|
|
if (state.scope.align === null) state.scope.align = false;
|
|
var scopeOffset = state.scope.offset;
|
|
if (stream.eatSpace()) {
|
|
var lineOffset = stream.indentation();
|
|
if (lineOffset > scopeOffset && state.scope.type == "coffee") {
|
|
return "indent";
|
|
} else if (lineOffset < scopeOffset) {
|
|
return "dedent";
|
|
}
|
|
return null;
|
|
} else {
|
|
if (scopeOffset > 0) {
|
|
dedent(stream, state);
|
|
}
|
|
}
|
|
}
|
|
if (stream.eatSpace()) {
|
|
return null;
|
|
}
|
|
|
|
var ch = stream.peek();
|
|
|
|
// Handle docco title comment (single line)
|
|
if (stream.match("####")) {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
|
|
// Handle multi line comments
|
|
if (stream.match("###")) {
|
|
state.tokenize = longComment;
|
|
return state.tokenize(stream, state);
|
|
}
|
|
|
|
// Single line comment
|
|
if (ch === "#") {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
|
|
// Handle number literals
|
|
if (stream.match(/^-?[0-9\.]/, false)) {
|
|
var floatLiteral = false;
|
|
// Floats
|
|
if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) {
|
|
floatLiteral = true;
|
|
}
|
|
if (stream.match(/^-?\d+\.\d*/)) {
|
|
floatLiteral = true;
|
|
}
|
|
if (stream.match(/^-?\.\d+/)) {
|
|
floatLiteral = true;
|
|
}
|
|
|
|
if (floatLiteral) {
|
|
// prevent from getting extra . on 1..
|
|
if (stream.peek() == "."){
|
|
stream.backUp(1);
|
|
}
|
|
return "number";
|
|
}
|
|
// Integers
|
|
var intLiteral = false;
|
|
// Hex
|
|
if (stream.match(/^-?0x[0-9a-f]+/i)) {
|
|
intLiteral = true;
|
|
}
|
|
// Decimal
|
|
if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) {
|
|
intLiteral = true;
|
|
}
|
|
// Zero by itself with no other piece of number.
|
|
if (stream.match(/^-?0(?![\dx])/i)) {
|
|
intLiteral = true;
|
|
}
|
|
if (intLiteral) {
|
|
return "number";
|
|
}
|
|
}
|
|
|
|
// Handle strings
|
|
if (stream.match(stringPrefixes)) {
|
|
state.tokenize = tokenFactory(stream.current(), false, "string");
|
|
return state.tokenize(stream, state);
|
|
}
|
|
// Handle regex literals
|
|
if (stream.match(regexPrefixes)) {
|
|
if (stream.current() != "/" || stream.match(/^.*\//, false)) { // prevent highlight of division
|
|
state.tokenize = tokenFactory(stream.current(), true, "string-2");
|
|
return state.tokenize(stream, state);
|
|
} else {
|
|
stream.backUp(1);
|
|
}
|
|
}
|
|
|
|
// Handle operators and delimiters
|
|
if (stream.match(operators) || stream.match(wordOperators)) {
|
|
return "operator";
|
|
}
|
|
if (stream.match(delimiters)) {
|
|
return "punctuation";
|
|
}
|
|
|
|
if (stream.match(constants)) {
|
|
return "atom";
|
|
}
|
|
|
|
if (stream.match(keywords)) {
|
|
return "keyword";
|
|
}
|
|
|
|
if (stream.match(identifiers)) {
|
|
return "variable";
|
|
}
|
|
|
|
if (stream.match(properties)) {
|
|
return "property";
|
|
}
|
|
|
|
// Handle non-detected items
|
|
stream.next();
|
|
return ERRORCLASS;
|
|
}
|
|
|
|
function tokenFactory(delimiter, singleline, outclass) {
|
|
return function(stream, state) {
|
|
while (!stream.eol()) {
|
|
stream.eatWhile(/[^'"\/\\]/);
|
|
if (stream.eat("\\")) {
|
|
stream.next();
|
|
if (singleline && stream.eol()) {
|
|
return outclass;
|
|
}
|
|
} else if (stream.match(delimiter)) {
|
|
state.tokenize = tokenBase;
|
|
return outclass;
|
|
} else {
|
|
stream.eat(/['"\/]/);
|
|
}
|
|
}
|
|
if (singleline) {
|
|
if (parserConf.singleLineStringErrors) {
|
|
outclass = ERRORCLASS;
|
|
} else {
|
|
state.tokenize = tokenBase;
|
|
}
|
|
}
|
|
return outclass;
|
|
};
|
|
}
|
|
|
|
function longComment(stream, state) {
|
|
while (!stream.eol()) {
|
|
stream.eatWhile(/[^#]/);
|
|
if (stream.match("###")) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
stream.eatWhile("#");
|
|
}
|
|
return "comment";
|
|
}
|
|
|
|
function indent(stream, state, type) {
|
|
type = type || "coffee";
|
|
var offset = 0, align = false, alignOffset = null;
|
|
for (var scope = state.scope; scope; scope = scope.prev) {
|
|
if (scope.type === "coffee" || scope.type == "}") {
|
|
offset = scope.offset + conf.indentUnit;
|
|
break;
|
|
}
|
|
}
|
|
if (type !== "coffee") {
|
|
align = null;
|
|
alignOffset = stream.column() + stream.current().length;
|
|
} else if (state.scope.align) {
|
|
state.scope.align = false;
|
|
}
|
|
state.scope = {
|
|
offset: offset,
|
|
type: type,
|
|
prev: state.scope,
|
|
align: align,
|
|
alignOffset: alignOffset
|
|
};
|
|
}
|
|
|
|
function dedent(stream, state) {
|
|
if (!state.scope.prev) return;
|
|
if (state.scope.type === "coffee") {
|
|
var _indent = stream.indentation();
|
|
var matched = false;
|
|
for (var scope = state.scope; scope; scope = scope.prev) {
|
|
if (_indent === scope.offset) {
|
|
matched = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!matched) {
|
|
return true;
|
|
}
|
|
while (state.scope.prev && state.scope.offset !== _indent) {
|
|
state.scope = state.scope.prev;
|
|
}
|
|
return false;
|
|
} else {
|
|
state.scope = state.scope.prev;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function tokenLexer(stream, state) {
|
|
var style = state.tokenize(stream, state);
|
|
var current = stream.current();
|
|
|
|
// Handle "." connected identifiers
|
|
if (current === ".") {
|
|
style = state.tokenize(stream, state);
|
|
current = stream.current();
|
|
if (/^\.[\w$]+$/.test(current)) {
|
|
return "variable";
|
|
} else {
|
|
return ERRORCLASS;
|
|
}
|
|
}
|
|
|
|
// Handle scope changes.
|
|
if (current === "return") {
|
|
state.dedent = true;
|
|
}
|
|
if (((current === "->" || current === "=>") &&
|
|
!state.lambda &&
|
|
!stream.peek())
|
|
|| style === "indent") {
|
|
indent(stream, state);
|
|
}
|
|
var delimiter_index = "[({".indexOf(current);
|
|
if (delimiter_index !== -1) {
|
|
indent(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
|
|
}
|
|
if (indentKeywords.exec(current)){
|
|
indent(stream, state);
|
|
}
|
|
if (current == "then"){
|
|
dedent(stream, state);
|
|
}
|
|
|
|
|
|
if (style === "dedent") {
|
|
if (dedent(stream, state)) {
|
|
return ERRORCLASS;
|
|
}
|
|
}
|
|
delimiter_index = "])}".indexOf(current);
|
|
if (delimiter_index !== -1) {
|
|
while (state.scope.type == "coffee" && state.scope.prev)
|
|
state.scope = state.scope.prev;
|
|
if (state.scope.type == current)
|
|
state.scope = state.scope.prev;
|
|
}
|
|
if (state.dedent && stream.eol()) {
|
|
if (state.scope.type == "coffee" && state.scope.prev)
|
|
state.scope = state.scope.prev;
|
|
state.dedent = false;
|
|
}
|
|
|
|
return style;
|
|
}
|
|
|
|
var external = {
|
|
startState: function(basecolumn) {
|
|
return {
|
|
tokenize: tokenBase,
|
|
scope: {offset:basecolumn || 0, type:"coffee", prev: null, align: false},
|
|
lastToken: null,
|
|
lambda: false,
|
|
dedent: 0
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
var fillAlign = state.scope.align === null && state.scope;
|
|
if (fillAlign && stream.sol()) fillAlign.align = false;
|
|
|
|
var style = tokenLexer(stream, state);
|
|
if (fillAlign && style && style != "comment") fillAlign.align = true;
|
|
|
|
state.lastToken = {style:style, content: stream.current()};
|
|
|
|
if (stream.eol() && stream.lambda) {
|
|
state.lambda = false;
|
|
}
|
|
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, text) {
|
|
if (state.tokenize != tokenBase) return 0;
|
|
var scope = state.scope;
|
|
var closer = text && "])}".indexOf(text.charAt(0)) > -1;
|
|
if (closer) while (scope.type == "coffee" && scope.prev) scope = scope.prev;
|
|
var closes = closer && scope.type === text.charAt(0);
|
|
if (scope.align)
|
|
return scope.alignOffset - (closes ? 1 : 0);
|
|
else
|
|
return (closes ? scope.prev : scope).offset;
|
|
},
|
|
|
|
lineComment: "#",
|
|
fold: "indent"
|
|
};
|
|
return external;
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-coffeescript", "coffeescript");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("nginx", function(config) {
|
|
|
|
function words(str) {
|
|
var obj = {}, words = str.split(" ");
|
|
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
|
return obj;
|
|
}
|
|
|
|
var keywords = words(
|
|
/* ngxDirectiveControl */ "break return rewrite set" +
|
|
/* ngxDirective */ " accept_mutex accept_mutex_delay access_log add_after_body add_before_body add_header addition_types aio alias allow ancient_browser ancient_browser_value auth_basic auth_basic_user_file auth_http auth_http_header auth_http_timeout autoindex autoindex_exact_size autoindex_localtime charset charset_types client_body_buffer_size client_body_in_file_only client_body_in_single_buffer client_body_temp_path client_body_timeout client_header_buffer_size client_header_timeout client_max_body_size connection_pool_size create_full_put_path daemon dav_access dav_methods debug_connection debug_points default_type degradation degrade deny devpoll_changes devpoll_events directio directio_alignment empty_gif env epoll_events error_log eventport_events expires fastcgi_bind fastcgi_buffer_size fastcgi_buffers fastcgi_busy_buffers_size fastcgi_cache fastcgi_cache_key fastcgi_cache_methods fastcgi_cache_min_uses fastcgi_cache_path fastcgi_cache_use_stale fastcgi_cache_valid fastcgi_catch_stderr fastcgi_connect_timeout fastcgi_hide_header fastcgi_ignore_client_abort fastcgi_ignore_headers fastcgi_index fastcgi_intercept_errors fastcgi_max_temp_file_size fastcgi_next_upstream fastcgi_param fastcgi_pass_header fastcgi_pass_request_body fastcgi_pass_request_headers fastcgi_read_timeout fastcgi_send_lowat fastcgi_send_timeout fastcgi_split_path_info fastcgi_store fastcgi_store_access fastcgi_temp_file_write_size fastcgi_temp_path fastcgi_upstream_fail_timeout fastcgi_upstream_max_fails flv geoip_city geoip_country google_perftools_profiles gzip gzip_buffers gzip_comp_level gzip_disable gzip_hash gzip_http_version gzip_min_length gzip_no_buffer gzip_proxied gzip_static gzip_types gzip_vary gzip_window if_modified_since ignore_invalid_headers image_filter image_filter_buffer image_filter_jpeg_quality image_filter_transparency imap_auth imap_capabilities imap_client_buffer index ip_hash keepalive_requests keepalive_timeout kqueue_changes kqueue_events large_client_header_buffers limit_conn limit_conn_log_level limit_rate limit_rate_after limit_req limit_req_log_level limit_req_zone limit_zone lingering_time lingering_timeout lock_file log_format log_not_found log_subrequest map_hash_bucket_size map_hash_max_size master_process memcached_bind memcached_buffer_size memcached_connect_timeout memcached_next_upstream memcached_read_timeout memcached_send_timeout memcached_upstream_fail_timeout memcached_upstream_max_fails merge_slashes min_delete_depth modern_browser modern_browser_value msie_padding msie_refresh multi_accept open_file_cache open_file_cache_errors open_file_cache_events open_file_cache_min_uses open_file_cache_valid open_log_file_cache output_buffers override_charset perl perl_modules perl_require perl_set pid pop3_auth pop3_capabilities port_in_redirect postpone_gzipping postpone_output protocol proxy proxy_bind proxy_buffer proxy_buffer_size proxy_buffering proxy_buffers proxy_busy_buffers_size proxy_cache proxy_cache_key proxy_cache_methods proxy_cache_min_uses proxy_cache_path proxy_cache_use_stale proxy_cache_valid proxy_connect_timeout proxy_headers_hash_bucket_size proxy_headers_hash_max_size proxy_hide_header proxy_ignore_client_abort proxy_ignore_headers proxy_intercept_errors proxy_max_temp_file_size proxy_method proxy_next_upstream proxy_pass_error_message proxy_pass_header proxy_pass_request_body proxy_pass_request_headers proxy_read_timeout proxy_redirect proxy_send_lowat proxy_send_timeout proxy_set_body proxy_set_header proxy_ssl_session_reuse proxy_store proxy_store_access proxy_temp_file_write_size proxy_temp_path proxy_timeout proxy_upstream_fail_timeout proxy_upstream_max_fails random_index read_ahead real_ip_header recursive_error_pages request_pool_size reset_timedout_connection resolver resolver_timeout rewrite_log rtsig_overflow_events rtsig_overflow_test rtsig_overflow_threshold rtsig_signo satisfy secure_link_secret send_lowat send_timeout sendfile sendfile_max_chunk server_name_in_redirect server_names_hash_bucket_size server_names_hash_max_size server_tokens set_real_ip_from smtp_auth smtp_capabilities smtp_client_buffer smtp_greeting_delay so_keepalive source_charset ssi ssi_ignore_recycled_buffers ssi_min_file_chunk ssi_silent_errors ssi_types ssi_value_length ssl ssl_certificate ssl_certificate_key ssl_ciphers ssl_client_certificate ssl_crl ssl_dhparam ssl_engine ssl_prefer_server_ciphers ssl_protocols ssl_session_cache ssl_session_timeout ssl_verify_client ssl_verify_depth starttls stub_status sub_filter sub_filter_once sub_filter_types tcp_nodelay tcp_nopush thread_stack_size timeout timer_resolution types_hash_bucket_size types_hash_max_size underscores_in_headers uninitialized_variable_warn use user userid userid_domain userid_expires userid_mark userid_name userid_p3p userid_path userid_service valid_referers variables_hash_bucket_size variables_hash_max_size worker_connections worker_cpu_affinity worker_priority worker_processes worker_rlimit_core worker_rlimit_nofile worker_rlimit_sigpending worker_threads working_directory xclient xml_entities xslt_stylesheet xslt_typesdrew@li229-23"
|
|
);
|
|
|
|
var keywords_block = words(
|
|
/* ngxDirectiveBlock */ "http mail events server types location upstream charset_map limit_except if geo map"
|
|
);
|
|
|
|
var keywords_important = words(
|
|
/* ngxDirectiveImportant */ "include root server server_name listen internal proxy_pass memcached_pass fastcgi_pass try_files"
|
|
);
|
|
|
|
var indentUnit = config.indentUnit, type;
|
|
function ret(style, tp) {type = tp; return style;}
|
|
|
|
function tokenBase(stream, state) {
|
|
|
|
|
|
stream.eatWhile(/[\w\$_]/);
|
|
|
|
var cur = stream.current();
|
|
|
|
|
|
if (keywords.propertyIsEnumerable(cur)) {
|
|
return "keyword";
|
|
}
|
|
else if (keywords_block.propertyIsEnumerable(cur)) {
|
|
return "variable-2";
|
|
}
|
|
else if (keywords_important.propertyIsEnumerable(cur)) {
|
|
return "string-2";
|
|
}
|
|
/**/
|
|
|
|
var ch = stream.next();
|
|
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
|
|
else if (ch == "/" && stream.eat("*")) {
|
|
state.tokenize = tokenCComment;
|
|
return tokenCComment(stream, state);
|
|
}
|
|
else if (ch == "<" && stream.eat("!")) {
|
|
state.tokenize = tokenSGMLComment;
|
|
return tokenSGMLComment(stream, state);
|
|
}
|
|
else if (ch == "=") ret(null, "compare");
|
|
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
|
|
else if (ch == "\"" || ch == "'") {
|
|
state.tokenize = tokenString(ch);
|
|
return state.tokenize(stream, state);
|
|
}
|
|
else if (ch == "#") {
|
|
stream.skipToEnd();
|
|
return ret("comment", "comment");
|
|
}
|
|
else if (ch == "!") {
|
|
stream.match(/^\s*\w*/);
|
|
return ret("keyword", "important");
|
|
}
|
|
else if (/\d/.test(ch)) {
|
|
stream.eatWhile(/[\w.%]/);
|
|
return ret("number", "unit");
|
|
}
|
|
else if (/[,.+>*\/]/.test(ch)) {
|
|
return ret(null, "select-op");
|
|
}
|
|
else if (/[;{}:\[\]]/.test(ch)) {
|
|
return ret(null, ch);
|
|
}
|
|
else {
|
|
stream.eatWhile(/[\w\\\-]/);
|
|
return ret("variable", "variable");
|
|
}
|
|
}
|
|
|
|
function tokenCComment(stream, state) {
|
|
var maybeEnd = false, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (maybeEnd && ch == "/") {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
maybeEnd = (ch == "*");
|
|
}
|
|
return ret("comment", "comment");
|
|
}
|
|
|
|
function tokenSGMLComment(stream, state) {
|
|
var dashes = 0, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (dashes >= 2 && ch == ">") {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
dashes = (ch == "-") ? dashes + 1 : 0;
|
|
}
|
|
return ret("comment", "comment");
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (ch == quote && !escaped)
|
|
break;
|
|
escaped = !escaped && ch == "\\";
|
|
}
|
|
if (!escaped) state.tokenize = tokenBase;
|
|
return ret("string", "string");
|
|
};
|
|
}
|
|
|
|
return {
|
|
startState: function(base) {
|
|
return {tokenize: tokenBase,
|
|
baseIndent: base || 0,
|
|
stack: []};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.eatSpace()) return null;
|
|
type = null;
|
|
var style = state.tokenize(stream, state);
|
|
|
|
var context = state.stack[state.stack.length-1];
|
|
if (type == "hash" && context == "rule") style = "atom";
|
|
else if (style == "variable") {
|
|
if (context == "rule") style = "number";
|
|
else if (!context || context == "@media{") style = "tag";
|
|
}
|
|
|
|
if (context == "rule" && /^[\{\};]$/.test(type))
|
|
state.stack.pop();
|
|
if (type == "{") {
|
|
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
|
|
else state.stack.push("{");
|
|
}
|
|
else if (type == "}") state.stack.pop();
|
|
else if (type == "@media") state.stack.push("@media");
|
|
else if (context == "{" && type != "comment") state.stack.push("rule");
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
var n = state.stack.length;
|
|
if (/^\}/.test(textAfter))
|
|
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
|
|
return state.baseIndent + n * indentUnit;
|
|
},
|
|
|
|
electricChars: "}"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/nginx", "text/x-nginx-conf");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
function wordRegexp(words) {
|
|
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
|
}
|
|
|
|
var wordOperators = wordRegexp(["and", "or", "not", "is"]);
|
|
var commonKeywords = ["as", "assert", "break", "class", "continue",
|
|
"def", "del", "elif", "else", "except", "finally",
|
|
"for", "from", "global", "if", "import",
|
|
"lambda", "pass", "raise", "return",
|
|
"try", "while", "with", "yield", "in"];
|
|
var commonBuiltins = ["abs", "all", "any", "bin", "bool", "bytearray", "callable", "chr",
|
|
"classmethod", "compile", "complex", "delattr", "dict", "dir", "divmod",
|
|
"enumerate", "eval", "filter", "float", "format", "frozenset",
|
|
"getattr", "globals", "hasattr", "hash", "help", "hex", "id",
|
|
"input", "int", "isinstance", "issubclass", "iter", "len",
|
|
"list", "locals", "map", "max", "memoryview", "min", "next",
|
|
"object", "oct", "open", "ord", "pow", "property", "range",
|
|
"repr", "reversed", "round", "set", "setattr", "slice",
|
|
"sorted", "staticmethod", "str", "sum", "super", "tuple",
|
|
"type", "vars", "zip", "__import__", "NotImplemented",
|
|
"Ellipsis", "__debug__"];
|
|
var py2 = {builtins: ["apply", "basestring", "buffer", "cmp", "coerce", "execfile",
|
|
"file", "intern", "long", "raw_input", "reduce", "reload",
|
|
"unichr", "unicode", "xrange", "False", "True", "None"],
|
|
keywords: ["exec", "print"]};
|
|
var py3 = {builtins: ["ascii", "bytes", "exec", "print"],
|
|
keywords: ["nonlocal", "False", "True", "None"]};
|
|
|
|
CodeMirror.registerHelper("hintWords", "python", commonKeywords.concat(commonBuiltins));
|
|
|
|
function top(state) {
|
|
return state.scopes[state.scopes.length - 1];
|
|
}
|
|
|
|
CodeMirror.defineMode("python", function(conf, parserConf) {
|
|
var ERRORCLASS = "error";
|
|
|
|
var singleDelimiters = parserConf.singleDelimiters || new RegExp("^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]");
|
|
var doubleOperators = parserConf.doubleOperators || new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
|
|
var doubleDelimiters = parserConf.doubleDelimiters || new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
|
var tripleDelimiters = parserConf.tripleDelimiters || new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
|
|
|
|
if (parserConf.version && parseInt(parserConf.version, 10) == 3){
|
|
// since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
|
|
var singleOperators = parserConf.singleOperators || new RegExp("^[\\+\\-\\*/%&|\\^~<>!@]");
|
|
var identifiers = parserConf.identifiers|| new RegExp("^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*");
|
|
} else {
|
|
var singleOperators = parserConf.singleOperators || new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
|
|
var identifiers = parserConf.identifiers|| new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
|
}
|
|
|
|
var hangingIndent = parserConf.hangingIndent || conf.indentUnit;
|
|
|
|
var myKeywords = commonKeywords, myBuiltins = commonBuiltins;
|
|
if(parserConf.extra_keywords != undefined){
|
|
myKeywords = myKeywords.concat(parserConf.extra_keywords);
|
|
}
|
|
if(parserConf.extra_builtins != undefined){
|
|
myBuiltins = myBuiltins.concat(parserConf.extra_builtins);
|
|
}
|
|
if (parserConf.version && parseInt(parserConf.version, 10) == 3) {
|
|
myKeywords = myKeywords.concat(py3.keywords);
|
|
myBuiltins = myBuiltins.concat(py3.builtins);
|
|
var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
|
|
} else {
|
|
myKeywords = myKeywords.concat(py2.keywords);
|
|
myBuiltins = myBuiltins.concat(py2.builtins);
|
|
var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
|
|
}
|
|
var keywords = wordRegexp(myKeywords);
|
|
var builtins = wordRegexp(myBuiltins);
|
|
|
|
// tokenizers
|
|
function tokenBase(stream, state) {
|
|
// Handle scope changes
|
|
if (stream.sol() && top(state).type == "py") {
|
|
var scopeOffset = top(state).offset;
|
|
if (stream.eatSpace()) {
|
|
var lineOffset = stream.indentation();
|
|
if (lineOffset > scopeOffset)
|
|
pushScope(stream, state, "py");
|
|
else if (lineOffset < scopeOffset && dedent(stream, state))
|
|
state.errorToken = true;
|
|
return null;
|
|
} else {
|
|
var style = tokenBaseInner(stream, state);
|
|
if (scopeOffset > 0 && dedent(stream, state))
|
|
style += " " + ERRORCLASS;
|
|
return style;
|
|
}
|
|
}
|
|
return tokenBaseInner(stream, state);
|
|
}
|
|
|
|
function tokenBaseInner(stream, state) {
|
|
if (stream.eatSpace()) return null;
|
|
|
|
var ch = stream.peek();
|
|
|
|
// Handle Comments
|
|
if (ch == "#") {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
|
|
// Handle Number Literals
|
|
if (stream.match(/^[0-9\.]/, false)) {
|
|
var floatLiteral = false;
|
|
// Floats
|
|
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
|
|
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
|
|
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
|
|
if (floatLiteral) {
|
|
// Float literals may be "imaginary"
|
|
stream.eat(/J/i);
|
|
return "number";
|
|
}
|
|
// Integers
|
|
var intLiteral = false;
|
|
// Hex
|
|
if (stream.match(/^0x[0-9a-f]+/i)) intLiteral = true;
|
|
// Binary
|
|
if (stream.match(/^0b[01]+/i)) intLiteral = true;
|
|
// Octal
|
|
if (stream.match(/^0o[0-7]+/i)) intLiteral = true;
|
|
// Decimal
|
|
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
|
|
// Decimal literals may be "imaginary"
|
|
stream.eat(/J/i);
|
|
// TODO - Can you have imaginary longs?
|
|
intLiteral = true;
|
|
}
|
|
// Zero by itself with no other piece of number.
|
|
if (stream.match(/^0(?![\dx])/i)) intLiteral = true;
|
|
if (intLiteral) {
|
|
// Integer literals may be "long"
|
|
stream.eat(/L/i);
|
|
return "number";
|
|
}
|
|
}
|
|
|
|
// Handle Strings
|
|
if (stream.match(stringPrefixes)) {
|
|
state.tokenize = tokenStringFactory(stream.current());
|
|
return state.tokenize(stream, state);
|
|
}
|
|
|
|
// Handle operators and Delimiters
|
|
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters))
|
|
return null;
|
|
|
|
if (stream.match(doubleOperators)
|
|
|| stream.match(singleOperators)
|
|
|| stream.match(wordOperators))
|
|
return "operator";
|
|
|
|
if (stream.match(singleDelimiters))
|
|
return null;
|
|
|
|
if (stream.match(keywords))
|
|
return "keyword";
|
|
|
|
if (stream.match(builtins))
|
|
return "builtin";
|
|
|
|
if (stream.match(/^(self|cls)\b/))
|
|
return "variable-2";
|
|
|
|
if (stream.match(identifiers)) {
|
|
if (state.lastToken == "def" || state.lastToken == "class")
|
|
return "def";
|
|
return "variable";
|
|
}
|
|
|
|
// Handle non-detected items
|
|
stream.next();
|
|
return ERRORCLASS;
|
|
}
|
|
|
|
function tokenStringFactory(delimiter) {
|
|
while ("rub".indexOf(delimiter.charAt(0).toLowerCase()) >= 0)
|
|
delimiter = delimiter.substr(1);
|
|
|
|
var singleline = delimiter.length == 1;
|
|
var OUTCLASS = "string";
|
|
|
|
function tokenString(stream, state) {
|
|
while (!stream.eol()) {
|
|
stream.eatWhile(/[^'"\\]/);
|
|
if (stream.eat("\\")) {
|
|
stream.next();
|
|
if (singleline && stream.eol())
|
|
return OUTCLASS;
|
|
} else if (stream.match(delimiter)) {
|
|
state.tokenize = tokenBase;
|
|
return OUTCLASS;
|
|
} else {
|
|
stream.eat(/['"]/);
|
|
}
|
|
}
|
|
if (singleline) {
|
|
if (parserConf.singleLineStringErrors)
|
|
return ERRORCLASS;
|
|
else
|
|
state.tokenize = tokenBase;
|
|
}
|
|
return OUTCLASS;
|
|
}
|
|
tokenString.isString = true;
|
|
return tokenString;
|
|
}
|
|
|
|
function pushScope(stream, state, type) {
|
|
var offset = 0, align = null;
|
|
if (type == "py") {
|
|
while (top(state).type != "py")
|
|
state.scopes.pop();
|
|
}
|
|
offset = top(state).offset + (type == "py" ? conf.indentUnit : hangingIndent);
|
|
if (type != "py" && !stream.match(/^(\s|#.*)*$/, false))
|
|
align = stream.column() + 1;
|
|
state.scopes.push({offset: offset, type: type, align: align});
|
|
}
|
|
|
|
function dedent(stream, state) {
|
|
var indented = stream.indentation();
|
|
while (top(state).offset > indented) {
|
|
if (top(state).type != "py") return true;
|
|
state.scopes.pop();
|
|
}
|
|
return top(state).offset != indented;
|
|
}
|
|
|
|
function tokenLexer(stream, state) {
|
|
var style = state.tokenize(stream, state);
|
|
var current = stream.current();
|
|
|
|
// Handle '.' connected identifiers
|
|
if (current == ".") {
|
|
style = stream.match(identifiers, false) ? null : ERRORCLASS;
|
|
if (style == null && state.lastStyle == "meta") {
|
|
// Apply 'meta' style to '.' connected identifiers when
|
|
// appropriate.
|
|
style = "meta";
|
|
}
|
|
return style;
|
|
}
|
|
|
|
// Handle decorators
|
|
if (current == "@"){
|
|
if(parserConf.version && parseInt(parserConf.version, 10) == 3){
|
|
return stream.match(identifiers, false) ? "meta" : "operator";
|
|
} else {
|
|
return stream.match(identifiers, false) ? "meta" : ERRORCLASS;
|
|
}
|
|
}
|
|
|
|
if ((style == "variable" || style == "builtin")
|
|
&& state.lastStyle == "meta")
|
|
style = "meta";
|
|
|
|
// Handle scope changes.
|
|
if (current == "pass" || current == "return")
|
|
state.dedent += 1;
|
|
|
|
if (current == "lambda") state.lambda = true;
|
|
if (current == ":" && !state.lambda && top(state).type == "py")
|
|
pushScope(stream, state, "py");
|
|
|
|
var delimiter_index = current.length == 1 ? "[({".indexOf(current) : -1;
|
|
if (delimiter_index != -1)
|
|
pushScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
|
|
|
|
delimiter_index = "])}".indexOf(current);
|
|
if (delimiter_index != -1) {
|
|
if (top(state).type == current) state.scopes.pop();
|
|
else return ERRORCLASS;
|
|
}
|
|
if (state.dedent > 0 && stream.eol() && top(state).type == "py") {
|
|
if (state.scopes.length > 1) state.scopes.pop();
|
|
state.dedent -= 1;
|
|
}
|
|
|
|
return style;
|
|
}
|
|
|
|
var external = {
|
|
startState: function(basecolumn) {
|
|
return {
|
|
tokenize: tokenBase,
|
|
scopes: [{offset: basecolumn || 0, type: "py", align: null}],
|
|
lastStyle: null,
|
|
lastToken: null,
|
|
lambda: false,
|
|
dedent: 0
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
var addErr = state.errorToken;
|
|
if (addErr) state.errorToken = false;
|
|
var style = tokenLexer(stream, state);
|
|
|
|
state.lastStyle = style;
|
|
|
|
var current = stream.current();
|
|
if (current && style)
|
|
state.lastToken = current;
|
|
|
|
if (stream.eol() && state.lambda)
|
|
state.lambda = false;
|
|
return addErr ? style + " " + ERRORCLASS : style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (state.tokenize != tokenBase)
|
|
return state.tokenize.isString ? CodeMirror.Pass : 0;
|
|
|
|
var scope = top(state);
|
|
var closing = textAfter && textAfter.charAt(0) == scope.type;
|
|
if (scope.align != null)
|
|
return scope.align - (closing ? 1 : 0);
|
|
else if (closing && state.scopes.length > 1)
|
|
return state.scopes[state.scopes.length - 2].offset;
|
|
else
|
|
return scope.offset;
|
|
},
|
|
|
|
lineComment: "#",
|
|
fold: "indent"
|
|
};
|
|
return external;
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-python", "python");
|
|
|
|
var words = function(str) { return str.split(" "); };
|
|
|
|
CodeMirror.defineMIME("text/x-cython", {
|
|
name: "python",
|
|
extra_keywords: words("by cdef cimport cpdef ctypedef enum except"+
|
|
"extern gil include nogil property public"+
|
|
"readonly struct union DEF IF ELIF ELSE")
|
|
});
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
// CodeMirror2 mode/perl/perl.js (text/x-perl) beta 0.10 (2011-11-08)
|
|
// This is a part of CodeMirror from https://github.com/sabaca/CodeMirror_mode_perl (mail@sabaca.com)
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("perl",function(){
|
|
// http://perldoc.perl.org
|
|
var PERL={ // null - magic touch
|
|
// 1 - keyword
|
|
// 2 - def
|
|
// 3 - atom
|
|
// 4 - operator
|
|
// 5 - variable-2 (predefined)
|
|
// [x,y] - x=1,2,3; y=must be defined if x{...}
|
|
// PERL operators
|
|
'->' : 4,
|
|
'++' : 4,
|
|
'--' : 4,
|
|
'**' : 4,
|
|
// ! ~ \ and unary + and -
|
|
'=~' : 4,
|
|
'!~' : 4,
|
|
'*' : 4,
|
|
'/' : 4,
|
|
'%' : 4,
|
|
'x' : 4,
|
|
'+' : 4,
|
|
'-' : 4,
|
|
'.' : 4,
|
|
'<<' : 4,
|
|
'>>' : 4,
|
|
// named unary operators
|
|
'<' : 4,
|
|
'>' : 4,
|
|
'<=' : 4,
|
|
'>=' : 4,
|
|
'lt' : 4,
|
|
'gt' : 4,
|
|
'le' : 4,
|
|
'ge' : 4,
|
|
'==' : 4,
|
|
'!=' : 4,
|
|
'<=>' : 4,
|
|
'eq' : 4,
|
|
'ne' : 4,
|
|
'cmp' : 4,
|
|
'~~' : 4,
|
|
'&' : 4,
|
|
'|' : 4,
|
|
'^' : 4,
|
|
'&&' : 4,
|
|
'||' : 4,
|
|
'//' : 4,
|
|
'..' : 4,
|
|
'...' : 4,
|
|
'?' : 4,
|
|
':' : 4,
|
|
'=' : 4,
|
|
'+=' : 4,
|
|
'-=' : 4,
|
|
'*=' : 4, // etc. ???
|
|
',' : 4,
|
|
'=>' : 4,
|
|
'::' : 4,
|
|
// list operators (rightward)
|
|
'not' : 4,
|
|
'and' : 4,
|
|
'or' : 4,
|
|
'xor' : 4,
|
|
// PERL predefined variables (I know, what this is a paranoid idea, but may be needed for people, who learn PERL, and for me as well, ...and may be for you?;)
|
|
'BEGIN' : [5,1],
|
|
'END' : [5,1],
|
|
'PRINT' : [5,1],
|
|
'PRINTF' : [5,1],
|
|
'GETC' : [5,1],
|
|
'READ' : [5,1],
|
|
'READLINE' : [5,1],
|
|
'DESTROY' : [5,1],
|
|
'TIE' : [5,1],
|
|
'TIEHANDLE' : [5,1],
|
|
'UNTIE' : [5,1],
|
|
'STDIN' : 5,
|
|
'STDIN_TOP' : 5,
|
|
'STDOUT' : 5,
|
|
'STDOUT_TOP' : 5,
|
|
'STDERR' : 5,
|
|
'STDERR_TOP' : 5,
|
|
'$ARG' : 5,
|
|
'$_' : 5,
|
|
'@ARG' : 5,
|
|
'@_' : 5,
|
|
'$LIST_SEPARATOR' : 5,
|
|
'$"' : 5,
|
|
'$PROCESS_ID' : 5,
|
|
'$PID' : 5,
|
|
'$$' : 5,
|
|
'$REAL_GROUP_ID' : 5,
|
|
'$GID' : 5,
|
|
'$(' : 5,
|
|
'$EFFECTIVE_GROUP_ID' : 5,
|
|
'$EGID' : 5,
|
|
'$)' : 5,
|
|
'$PROGRAM_NAME' : 5,
|
|
'$0' : 5,
|
|
'$SUBSCRIPT_SEPARATOR' : 5,
|
|
'$SUBSEP' : 5,
|
|
'$;' : 5,
|
|
'$REAL_USER_ID' : 5,
|
|
'$UID' : 5,
|
|
'$<' : 5,
|
|
'$EFFECTIVE_USER_ID' : 5,
|
|
'$EUID' : 5,
|
|
'$>' : 5,
|
|
'$a' : 5,
|
|
'$b' : 5,
|
|
'$COMPILING' : 5,
|
|
'$^C' : 5,
|
|
'$DEBUGGING' : 5,
|
|
'$^D' : 5,
|
|
'${^ENCODING}' : 5,
|
|
'$ENV' : 5,
|
|
'%ENV' : 5,
|
|
'$SYSTEM_FD_MAX' : 5,
|
|
'$^F' : 5,
|
|
'@F' : 5,
|
|
'${^GLOBAL_PHASE}' : 5,
|
|
'$^H' : 5,
|
|
'%^H' : 5,
|
|
'@INC' : 5,
|
|
'%INC' : 5,
|
|
'$INPLACE_EDIT' : 5,
|
|
'$^I' : 5,
|
|
'$^M' : 5,
|
|
'$OSNAME' : 5,
|
|
'$^O' : 5,
|
|
'${^OPEN}' : 5,
|
|
'$PERLDB' : 5,
|
|
'$^P' : 5,
|
|
'$SIG' : 5,
|
|
'%SIG' : 5,
|
|
'$BASETIME' : 5,
|
|
'$^T' : 5,
|
|
'${^TAINT}' : 5,
|
|
'${^UNICODE}' : 5,
|
|
'${^UTF8CACHE}' : 5,
|
|
'${^UTF8LOCALE}' : 5,
|
|
'$PERL_VERSION' : 5,
|
|
'$^V' : 5,
|
|
'${^WIN32_SLOPPY_STAT}' : 5,
|
|
'$EXECUTABLE_NAME' : 5,
|
|
'$^X' : 5,
|
|
'$1' : 5, // - regexp $1, $2...
|
|
'$MATCH' : 5,
|
|
'$&' : 5,
|
|
'${^MATCH}' : 5,
|
|
'$PREMATCH' : 5,
|
|
'$`' : 5,
|
|
'${^PREMATCH}' : 5,
|
|
'$POSTMATCH' : 5,
|
|
"$'" : 5,
|
|
'${^POSTMATCH}' : 5,
|
|
'$LAST_PAREN_MATCH' : 5,
|
|
'$+' : 5,
|
|
'$LAST_SUBMATCH_RESULT' : 5,
|
|
'$^N' : 5,
|
|
'@LAST_MATCH_END' : 5,
|
|
'@+' : 5,
|
|
'%LAST_PAREN_MATCH' : 5,
|
|
'%+' : 5,
|
|
'@LAST_MATCH_START' : 5,
|
|
'@-' : 5,
|
|
'%LAST_MATCH_START' : 5,
|
|
'%-' : 5,
|
|
'$LAST_REGEXP_CODE_RESULT' : 5,
|
|
'$^R' : 5,
|
|
'${^RE_DEBUG_FLAGS}' : 5,
|
|
'${^RE_TRIE_MAXBUF}' : 5,
|
|
'$ARGV' : 5,
|
|
'@ARGV' : 5,
|
|
'ARGV' : 5,
|
|
'ARGVOUT' : 5,
|
|
'$OUTPUT_FIELD_SEPARATOR' : 5,
|
|
'$OFS' : 5,
|
|
'$,' : 5,
|
|
'$INPUT_LINE_NUMBER' : 5,
|
|
'$NR' : 5,
|
|
'$.' : 5,
|
|
'$INPUT_RECORD_SEPARATOR' : 5,
|
|
'$RS' : 5,
|
|
'$/' : 5,
|
|
'$OUTPUT_RECORD_SEPARATOR' : 5,
|
|
'$ORS' : 5,
|
|
'$\\' : 5,
|
|
'$OUTPUT_AUTOFLUSH' : 5,
|
|
'$|' : 5,
|
|
'$ACCUMULATOR' : 5,
|
|
'$^A' : 5,
|
|
'$FORMAT_FORMFEED' : 5,
|
|
'$^L' : 5,
|
|
'$FORMAT_PAGE_NUMBER' : 5,
|
|
'$%' : 5,
|
|
'$FORMAT_LINES_LEFT' : 5,
|
|
'$-' : 5,
|
|
'$FORMAT_LINE_BREAK_CHARACTERS' : 5,
|
|
'$:' : 5,
|
|
'$FORMAT_LINES_PER_PAGE' : 5,
|
|
'$=' : 5,
|
|
'$FORMAT_TOP_NAME' : 5,
|
|
'$^' : 5,
|
|
'$FORMAT_NAME' : 5,
|
|
'$~' : 5,
|
|
'${^CHILD_ERROR_NATIVE}' : 5,
|
|
'$EXTENDED_OS_ERROR' : 5,
|
|
'$^E' : 5,
|
|
'$EXCEPTIONS_BEING_CAUGHT' : 5,
|
|
'$^S' : 5,
|
|
'$WARNING' : 5,
|
|
'$^W' : 5,
|
|
'${^WARNING_BITS}' : 5,
|
|
'$OS_ERROR' : 5,
|
|
'$ERRNO' : 5,
|
|
'$!' : 5,
|
|
'%OS_ERROR' : 5,
|
|
'%ERRNO' : 5,
|
|
'%!' : 5,
|
|
'$CHILD_ERROR' : 5,
|
|
'$?' : 5,
|
|
'$EVAL_ERROR' : 5,
|
|
'$@' : 5,
|
|
'$OFMT' : 5,
|
|
'$#' : 5,
|
|
'$*' : 5,
|
|
'$ARRAY_BASE' : 5,
|
|
'$[' : 5,
|
|
'$OLD_PERL_VERSION' : 5,
|
|
'$]' : 5,
|
|
// PERL blocks
|
|
'if' :[1,1],
|
|
elsif :[1,1],
|
|
'else' :[1,1],
|
|
'while' :[1,1],
|
|
unless :[1,1],
|
|
'for' :[1,1],
|
|
foreach :[1,1],
|
|
// PERL functions
|
|
'abs' :1, // - absolute value function
|
|
accept :1, // - accept an incoming socket connect
|
|
alarm :1, // - schedule a SIGALRM
|
|
'atan2' :1, // - arctangent of Y/X in the range -PI to PI
|
|
bind :1, // - binds an address to a socket
|
|
binmode :1, // - prepare binary files for I/O
|
|
bless :1, // - create an object
|
|
bootstrap :1, //
|
|
'break' :1, // - break out of a "given" block
|
|
caller :1, // - get context of the current subroutine call
|
|
chdir :1, // - change your current working directory
|
|
chmod :1, // - changes the permissions on a list of files
|
|
chomp :1, // - remove a trailing record separator from a string
|
|
chop :1, // - remove the last character from a string
|
|
chown :1, // - change the owership on a list of files
|
|
chr :1, // - get character this number represents
|
|
chroot :1, // - make directory new root for path lookups
|
|
close :1, // - close file (or pipe or socket) handle
|
|
closedir :1, // - close directory handle
|
|
connect :1, // - connect to a remote socket
|
|
'continue' :[1,1], // - optional trailing block in a while or foreach
|
|
'cos' :1, // - cosine function
|
|
crypt :1, // - one-way passwd-style encryption
|
|
dbmclose :1, // - breaks binding on a tied dbm file
|
|
dbmopen :1, // - create binding on a tied dbm file
|
|
'default' :1, //
|
|
defined :1, // - test whether a value, variable, or function is defined
|
|
'delete' :1, // - deletes a value from a hash
|
|
die :1, // - raise an exception or bail out
|
|
'do' :1, // - turn a BLOCK into a TERM
|
|
dump :1, // - create an immediate core dump
|
|
each :1, // - retrieve the next key/value pair from a hash
|
|
endgrent :1, // - be done using group file
|
|
endhostent :1, // - be done using hosts file
|
|
endnetent :1, // - be done using networks file
|
|
endprotoent :1, // - be done using protocols file
|
|
endpwent :1, // - be done using passwd file
|
|
endservent :1, // - be done using services file
|
|
eof :1, // - test a filehandle for its end
|
|
'eval' :1, // - catch exceptions or compile and run code
|
|
'exec' :1, // - abandon this program to run another
|
|
exists :1, // - test whether a hash key is present
|
|
exit :1, // - terminate this program
|
|
'exp' :1, // - raise I to a power
|
|
fcntl :1, // - file control system call
|
|
fileno :1, // - return file descriptor from filehandle
|
|
flock :1, // - lock an entire file with an advisory lock
|
|
fork :1, // - create a new process just like this one
|
|
format :1, // - declare a picture format with use by the write() function
|
|
formline :1, // - internal function used for formats
|
|
getc :1, // - get the next character from the filehandle
|
|
getgrent :1, // - get next group record
|
|
getgrgid :1, // - get group record given group user ID
|
|
getgrnam :1, // - get group record given group name
|
|
gethostbyaddr :1, // - get host record given its address
|
|
gethostbyname :1, // - get host record given name
|
|
gethostent :1, // - get next hosts record
|
|
getlogin :1, // - return who logged in at this tty
|
|
getnetbyaddr :1, // - get network record given its address
|
|
getnetbyname :1, // - get networks record given name
|
|
getnetent :1, // - get next networks record
|
|
getpeername :1, // - find the other end of a socket connection
|
|
getpgrp :1, // - get process group
|
|
getppid :1, // - get parent process ID
|
|
getpriority :1, // - get current nice value
|
|
getprotobyname :1, // - get protocol record given name
|
|
getprotobynumber :1, // - get protocol record numeric protocol
|
|
getprotoent :1, // - get next protocols record
|
|
getpwent :1, // - get next passwd record
|
|
getpwnam :1, // - get passwd record given user login name
|
|
getpwuid :1, // - get passwd record given user ID
|
|
getservbyname :1, // - get services record given its name
|
|
getservbyport :1, // - get services record given numeric port
|
|
getservent :1, // - get next services record
|
|
getsockname :1, // - retrieve the sockaddr for a given socket
|
|
getsockopt :1, // - get socket options on a given socket
|
|
given :1, //
|
|
glob :1, // - expand filenames using wildcards
|
|
gmtime :1, // - convert UNIX time into record or string using Greenwich time
|
|
'goto' :1, // - create spaghetti code
|
|
grep :1, // - locate elements in a list test true against a given criterion
|
|
hex :1, // - convert a string to a hexadecimal number
|
|
'import' :1, // - patch a module's namespace into your own
|
|
index :1, // - find a substring within a string
|
|
'int' :1, // - get the integer portion of a number
|
|
ioctl :1, // - system-dependent device control system call
|
|
'join' :1, // - join a list into a string using a separator
|
|
keys :1, // - retrieve list of indices from a hash
|
|
kill :1, // - send a signal to a process or process group
|
|
last :1, // - exit a block prematurely
|
|
lc :1, // - return lower-case version of a string
|
|
lcfirst :1, // - return a string with just the next letter in lower case
|
|
length :1, // - return the number of bytes in a string
|
|
'link' :1, // - create a hard link in the filesytem
|
|
listen :1, // - register your socket as a server
|
|
local : 2, // - create a temporary value for a global variable (dynamic scoping)
|
|
localtime :1, // - convert UNIX time into record or string using local time
|
|
lock :1, // - get a thread lock on a variable, subroutine, or method
|
|
'log' :1, // - retrieve the natural logarithm for a number
|
|
lstat :1, // - stat a symbolic link
|
|
m :null, // - match a string with a regular expression pattern
|
|
map :1, // - apply a change to a list to get back a new list with the changes
|
|
mkdir :1, // - create a directory
|
|
msgctl :1, // - SysV IPC message control operations
|
|
msgget :1, // - get SysV IPC message queue
|
|
msgrcv :1, // - receive a SysV IPC message from a message queue
|
|
msgsnd :1, // - send a SysV IPC message to a message queue
|
|
my : 2, // - declare and assign a local variable (lexical scoping)
|
|
'new' :1, //
|
|
next :1, // - iterate a block prematurely
|
|
no :1, // - unimport some module symbols or semantics at compile time
|
|
oct :1, // - convert a string to an octal number
|
|
open :1, // - open a file, pipe, or descriptor
|
|
opendir :1, // - open a directory
|
|
ord :1, // - find a character's numeric representation
|
|
our : 2, // - declare and assign a package variable (lexical scoping)
|
|
pack :1, // - convert a list into a binary representation
|
|
'package' :1, // - declare a separate global namespace
|
|
pipe :1, // - open a pair of connected filehandles
|
|
pop :1, // - remove the last element from an array and return it
|
|
pos :1, // - find or set the offset for the last/next m//g search
|
|
print :1, // - output a list to a filehandle
|
|
printf :1, // - output a formatted list to a filehandle
|
|
prototype :1, // - get the prototype (if any) of a subroutine
|
|
push :1, // - append one or more elements to an array
|
|
q :null, // - singly quote a string
|
|
qq :null, // - doubly quote a string
|
|
qr :null, // - Compile pattern
|
|
quotemeta :null, // - quote regular expression magic characters
|
|
qw :null, // - quote a list of words
|
|
qx :null, // - backquote quote a string
|
|
rand :1, // - retrieve the next pseudorandom number
|
|
read :1, // - fixed-length buffered input from a filehandle
|
|
readdir :1, // - get a directory from a directory handle
|
|
readline :1, // - fetch a record from a file
|
|
readlink :1, // - determine where a symbolic link is pointing
|
|
readpipe :1, // - execute a system command and collect standard output
|
|
recv :1, // - receive a message over a Socket
|
|
redo :1, // - start this loop iteration over again
|
|
ref :1, // - find out the type of thing being referenced
|
|
rename :1, // - change a filename
|
|
require :1, // - load in external functions from a library at runtime
|
|
reset :1, // - clear all variables of a given name
|
|
'return' :1, // - get out of a function early
|
|
reverse :1, // - flip a string or a list
|
|
rewinddir :1, // - reset directory handle
|
|
rindex :1, // - right-to-left substring search
|
|
rmdir :1, // - remove a directory
|
|
s :null, // - replace a pattern with a string
|
|
say :1, // - print with newline
|
|
scalar :1, // - force a scalar context
|
|
seek :1, // - reposition file pointer for random-access I/O
|
|
seekdir :1, // - reposition directory pointer
|
|
select :1, // - reset default output or do I/O multiplexing
|
|
semctl :1, // - SysV semaphore control operations
|
|
semget :1, // - get set of SysV semaphores
|
|
semop :1, // - SysV semaphore operations
|
|
send :1, // - send a message over a socket
|
|
setgrent :1, // - prepare group file for use
|
|
sethostent :1, // - prepare hosts file for use
|
|
setnetent :1, // - prepare networks file for use
|
|
setpgrp :1, // - set the process group of a process
|
|
setpriority :1, // - set a process's nice value
|
|
setprotoent :1, // - prepare protocols file for use
|
|
setpwent :1, // - prepare passwd file for use
|
|
setservent :1, // - prepare services file for use
|
|
setsockopt :1, // - set some socket options
|
|
shift :1, // - remove the first element of an array, and return it
|
|
shmctl :1, // - SysV shared memory operations
|
|
shmget :1, // - get SysV shared memory segment identifier
|
|
shmread :1, // - read SysV shared memory
|
|
shmwrite :1, // - write SysV shared memory
|
|
shutdown :1, // - close down just half of a socket connection
|
|
'sin' :1, // - return the sine of a number
|
|
sleep :1, // - block for some number of seconds
|
|
socket :1, // - create a socket
|
|
socketpair :1, // - create a pair of sockets
|
|
'sort' :1, // - sort a list of values
|
|
splice :1, // - add or remove elements anywhere in an array
|
|
'split' :1, // - split up a string using a regexp delimiter
|
|
sprintf :1, // - formatted print into a string
|
|
'sqrt' :1, // - square root function
|
|
srand :1, // - seed the random number generator
|
|
stat :1, // - get a file's status information
|
|
state :1, // - declare and assign a state variable (persistent lexical scoping)
|
|
study :1, // - optimize input data for repeated searches
|
|
'sub' :1, // - declare a subroutine, possibly anonymously
|
|
'substr' :1, // - get or alter a portion of a stirng
|
|
symlink :1, // - create a symbolic link to a file
|
|
syscall :1, // - execute an arbitrary system call
|
|
sysopen :1, // - open a file, pipe, or descriptor
|
|
sysread :1, // - fixed-length unbuffered input from a filehandle
|
|
sysseek :1, // - position I/O pointer on handle used with sysread and syswrite
|
|
system :1, // - run a separate program
|
|
syswrite :1, // - fixed-length unbuffered output to a filehandle
|
|
tell :1, // - get current seekpointer on a filehandle
|
|
telldir :1, // - get current seekpointer on a directory handle
|
|
tie :1, // - bind a variable to an object class
|
|
tied :1, // - get a reference to the object underlying a tied variable
|
|
time :1, // - return number of seconds since 1970
|
|
times :1, // - return elapsed time for self and child processes
|
|
tr :null, // - transliterate a string
|
|
truncate :1, // - shorten a file
|
|
uc :1, // - return upper-case version of a string
|
|
ucfirst :1, // - return a string with just the next letter in upper case
|
|
umask :1, // - set file creation mode mask
|
|
undef :1, // - remove a variable or function definition
|
|
unlink :1, // - remove one link to a file
|
|
unpack :1, // - convert binary structure into normal perl variables
|
|
unshift :1, // - prepend more elements to the beginning of a list
|
|
untie :1, // - break a tie binding to a variable
|
|
use :1, // - load in a module at compile time
|
|
utime :1, // - set a file's last access and modify times
|
|
values :1, // - return a list of the values in a hash
|
|
vec :1, // - test or set particular bits in a string
|
|
wait :1, // - wait for any child process to die
|
|
waitpid :1, // - wait for a particular child process to die
|
|
wantarray :1, // - get void vs scalar vs list context of current subroutine call
|
|
warn :1, // - print debugging info
|
|
when :1, //
|
|
write :1, // - print a picture record
|
|
y :null}; // - transliterate a string
|
|
|
|
var RXstyle="string-2";
|
|
var RXmodifiers=/[goseximacplud]/; // NOTE: "m", "s", "y" and "tr" need to correct real modifiers for each regexp type
|
|
|
|
function tokenChain(stream,state,chain,style,tail){ // NOTE: chain.length > 2 is not working now (it's for s[...][...]geos;)
|
|
state.chain=null; // 12 3tail
|
|
state.style=null;
|
|
state.tail=null;
|
|
state.tokenize=function(stream,state){
|
|
var e=false,c,i=0;
|
|
while(c=stream.next()){
|
|
if(c===chain[i]&&!e){
|
|
if(chain[++i]!==undefined){
|
|
state.chain=chain[i];
|
|
state.style=style;
|
|
state.tail=tail;}
|
|
else if(tail)
|
|
stream.eatWhile(tail);
|
|
state.tokenize=tokenPerl;
|
|
return style;}
|
|
e=!e&&c=="\\";}
|
|
return style;};
|
|
return state.tokenize(stream,state);}
|
|
|
|
function tokenSOMETHING(stream,state,string){
|
|
state.tokenize=function(stream,state){
|
|
if(stream.string==string)
|
|
state.tokenize=tokenPerl;
|
|
stream.skipToEnd();
|
|
return "string";};
|
|
return state.tokenize(stream,state);}
|
|
|
|
function tokenPerl(stream,state){
|
|
if(stream.eatSpace())
|
|
return null;
|
|
if(state.chain)
|
|
return tokenChain(stream,state,state.chain,state.style,state.tail);
|
|
if(stream.match(/^\-?[\d\.]/,false))
|
|
if(stream.match(/^(\-?(\d*\.\d+(e[+-]?\d+)?|\d+\.\d*)|0x[\da-fA-F]+|0b[01]+|\d+(e[+-]?\d+)?)/))
|
|
return 'number';
|
|
if(stream.match(/^<<(?=\w)/)){ // NOTE: <<SOMETHING\n...\nSOMETHING\n
|
|
stream.eatWhile(/\w/);
|
|
return tokenSOMETHING(stream,state,stream.current().substr(2));}
|
|
if(stream.sol()&&stream.match(/^\=item(?!\w)/)){// NOTE: \n=item...\n=cut\n
|
|
return tokenSOMETHING(stream,state,'=cut');}
|
|
var ch=stream.next();
|
|
if(ch=='"'||ch=="'"){ // NOTE: ' or " or <<'SOMETHING'\n...\nSOMETHING\n or <<"SOMETHING"\n...\nSOMETHING\n
|
|
if(prefix(stream, 3)=="<<"+ch){
|
|
var p=stream.pos;
|
|
stream.eatWhile(/\w/);
|
|
var n=stream.current().substr(1);
|
|
if(n&&stream.eat(ch))
|
|
return tokenSOMETHING(stream,state,n);
|
|
stream.pos=p;}
|
|
return tokenChain(stream,state,[ch],"string");}
|
|
if(ch=="q"){
|
|
var c=look(stream, -2);
|
|
if(!(c&&/\w/.test(c))){
|
|
c=look(stream, 0);
|
|
if(c=="x"){
|
|
c=look(stream, 1);
|
|
if(c=="("){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
|
|
if(c=="["){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
|
|
if(c=="{"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
|
|
if(c=="<"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}
|
|
if(/[\^'"!~\/]/.test(c)){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers);}}
|
|
else if(c=="q"){
|
|
c=look(stream, 1);
|
|
if(c=="("){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[")"],"string");}
|
|
if(c=="["){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["]"],"string");}
|
|
if(c=="{"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["}"],"string");}
|
|
if(c=="<"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[">"],"string");}
|
|
if(/[\^'"!~\/]/.test(c)){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,[stream.eat(c)],"string");}}
|
|
else if(c=="w"){
|
|
c=look(stream, 1);
|
|
if(c=="("){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[")"],"bracket");}
|
|
if(c=="["){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["]"],"bracket");}
|
|
if(c=="{"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["}"],"bracket");}
|
|
if(c=="<"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[">"],"bracket");}
|
|
if(/[\^'"!~\/]/.test(c)){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,[stream.eat(c)],"bracket");}}
|
|
else if(c=="r"){
|
|
c=look(stream, 1);
|
|
if(c=="("){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
|
|
if(c=="["){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
|
|
if(c=="{"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
|
|
if(c=="<"){
|
|
eatSuffix(stream, 2);
|
|
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}
|
|
if(/[\^'"!~\/]/.test(c)){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers);}}
|
|
else if(/[\^'"!~\/(\[{<]/.test(c)){
|
|
if(c=="("){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,[")"],"string");}
|
|
if(c=="["){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,["]"],"string");}
|
|
if(c=="{"){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,["}"],"string");}
|
|
if(c=="<"){
|
|
eatSuffix(stream, 1);
|
|
return tokenChain(stream,state,[">"],"string");}
|
|
if(/[\^'"!~\/]/.test(c)){
|
|
return tokenChain(stream,state,[stream.eat(c)],"string");}}}}
|
|
if(ch=="m"){
|
|
var c=look(stream, -2);
|
|
if(!(c&&/\w/.test(c))){
|
|
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
|
if(c){
|
|
if(/[\^'"!~\/]/.test(c)){
|
|
return tokenChain(stream,state,[c],RXstyle,RXmodifiers);}
|
|
if(c=="("){
|
|
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
|
|
if(c=="["){
|
|
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
|
|
if(c=="{"){
|
|
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
|
|
if(c=="<"){
|
|
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}}}}
|
|
if(ch=="s"){
|
|
var c=/[\/>\]})\w]/.test(look(stream, -2));
|
|
if(!c){
|
|
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
|
if(c){
|
|
if(c=="[")
|
|
return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
|
|
if(c=="{")
|
|
return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
|
|
if(c=="<")
|
|
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
|
|
if(c=="(")
|
|
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
|
|
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}
|
|
if(ch=="y"){
|
|
var c=/[\/>\]})\w]/.test(look(stream, -2));
|
|
if(!c){
|
|
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
|
if(c){
|
|
if(c=="[")
|
|
return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
|
|
if(c=="{")
|
|
return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
|
|
if(c=="<")
|
|
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
|
|
if(c=="(")
|
|
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
|
|
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}
|
|
if(ch=="t"){
|
|
var c=/[\/>\]})\w]/.test(look(stream, -2));
|
|
if(!c){
|
|
c=stream.eat("r");if(c){
|
|
c=stream.eat(/[(\[{<\^'"!~\/]/);
|
|
if(c){
|
|
if(c=="[")
|
|
return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
|
|
if(c=="{")
|
|
return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
|
|
if(c=="<")
|
|
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
|
|
if(c=="(")
|
|
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
|
|
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}}
|
|
if(ch=="`"){
|
|
return tokenChain(stream,state,[ch],"variable-2");}
|
|
if(ch=="/"){
|
|
if(!/~\s*$/.test(prefix(stream)))
|
|
return "operator";
|
|
else
|
|
return tokenChain(stream,state,[ch],RXstyle,RXmodifiers);}
|
|
if(ch=="$"){
|
|
var p=stream.pos;
|
|
if(stream.eatWhile(/\d/)||stream.eat("{")&&stream.eatWhile(/\d/)&&stream.eat("}"))
|
|
return "variable-2";
|
|
else
|
|
stream.pos=p;}
|
|
if(/[$@%]/.test(ch)){
|
|
var p=stream.pos;
|
|
if(stream.eat("^")&&stream.eat(/[A-Z]/)||!/[@$%&]/.test(look(stream, -2))&&stream.eat(/[=|\\\-#?@;:&`~\^!\[\]*'"$+.,\/<>()]/)){
|
|
var c=stream.current();
|
|
if(PERL[c])
|
|
return "variable-2";}
|
|
stream.pos=p;}
|
|
if(/[$@%&]/.test(ch)){
|
|
if(stream.eatWhile(/[\w$\[\]]/)||stream.eat("{")&&stream.eatWhile(/[\w$\[\]]/)&&stream.eat("}")){
|
|
var c=stream.current();
|
|
if(PERL[c])
|
|
return "variable-2";
|
|
else
|
|
return "variable";}}
|
|
if(ch=="#"){
|
|
if(look(stream, -2)!="$"){
|
|
stream.skipToEnd();
|
|
return "comment";}}
|
|
if(/[:+\-\^*$&%@=<>!?|\/~\.]/.test(ch)){
|
|
var p=stream.pos;
|
|
stream.eatWhile(/[:+\-\^*$&%@=<>!?|\/~\.]/);
|
|
if(PERL[stream.current()])
|
|
return "operator";
|
|
else
|
|
stream.pos=p;}
|
|
if(ch=="_"){
|
|
if(stream.pos==1){
|
|
if(suffix(stream, 6)=="_END__"){
|
|
return tokenChain(stream,state,['\0'],"comment");}
|
|
else if(suffix(stream, 7)=="_DATA__"){
|
|
return tokenChain(stream,state,['\0'],"variable-2");}
|
|
else if(suffix(stream, 7)=="_C__"){
|
|
return tokenChain(stream,state,['\0'],"string");}}}
|
|
if(/\w/.test(ch)){
|
|
var p=stream.pos;
|
|
if(look(stream, -2)=="{"&&(look(stream, 0)=="}"||stream.eatWhile(/\w/)&&look(stream, 0)=="}"))
|
|
return "string";
|
|
else
|
|
stream.pos=p;}
|
|
if(/[A-Z]/.test(ch)){
|
|
var l=look(stream, -2);
|
|
var p=stream.pos;
|
|
stream.eatWhile(/[A-Z_]/);
|
|
if(/[\da-z]/.test(look(stream, 0))){
|
|
stream.pos=p;}
|
|
else{
|
|
var c=PERL[stream.current()];
|
|
if(!c)
|
|
return "meta";
|
|
if(c[1])
|
|
c=c[0];
|
|
if(l!=":"){
|
|
if(c==1)
|
|
return "keyword";
|
|
else if(c==2)
|
|
return "def";
|
|
else if(c==3)
|
|
return "atom";
|
|
else if(c==4)
|
|
return "operator";
|
|
else if(c==5)
|
|
return "variable-2";
|
|
else
|
|
return "meta";}
|
|
else
|
|
return "meta";}}
|
|
if(/[a-zA-Z_]/.test(ch)){
|
|
var l=look(stream, -2);
|
|
stream.eatWhile(/\w/);
|
|
var c=PERL[stream.current()];
|
|
if(!c)
|
|
return "meta";
|
|
if(c[1])
|
|
c=c[0];
|
|
if(l!=":"){
|
|
if(c==1)
|
|
return "keyword";
|
|
else if(c==2)
|
|
return "def";
|
|
else if(c==3)
|
|
return "atom";
|
|
else if(c==4)
|
|
return "operator";
|
|
else if(c==5)
|
|
return "variable-2";
|
|
else
|
|
return "meta";}
|
|
else
|
|
return "meta";}
|
|
return null;}
|
|
|
|
return {
|
|
startState: function() {
|
|
return {
|
|
tokenize: tokenPerl,
|
|
chain: null,
|
|
style: null,
|
|
tail: null
|
|
};
|
|
},
|
|
token: function(stream, state) {
|
|
return (state.tokenize || tokenPerl)(stream, state);
|
|
},
|
|
lineComment: '#'
|
|
};
|
|
});
|
|
|
|
CodeMirror.registerHelper("wordChars", "perl", /[\w$]/);
|
|
|
|
CodeMirror.defineMIME("text/x-perl", "perl");
|
|
|
|
// it's like "peek", but need for look-ahead or look-behind if index < 0
|
|
function look(stream, c){
|
|
return stream.string.charAt(stream.pos+(c||0));
|
|
}
|
|
|
|
// return a part of prefix of current stream from current position
|
|
function prefix(stream, c){
|
|
if(c){
|
|
var x=stream.pos-c;
|
|
return stream.string.substr((x>=0?x:0),c);}
|
|
else{
|
|
return stream.string.substr(0,stream.pos-1);
|
|
}
|
|
}
|
|
|
|
// return a part of suffix of current stream from current position
|
|
function suffix(stream, c){
|
|
var y=stream.string.length;
|
|
var x=y-stream.pos+1;
|
|
return stream.string.substr(stream.pos,(c&&c<y?c:x));
|
|
}
|
|
|
|
// eating and vomiting a part of stream from current position
|
|
function eatSuffix(stream, c){
|
|
var x=stream.pos+c;
|
|
var y;
|
|
if(x<=0)
|
|
stream.pos=0;
|
|
else if(x>=(y=stream.string.length-1))
|
|
stream.pos=y;
|
|
else
|
|
stream.pos=x;
|
|
}
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
// LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's
|
|
// CodeMirror 1 mode.
|
|
// highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("lua", function(config, parserConfig) {
|
|
var indentUnit = config.indentUnit;
|
|
|
|
function prefixRE(words) {
|
|
return new RegExp("^(?:" + words.join("|") + ")", "i");
|
|
}
|
|
function wordRE(words) {
|
|
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
|
}
|
|
var specials = wordRE(parserConfig.specials || []);
|
|
|
|
// long list of standard functions from lua manual
|
|
var builtins = wordRE([
|
|
"_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load",
|
|
"loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require",
|
|
"select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall",
|
|
|
|
"coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield",
|
|
|
|
"debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable",
|
|
"debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable",
|
|
"debug.setupvalue","debug.traceback",
|
|
|
|
"close","flush","lines","read","seek","setvbuf","write",
|
|
|
|
"io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin",
|
|
"io.stdout","io.tmpfile","io.type","io.write",
|
|
|
|
"math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg",
|
|
"math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max",
|
|
"math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh",
|
|
"math.sqrt","math.tan","math.tanh",
|
|
|
|
"os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale",
|
|
"os.time","os.tmpname",
|
|
|
|
"package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload",
|
|
"package.seeall",
|
|
|
|
"string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub",
|
|
"string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper",
|
|
|
|
"table.concat","table.insert","table.maxn","table.remove","table.sort"
|
|
]);
|
|
var keywords = wordRE(["and","break","elseif","false","nil","not","or","return",
|
|
"true","function", "end", "if", "then", "else", "do",
|
|
"while", "repeat", "until", "for", "in", "local" ]);
|
|
|
|
var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]);
|
|
var dedentTokens = wordRE(["end", "until", "\\)", "}"]);
|
|
var dedentPartial = prefixRE(["end", "until", "\\)", "}", "else", "elseif"]);
|
|
|
|
function readBracket(stream) {
|
|
var level = 0;
|
|
while (stream.eat("=")) ++level;
|
|
stream.eat("[");
|
|
return level;
|
|
}
|
|
|
|
function normal(stream, state) {
|
|
var ch = stream.next();
|
|
if (ch == "-" && stream.eat("-")) {
|
|
if (stream.eat("[") && stream.eat("["))
|
|
return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state);
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
if (ch == "\"" || ch == "'")
|
|
return (state.cur = string(ch))(stream, state);
|
|
if (ch == "[" && /[\[=]/.test(stream.peek()))
|
|
return (state.cur = bracketed(readBracket(stream), "string"))(stream, state);
|
|
if (/\d/.test(ch)) {
|
|
stream.eatWhile(/[\w.%]/);
|
|
return "number";
|
|
}
|
|
if (/[\w_]/.test(ch)) {
|
|
stream.eatWhile(/[\w\\\-_.]/);
|
|
return "variable";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function bracketed(level, style) {
|
|
return function(stream, state) {
|
|
var curlev = null, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (curlev == null) {if (ch == "]") curlev = 0;}
|
|
else if (ch == "=") ++curlev;
|
|
else if (ch == "]" && curlev == level) { state.cur = normal; break; }
|
|
else curlev = null;
|
|
}
|
|
return style;
|
|
};
|
|
}
|
|
|
|
function string(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, ch;
|
|
while ((ch = stream.next()) != null) {
|
|
if (ch == quote && !escaped) break;
|
|
escaped = !escaped && ch == "\\";
|
|
}
|
|
if (!escaped) state.cur = normal;
|
|
return "string";
|
|
};
|
|
}
|
|
|
|
return {
|
|
startState: function(basecol) {
|
|
return {basecol: basecol || 0, indentDepth: 0, cur: normal};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.eatSpace()) return null;
|
|
var style = state.cur(stream, state);
|
|
var word = stream.current();
|
|
if (style == "variable") {
|
|
if (keywords.test(word)) style = "keyword";
|
|
else if (builtins.test(word)) style = "builtin";
|
|
else if (specials.test(word)) style = "variable-2";
|
|
}
|
|
if ((style != "comment") && (style != "string")){
|
|
if (indentTokens.test(word)) ++state.indentDepth;
|
|
else if (dedentTokens.test(word)) --state.indentDepth;
|
|
}
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
var closing = dedentPartial.test(textAfter);
|
|
return state.basecol + indentUnit * (state.indentDepth - (closing ? 1 : 0));
|
|
},
|
|
|
|
lineComment: "--",
|
|
blockCommentStart: "--[[",
|
|
blockCommentEnd: "]]"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-lua", "lua");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("r", function(config) {
|
|
function wordObj(str) {
|
|
var words = str.split(" "), res = {};
|
|
for (var i = 0; i < words.length; ++i) res[words[i]] = true;
|
|
return res;
|
|
}
|
|
var atoms = wordObj("NULL NA Inf NaN NA_integer_ NA_real_ NA_complex_ NA_character_");
|
|
var builtins = wordObj("list quote bquote eval return call parse deparse");
|
|
var keywords = wordObj("if else repeat while function for in next break");
|
|
var blockkeywords = wordObj("if else repeat while function for");
|
|
var opChars = /[+\-*\/^<>=!&|~$:]/;
|
|
var curPunc;
|
|
|
|
function tokenBase(stream, state) {
|
|
curPunc = null;
|
|
var ch = stream.next();
|
|
if (ch == "#") {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
} else if (ch == "0" && stream.eat("x")) {
|
|
stream.eatWhile(/[\da-f]/i);
|
|
return "number";
|
|
} else if (ch == "." && stream.eat(/\d/)) {
|
|
stream.match(/\d*(?:e[+\-]?\d+)?/);
|
|
return "number";
|
|
} else if (/\d/.test(ch)) {
|
|
stream.match(/\d*(?:\.\d+)?(?:e[+\-]\d+)?L?/);
|
|
return "number";
|
|
} else if (ch == "'" || ch == '"') {
|
|
state.tokenize = tokenString(ch);
|
|
return "string";
|
|
} else if (ch == "." && stream.match(/.[.\d]+/)) {
|
|
return "keyword";
|
|
} else if (/[\w\.]/.test(ch) && ch != "_") {
|
|
stream.eatWhile(/[\w\.]/);
|
|
var word = stream.current();
|
|
if (atoms.propertyIsEnumerable(word)) return "atom";
|
|
if (keywords.propertyIsEnumerable(word)) {
|
|
// Block keywords start new blocks, except 'else if', which only starts
|
|
// one new block for the 'if', no block for the 'else'.
|
|
if (blockkeywords.propertyIsEnumerable(word) &&
|
|
!stream.match(/\s*if(\s+|$)/, false))
|
|
curPunc = "block";
|
|
return "keyword";
|
|
}
|
|
if (builtins.propertyIsEnumerable(word)) return "builtin";
|
|
return "variable";
|
|
} else if (ch == "%") {
|
|
if (stream.skipTo("%")) stream.next();
|
|
return "variable-2";
|
|
} else if (ch == "<" && stream.eat("-")) {
|
|
return "arrow";
|
|
} else if (ch == "=" && state.ctx.argList) {
|
|
return "arg-is";
|
|
} else if (opChars.test(ch)) {
|
|
if (ch == "$") return "dollar";
|
|
stream.eatWhile(opChars);
|
|
return "operator";
|
|
} else if (/[\(\){}\[\];]/.test(ch)) {
|
|
curPunc = ch;
|
|
if (ch == ";") return "semi";
|
|
return null;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
if (stream.eat("\\")) {
|
|
var ch = stream.next();
|
|
if (ch == "x") stream.match(/^[a-f0-9]{2}/i);
|
|
else if ((ch == "u" || ch == "U") && stream.eat("{") && stream.skipTo("}")) stream.next();
|
|
else if (ch == "u") stream.match(/^[a-f0-9]{4}/i);
|
|
else if (ch == "U") stream.match(/^[a-f0-9]{8}/i);
|
|
else if (/[0-7]/.test(ch)) stream.match(/^[0-7]{1,2}/);
|
|
return "string-2";
|
|
} else {
|
|
var next;
|
|
while ((next = stream.next()) != null) {
|
|
if (next == quote) { state.tokenize = tokenBase; break; }
|
|
if (next == "\\") { stream.backUp(1); break; }
|
|
}
|
|
return "string";
|
|
}
|
|
};
|
|
}
|
|
|
|
function push(state, type, stream) {
|
|
state.ctx = {type: type,
|
|
indent: state.indent,
|
|
align: null,
|
|
column: stream.column(),
|
|
prev: state.ctx};
|
|
}
|
|
function pop(state) {
|
|
state.indent = state.ctx.indent;
|
|
state.ctx = state.ctx.prev;
|
|
}
|
|
|
|
return {
|
|
startState: function() {
|
|
return {tokenize: tokenBase,
|
|
ctx: {type: "top",
|
|
indent: -config.indentUnit,
|
|
align: false},
|
|
indent: 0,
|
|
afterIdent: false};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.sol()) {
|
|
if (state.ctx.align == null) state.ctx.align = false;
|
|
state.indent = stream.indentation();
|
|
}
|
|
if (stream.eatSpace()) return null;
|
|
var style = state.tokenize(stream, state);
|
|
if (style != "comment" && state.ctx.align == null) state.ctx.align = true;
|
|
|
|
var ctype = state.ctx.type;
|
|
if ((curPunc == ";" || curPunc == "{" || curPunc == "}") && ctype == "block") pop(state);
|
|
if (curPunc == "{") push(state, "}", stream);
|
|
else if (curPunc == "(") {
|
|
push(state, ")", stream);
|
|
if (state.afterIdent) state.ctx.argList = true;
|
|
}
|
|
else if (curPunc == "[") push(state, "]", stream);
|
|
else if (curPunc == "block") push(state, "block", stream);
|
|
else if (curPunc == ctype) pop(state);
|
|
state.afterIdent = style == "variable" || style == "keyword";
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (state.tokenize != tokenBase) return 0;
|
|
var firstChar = textAfter && textAfter.charAt(0), ctx = state.ctx,
|
|
closing = firstChar == ctx.type;
|
|
if (ctx.type == "block") return ctx.indent + (firstChar == "{" ? 0 : config.indentUnit);
|
|
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
|
else return ctx.indent + (closing ? 0 : config.indentUnit);
|
|
},
|
|
|
|
lineComment: "#"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-rsrc", "r");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("ruby", function(config) {
|
|
function wordObj(words) {
|
|
var o = {};
|
|
for (var i = 0, e = words.length; i < e; ++i) o[words[i]] = true;
|
|
return o;
|
|
}
|
|
var keywords = wordObj([
|
|
"alias", "and", "BEGIN", "begin", "break", "case", "class", "def", "defined?", "do", "else",
|
|
"elsif", "END", "end", "ensure", "false", "for", "if", "in", "module", "next", "not", "or",
|
|
"redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless",
|
|
"until", "when", "while", "yield", "nil", "raise", "throw", "catch", "fail", "loop", "callcc",
|
|
"caller", "lambda", "proc", "public", "protected", "private", "require", "load",
|
|
"require_relative", "extend", "autoload", "__END__", "__FILE__", "__LINE__", "__dir__"
|
|
]);
|
|
var indentWords = wordObj(["def", "class", "case", "for", "while", "module", "then",
|
|
"catch", "loop", "proc", "begin"]);
|
|
var dedentWords = wordObj(["end", "until"]);
|
|
var matching = {"[": "]", "{": "}", "(": ")"};
|
|
var curPunc;
|
|
|
|
function chain(newtok, stream, state) {
|
|
state.tokenize.push(newtok);
|
|
return newtok(stream, state);
|
|
}
|
|
|
|
function tokenBase(stream, state) {
|
|
curPunc = null;
|
|
if (stream.sol() && stream.match("=begin") && stream.eol()) {
|
|
state.tokenize.push(readBlockComment);
|
|
return "comment";
|
|
}
|
|
if (stream.eatSpace()) return null;
|
|
var ch = stream.next(), m;
|
|
if (ch == "`" || ch == "'" || ch == '"') {
|
|
return chain(readQuoted(ch, "string", ch == '"' || ch == "`"), stream, state);
|
|
} else if (ch == "/") {
|
|
var currentIndex = stream.current().length;
|
|
if (stream.skipTo("/")) {
|
|
var search_till = stream.current().length;
|
|
stream.backUp(stream.current().length - currentIndex);
|
|
var balance = 0; // balance brackets
|
|
while (stream.current().length < search_till) {
|
|
var chchr = stream.next();
|
|
if (chchr == "(") balance += 1;
|
|
else if (chchr == ")") balance -= 1;
|
|
if (balance < 0) break;
|
|
}
|
|
stream.backUp(stream.current().length - currentIndex);
|
|
if (balance == 0)
|
|
return chain(readQuoted(ch, "string-2", true), stream, state);
|
|
}
|
|
return "operator";
|
|
} else if (ch == "%") {
|
|
var style = "string", embed = true;
|
|
if (stream.eat("s")) style = "atom";
|
|
else if (stream.eat(/[WQ]/)) style = "string";
|
|
else if (stream.eat(/[r]/)) style = "string-2";
|
|
else if (stream.eat(/[wxq]/)) { style = "string"; embed = false; }
|
|
var delim = stream.eat(/[^\w\s=]/);
|
|
if (!delim) return "operator";
|
|
if (matching.propertyIsEnumerable(delim)) delim = matching[delim];
|
|
return chain(readQuoted(delim, style, embed, true), stream, state);
|
|
} else if (ch == "#") {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
} else if (ch == "<" && (m = stream.match(/^<-?[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/))) {
|
|
return chain(readHereDoc(m[1]), stream, state);
|
|
} else if (ch == "0") {
|
|
if (stream.eat("x")) stream.eatWhile(/[\da-fA-F]/);
|
|
else if (stream.eat("b")) stream.eatWhile(/[01]/);
|
|
else stream.eatWhile(/[0-7]/);
|
|
return "number";
|
|
} else if (/\d/.test(ch)) {
|
|
stream.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/);
|
|
return "number";
|
|
} else if (ch == "?") {
|
|
while (stream.match(/^\\[CM]-/)) {}
|
|
if (stream.eat("\\")) stream.eatWhile(/\w/);
|
|
else stream.next();
|
|
return "string";
|
|
} else if (ch == ":") {
|
|
if (stream.eat("'")) return chain(readQuoted("'", "atom", false), stream, state);
|
|
if (stream.eat('"')) return chain(readQuoted('"', "atom", true), stream, state);
|
|
|
|
// :> :>> :< :<< are valid symbols
|
|
if (stream.eat(/[\<\>]/)) {
|
|
stream.eat(/[\<\>]/);
|
|
return "atom";
|
|
}
|
|
|
|
// :+ :- :/ :* :| :& :! are valid symbols
|
|
if (stream.eat(/[\+\-\*\/\&\|\:\!]/)) {
|
|
return "atom";
|
|
}
|
|
|
|
// Symbols can't start by a digit
|
|
if (stream.eat(/[a-zA-Z$@_\xa1-\uffff]/)) {
|
|
stream.eatWhile(/[\w$\xa1-\uffff]/);
|
|
// Only one ? ! = is allowed and only as the last character
|
|
stream.eat(/[\?\!\=]/);
|
|
return "atom";
|
|
}
|
|
return "operator";
|
|
} else if (ch == "@" && stream.match(/^@?[a-zA-Z_\xa1-\uffff]/)) {
|
|
stream.eat("@");
|
|
stream.eatWhile(/[\w\xa1-\uffff]/);
|
|
return "variable-2";
|
|
} else if (ch == "$") {
|
|
if (stream.eat(/[a-zA-Z_]/)) {
|
|
stream.eatWhile(/[\w]/);
|
|
} else if (stream.eat(/\d/)) {
|
|
stream.eat(/\d/);
|
|
} else {
|
|
stream.next(); // Must be a special global like $: or $!
|
|
}
|
|
return "variable-3";
|
|
} else if (/[a-zA-Z_\xa1-\uffff]/.test(ch)) {
|
|
stream.eatWhile(/[\w\xa1-\uffff]/);
|
|
stream.eat(/[\?\!]/);
|
|
if (stream.eat(":")) return "atom";
|
|
return "ident";
|
|
} else if (ch == "|" && (state.varList || state.lastTok == "{" || state.lastTok == "do")) {
|
|
curPunc = "|";
|
|
return null;
|
|
} else if (/[\(\)\[\]{}\\;]/.test(ch)) {
|
|
curPunc = ch;
|
|
return null;
|
|
} else if (ch == "-" && stream.eat(">")) {
|
|
return "arrow";
|
|
} else if (/[=+\-\/*:\.^%<>~|]/.test(ch)) {
|
|
var more = stream.eatWhile(/[=+\-\/*:\.^%<>~|]/);
|
|
if (ch == "." && !more) curPunc = ".";
|
|
return "operator";
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function tokenBaseUntilBrace(depth) {
|
|
if (!depth) depth = 1;
|
|
return function(stream, state) {
|
|
if (stream.peek() == "}") {
|
|
if (depth == 1) {
|
|
state.tokenize.pop();
|
|
return state.tokenize[state.tokenize.length-1](stream, state);
|
|
} else {
|
|
state.tokenize[state.tokenize.length - 1] = tokenBaseUntilBrace(depth - 1);
|
|
}
|
|
} else if (stream.peek() == "{") {
|
|
state.tokenize[state.tokenize.length - 1] = tokenBaseUntilBrace(depth + 1);
|
|
}
|
|
return tokenBase(stream, state);
|
|
};
|
|
}
|
|
function tokenBaseOnce() {
|
|
var alreadyCalled = false;
|
|
return function(stream, state) {
|
|
if (alreadyCalled) {
|
|
state.tokenize.pop();
|
|
return state.tokenize[state.tokenize.length-1](stream, state);
|
|
}
|
|
alreadyCalled = true;
|
|
return tokenBase(stream, state);
|
|
};
|
|
}
|
|
function readQuoted(quote, style, embed, unescaped) {
|
|
return function(stream, state) {
|
|
var escaped = false, ch;
|
|
|
|
if (state.context.type === 'read-quoted-paused') {
|
|
state.context = state.context.prev;
|
|
stream.eat("}");
|
|
}
|
|
|
|
while ((ch = stream.next()) != null) {
|
|
if (ch == quote && (unescaped || !escaped)) {
|
|
state.tokenize.pop();
|
|
break;
|
|
}
|
|
if (embed && ch == "#" && !escaped) {
|
|
if (stream.eat("{")) {
|
|
if (quote == "}") {
|
|
state.context = {prev: state.context, type: 'read-quoted-paused'};
|
|
}
|
|
state.tokenize.push(tokenBaseUntilBrace());
|
|
break;
|
|
} else if (/[@\$]/.test(stream.peek())) {
|
|
state.tokenize.push(tokenBaseOnce());
|
|
break;
|
|
}
|
|
}
|
|
escaped = !escaped && ch == "\\";
|
|
}
|
|
return style;
|
|
};
|
|
}
|
|
function readHereDoc(phrase) {
|
|
return function(stream, state) {
|
|
if (stream.match(phrase)) state.tokenize.pop();
|
|
else stream.skipToEnd();
|
|
return "string";
|
|
};
|
|
}
|
|
function readBlockComment(stream, state) {
|
|
if (stream.sol() && stream.match("=end") && stream.eol())
|
|
state.tokenize.pop();
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
|
|
return {
|
|
startState: function() {
|
|
return {tokenize: [tokenBase],
|
|
indented: 0,
|
|
context: {type: "top", indented: -config.indentUnit},
|
|
continuedLine: false,
|
|
lastTok: null,
|
|
varList: false};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.sol()) state.indented = stream.indentation();
|
|
var style = state.tokenize[state.tokenize.length-1](stream, state), kwtype;
|
|
var thisTok = curPunc;
|
|
if (style == "ident") {
|
|
var word = stream.current();
|
|
style = state.lastTok == "." ? "property"
|
|
: keywords.propertyIsEnumerable(stream.current()) ? "keyword"
|
|
: /^[A-Z]/.test(word) ? "tag"
|
|
: (state.lastTok == "def" || state.lastTok == "class" || state.varList) ? "def"
|
|
: "variable";
|
|
if (style == "keyword") {
|
|
thisTok = word;
|
|
if (indentWords.propertyIsEnumerable(word)) kwtype = "indent";
|
|
else if (dedentWords.propertyIsEnumerable(word)) kwtype = "dedent";
|
|
else if ((word == "if" || word == "unless") && stream.column() == stream.indentation())
|
|
kwtype = "indent";
|
|
else if (word == "do" && state.context.indented < state.indented)
|
|
kwtype = "indent";
|
|
}
|
|
}
|
|
if (curPunc || (style && style != "comment")) state.lastTok = thisTok;
|
|
if (curPunc == "|") state.varList = !state.varList;
|
|
|
|
if (kwtype == "indent" || /[\(\[\{]/.test(curPunc))
|
|
state.context = {prev: state.context, type: curPunc || style, indented: state.indented};
|
|
else if ((kwtype == "dedent" || /[\)\]\}]/.test(curPunc)) && state.context.prev)
|
|
state.context = state.context.prev;
|
|
|
|
if (stream.eol())
|
|
state.continuedLine = (curPunc == "\\" || style == "operator");
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (state.tokenize[state.tokenize.length-1] != tokenBase) return 0;
|
|
var firstChar = textAfter && textAfter.charAt(0);
|
|
var ct = state.context;
|
|
var closing = ct.type == matching[firstChar] ||
|
|
ct.type == "keyword" && /^(?:end|until|else|elsif|when|rescue)\b/.test(textAfter);
|
|
return ct.indented + (closing ? 0 : config.indentUnit) +
|
|
(state.continuedLine ? config.indentUnit : 0);
|
|
},
|
|
|
|
electricChars: "}de", // enD and rescuE
|
|
lineComment: "#"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-ruby", "ruby");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../python/python"), require("../stex/stex"), require("../../addon/mode/overlay"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../python/python", "../stex/stex", "../../addon/mode/overlay"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode('rst', function (config, options) {
|
|
|
|
var rx_strong = /^\*\*[^\*\s](?:[^\*]*[^\*\s])?\*\*/;
|
|
var rx_emphasis = /^\*[^\*\s](?:[^\*]*[^\*\s])?\*/;
|
|
var rx_literal = /^``[^`\s](?:[^`]*[^`\s])``/;
|
|
|
|
var rx_number = /^(?:[\d]+(?:[\.,]\d+)*)/;
|
|
var rx_positive = /^(?:\s\+[\d]+(?:[\.,]\d+)*)/;
|
|
var rx_negative = /^(?:\s\-[\d]+(?:[\.,]\d+)*)/;
|
|
|
|
var rx_uri_protocol = "[Hh][Tt][Tt][Pp][Ss]?://";
|
|
var rx_uri_domain = "(?:[\\d\\w.-]+)\\.(?:\\w{2,6})";
|
|
var rx_uri_path = "(?:/[\\d\\w\\#\\%\\&\\-\\.\\,\\/\\:\\=\\?\\~]+)*";
|
|
var rx_uri = new RegExp("^" + rx_uri_protocol + rx_uri_domain + rx_uri_path);
|
|
|
|
var overlay = {
|
|
token: function (stream) {
|
|
|
|
if (stream.match(rx_strong) && stream.match (/\W+|$/, false))
|
|
return 'strong';
|
|
if (stream.match(rx_emphasis) && stream.match (/\W+|$/, false))
|
|
return 'em';
|
|
if (stream.match(rx_literal) && stream.match (/\W+|$/, false))
|
|
return 'string-2';
|
|
if (stream.match(rx_number))
|
|
return 'number';
|
|
if (stream.match(rx_positive))
|
|
return 'positive';
|
|
if (stream.match(rx_negative))
|
|
return 'negative';
|
|
if (stream.match(rx_uri))
|
|
return 'link';
|
|
|
|
while (stream.next() != null) {
|
|
if (stream.match(rx_strong, false)) break;
|
|
if (stream.match(rx_emphasis, false)) break;
|
|
if (stream.match(rx_literal, false)) break;
|
|
if (stream.match(rx_number, false)) break;
|
|
if (stream.match(rx_positive, false)) break;
|
|
if (stream.match(rx_negative, false)) break;
|
|
if (stream.match(rx_uri, false)) break;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
};
|
|
|
|
var mode = CodeMirror.getMode(
|
|
config, options.backdrop || 'rst-base'
|
|
);
|
|
|
|
return CodeMirror.overlayMode(mode, overlay, true); // combine
|
|
}, 'python', 'stex');
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
CodeMirror.defineMode('rst-base', function (config) {
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
function format(string) {
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
return string.replace(/{(\d+)}/g, function (match, n) {
|
|
return typeof args[n] != 'undefined' ? args[n] : match;
|
|
});
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
var mode_python = CodeMirror.getMode(config, 'python');
|
|
var mode_stex = CodeMirror.getMode(config, 'stex');
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
var SEPA = "\\s+";
|
|
var TAIL = "(?:\\s*|\\W|$)",
|
|
rx_TAIL = new RegExp(format('^{0}', TAIL));
|
|
|
|
var NAME =
|
|
"(?:[^\\W\\d_](?:[\\w!\"#$%&'()\\*\\+,\\-\\.\/:;<=>\\?]*[^\\W_])?)",
|
|
rx_NAME = new RegExp(format('^{0}', NAME));
|
|
var NAME_WWS =
|
|
"(?:[^\\W\\d_](?:[\\w\\s!\"#$%&'()\\*\\+,\\-\\.\/:;<=>\\?]*[^\\W_])?)";
|
|
var REF_NAME = format('(?:{0}|`{1}`)', NAME, NAME_WWS);
|
|
|
|
var TEXT1 = "(?:[^\\s\\|](?:[^\\|]*[^\\s\\|])?)";
|
|
var TEXT2 = "(?:[^\\`]+)",
|
|
rx_TEXT2 = new RegExp(format('^{0}', TEXT2));
|
|
|
|
var rx_section = new RegExp(
|
|
"^([!'#$%&\"()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~])\\1{3,}\\s*$");
|
|
var rx_explicit = new RegExp(
|
|
format('^\\.\\.{0}', SEPA));
|
|
var rx_link = new RegExp(
|
|
format('^_{0}:{1}|^__:{1}', REF_NAME, TAIL));
|
|
var rx_directive = new RegExp(
|
|
format('^{0}::{1}', REF_NAME, TAIL));
|
|
var rx_substitution = new RegExp(
|
|
format('^\\|{0}\\|{1}{2}::{3}', TEXT1, SEPA, REF_NAME, TAIL));
|
|
var rx_footnote = new RegExp(
|
|
format('^\\[(?:\\d+|#{0}?|\\*)]{1}', REF_NAME, TAIL));
|
|
var rx_citation = new RegExp(
|
|
format('^\\[{0}\\]{1}', REF_NAME, TAIL));
|
|
|
|
var rx_substitution_ref = new RegExp(
|
|
format('^\\|{0}\\|', TEXT1));
|
|
var rx_footnote_ref = new RegExp(
|
|
format('^\\[(?:\\d+|#{0}?|\\*)]_', REF_NAME));
|
|
var rx_citation_ref = new RegExp(
|
|
format('^\\[{0}\\]_', REF_NAME));
|
|
var rx_link_ref1 = new RegExp(
|
|
format('^{0}__?', REF_NAME));
|
|
var rx_link_ref2 = new RegExp(
|
|
format('^`{0}`_', TEXT2));
|
|
|
|
var rx_role_pre = new RegExp(
|
|
format('^:{0}:`{1}`{2}', NAME, TEXT2, TAIL));
|
|
var rx_role_suf = new RegExp(
|
|
format('^`{1}`:{0}:{2}', NAME, TEXT2, TAIL));
|
|
var rx_role = new RegExp(
|
|
format('^:{0}:{1}', NAME, TAIL));
|
|
|
|
var rx_directive_name = new RegExp(format('^{0}', REF_NAME));
|
|
var rx_directive_tail = new RegExp(format('^::{0}', TAIL));
|
|
var rx_substitution_text = new RegExp(format('^\\|{0}\\|', TEXT1));
|
|
var rx_substitution_sepa = new RegExp(format('^{0}', SEPA));
|
|
var rx_substitution_name = new RegExp(format('^{0}', REF_NAME));
|
|
var rx_substitution_tail = new RegExp(format('^::{0}', TAIL));
|
|
var rx_link_head = new RegExp("^_");
|
|
var rx_link_name = new RegExp(format('^{0}|_', REF_NAME));
|
|
var rx_link_tail = new RegExp(format('^:{0}', TAIL));
|
|
|
|
var rx_verbatim = new RegExp('^::\\s*$');
|
|
var rx_examples = new RegExp('^\\s+(?:>>>|In \\[\\d+\\]:)\\s');
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
function to_normal(stream, state) {
|
|
var token = null;
|
|
|
|
if (stream.sol() && stream.match(rx_examples, false)) {
|
|
change(state, to_mode, {
|
|
mode: mode_python, local: CodeMirror.startState(mode_python)
|
|
});
|
|
} else if (stream.sol() && stream.match(rx_explicit)) {
|
|
change(state, to_explicit);
|
|
token = 'meta';
|
|
} else if (stream.sol() && stream.match(rx_section)) {
|
|
change(state, to_normal);
|
|
token = 'header';
|
|
} else if (phase(state) == rx_role_pre ||
|
|
stream.match(rx_role_pre, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
change(state, to_normal, context(rx_role_pre, 1));
|
|
stream.match(/^:/);
|
|
token = 'meta';
|
|
break;
|
|
case 1:
|
|
change(state, to_normal, context(rx_role_pre, 2));
|
|
stream.match(rx_NAME);
|
|
token = 'keyword';
|
|
|
|
if (stream.current().match(/^(?:math|latex)/)) {
|
|
state.tmp_stex = true;
|
|
}
|
|
break;
|
|
case 2:
|
|
change(state, to_normal, context(rx_role_pre, 3));
|
|
stream.match(/^:`/);
|
|
token = 'meta';
|
|
break;
|
|
case 3:
|
|
if (state.tmp_stex) {
|
|
state.tmp_stex = undefined; state.tmp = {
|
|
mode: mode_stex, local: CodeMirror.startState(mode_stex)
|
|
};
|
|
}
|
|
|
|
if (state.tmp) {
|
|
if (stream.peek() == '`') {
|
|
change(state, to_normal, context(rx_role_pre, 4));
|
|
state.tmp = undefined;
|
|
break;
|
|
}
|
|
|
|
token = state.tmp.mode.token(stream, state.tmp.local);
|
|
break;
|
|
}
|
|
|
|
change(state, to_normal, context(rx_role_pre, 4));
|
|
stream.match(rx_TEXT2);
|
|
token = 'string';
|
|
break;
|
|
case 4:
|
|
change(state, to_normal, context(rx_role_pre, 5));
|
|
stream.match(/^`/);
|
|
token = 'meta';
|
|
break;
|
|
case 5:
|
|
change(state, to_normal, context(rx_role_pre, 6));
|
|
stream.match(rx_TAIL);
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (phase(state) == rx_role_suf ||
|
|
stream.match(rx_role_suf, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
change(state, to_normal, context(rx_role_suf, 1));
|
|
stream.match(/^`/);
|
|
token = 'meta';
|
|
break;
|
|
case 1:
|
|
change(state, to_normal, context(rx_role_suf, 2));
|
|
stream.match(rx_TEXT2);
|
|
token = 'string';
|
|
break;
|
|
case 2:
|
|
change(state, to_normal, context(rx_role_suf, 3));
|
|
stream.match(/^`:/);
|
|
token = 'meta';
|
|
break;
|
|
case 3:
|
|
change(state, to_normal, context(rx_role_suf, 4));
|
|
stream.match(rx_NAME);
|
|
token = 'keyword';
|
|
break;
|
|
case 4:
|
|
change(state, to_normal, context(rx_role_suf, 5));
|
|
stream.match(/^:/);
|
|
token = 'meta';
|
|
break;
|
|
case 5:
|
|
change(state, to_normal, context(rx_role_suf, 6));
|
|
stream.match(rx_TAIL);
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (phase(state) == rx_role || stream.match(rx_role, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
change(state, to_normal, context(rx_role, 1));
|
|
stream.match(/^:/);
|
|
token = 'meta';
|
|
break;
|
|
case 1:
|
|
change(state, to_normal, context(rx_role, 2));
|
|
stream.match(rx_NAME);
|
|
token = 'keyword';
|
|
break;
|
|
case 2:
|
|
change(state, to_normal, context(rx_role, 3));
|
|
stream.match(/^:/);
|
|
token = 'meta';
|
|
break;
|
|
case 3:
|
|
change(state, to_normal, context(rx_role, 4));
|
|
stream.match(rx_TAIL);
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (phase(state) == rx_substitution_ref ||
|
|
stream.match(rx_substitution_ref, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
change(state, to_normal, context(rx_substitution_ref, 1));
|
|
stream.match(rx_substitution_text);
|
|
token = 'variable-2';
|
|
break;
|
|
case 1:
|
|
change(state, to_normal, context(rx_substitution_ref, 2));
|
|
if (stream.match(/^_?_?/)) token = 'link';
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (stream.match(rx_footnote_ref)) {
|
|
change(state, to_normal);
|
|
token = 'quote';
|
|
} else if (stream.match(rx_citation_ref)) {
|
|
change(state, to_normal);
|
|
token = 'quote';
|
|
} else if (stream.match(rx_link_ref1)) {
|
|
change(state, to_normal);
|
|
if (!stream.peek() || stream.peek().match(/^\W$/)) {
|
|
token = 'link';
|
|
}
|
|
} else if (phase(state) == rx_link_ref2 ||
|
|
stream.match(rx_link_ref2, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
if (!stream.peek() || stream.peek().match(/^\W$/)) {
|
|
change(state, to_normal, context(rx_link_ref2, 1));
|
|
} else {
|
|
stream.match(rx_link_ref2);
|
|
}
|
|
break;
|
|
case 1:
|
|
change(state, to_normal, context(rx_link_ref2, 2));
|
|
stream.match(/^`/);
|
|
token = 'link';
|
|
break;
|
|
case 2:
|
|
change(state, to_normal, context(rx_link_ref2, 3));
|
|
stream.match(rx_TEXT2);
|
|
break;
|
|
case 3:
|
|
change(state, to_normal, context(rx_link_ref2, 4));
|
|
stream.match(/^`_/);
|
|
token = 'link';
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (stream.match(rx_verbatim)) {
|
|
change(state, to_verbatim);
|
|
}
|
|
|
|
else {
|
|
if (stream.next()) change(state, to_normal);
|
|
}
|
|
|
|
return token;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
function to_explicit(stream, state) {
|
|
var token = null;
|
|
|
|
if (phase(state) == rx_substitution ||
|
|
stream.match(rx_substitution, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
change(state, to_explicit, context(rx_substitution, 1));
|
|
stream.match(rx_substitution_text);
|
|
token = 'variable-2';
|
|
break;
|
|
case 1:
|
|
change(state, to_explicit, context(rx_substitution, 2));
|
|
stream.match(rx_substitution_sepa);
|
|
break;
|
|
case 2:
|
|
change(state, to_explicit, context(rx_substitution, 3));
|
|
stream.match(rx_substitution_name);
|
|
token = 'keyword';
|
|
break;
|
|
case 3:
|
|
change(state, to_explicit, context(rx_substitution, 4));
|
|
stream.match(rx_substitution_tail);
|
|
token = 'meta';
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (phase(state) == rx_directive ||
|
|
stream.match(rx_directive, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
change(state, to_explicit, context(rx_directive, 1));
|
|
stream.match(rx_directive_name);
|
|
token = 'keyword';
|
|
|
|
if (stream.current().match(/^(?:math|latex)/))
|
|
state.tmp_stex = true;
|
|
else if (stream.current().match(/^python/))
|
|
state.tmp_py = true;
|
|
break;
|
|
case 1:
|
|
change(state, to_explicit, context(rx_directive, 2));
|
|
stream.match(rx_directive_tail);
|
|
token = 'meta';
|
|
|
|
if (stream.match(/^latex\s*$/) || state.tmp_stex) {
|
|
state.tmp_stex = undefined; change(state, to_mode, {
|
|
mode: mode_stex, local: CodeMirror.startState(mode_stex)
|
|
});
|
|
}
|
|
break;
|
|
case 2:
|
|
change(state, to_explicit, context(rx_directive, 3));
|
|
if (stream.match(/^python\s*$/) || state.tmp_py) {
|
|
state.tmp_py = undefined; change(state, to_mode, {
|
|
mode: mode_python, local: CodeMirror.startState(mode_python)
|
|
});
|
|
}
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (phase(state) == rx_link || stream.match(rx_link, false)) {
|
|
|
|
switch (stage(state)) {
|
|
case 0:
|
|
change(state, to_explicit, context(rx_link, 1));
|
|
stream.match(rx_link_head);
|
|
stream.match(rx_link_name);
|
|
token = 'link';
|
|
break;
|
|
case 1:
|
|
change(state, to_explicit, context(rx_link, 2));
|
|
stream.match(rx_link_tail);
|
|
token = 'meta';
|
|
break;
|
|
default:
|
|
change(state, to_normal);
|
|
}
|
|
} else if (stream.match(rx_footnote)) {
|
|
change(state, to_normal);
|
|
token = 'quote';
|
|
} else if (stream.match(rx_citation)) {
|
|
change(state, to_normal);
|
|
token = 'quote';
|
|
}
|
|
|
|
else {
|
|
stream.eatSpace();
|
|
if (stream.eol()) {
|
|
change(state, to_normal);
|
|
} else {
|
|
stream.skipToEnd();
|
|
change(state, to_comment);
|
|
token = 'comment';
|
|
}
|
|
}
|
|
|
|
return token;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
function to_comment(stream, state) {
|
|
return as_block(stream, state, 'comment');
|
|
}
|
|
|
|
function to_verbatim(stream, state) {
|
|
return as_block(stream, state, 'meta');
|
|
}
|
|
|
|
function as_block(stream, state, token) {
|
|
if (stream.eol() || stream.eatSpace()) {
|
|
stream.skipToEnd();
|
|
return token;
|
|
} else {
|
|
change(state, to_normal);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
function to_mode(stream, state) {
|
|
|
|
if (state.ctx.mode && state.ctx.local) {
|
|
|
|
if (stream.sol()) {
|
|
if (!stream.eatSpace()) change(state, to_normal);
|
|
return null;
|
|
}
|
|
|
|
return state.ctx.mode.token(stream, state.ctx.local);
|
|
}
|
|
|
|
change(state, to_normal);
|
|
return null;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
function context(phase, stage, mode, local) {
|
|
return {phase: phase, stage: stage, mode: mode, local: local};
|
|
}
|
|
|
|
function change(state, tok, ctx) {
|
|
state.tok = tok;
|
|
state.ctx = ctx || {};
|
|
}
|
|
|
|
function stage(state) {
|
|
return state.ctx.stage || 0;
|
|
}
|
|
|
|
function phase(state) {
|
|
return state.ctx.phase;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
return {
|
|
startState: function () {
|
|
return {tok: to_normal, ctx: context(undefined, 0)};
|
|
},
|
|
|
|
copyState: function (state) {
|
|
var ctx = state.ctx, tmp = state.tmp;
|
|
if (ctx.local)
|
|
ctx = {mode: ctx.mode, local: CodeMirror.copyState(ctx.mode, ctx.local)};
|
|
if (tmp)
|
|
tmp = {mode: tmp.mode, local: CodeMirror.copyState(tmp.mode, tmp.local)};
|
|
return {tok: state.tok, ctx: ctx, tmp: tmp};
|
|
},
|
|
|
|
innerMode: function (state) {
|
|
return state.tmp ? {state: state.tmp.local, mode: state.tmp.mode}
|
|
: state.ctx.mode ? {state: state.ctx.local, mode: state.ctx.mode}
|
|
: null;
|
|
},
|
|
|
|
token: function (stream, state) {
|
|
return state.tok(stream, state);
|
|
}
|
|
};
|
|
}, 'python', 'stex');
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
CodeMirror.defineMIME('text/x-rst', 'rst');
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
/**
|
|
* @file smartymixed.js
|
|
* @brief Smarty Mixed Codemirror mode (Smarty + Mixed HTML)
|
|
* @author Ruslan Osmanov <rrosmanov at gmail dot com>
|
|
* @version 3.0
|
|
* @date 05.07.2013
|
|
*/
|
|
|
|
// Warning: Don't base other modes on this one. This here is a
|
|
// terrible way to write a mixed mode.
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), require("../smarty/smarty"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../htmlmixed/htmlmixed", "../smarty/smarty"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("smartymixed", function(config) {
|
|
var htmlMixedMode = CodeMirror.getMode(config, "htmlmixed");
|
|
var smartyMode = CodeMirror.getMode(config, "smarty");
|
|
|
|
var settings = {
|
|
rightDelimiter: '}',
|
|
leftDelimiter: '{'
|
|
};
|
|
|
|
if (config.hasOwnProperty("leftDelimiter")) {
|
|
settings.leftDelimiter = config.leftDelimiter;
|
|
}
|
|
if (config.hasOwnProperty("rightDelimiter")) {
|
|
settings.rightDelimiter = config.rightDelimiter;
|
|
}
|
|
|
|
function reEsc(str) { return str.replace(/[^\s\w]/g, "\\$&"); }
|
|
|
|
var reLeft = reEsc(settings.leftDelimiter), reRight = reEsc(settings.rightDelimiter);
|
|
var regs = {
|
|
smartyComment: new RegExp("^" + reRight + "\\*"),
|
|
literalOpen: new RegExp(reLeft + "literal" + reRight),
|
|
literalClose: new RegExp(reLeft + "\/literal" + reRight),
|
|
hasLeftDelimeter: new RegExp(".*" + reLeft),
|
|
htmlHasLeftDelimeter: new RegExp("[^<>]*" + reLeft)
|
|
};
|
|
|
|
var helpers = {
|
|
chain: function(stream, state, parser) {
|
|
state.tokenize = parser;
|
|
return parser(stream, state);
|
|
},
|
|
|
|
cleanChain: function(stream, state, parser) {
|
|
state.tokenize = null;
|
|
state.localState = null;
|
|
state.localMode = null;
|
|
return (typeof parser == "string") ? (parser ? parser : null) : parser(stream, state);
|
|
},
|
|
|
|
maybeBackup: function(stream, pat, style) {
|
|
var cur = stream.current();
|
|
var close = cur.search(pat),
|
|
m;
|
|
if (close > - 1) stream.backUp(cur.length - close);
|
|
else if (m = cur.match(/<\/?$/)) {
|
|
stream.backUp(cur.length);
|
|
if (!stream.match(pat, false)) stream.match(cur[0]);
|
|
}
|
|
return style;
|
|
}
|
|
};
|
|
|
|
var parsers = {
|
|
html: function(stream, state) {
|
|
var htmlTagName = state.htmlMixedState.htmlState.context && state.htmlMixedState.htmlState.context.tagName
|
|
? state.htmlMixedState.htmlState.context.tagName
|
|
: null;
|
|
|
|
if (!state.inLiteral && stream.match(regs.htmlHasLeftDelimeter, false) && htmlTagName === null) {
|
|
state.tokenize = parsers.smarty;
|
|
state.localMode = smartyMode;
|
|
state.localState = smartyMode.startState(htmlMixedMode.indent(state.htmlMixedState, ""));
|
|
return helpers.maybeBackup(stream, settings.leftDelimiter, smartyMode.token(stream, state.localState));
|
|
} else if (!state.inLiteral && stream.match(settings.leftDelimiter, false)) {
|
|
state.tokenize = parsers.smarty;
|
|
state.localMode = smartyMode;
|
|
state.localState = smartyMode.startState(htmlMixedMode.indent(state.htmlMixedState, ""));
|
|
return helpers.maybeBackup(stream, settings.leftDelimiter, smartyMode.token(stream, state.localState));
|
|
}
|
|
return htmlMixedMode.token(stream, state.htmlMixedState);
|
|
},
|
|
|
|
smarty: function(stream, state) {
|
|
if (stream.match(settings.leftDelimiter, false)) {
|
|
if (stream.match(regs.smartyComment, false)) {
|
|
return helpers.chain(stream, state, parsers.inBlock("comment", "*" + settings.rightDelimiter));
|
|
}
|
|
} else if (stream.match(settings.rightDelimiter, false)) {
|
|
stream.eat(settings.rightDelimiter);
|
|
state.tokenize = parsers.html;
|
|
state.localMode = htmlMixedMode;
|
|
state.localState = state.htmlMixedState;
|
|
return "tag";
|
|
}
|
|
|
|
return helpers.maybeBackup(stream, settings.rightDelimiter, smartyMode.token(stream, state.localState));
|
|
},
|
|
|
|
inBlock: function(style, terminator) {
|
|
return function(stream, state) {
|
|
while (!stream.eol()) {
|
|
if (stream.match(terminator)) {
|
|
helpers.cleanChain(stream, state, "");
|
|
break;
|
|
}
|
|
stream.next();
|
|
}
|
|
return style;
|
|
};
|
|
}
|
|
};
|
|
|
|
return {
|
|
startState: function() {
|
|
var state = htmlMixedMode.startState();
|
|
return {
|
|
token: parsers.html,
|
|
localMode: null,
|
|
localState: null,
|
|
htmlMixedState: state,
|
|
tokenize: null,
|
|
inLiteral: false
|
|
};
|
|
},
|
|
|
|
copyState: function(state) {
|
|
var local = null, tok = (state.tokenize || state.token);
|
|
if (state.localState) {
|
|
local = CodeMirror.copyState((tok != parsers.html ? smartyMode : htmlMixedMode), state.localState);
|
|
}
|
|
return {
|
|
token: state.token,
|
|
tokenize: state.tokenize,
|
|
localMode: state.localMode,
|
|
localState: local,
|
|
htmlMixedState: CodeMirror.copyState(htmlMixedMode, state.htmlMixedState),
|
|
inLiteral: state.inLiteral
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.match(settings.leftDelimiter, false)) {
|
|
if (!state.inLiteral && stream.match(regs.literalOpen, true)) {
|
|
state.inLiteral = true;
|
|
return "keyword";
|
|
} else if (state.inLiteral && stream.match(regs.literalClose, true)) {
|
|
state.inLiteral = false;
|
|
return "keyword";
|
|
}
|
|
}
|
|
if (state.inLiteral && state.localState != state.htmlMixedState) {
|
|
state.tokenize = parsers.html;
|
|
state.localMode = htmlMixedMode;
|
|
state.localState = state.htmlMixedState;
|
|
}
|
|
|
|
var style = (state.tokenize || state.token)(stream, state);
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
if (state.localMode == smartyMode
|
|
|| (state.inLiteral && !state.localMode)
|
|
|| regs.hasLeftDelimeter.test(textAfter)) {
|
|
return CodeMirror.Pass;
|
|
}
|
|
return htmlMixedMode.indent(state.htmlMixedState, textAfter);
|
|
},
|
|
|
|
innerMode: function(state) {
|
|
return {
|
|
state: state.localState || state.htmlMixedState,
|
|
mode: state.localMode || htmlMixedMode
|
|
};
|
|
}
|
|
};
|
|
}, "htmlmixed", "smarty");
|
|
|
|
CodeMirror.defineMIME("text/x-smarty", "smartymixed");
|
|
// vim: et ts=2 sts=2 sw=2
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("vb", function(conf, parserConf) {
|
|
var ERRORCLASS = 'error';
|
|
|
|
function wordRegexp(words) {
|
|
return new RegExp("^((" + words.join(")|(") + "))\\b", "i");
|
|
}
|
|
|
|
var singleOperators = new RegExp("^[\\+\\-\\*/%&\\\\|\\^~<>!]");
|
|
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
|
|
var doubleOperators = new RegExp("^((==)|(<>)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
|
|
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
|
var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
|
|
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
|
|
|
var openingKeywords = ['class','module', 'sub','enum','select','while','if','function', 'get','set','property', 'try'];
|
|
var middleKeywords = ['else','elseif','case', 'catch'];
|
|
var endKeywords = ['next','loop'];
|
|
|
|
var wordOperators = wordRegexp(['and', 'or', 'not', 'xor', 'in']);
|
|
var commonkeywords = ['as', 'dim', 'break', 'continue','optional', 'then', 'until',
|
|
'goto', 'byval','byref','new','handles','property', 'return',
|
|
'const','private', 'protected', 'friend', 'public', 'shared', 'static', 'true','false'];
|
|
var commontypes = ['integer','string','double','decimal','boolean','short','char', 'float','single'];
|
|
|
|
var keywords = wordRegexp(commonkeywords);
|
|
var types = wordRegexp(commontypes);
|
|
var stringPrefixes = '"';
|
|
|
|
var opening = wordRegexp(openingKeywords);
|
|
var middle = wordRegexp(middleKeywords);
|
|
var closing = wordRegexp(endKeywords);
|
|
var doubleClosing = wordRegexp(['end']);
|
|
var doOpening = wordRegexp(['do']);
|
|
|
|
var indentInfo = null;
|
|
|
|
|
|
|
|
|
|
function indent(_stream, state) {
|
|
state.currentIndent++;
|
|
}
|
|
|
|
function dedent(_stream, state) {
|
|
state.currentIndent--;
|
|
}
|
|
// tokenizers
|
|
function tokenBase(stream, state) {
|
|
if (stream.eatSpace()) {
|
|
return null;
|
|
}
|
|
|
|
var ch = stream.peek();
|
|
|
|
// Handle Comments
|
|
if (ch === "'") {
|
|
stream.skipToEnd();
|
|
return 'comment';
|
|
}
|
|
|
|
|
|
// Handle Number Literals
|
|
if (stream.match(/^((&H)|(&O))?[0-9\.a-f]/i, false)) {
|
|
var floatLiteral = false;
|
|
// Floats
|
|
if (stream.match(/^\d*\.\d+F?/i)) { floatLiteral = true; }
|
|
else if (stream.match(/^\d+\.\d*F?/)) { floatLiteral = true; }
|
|
else if (stream.match(/^\.\d+F?/)) { floatLiteral = true; }
|
|
|
|
if (floatLiteral) {
|
|
// Float literals may be "imaginary"
|
|
stream.eat(/J/i);
|
|
return 'number';
|
|
}
|
|
// Integers
|
|
var intLiteral = false;
|
|
// Hex
|
|
if (stream.match(/^&H[0-9a-f]+/i)) { intLiteral = true; }
|
|
// Octal
|
|
else if (stream.match(/^&O[0-7]+/i)) { intLiteral = true; }
|
|
// Decimal
|
|
else if (stream.match(/^[1-9]\d*F?/)) {
|
|
// Decimal literals may be "imaginary"
|
|
stream.eat(/J/i);
|
|
// TODO - Can you have imaginary longs?
|
|
intLiteral = true;
|
|
}
|
|
// Zero by itself with no other piece of number.
|
|
else if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
|
|
if (intLiteral) {
|
|
// Integer literals may be "long"
|
|
stream.eat(/L/i);
|
|
return 'number';
|
|
}
|
|
}
|
|
|
|
// Handle Strings
|
|
if (stream.match(stringPrefixes)) {
|
|
state.tokenize = tokenStringFactory(stream.current());
|
|
return state.tokenize(stream, state);
|
|
}
|
|
|
|
// Handle operators and Delimiters
|
|
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
|
|
return null;
|
|
}
|
|
if (stream.match(doubleOperators)
|
|
|| stream.match(singleOperators)
|
|
|| stream.match(wordOperators)) {
|
|
return 'operator';
|
|
}
|
|
if (stream.match(singleDelimiters)) {
|
|
return null;
|
|
}
|
|
if (stream.match(doOpening)) {
|
|
indent(stream,state);
|
|
state.doInCurrentLine = true;
|
|
return 'keyword';
|
|
}
|
|
if (stream.match(opening)) {
|
|
if (! state.doInCurrentLine)
|
|
indent(stream,state);
|
|
else
|
|
state.doInCurrentLine = false;
|
|
return 'keyword';
|
|
}
|
|
if (stream.match(middle)) {
|
|
return 'keyword';
|
|
}
|
|
|
|
if (stream.match(doubleClosing)) {
|
|
dedent(stream,state);
|
|
dedent(stream,state);
|
|
return 'keyword';
|
|
}
|
|
if (stream.match(closing)) {
|
|
dedent(stream,state);
|
|
return 'keyword';
|
|
}
|
|
|
|
if (stream.match(types)) {
|
|
return 'keyword';
|
|
}
|
|
|
|
if (stream.match(keywords)) {
|
|
return 'keyword';
|
|
}
|
|
|
|
if (stream.match(identifiers)) {
|
|
return 'variable';
|
|
}
|
|
|
|
// Handle non-detected items
|
|
stream.next();
|
|
return ERRORCLASS;
|
|
}
|
|
|
|
function tokenStringFactory(delimiter) {
|
|
var singleline = delimiter.length == 1;
|
|
var OUTCLASS = 'string';
|
|
|
|
return function(stream, state) {
|
|
while (!stream.eol()) {
|
|
stream.eatWhile(/[^'"]/);
|
|
if (stream.match(delimiter)) {
|
|
state.tokenize = tokenBase;
|
|
return OUTCLASS;
|
|
} else {
|
|
stream.eat(/['"]/);
|
|
}
|
|
}
|
|
if (singleline) {
|
|
if (parserConf.singleLineStringErrors) {
|
|
return ERRORCLASS;
|
|
} else {
|
|
state.tokenize = tokenBase;
|
|
}
|
|
}
|
|
return OUTCLASS;
|
|
};
|
|
}
|
|
|
|
|
|
function tokenLexer(stream, state) {
|
|
var style = state.tokenize(stream, state);
|
|
var current = stream.current();
|
|
|
|
// Handle '.' connected identifiers
|
|
if (current === '.') {
|
|
style = state.tokenize(stream, state);
|
|
current = stream.current();
|
|
if (style === 'variable') {
|
|
return 'variable';
|
|
} else {
|
|
return ERRORCLASS;
|
|
}
|
|
}
|
|
|
|
|
|
var delimiter_index = '[({'.indexOf(current);
|
|
if (delimiter_index !== -1) {
|
|
indent(stream, state );
|
|
}
|
|
if (indentInfo === 'dedent') {
|
|
if (dedent(stream, state)) {
|
|
return ERRORCLASS;
|
|
}
|
|
}
|
|
delimiter_index = '])}'.indexOf(current);
|
|
if (delimiter_index !== -1) {
|
|
if (dedent(stream, state)) {
|
|
return ERRORCLASS;
|
|
}
|
|
}
|
|
|
|
return style;
|
|
}
|
|
|
|
var external = {
|
|
electricChars:"dDpPtTfFeE ",
|
|
startState: function() {
|
|
return {
|
|
tokenize: tokenBase,
|
|
lastToken: null,
|
|
currentIndent: 0,
|
|
nextLineIndent: 0,
|
|
doInCurrentLine: false
|
|
|
|
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.sol()) {
|
|
state.currentIndent += state.nextLineIndent;
|
|
state.nextLineIndent = 0;
|
|
state.doInCurrentLine = 0;
|
|
}
|
|
var style = tokenLexer(stream, state);
|
|
|
|
state.lastToken = {style:style, content: stream.current()};
|
|
|
|
|
|
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
var trueText = textAfter.replace(/^\s+|\s+$/g, '') ;
|
|
if (trueText.match(closing) || trueText.match(doubleClosing) || trueText.match(middle)) return conf.indentUnit*(state.currentIndent-1);
|
|
if(state.currentIndent < 0) return 0;
|
|
return state.currentIndent * conf.indentUnit;
|
|
}
|
|
|
|
};
|
|
return external;
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-vb", "vb");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
/*
|
|
For extra ASP classic objects, initialize CodeMirror instance with this option:
|
|
isASP: true
|
|
|
|
E.G.:
|
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
|
lineNumbers: true,
|
|
isASP: true
|
|
});
|
|
*/
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("vbscript", function(conf, parserConf) {
|
|
var ERRORCLASS = 'error';
|
|
|
|
function wordRegexp(words) {
|
|
return new RegExp("^((" + words.join(")|(") + "))\\b", "i");
|
|
}
|
|
|
|
var singleOperators = new RegExp("^[\\+\\-\\*/&\\\\\\^<>=]");
|
|
var doubleOperators = new RegExp("^((<>)|(<=)|(>=))");
|
|
var singleDelimiters = new RegExp('^[\\.,]');
|
|
var brakets = new RegExp('^[\\(\\)]');
|
|
var identifiers = new RegExp("^[A-Za-z][_A-Za-z0-9]*");
|
|
|
|
var openingKeywords = ['class','sub','select','while','if','function', 'property', 'with', 'for'];
|
|
var middleKeywords = ['else','elseif','case'];
|
|
var endKeywords = ['next','loop','wend'];
|
|
|
|
var wordOperators = wordRegexp(['and', 'or', 'not', 'xor', 'is', 'mod', 'eqv', 'imp']);
|
|
var commonkeywords = ['dim', 'redim', 'then', 'until', 'randomize',
|
|
'byval','byref','new','property', 'exit', 'in',
|
|
'const','private', 'public',
|
|
'get','set','let', 'stop', 'on error resume next', 'on error goto 0', 'option explicit', 'call', 'me'];
|
|
|
|
//This list was from: http://msdn.microsoft.com/en-us/library/f8tbc79x(v=vs.84).aspx
|
|
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
|
|
//This list was from: http://msdn.microsoft.com/en-us/library/3ca8tfek(v=vs.84).aspx
|
|
var builtinFuncsWords = ['abs', 'array', 'asc', 'atn', 'cbool', 'cbyte', 'ccur', 'cdate', 'cdbl', 'chr', 'cint', 'clng', 'cos', 'csng', 'cstr', 'date', 'dateadd', 'datediff', 'datepart',
|
|
'dateserial', 'datevalue', 'day', 'escape', 'eval', 'execute', 'exp', 'filter', 'formatcurrency', 'formatdatetime', 'formatnumber', 'formatpercent', 'getlocale', 'getobject',
|
|
'getref', 'hex', 'hour', 'inputbox', 'instr', 'instrrev', 'int', 'fix', 'isarray', 'isdate', 'isempty', 'isnull', 'isnumeric', 'isobject', 'join', 'lbound', 'lcase', 'left',
|
|
'len', 'loadpicture', 'log', 'ltrim', 'rtrim', 'trim', 'maths', 'mid', 'minute', 'month', 'monthname', 'msgbox', 'now', 'oct', 'replace', 'rgb', 'right', 'rnd', 'round',
|
|
'scriptengine', 'scriptenginebuildversion', 'scriptenginemajorversion', 'scriptengineminorversion', 'second', 'setlocale', 'sgn', 'sin', 'space', 'split', 'sqr', 'strcomp',
|
|
'string', 'strreverse', 'tan', 'time', 'timer', 'timeserial', 'timevalue', 'typename', 'ubound', 'ucase', 'unescape', 'vartype', 'weekday', 'weekdayname', 'year'];
|
|
|
|
//This list was from: http://msdn.microsoft.com/en-us/library/ydz4cfk3(v=vs.84).aspx
|
|
var builtinConsts = ['vbBlack', 'vbRed', 'vbGreen', 'vbYellow', 'vbBlue', 'vbMagenta', 'vbCyan', 'vbWhite', 'vbBinaryCompare', 'vbTextCompare',
|
|
'vbSunday', 'vbMonday', 'vbTuesday', 'vbWednesday', 'vbThursday', 'vbFriday', 'vbSaturday', 'vbUseSystemDayOfWeek', 'vbFirstJan1', 'vbFirstFourDays', 'vbFirstFullWeek',
|
|
'vbGeneralDate', 'vbLongDate', 'vbShortDate', 'vbLongTime', 'vbShortTime', 'vbObjectError',
|
|
'vbOKOnly', 'vbOKCancel', 'vbAbortRetryIgnore', 'vbYesNoCancel', 'vbYesNo', 'vbRetryCancel', 'vbCritical', 'vbQuestion', 'vbExclamation', 'vbInformation', 'vbDefaultButton1', 'vbDefaultButton2',
|
|
'vbDefaultButton3', 'vbDefaultButton4', 'vbApplicationModal', 'vbSystemModal', 'vbOK', 'vbCancel', 'vbAbort', 'vbRetry', 'vbIgnore', 'vbYes', 'vbNo',
|
|
'vbCr', 'VbCrLf', 'vbFormFeed', 'vbLf', 'vbNewLine', 'vbNullChar', 'vbNullString', 'vbTab', 'vbVerticalTab', 'vbUseDefault', 'vbTrue', 'vbFalse',
|
|
'vbEmpty', 'vbNull', 'vbInteger', 'vbLong', 'vbSingle', 'vbDouble', 'vbCurrency', 'vbDate', 'vbString', 'vbObject', 'vbError', 'vbBoolean', 'vbVariant', 'vbDataObject', 'vbDecimal', 'vbByte', 'vbArray'];
|
|
//This list was from: http://msdn.microsoft.com/en-us/library/hkc375ea(v=vs.84).aspx
|
|
var builtinObjsWords = ['WScript', 'err', 'debug', 'RegExp'];
|
|
var knownProperties = ['description', 'firstindex', 'global', 'helpcontext', 'helpfile', 'ignorecase', 'length', 'number', 'pattern', 'source', 'value', 'count'];
|
|
var knownMethods = ['clear', 'execute', 'raise', 'replace', 'test', 'write', 'writeline', 'close', 'open', 'state', 'eof', 'update', 'addnew', 'end', 'createobject', 'quit'];
|
|
|
|
var aspBuiltinObjsWords = ['server', 'response', 'request', 'session', 'application'];
|
|
var aspKnownProperties = ['buffer', 'cachecontrol', 'charset', 'contenttype', 'expires', 'expiresabsolute', 'isclientconnected', 'pics', 'status', //response
|
|
'clientcertificate', 'cookies', 'form', 'querystring', 'servervariables', 'totalbytes', //request
|
|
'contents', 'staticobjects', //application
|
|
'codepage', 'lcid', 'sessionid', 'timeout', //session
|
|
'scripttimeout']; //server
|
|
var aspKnownMethods = ['addheader', 'appendtolog', 'binarywrite', 'end', 'flush', 'redirect', //response
|
|
'binaryread', //request
|
|
'remove', 'removeall', 'lock', 'unlock', //application
|
|
'abandon', //session
|
|
'getlasterror', 'htmlencode', 'mappath', 'transfer', 'urlencode']; //server
|
|
|
|
var knownWords = knownMethods.concat(knownProperties);
|
|
|
|
builtinObjsWords = builtinObjsWords.concat(builtinConsts);
|
|
|
|
if (conf.isASP){
|
|
builtinObjsWords = builtinObjsWords.concat(aspBuiltinObjsWords);
|
|
knownWords = knownWords.concat(aspKnownMethods, aspKnownProperties);
|
|
};
|
|
|
|
var keywords = wordRegexp(commonkeywords);
|
|
var atoms = wordRegexp(atomWords);
|
|
var builtinFuncs = wordRegexp(builtinFuncsWords);
|
|
var builtinObjs = wordRegexp(builtinObjsWords);
|
|
var known = wordRegexp(knownWords);
|
|
var stringPrefixes = '"';
|
|
|
|
var opening = wordRegexp(openingKeywords);
|
|
var middle = wordRegexp(middleKeywords);
|
|
var closing = wordRegexp(endKeywords);
|
|
var doubleClosing = wordRegexp(['end']);
|
|
var doOpening = wordRegexp(['do']);
|
|
var noIndentWords = wordRegexp(['on error resume next', 'exit']);
|
|
var comment = wordRegexp(['rem']);
|
|
|
|
|
|
function indent(_stream, state) {
|
|
state.currentIndent++;
|
|
}
|
|
|
|
function dedent(_stream, state) {
|
|
state.currentIndent--;
|
|
}
|
|
// tokenizers
|
|
function tokenBase(stream, state) {
|
|
if (stream.eatSpace()) {
|
|
return 'space';
|
|
//return null;
|
|
}
|
|
|
|
var ch = stream.peek();
|
|
|
|
// Handle Comments
|
|
if (ch === "'") {
|
|
stream.skipToEnd();
|
|
return 'comment';
|
|
}
|
|
if (stream.match(comment)){
|
|
stream.skipToEnd();
|
|
return 'comment';
|
|
}
|
|
|
|
|
|
// Handle Number Literals
|
|
if (stream.match(/^((&H)|(&O))?[0-9\.]/i, false) && !stream.match(/^((&H)|(&O))?[0-9\.]+[a-z_]/i, false)) {
|
|
var floatLiteral = false;
|
|
// Floats
|
|
if (stream.match(/^\d*\.\d+/i)) { floatLiteral = true; }
|
|
else if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
|
|
else if (stream.match(/^\.\d+/)) { floatLiteral = true; }
|
|
|
|
if (floatLiteral) {
|
|
// Float literals may be "imaginary"
|
|
stream.eat(/J/i);
|
|
return 'number';
|
|
}
|
|
// Integers
|
|
var intLiteral = false;
|
|
// Hex
|
|
if (stream.match(/^&H[0-9a-f]+/i)) { intLiteral = true; }
|
|
// Octal
|
|
else if (stream.match(/^&O[0-7]+/i)) { intLiteral = true; }
|
|
// Decimal
|
|
else if (stream.match(/^[1-9]\d*F?/)) {
|
|
// Decimal literals may be "imaginary"
|
|
stream.eat(/J/i);
|
|
// TODO - Can you have imaginary longs?
|
|
intLiteral = true;
|
|
}
|
|
// Zero by itself with no other piece of number.
|
|
else if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
|
|
if (intLiteral) {
|
|
// Integer literals may be "long"
|
|
stream.eat(/L/i);
|
|
return 'number';
|
|
}
|
|
}
|
|
|
|
// Handle Strings
|
|
if (stream.match(stringPrefixes)) {
|
|
state.tokenize = tokenStringFactory(stream.current());
|
|
return state.tokenize(stream, state);
|
|
}
|
|
|
|
// Handle operators and Delimiters
|
|
if (stream.match(doubleOperators)
|
|
|| stream.match(singleOperators)
|
|
|| stream.match(wordOperators)) {
|
|
return 'operator';
|
|
}
|
|
if (stream.match(singleDelimiters)) {
|
|
return null;
|
|
}
|
|
|
|
if (stream.match(brakets)) {
|
|
return "bracket";
|
|
}
|
|
|
|
if (stream.match(noIndentWords)) {
|
|
state.doInCurrentLine = true;
|
|
|
|
return 'keyword';
|
|
}
|
|
|
|
if (stream.match(doOpening)) {
|
|
indent(stream,state);
|
|
state.doInCurrentLine = true;
|
|
|
|
return 'keyword';
|
|
}
|
|
if (stream.match(opening)) {
|
|
if (! state.doInCurrentLine)
|
|
indent(stream,state);
|
|
else
|
|
state.doInCurrentLine = false;
|
|
|
|
return 'keyword';
|
|
}
|
|
if (stream.match(middle)) {
|
|
return 'keyword';
|
|
}
|
|
|
|
|
|
if (stream.match(doubleClosing)) {
|
|
dedent(stream,state);
|
|
dedent(stream,state);
|
|
|
|
return 'keyword';
|
|
}
|
|
if (stream.match(closing)) {
|
|
if (! state.doInCurrentLine)
|
|
dedent(stream,state);
|
|
else
|
|
state.doInCurrentLine = false;
|
|
|
|
return 'keyword';
|
|
}
|
|
|
|
if (stream.match(keywords)) {
|
|
return 'keyword';
|
|
}
|
|
|
|
if (stream.match(atoms)) {
|
|
return 'atom';
|
|
}
|
|
|
|
if (stream.match(known)) {
|
|
return 'variable-2';
|
|
}
|
|
|
|
if (stream.match(builtinFuncs)) {
|
|
return 'builtin';
|
|
}
|
|
|
|
if (stream.match(builtinObjs)){
|
|
return 'variable-2';
|
|
}
|
|
|
|
if (stream.match(identifiers)) {
|
|
return 'variable';
|
|
}
|
|
|
|
// Handle non-detected items
|
|
stream.next();
|
|
return ERRORCLASS;
|
|
}
|
|
|
|
function tokenStringFactory(delimiter) {
|
|
var singleline = delimiter.length == 1;
|
|
var OUTCLASS = 'string';
|
|
|
|
return function(stream, state) {
|
|
while (!stream.eol()) {
|
|
stream.eatWhile(/[^'"]/);
|
|
if (stream.match(delimiter)) {
|
|
state.tokenize = tokenBase;
|
|
return OUTCLASS;
|
|
} else {
|
|
stream.eat(/['"]/);
|
|
}
|
|
}
|
|
if (singleline) {
|
|
if (parserConf.singleLineStringErrors) {
|
|
return ERRORCLASS;
|
|
} else {
|
|
state.tokenize = tokenBase;
|
|
}
|
|
}
|
|
return OUTCLASS;
|
|
};
|
|
}
|
|
|
|
|
|
function tokenLexer(stream, state) {
|
|
var style = state.tokenize(stream, state);
|
|
var current = stream.current();
|
|
|
|
// Handle '.' connected identifiers
|
|
if (current === '.') {
|
|
style = state.tokenize(stream, state);
|
|
|
|
current = stream.current();
|
|
if (style && (style.substr(0, 8) === 'variable' || style==='builtin' || style==='keyword')){//|| knownWords.indexOf(current.substring(1)) > -1) {
|
|
if (style === 'builtin' || style === 'keyword') style='variable';
|
|
if (knownWords.indexOf(current.substr(1)) > -1) style='variable-2';
|
|
|
|
return style;
|
|
} else {
|
|
return ERRORCLASS;
|
|
}
|
|
}
|
|
|
|
return style;
|
|
}
|
|
|
|
var external = {
|
|
electricChars:"dDpPtTfFeE ",
|
|
startState: function() {
|
|
return {
|
|
tokenize: tokenBase,
|
|
lastToken: null,
|
|
currentIndent: 0,
|
|
nextLineIndent: 0,
|
|
doInCurrentLine: false,
|
|
ignoreKeyword: false
|
|
|
|
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.sol()) {
|
|
state.currentIndent += state.nextLineIndent;
|
|
state.nextLineIndent = 0;
|
|
state.doInCurrentLine = 0;
|
|
}
|
|
var style = tokenLexer(stream, state);
|
|
|
|
state.lastToken = {style:style, content: stream.current()};
|
|
|
|
if (style==='space') style=null;
|
|
|
|
return style;
|
|
},
|
|
|
|
indent: function(state, textAfter) {
|
|
var trueText = textAfter.replace(/^\s+|\s+$/g, '') ;
|
|
if (trueText.match(closing) || trueText.match(doubleClosing) || trueText.match(middle)) return conf.indentUnit*(state.currentIndent-1);
|
|
if(state.currentIndent < 0) return 0;
|
|
return state.currentIndent * conf.indentUnit;
|
|
}
|
|
|
|
};
|
|
return external;
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/vbscript", "vbscript");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("velocity", function() {
|
|
function parseWords(str) {
|
|
var obj = {}, words = str.split(" ");
|
|
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
|
return obj;
|
|
}
|
|
|
|
var keywords = parseWords("#end #else #break #stop #[[ #]] " +
|
|
"#{end} #{else} #{break} #{stop}");
|
|
var functions = parseWords("#if #elseif #foreach #set #include #parse #macro #define #evaluate " +
|
|
"#{if} #{elseif} #{foreach} #{set} #{include} #{parse} #{macro} #{define} #{evaluate}");
|
|
var specials = parseWords("$foreach.count $foreach.hasNext $foreach.first $foreach.last $foreach.topmost $foreach.parent.count $foreach.parent.hasNext $foreach.parent.first $foreach.parent.last $foreach.parent $velocityCount $!bodyContent $bodyContent");
|
|
var isOperatorChar = /[+\-*&%=<>!?:\/|]/;
|
|
|
|
function chain(stream, state, f) {
|
|
state.tokenize = f;
|
|
return f(stream, state);
|
|
}
|
|
function tokenBase(stream, state) {
|
|
var beforeParams = state.beforeParams;
|
|
state.beforeParams = false;
|
|
var ch = stream.next();
|
|
// start of unparsed string?
|
|
if ((ch == "'") && state.inParams) {
|
|
state.lastTokenWasBuiltin = false;
|
|
return chain(stream, state, tokenString(ch));
|
|
}
|
|
// start of parsed string?
|
|
else if ((ch == '"')) {
|
|
state.lastTokenWasBuiltin = false;
|
|
if (state.inString) {
|
|
state.inString = false;
|
|
return "string";
|
|
}
|
|
else if (state.inParams)
|
|
return chain(stream, state, tokenString(ch));
|
|
}
|
|
// is it one of the special signs []{}().,;? Seperator?
|
|
else if (/[\[\]{}\(\),;\.]/.test(ch)) {
|
|
if (ch == "(" && beforeParams)
|
|
state.inParams = true;
|
|
else if (ch == ")") {
|
|
state.inParams = false;
|
|
state.lastTokenWasBuiltin = true;
|
|
}
|
|
return null;
|
|
}
|
|
// start of a number value?
|
|
else if (/\d/.test(ch)) {
|
|
state.lastTokenWasBuiltin = false;
|
|
stream.eatWhile(/[\w\.]/);
|
|
return "number";
|
|
}
|
|
// multi line comment?
|
|
else if (ch == "#" && stream.eat("*")) {
|
|
state.lastTokenWasBuiltin = false;
|
|
return chain(stream, state, tokenComment);
|
|
}
|
|
// unparsed content?
|
|
else if (ch == "#" && stream.match(/ *\[ *\[/)) {
|
|
state.lastTokenWasBuiltin = false;
|
|
return chain(stream, state, tokenUnparsed);
|
|
}
|
|
// single line comment?
|
|
else if (ch == "#" && stream.eat("#")) {
|
|
state.lastTokenWasBuiltin = false;
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
// variable?
|
|
else if (ch == "$") {
|
|
stream.eatWhile(/[\w\d\$_\.{}]/);
|
|
// is it one of the specials?
|
|
if (specials && specials.propertyIsEnumerable(stream.current())) {
|
|
return "keyword";
|
|
}
|
|
else {
|
|
state.lastTokenWasBuiltin = true;
|
|
state.beforeParams = true;
|
|
return "builtin";
|
|
}
|
|
}
|
|
// is it a operator?
|
|
else if (isOperatorChar.test(ch)) {
|
|
state.lastTokenWasBuiltin = false;
|
|
stream.eatWhile(isOperatorChar);
|
|
return "operator";
|
|
}
|
|
else {
|
|
// get the whole word
|
|
stream.eatWhile(/[\w\$_{}@]/);
|
|
var word = stream.current();
|
|
// is it one of the listed keywords?
|
|
if (keywords && keywords.propertyIsEnumerable(word))
|
|
return "keyword";
|
|
// is it one of the listed functions?
|
|
if (functions && functions.propertyIsEnumerable(word) ||
|
|
(stream.current().match(/^#@?[a-z0-9_]+ *$/i) && stream.peek()=="(") &&
|
|
!(functions && functions.propertyIsEnumerable(word.toLowerCase()))) {
|
|
state.beforeParams = true;
|
|
state.lastTokenWasBuiltin = false;
|
|
return "keyword";
|
|
}
|
|
if (state.inString) {
|
|
state.lastTokenWasBuiltin = false;
|
|
return "string";
|
|
}
|
|
if (stream.pos > word.length && stream.string.charAt(stream.pos-word.length-1)=="." && state.lastTokenWasBuiltin)
|
|
return "builtin";
|
|
// default: just a "word"
|
|
state.lastTokenWasBuiltin = false;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function tokenString(quote) {
|
|
return function(stream, state) {
|
|
var escaped = false, next, end = false;
|
|
while ((next = stream.next()) != null) {
|
|
if ((next == quote) && !escaped) {
|
|
end = true;
|
|
break;
|
|
}
|
|
if (quote=='"' && stream.peek() == '$' && !escaped) {
|
|
state.inString = true;
|
|
end = true;
|
|
break;
|
|
}
|
|
escaped = !escaped && next == "\\";
|
|
}
|
|
if (end) state.tokenize = tokenBase;
|
|
return "string";
|
|
};
|
|
}
|
|
|
|
function tokenComment(stream, state) {
|
|
var maybeEnd = false, ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "#" && maybeEnd) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
maybeEnd = (ch == "*");
|
|
}
|
|
return "comment";
|
|
}
|
|
|
|
function tokenUnparsed(stream, state) {
|
|
var maybeEnd = 0, ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "#" && maybeEnd == 2) {
|
|
state.tokenize = tokenBase;
|
|
break;
|
|
}
|
|
if (ch == "]")
|
|
maybeEnd++;
|
|
else if (ch != " ")
|
|
maybeEnd = 0;
|
|
}
|
|
return "meta";
|
|
}
|
|
// Interface
|
|
|
|
return {
|
|
startState: function() {
|
|
return {
|
|
tokenize: tokenBase,
|
|
beforeParams: false,
|
|
inParams: false,
|
|
inString: false,
|
|
lastTokenWasBuiltin: false
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.eatSpace()) return null;
|
|
return state.tokenize(stream, state);
|
|
},
|
|
blockCommentStart: "#*",
|
|
blockCommentEnd: "*#",
|
|
lineComment: "##",
|
|
fold: "velocity"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/velocity", "velocity");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("xquery", function() {
|
|
|
|
// The keywords object is set to the result of this self executing
|
|
// function. Each keyword is a property of the keywords object whose
|
|
// value is {type: atype, style: astyle}
|
|
var keywords = function(){
|
|
// conveinence functions used to build keywords object
|
|
function kw(type) {return {type: type, style: "keyword"};}
|
|
var A = kw("keyword a")
|
|
, B = kw("keyword b")
|
|
, C = kw("keyword c")
|
|
, operator = kw("operator")
|
|
, atom = {type: "atom", style: "atom"}
|
|
, punctuation = {type: "punctuation", style: null}
|
|
, qualifier = {type: "axis_specifier", style: "qualifier"};
|
|
|
|
// kwObj is what is return from this function at the end
|
|
var kwObj = {
|
|
'if': A, 'switch': A, 'while': A, 'for': A,
|
|
'else': B, 'then': B, 'try': B, 'finally': B, 'catch': B,
|
|
'element': C, 'attribute': C, 'let': C, 'implements': C, 'import': C, 'module': C, 'namespace': C,
|
|
'return': C, 'super': C, 'this': C, 'throws': C, 'where': C, 'private': C,
|
|
',': punctuation,
|
|
'null': atom, 'fn:false()': atom, 'fn:true()': atom
|
|
};
|
|
|
|
// a list of 'basic' keywords. For each add a property to kwObj with the value of
|
|
// {type: basic[i], style: "keyword"} e.g. 'after' --> {type: "after", style: "keyword"}
|
|
var basic = ['after','ancestor','ancestor-or-self','and','as','ascending','assert','attribute','before',
|
|
'by','case','cast','child','comment','declare','default','define','descendant','descendant-or-self',
|
|
'descending','document','document-node','element','else','eq','every','except','external','following',
|
|
'following-sibling','follows','for','function','if','import','in','instance','intersect','item',
|
|
'let','module','namespace','node','node','of','only','or','order','parent','precedes','preceding',
|
|
'preceding-sibling','processing-instruction','ref','return','returns','satisfies','schema','schema-element',
|
|
'self','some','sortby','stable','text','then','to','treat','typeswitch','union','variable','version','where',
|
|
'xquery', 'empty-sequence'];
|
|
for(var i=0, l=basic.length; i < l; i++) { kwObj[basic[i]] = kw(basic[i]);};
|
|
|
|
// a list of types. For each add a property to kwObj with the value of
|
|
// {type: "atom", style: "atom"}
|
|
var types = ['xs:string', 'xs:float', 'xs:decimal', 'xs:double', 'xs:integer', 'xs:boolean', 'xs:date', 'xs:dateTime',
|
|
'xs:time', 'xs:duration', 'xs:dayTimeDuration', 'xs:time', 'xs:yearMonthDuration', 'numeric', 'xs:hexBinary',
|
|
'xs:base64Binary', 'xs:anyURI', 'xs:QName', 'xs:byte','xs:boolean','xs:anyURI','xf:yearMonthDuration'];
|
|
for(var i=0, l=types.length; i < l; i++) { kwObj[types[i]] = atom;};
|
|
|
|
// each operator will add a property to kwObj with value of {type: "operator", style: "keyword"}
|
|
var operators = ['eq', 'ne', 'lt', 'le', 'gt', 'ge', ':=', '=', '>', '>=', '<', '<=', '.', '|', '?', 'and', 'or', 'div', 'idiv', 'mod', '*', '/', '+', '-'];
|
|
for(var i=0, l=operators.length; i < l; i++) { kwObj[operators[i]] = operator;};
|
|
|
|
// each axis_specifiers will add a property to kwObj with value of {type: "axis_specifier", style: "qualifier"}
|
|
var axis_specifiers = ["self::", "attribute::", "child::", "descendant::", "descendant-or-self::", "parent::",
|
|
"ancestor::", "ancestor-or-self::", "following::", "preceding::", "following-sibling::", "preceding-sibling::"];
|
|
for(var i=0, l=axis_specifiers.length; i < l; i++) { kwObj[axis_specifiers[i]] = qualifier; };
|
|
|
|
return kwObj;
|
|
}();
|
|
|
|
// Used as scratch variables to communicate multiple values without
|
|
// consing up tons of objects.
|
|
var type, content;
|
|
|
|
function ret(tp, style, cont) {
|
|
type = tp; content = cont;
|
|
return style;
|
|
}
|
|
|
|
function chain(stream, state, f) {
|
|
state.tokenize = f;
|
|
return f(stream, state);
|
|
}
|
|
|
|
// the primary mode tokenizer
|
|
function tokenBase(stream, state) {
|
|
var ch = stream.next(),
|
|
mightBeFunction = false,
|
|
isEQName = isEQNameAhead(stream);
|
|
|
|
// an XML tag (if not in some sub, chained tokenizer)
|
|
if (ch == "<") {
|
|
if(stream.match("!--", true))
|
|
return chain(stream, state, tokenXMLComment);
|
|
|
|
if(stream.match("![CDATA", false)) {
|
|
state.tokenize = tokenCDATA;
|
|
return ret("tag", "tag");
|
|
}
|
|
|
|
if(stream.match("?", false)) {
|
|
return chain(stream, state, tokenPreProcessing);
|
|
}
|
|
|
|
var isclose = stream.eat("/");
|
|
stream.eatSpace();
|
|
var tagName = "", c;
|
|
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
|
|
|
|
return chain(stream, state, tokenTag(tagName, isclose));
|
|
}
|
|
// start code block
|
|
else if(ch == "{") {
|
|
pushStateStack(state,{ type: "codeblock"});
|
|
return ret("", null);
|
|
}
|
|
// end code block
|
|
else if(ch == "}") {
|
|
popStateStack(state);
|
|
return ret("", null);
|
|
}
|
|
// if we're in an XML block
|
|
else if(isInXmlBlock(state)) {
|
|
if(ch == ">")
|
|
return ret("tag", "tag");
|
|
else if(ch == "/" && stream.eat(">")) {
|
|
popStateStack(state);
|
|
return ret("tag", "tag");
|
|
}
|
|
else
|
|
return ret("word", "variable");
|
|
}
|
|
// if a number
|
|
else if (/\d/.test(ch)) {
|
|
stream.match(/^\d*(?:\.\d*)?(?:E[+\-]?\d+)?/);
|
|
return ret("number", "atom");
|
|
}
|
|
// comment start
|
|
else if (ch === "(" && stream.eat(":")) {
|
|
pushStateStack(state, { type: "comment"});
|
|
return chain(stream, state, tokenComment);
|
|
}
|
|
// quoted string
|
|
else if ( !isEQName && (ch === '"' || ch === "'"))
|
|
return chain(stream, state, tokenString(ch));
|
|
// variable
|
|
else if(ch === "$") {
|
|
return chain(stream, state, tokenVariable);
|
|
}
|
|
// assignment
|
|
else if(ch ===":" && stream.eat("=")) {
|
|
return ret("operator", "keyword");
|
|
}
|
|
// open paren
|
|
else if(ch === "(") {
|
|
pushStateStack(state, { type: "paren"});
|
|
return ret("", null);
|
|
}
|
|
// close paren
|
|
else if(ch === ")") {
|
|
popStateStack(state);
|
|
return ret("", null);
|
|
}
|
|
// open paren
|
|
else if(ch === "[") {
|
|
pushStateStack(state, { type: "bracket"});
|
|
return ret("", null);
|
|
}
|
|
// close paren
|
|
else if(ch === "]") {
|
|
popStateStack(state);
|
|
return ret("", null);
|
|
}
|
|
else {
|
|
var known = keywords.propertyIsEnumerable(ch) && keywords[ch];
|
|
|
|
// if there's a EQName ahead, consume the rest of the string portion, it's likely a function
|
|
if(isEQName && ch === '\"') while(stream.next() !== '"'){}
|
|
if(isEQName && ch === '\'') while(stream.next() !== '\''){}
|
|
|
|
// gobble up a word if the character is not known
|
|
if(!known) stream.eatWhile(/[\w\$_-]/);
|
|
|
|
// gobble a colon in the case that is a lib func type call fn:doc
|
|
var foundColon = stream.eat(":");
|
|
|
|
// if there's not a second colon, gobble another word. Otherwise, it's probably an axis specifier
|
|
// which should get matched as a keyword
|
|
if(!stream.eat(":") && foundColon) {
|
|
stream.eatWhile(/[\w\$_-]/);
|
|
}
|
|
// if the next non whitespace character is an open paren, this is probably a function (if not a keyword of other sort)
|
|
if(stream.match(/^[ \t]*\(/, false)) {
|
|
mightBeFunction = true;
|
|
}
|
|
// is the word a keyword?
|
|
var word = stream.current();
|
|
known = keywords.propertyIsEnumerable(word) && keywords[word];
|
|
|
|
// if we think it's a function call but not yet known,
|
|
// set style to variable for now for lack of something better
|
|
if(mightBeFunction && !known) known = {type: "function_call", style: "variable def"};
|
|
|
|
// if the previous word was element, attribute, axis specifier, this word should be the name of that
|
|
if(isInXmlConstructor(state)) {
|
|
popStateStack(state);
|
|
return ret("word", "variable", word);
|
|
}
|
|
// as previously checked, if the word is element,attribute, axis specifier, call it an "xmlconstructor" and
|
|
// push the stack so we know to look for it on the next word
|
|
if(word == "element" || word == "attribute" || known.type == "axis_specifier") pushStateStack(state, {type: "xmlconstructor"});
|
|
|
|
// if the word is known, return the details of that else just call this a generic 'word'
|
|
return known ? ret(known.type, known.style, word) :
|
|
ret("word", "variable", word);
|
|
}
|
|
}
|
|
|
|
// handle comments, including nested
|
|
function tokenComment(stream, state) {
|
|
var maybeEnd = false, maybeNested = false, nestedCount = 0, ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == ")" && maybeEnd) {
|
|
if(nestedCount > 0)
|
|
nestedCount--;
|
|
else {
|
|
popStateStack(state);
|
|
break;
|
|
}
|
|
}
|
|
else if(ch == ":" && maybeNested) {
|
|
nestedCount++;
|
|
}
|
|
maybeEnd = (ch == ":");
|
|
maybeNested = (ch == "(");
|
|
}
|
|
|
|
return ret("comment", "comment");
|
|
}
|
|
|
|
// tokenizer for string literals
|
|
// optionally pass a tokenizer function to set state.tokenize back to when finished
|
|
function tokenString(quote, f) {
|
|
return function(stream, state) {
|
|
var ch;
|
|
|
|
if(isInString(state) && stream.current() == quote) {
|
|
popStateStack(state);
|
|
if(f) state.tokenize = f;
|
|
return ret("string", "string");
|
|
}
|
|
|
|
pushStateStack(state, { type: "string", name: quote, tokenize: tokenString(quote, f) });
|
|
|
|
// if we're in a string and in an XML block, allow an embedded code block
|
|
if(stream.match("{", false) && isInXmlAttributeBlock(state)) {
|
|
state.tokenize = tokenBase;
|
|
return ret("string", "string");
|
|
}
|
|
|
|
|
|
while (ch = stream.next()) {
|
|
if (ch == quote) {
|
|
popStateStack(state);
|
|
if(f) state.tokenize = f;
|
|
break;
|
|
}
|
|
else {
|
|
// if we're in a string and in an XML block, allow an embedded code block in an attribute
|
|
if(stream.match("{", false) && isInXmlAttributeBlock(state)) {
|
|
state.tokenize = tokenBase;
|
|
return ret("string", "string");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return ret("string", "string");
|
|
};
|
|
}
|
|
|
|
// tokenizer for variables
|
|
function tokenVariable(stream, state) {
|
|
var isVariableChar = /[\w\$_-]/;
|
|
|
|
// a variable may start with a quoted EQName so if the next character is quote, consume to the next quote
|
|
if(stream.eat("\"")) {
|
|
while(stream.next() !== '\"'){};
|
|
stream.eat(":");
|
|
} else {
|
|
stream.eatWhile(isVariableChar);
|
|
if(!stream.match(":=", false)) stream.eat(":");
|
|
}
|
|
stream.eatWhile(isVariableChar);
|
|
state.tokenize = tokenBase;
|
|
return ret("variable", "variable");
|
|
}
|
|
|
|
// tokenizer for XML tags
|
|
function tokenTag(name, isclose) {
|
|
return function(stream, state) {
|
|
stream.eatSpace();
|
|
if(isclose && stream.eat(">")) {
|
|
popStateStack(state);
|
|
state.tokenize = tokenBase;
|
|
return ret("tag", "tag");
|
|
}
|
|
// self closing tag without attributes?
|
|
if(!stream.eat("/"))
|
|
pushStateStack(state, { type: "tag", name: name, tokenize: tokenBase});
|
|
if(!stream.eat(">")) {
|
|
state.tokenize = tokenAttribute;
|
|
return ret("tag", "tag");
|
|
}
|
|
else {
|
|
state.tokenize = tokenBase;
|
|
}
|
|
return ret("tag", "tag");
|
|
};
|
|
}
|
|
|
|
// tokenizer for XML attributes
|
|
function tokenAttribute(stream, state) {
|
|
var ch = stream.next();
|
|
|
|
if(ch == "/" && stream.eat(">")) {
|
|
if(isInXmlAttributeBlock(state)) popStateStack(state);
|
|
if(isInXmlBlock(state)) popStateStack(state);
|
|
return ret("tag", "tag");
|
|
}
|
|
if(ch == ">") {
|
|
if(isInXmlAttributeBlock(state)) popStateStack(state);
|
|
return ret("tag", "tag");
|
|
}
|
|
if(ch == "=")
|
|
return ret("", null);
|
|
// quoted string
|
|
if (ch == '"' || ch == "'")
|
|
return chain(stream, state, tokenString(ch, tokenAttribute));
|
|
|
|
if(!isInXmlAttributeBlock(state))
|
|
pushStateStack(state, { type: "attribute", tokenize: tokenAttribute});
|
|
|
|
stream.eat(/[a-zA-Z_:]/);
|
|
stream.eatWhile(/[-a-zA-Z0-9_:.]/);
|
|
stream.eatSpace();
|
|
|
|
// the case where the attribute has not value and the tag was closed
|
|
if(stream.match(">", false) || stream.match("/", false)) {
|
|
popStateStack(state);
|
|
state.tokenize = tokenBase;
|
|
}
|
|
|
|
return ret("attribute", "attribute");
|
|
}
|
|
|
|
// handle comments, including nested
|
|
function tokenXMLComment(stream, state) {
|
|
var ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "-" && stream.match("->", true)) {
|
|
state.tokenize = tokenBase;
|
|
return ret("comment", "comment");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// handle CDATA
|
|
function tokenCDATA(stream, state) {
|
|
var ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "]" && stream.match("]", true)) {
|
|
state.tokenize = tokenBase;
|
|
return ret("comment", "comment");
|
|
}
|
|
}
|
|
}
|
|
|
|
// handle preprocessing instructions
|
|
function tokenPreProcessing(stream, state) {
|
|
var ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "?" && stream.match(">", true)) {
|
|
state.tokenize = tokenBase;
|
|
return ret("comment", "comment meta");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// functions to test the current context of the state
|
|
function isInXmlBlock(state) { return isIn(state, "tag"); }
|
|
function isInXmlAttributeBlock(state) { return isIn(state, "attribute"); }
|
|
function isInXmlConstructor(state) { return isIn(state, "xmlconstructor"); }
|
|
function isInString(state) { return isIn(state, "string"); }
|
|
|
|
function isEQNameAhead(stream) {
|
|
// assume we've already eaten a quote (")
|
|
if(stream.current() === '"')
|
|
return stream.match(/^[^\"]+\"\:/, false);
|
|
else if(stream.current() === '\'')
|
|
return stream.match(/^[^\"]+\'\:/, false);
|
|
else
|
|
return false;
|
|
}
|
|
|
|
function isIn(state, type) {
|
|
return (state.stack.length && state.stack[state.stack.length - 1].type == type);
|
|
}
|
|
|
|
function pushStateStack(state, newState) {
|
|
state.stack.push(newState);
|
|
}
|
|
|
|
function popStateStack(state) {
|
|
state.stack.pop();
|
|
var reinstateTokenize = state.stack.length && state.stack[state.stack.length-1].tokenize;
|
|
state.tokenize = reinstateTokenize || tokenBase;
|
|
}
|
|
|
|
// the interface for the mode API
|
|
return {
|
|
startState: function() {
|
|
return {
|
|
tokenize: tokenBase,
|
|
cc: [],
|
|
stack: []
|
|
};
|
|
},
|
|
|
|
token: function(stream, state) {
|
|
if (stream.eatSpace()) return null;
|
|
var style = state.tokenize(stream, state);
|
|
return style;
|
|
},
|
|
|
|
blockCommentStart: "(:",
|
|
blockCommentEnd: ":)"
|
|
|
|
};
|
|
|
|
});
|
|
|
|
CodeMirror.defineMIME("application/xquery", "xquery");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("yaml", function() {
|
|
|
|
var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
|
|
var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');
|
|
|
|
return {
|
|
token: function(stream, state) {
|
|
var ch = stream.peek();
|
|
var esc = state.escaped;
|
|
state.escaped = false;
|
|
/* comments */
|
|
if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {
|
|
stream.skipToEnd();
|
|
return "comment";
|
|
}
|
|
|
|
if (stream.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))
|
|
return "string";
|
|
|
|
if (state.literal && stream.indentation() > state.keyCol) {
|
|
stream.skipToEnd(); return "string";
|
|
} else if (state.literal) { state.literal = false; }
|
|
if (stream.sol()) {
|
|
state.keyCol = 0;
|
|
state.pair = false;
|
|
state.pairStart = false;
|
|
/* document start */
|
|
if(stream.match(/---/)) { return "def"; }
|
|
/* document end */
|
|
if (stream.match(/\.\.\./)) { return "def"; }
|
|
/* array list item */
|
|
if (stream.match(/\s*-\s+/)) { return 'meta'; }
|
|
}
|
|
/* inline pairs/lists */
|
|
if (stream.match(/^(\{|\}|\[|\])/)) {
|
|
if (ch == '{')
|
|
state.inlinePairs++;
|
|
else if (ch == '}')
|
|
state.inlinePairs--;
|
|
else if (ch == '[')
|
|
state.inlineList++;
|
|
else
|
|
state.inlineList--;
|
|
return 'meta';
|
|
}
|
|
|
|
/* list seperator */
|
|
if (state.inlineList > 0 && !esc && ch == ',') {
|
|
stream.next();
|
|
return 'meta';
|
|
}
|
|
/* pairs seperator */
|
|
if (state.inlinePairs > 0 && !esc && ch == ',') {
|
|
state.keyCol = 0;
|
|
state.pair = false;
|
|
state.pairStart = false;
|
|
stream.next();
|
|
return 'meta';
|
|
}
|
|
|
|
/* start of value of a pair */
|
|
if (state.pairStart) {
|
|
/* block literals */
|
|
if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
|
|
/* references */
|
|
if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
|
|
/* numbers */
|
|
if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
|
|
if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
|
|
/* keywords */
|
|
if (stream.match(keywordRegex)) { return 'keyword'; }
|
|
}
|
|
|
|
/* pairs (associative arrays) -> key */
|
|
if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) {
|
|
state.pair = true;
|
|
state.keyCol = stream.indentation();
|
|
return "atom";
|
|
}
|
|
if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
|
|
|
|
/* nothing found, continue */
|
|
state.pairStart = false;
|
|
state.escaped = (ch == '\\');
|
|
stream.next();
|
|
return null;
|
|
},
|
|
startState: function() {
|
|
return {
|
|
pair: false,
|
|
pairStart: false,
|
|
keyCol: 0,
|
|
inlinePairs: 0,
|
|
inlineList: 0,
|
|
literal: false,
|
|
escaped: false
|
|
};
|
|
}
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-yaml", "yaml");
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
/*jshint unused:true, eqnull:true, curly:true, bitwise:true */
|
|
/*jshint undef:true, latedef:true, trailing:true */
|
|
/*global CodeMirror:true */
|
|
|
|
// erlang mode.
|
|
// tokenizer -> token types -> CodeMirror styles
|
|
// tokenizer maintains a parse stack
|
|
// indenter uses the parse stack
|
|
|
|
// TODO indenter:
|
|
// bit syntax
|
|
// old guard/bif/conversion clashes (e.g. "float/1")
|
|
// type/spec/opaque
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMIME("text/x-erlang", "erlang");
|
|
|
|
CodeMirror.defineMode("erlang", function(cmCfg) {
|
|
"use strict";
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// constants
|
|
|
|
var typeWords = [
|
|
"-type", "-spec", "-export_type", "-opaque"];
|
|
|
|
var keywordWords = [
|
|
"after","begin","catch","case","cond","end","fun","if",
|
|
"let","of","query","receive","try","when"];
|
|
|
|
var separatorRE = /[\->,;]/;
|
|
var separatorWords = [
|
|
"->",";",","];
|
|
|
|
var operatorAtomWords = [
|
|
"and","andalso","band","bnot","bor","bsl","bsr","bxor",
|
|
"div","not","or","orelse","rem","xor"];
|
|
|
|
var operatorSymbolRE = /[\+\-\*\/<>=\|:!]/;
|
|
var operatorSymbolWords = [
|
|
"=","+","-","*","/",">",">=","<","=<","=:=","==","=/=","/=","||","<-","!"];
|
|
|
|
var openParenRE = /[<\(\[\{]/;
|
|
var openParenWords = [
|
|
"<<","(","[","{"];
|
|
|
|
var closeParenRE = /[>\)\]\}]/;
|
|
var closeParenWords = [
|
|
"}","]",")",">>"];
|
|
|
|
var guardWords = [
|
|
"is_atom","is_binary","is_bitstring","is_boolean","is_float",
|
|
"is_function","is_integer","is_list","is_number","is_pid",
|
|
"is_port","is_record","is_reference","is_tuple",
|
|
"atom","binary","bitstring","boolean","function","integer","list",
|
|
"number","pid","port","record","reference","tuple"];
|
|
|
|
var bifWords = [
|
|
"abs","adler32","adler32_combine","alive","apply","atom_to_binary",
|
|
"atom_to_list","binary_to_atom","binary_to_existing_atom",
|
|
"binary_to_list","binary_to_term","bit_size","bitstring_to_list",
|
|
"byte_size","check_process_code","contact_binary","crc32",
|
|
"crc32_combine","date","decode_packet","delete_module",
|
|
"disconnect_node","element","erase","exit","float","float_to_list",
|
|
"garbage_collect","get","get_keys","group_leader","halt","hd",
|
|
"integer_to_list","internal_bif","iolist_size","iolist_to_binary",
|
|
"is_alive","is_atom","is_binary","is_bitstring","is_boolean",
|
|
"is_float","is_function","is_integer","is_list","is_number","is_pid",
|
|
"is_port","is_process_alive","is_record","is_reference","is_tuple",
|
|
"length","link","list_to_atom","list_to_binary","list_to_bitstring",
|
|
"list_to_existing_atom","list_to_float","list_to_integer",
|
|
"list_to_pid","list_to_tuple","load_module","make_ref","module_loaded",
|
|
"monitor_node","node","node_link","node_unlink","nodes","notalive",
|
|
"now","open_port","pid_to_list","port_close","port_command",
|
|
"port_connect","port_control","pre_loaded","process_flag",
|
|
"process_info","processes","purge_module","put","register",
|
|
"registered","round","self","setelement","size","spawn","spawn_link",
|
|
"spawn_monitor","spawn_opt","split_binary","statistics",
|
|
"term_to_binary","time","throw","tl","trunc","tuple_size",
|
|
"tuple_to_list","unlink","unregister","whereis"];
|
|
|
|
// upper case: [A-Z] [Ø-Þ] [À-Ö]
|
|
// lower case: [a-z] [ß-ö] [ø-ÿ]
|
|
var anumRE = /[\w@Ø-ÞÀ-Öß-öø-ÿ]/;
|
|
var escapesRE =
|
|
/[0-7]{1,3}|[bdefnrstv\\"']|\^[a-zA-Z]|x[0-9a-zA-Z]{2}|x{[0-9a-zA-Z]+}/;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// tokenizer
|
|
|
|
function tokenizer(stream,state) {
|
|
// in multi-line string
|
|
if (state.in_string) {
|
|
state.in_string = (!doubleQuote(stream));
|
|
return rval(state,stream,"string");
|
|
}
|
|
|
|
// in multi-line atom
|
|
if (state.in_atom) {
|
|
state.in_atom = (!singleQuote(stream));
|
|
return rval(state,stream,"atom");
|
|
}
|
|
|
|
// whitespace
|
|
if (stream.eatSpace()) {
|
|
return rval(state,stream,"whitespace");
|
|
}
|
|
|
|
// attributes and type specs
|
|
if (!peekToken(state) &&
|
|
stream.match(/-\s*[a-zß-öø-ÿ][\wØ-ÞÀ-Öß-öø-ÿ]*/)) {
|
|
if (is_member(stream.current(),typeWords)) {
|
|
return rval(state,stream,"type");
|
|
}else{
|
|
return rval(state,stream,"attribute");
|
|
}
|
|
}
|
|
|
|
var ch = stream.next();
|
|
|
|
// comment
|
|
if (ch == '%') {
|
|
stream.skipToEnd();
|
|
return rval(state,stream,"comment");
|
|
}
|
|
|
|
// colon
|
|
if (ch == ":") {
|
|
return rval(state,stream,"colon");
|
|
}
|
|
|
|
// macro
|
|
if (ch == '?') {
|
|
stream.eatSpace();
|
|
stream.eatWhile(anumRE);
|
|
return rval(state,stream,"macro");
|
|
}
|
|
|
|
// record
|
|
if (ch == "#") {
|
|
stream.eatSpace();
|
|
stream.eatWhile(anumRE);
|
|
return rval(state,stream,"record");
|
|
}
|
|
|
|
// dollar escape
|
|
if (ch == "$") {
|
|
if (stream.next() == "\\" && !stream.match(escapesRE)) {
|
|
return rval(state,stream,"error");
|
|
}
|
|
return rval(state,stream,"number");
|
|
}
|
|
|
|
// dot
|
|
if (ch == ".") {
|
|
return rval(state,stream,"dot");
|
|
}
|
|
|
|
// quoted atom
|
|
if (ch == '\'') {
|
|
if (!(state.in_atom = (!singleQuote(stream)))) {
|
|
if (stream.match(/\s*\/\s*[0-9]/,false)) {
|
|
stream.match(/\s*\/\s*[0-9]/,true);
|
|
return rval(state,stream,"fun"); // 'f'/0 style fun
|
|
}
|
|
if (stream.match(/\s*\(/,false) || stream.match(/\s*:/,false)) {
|
|
return rval(state,stream,"function");
|
|
}
|
|
}
|
|
return rval(state,stream,"atom");
|
|
}
|
|
|
|
// string
|
|
if (ch == '"') {
|
|
state.in_string = (!doubleQuote(stream));
|
|
return rval(state,stream,"string");
|
|
}
|
|
|
|
// variable
|
|
if (/[A-Z_Ø-ÞÀ-Ö]/.test(ch)) {
|
|
stream.eatWhile(anumRE);
|
|
return rval(state,stream,"variable");
|
|
}
|
|
|
|
// atom/keyword/BIF/function
|
|
if (/[a-z_ß-öø-ÿ]/.test(ch)) {
|
|
stream.eatWhile(anumRE);
|
|
|
|
if (stream.match(/\s*\/\s*[0-9]/,false)) {
|
|
stream.match(/\s*\/\s*[0-9]/,true);
|
|
return rval(state,stream,"fun"); // f/0 style fun
|
|
}
|
|
|
|
var w = stream.current();
|
|
|
|
if (is_member(w,keywordWords)) {
|
|
return rval(state,stream,"keyword");
|
|
}else if (is_member(w,operatorAtomWords)) {
|
|
return rval(state,stream,"operator");
|
|
}else if (stream.match(/\s*\(/,false)) {
|
|
// 'put' and 'erlang:put' are bifs, 'foo:put' is not
|
|
if (is_member(w,bifWords) &&
|
|
((peekToken(state).token != ":") ||
|
|
(peekToken(state,2).token == "erlang"))) {
|
|
return rval(state,stream,"builtin");
|
|
}else if (is_member(w,guardWords)) {
|
|
return rval(state,stream,"guard");
|
|
}else{
|
|
return rval(state,stream,"function");
|
|
}
|
|
}else if (is_member(w,operatorAtomWords)) {
|
|
return rval(state,stream,"operator");
|
|
}else if (lookahead(stream) == ":") {
|
|
if (w == "erlang") {
|
|
return rval(state,stream,"builtin");
|
|
} else {
|
|
return rval(state,stream,"function");
|
|
}
|
|
}else if (is_member(w,["true","false"])) {
|
|
return rval(state,stream,"boolean");
|
|
}else if (is_member(w,["true","false"])) {
|
|
return rval(state,stream,"boolean");
|
|
}else{
|
|
return rval(state,stream,"atom");
|
|
}
|
|
}
|
|
|
|
// number
|
|
var digitRE = /[0-9]/;
|
|
var radixRE = /[0-9a-zA-Z]/; // 36#zZ style int
|
|
if (digitRE.test(ch)) {
|
|
stream.eatWhile(digitRE);
|
|
if (stream.eat('#')) { // 36#aZ style integer
|
|
if (!stream.eatWhile(radixRE)) {
|
|
stream.backUp(1); //"36#" - syntax error
|
|
}
|
|
} else if (stream.eat('.')) { // float
|
|
if (!stream.eatWhile(digitRE)) {
|
|
stream.backUp(1); // "3." - probably end of function
|
|
} else {
|
|
if (stream.eat(/[eE]/)) { // float with exponent
|
|
if (stream.eat(/[-+]/)) {
|
|
if (!stream.eatWhile(digitRE)) {
|
|
stream.backUp(2); // "2e-" - syntax error
|
|
}
|
|
} else {
|
|
if (!stream.eatWhile(digitRE)) {
|
|
stream.backUp(1); // "2e" - syntax error
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return rval(state,stream,"number"); // normal integer
|
|
}
|
|
|
|
// open parens
|
|
if (nongreedy(stream,openParenRE,openParenWords)) {
|
|
return rval(state,stream,"open_paren");
|
|
}
|
|
|
|
// close parens
|
|
if (nongreedy(stream,closeParenRE,closeParenWords)) {
|
|
return rval(state,stream,"close_paren");
|
|
}
|
|
|
|
// separators
|
|
if (greedy(stream,separatorRE,separatorWords)) {
|
|
return rval(state,stream,"separator");
|
|
}
|
|
|
|
// operators
|
|
if (greedy(stream,operatorSymbolRE,operatorSymbolWords)) {
|
|
return rval(state,stream,"operator");
|
|
}
|
|
|
|
return rval(state,stream,null);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// utilities
|
|
function nongreedy(stream,re,words) {
|
|
if (stream.current().length == 1 && re.test(stream.current())) {
|
|
stream.backUp(1);
|
|
while (re.test(stream.peek())) {
|
|
stream.next();
|
|
if (is_member(stream.current(),words)) {
|
|
return true;
|
|
}
|
|
}
|
|
stream.backUp(stream.current().length-1);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function greedy(stream,re,words) {
|
|
if (stream.current().length == 1 && re.test(stream.current())) {
|
|
while (re.test(stream.peek())) {
|
|
stream.next();
|
|
}
|
|
while (0 < stream.current().length) {
|
|
if (is_member(stream.current(),words)) {
|
|
return true;
|
|
}else{
|
|
stream.backUp(1);
|
|
}
|
|
}
|
|
stream.next();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function doubleQuote(stream) {
|
|
return quote(stream, '"', '\\');
|
|
}
|
|
|
|
function singleQuote(stream) {
|
|
return quote(stream,'\'','\\');
|
|
}
|
|
|
|
function quote(stream,quoteChar,escapeChar) {
|
|
while (!stream.eol()) {
|
|
var ch = stream.next();
|
|
if (ch == quoteChar) {
|
|
return true;
|
|
}else if (ch == escapeChar) {
|
|
stream.next();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function lookahead(stream) {
|
|
var m = stream.match(/([\n\s]+|%[^\n]*\n)*(.)/,false);
|
|
return m ? m.pop() : "";
|
|
}
|
|
|
|
function is_member(element,list) {
|
|
return (-1 < list.indexOf(element));
|
|
}
|
|
|
|
function rval(state,stream,type) {
|
|
|
|
// parse stack
|
|
pushToken(state,realToken(type,stream));
|
|
|
|
// map erlang token type to CodeMirror style class
|
|
// erlang -> CodeMirror tag
|
|
switch (type) {
|
|
case "atom": return "atom";
|
|
case "attribute": return "attribute";
|
|
case "boolean": return "atom";
|
|
case "builtin": return "builtin";
|
|
case "close_paren": return null;
|
|
case "colon": return null;
|
|
case "comment": return "comment";
|
|
case "dot": return null;
|
|
case "error": return "error";
|
|
case "fun": return "meta";
|
|
case "function": return "tag";
|
|
case "guard": return "property";
|
|
case "keyword": return "keyword";
|
|
case "macro": return "variable-2";
|
|
case "number": return "number";
|
|
case "open_paren": return null;
|
|
case "operator": return "operator";
|
|
case "record": return "bracket";
|
|
case "separator": return null;
|
|
case "string": return "string";
|
|
case "type": return "def";
|
|
case "variable": return "variable";
|
|
default: return null;
|
|
}
|
|
}
|
|
|
|
function aToken(tok,col,ind,typ) {
|
|
return {token: tok,
|
|
column: col,
|
|
indent: ind,
|
|
type: typ};
|
|
}
|
|
|
|
function realToken(type,stream) {
|
|
return aToken(stream.current(),
|
|
stream.column(),
|
|
stream.indentation(),
|
|
type);
|
|
}
|
|
|
|
function fakeToken(type) {
|
|
return aToken(type,0,0,type);
|
|
}
|
|
|
|
function peekToken(state,depth) {
|
|
var len = state.tokenStack.length;
|
|
var dep = (depth ? depth : 1);
|
|
|
|
if (len < dep) {
|
|
return false;
|
|
}else{
|
|
return state.tokenStack[len-dep];
|
|
}
|
|
}
|
|
|
|
function pushToken(state,token) {
|
|
|
|
if (!(token.type == "comment" || token.type == "whitespace")) {
|
|
state.tokenStack = maybe_drop_pre(state.tokenStack,token);
|
|
state.tokenStack = maybe_drop_post(state.tokenStack);
|
|
}
|
|
}
|
|
|
|
function maybe_drop_pre(s,token) {
|
|
var last = s.length-1;
|
|
|
|
if (0 < last && s[last].type === "record" && token.type === "dot") {
|
|
s.pop();
|
|
}else if (0 < last && s[last].type === "group") {
|
|
s.pop();
|
|
s.push(token);
|
|
}else{
|
|
s.push(token);
|
|
}
|
|
return s;
|
|
}
|
|
|
|
function maybe_drop_post(s) {
|
|
var last = s.length-1;
|
|
|
|
if (s[last].type === "dot") {
|
|
return [];
|
|
}
|
|
if (s[last].type === "fun" && s[last-1].token === "fun") {
|
|
return s.slice(0,last-1);
|
|
}
|
|
switch (s[s.length-1].token) {
|
|
case "}": return d(s,{g:["{"]});
|
|
case "]": return d(s,{i:["["]});
|
|
case ")": return d(s,{i:["("]});
|
|
case ">>": return d(s,{i:["<<"]});
|
|
case "end": return d(s,{i:["begin","case","fun","if","receive","try"]});
|
|
case ",": return d(s,{e:["begin","try","when","->",
|
|
",","(","[","{","<<"]});
|
|
case "->": return d(s,{r:["when"],
|
|
m:["try","if","case","receive"]});
|
|
case ";": return d(s,{E:["case","fun","if","receive","try","when"]});
|
|
case "catch":return d(s,{e:["try"]});
|
|
case "of": return d(s,{e:["case"]});
|
|
case "after":return d(s,{e:["receive","try"]});
|
|
default: return s;
|
|
}
|
|
}
|
|
|
|
function d(stack,tt) {
|
|
// stack is a stack of Token objects.
|
|
// tt is an object; {type:tokens}
|
|
// type is a char, tokens is a list of token strings.
|
|
// The function returns (possibly truncated) stack.
|
|
// It will descend the stack, looking for a Token such that Token.token
|
|
// is a member of tokens. If it does not find that, it will normally (but
|
|
// see "E" below) return stack. If it does find a match, it will remove
|
|
// all the Tokens between the top and the matched Token.
|
|
// If type is "m", that is all it does.
|
|
// If type is "i", it will also remove the matched Token and the top Token.
|
|
// If type is "g", like "i", but add a fake "group" token at the top.
|
|
// If type is "r", it will remove the matched Token, but not the top Token.
|
|
// If type is "e", it will keep the matched Token but not the top Token.
|
|
// If type is "E", it behaves as for type "e", except if there is no match,
|
|
// in which case it will return an empty stack.
|
|
|
|
for (var type in tt) {
|
|
var len = stack.length-1;
|
|
var tokens = tt[type];
|
|
for (var i = len-1; -1 < i ; i--) {
|
|
if (is_member(stack[i].token,tokens)) {
|
|
var ss = stack.slice(0,i);
|
|
switch (type) {
|
|
case "m": return ss.concat(stack[i]).concat(stack[len]);
|
|
case "r": return ss.concat(stack[len]);
|
|
case "i": return ss;
|
|
case "g": return ss.concat(fakeToken("group"));
|
|
case "E": return ss.concat(stack[i]);
|
|
case "e": return ss.concat(stack[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return (type == "E" ? [] : stack);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// indenter
|
|
|
|
function indenter(state,textAfter) {
|
|
var t;
|
|
var unit = cmCfg.indentUnit;
|
|
var wordAfter = wordafter(textAfter);
|
|
var currT = peekToken(state,1);
|
|
var prevT = peekToken(state,2);
|
|
|
|
if (state.in_string || state.in_atom) {
|
|
return CodeMirror.Pass;
|
|
}else if (!prevT) {
|
|
return 0;
|
|
}else if (currT.token == "when") {
|
|
return currT.column+unit;
|
|
}else if (wordAfter === "when" && prevT.type === "function") {
|
|
return prevT.indent+unit;
|
|
}else if (wordAfter === "(" && currT.token === "fun") {
|
|
return currT.column+3;
|
|
}else if (wordAfter === "catch" && (t = getToken(state,["try"]))) {
|
|
return t.column;
|
|
}else if (is_member(wordAfter,["end","after","of"])) {
|
|
t = getToken(state,["begin","case","fun","if","receive","try"]);
|
|
return t ? t.column : CodeMirror.Pass;
|
|
}else if (is_member(wordAfter,closeParenWords)) {
|
|
t = getToken(state,openParenWords);
|
|
return t ? t.column : CodeMirror.Pass;
|
|
}else if (is_member(currT.token,[",","|","||"]) ||
|
|
is_member(wordAfter,[",","|","||"])) {
|
|
t = postcommaToken(state);
|
|
return t ? t.column+t.token.length : unit;
|
|
}else if (currT.token == "->") {
|
|
if (is_member(prevT.token, ["receive","case","if","try"])) {
|
|
return prevT.column+unit+unit;
|
|
}else{
|
|
return prevT.column+unit;
|
|
}
|
|
}else if (is_member(currT.token,openParenWords)) {
|
|
return currT.column+currT.token.length;
|
|
}else{
|
|
t = defaultToken(state);
|
|
return truthy(t) ? t.column+unit : 0;
|
|
}
|
|
}
|
|
|
|
function wordafter(str) {
|
|
var m = str.match(/,|[a-z]+|\}|\]|\)|>>|\|+|\(/);
|
|
|
|
return truthy(m) && (m.index === 0) ? m[0] : "";
|
|
}
|
|
|
|
function postcommaToken(state) {
|
|
var objs = state.tokenStack.slice(0,-1);
|
|
var i = getTokenIndex(objs,"type",["open_paren"]);
|
|
|
|
return truthy(objs[i]) ? objs[i] : false;
|
|
}
|
|
|
|
function defaultToken(state) {
|
|
var objs = state.tokenStack;
|
|
var stop = getTokenIndex(objs,"type",["open_paren","separator","keyword"]);
|
|
var oper = getTokenIndex(objs,"type",["operator"]);
|
|
|
|
if (truthy(stop) && truthy(oper) && stop < oper) {
|
|
return objs[stop+1];
|
|
} else if (truthy(stop)) {
|
|
return objs[stop];
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function getToken(state,tokens) {
|
|
var objs = state.tokenStack;
|
|
var i = getTokenIndex(objs,"token",tokens);
|
|
|
|
return truthy(objs[i]) ? objs[i] : false;
|
|
}
|
|
|
|
function getTokenIndex(objs,propname,propvals) {
|
|
|
|
for (var i = objs.length-1; -1 < i ; i--) {
|
|
if (is_member(objs[i][propname],propvals)) {
|
|
return i;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function truthy(x) {
|
|
return (x !== false) && (x != null);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// this object defines the mode
|
|
|
|
return {
|
|
startState:
|
|
function() {
|
|
return {tokenStack: [],
|
|
in_string: false,
|
|
in_atom: false};
|
|
},
|
|
|
|
token:
|
|
function(stream, state) {
|
|
return tokenizer(stream, state);
|
|
},
|
|
|
|
indent:
|
|
function(state, textAfter) {
|
|
return indenter(state,textAfter);
|
|
},
|
|
|
|
lineComment: "%"
|
|
};
|
|
});
|
|
|
|
});
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"), require("../javascript/javascript"), require("../css/css"), require("../htmlmixed/htmlmixed"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror", "../javascript/javascript", "../css/css", "../htmlmixed/htmlmixed"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode('jade', function (config) {
|
|
// token types
|
|
var KEYWORD = 'keyword';
|
|
var DOCTYPE = 'meta';
|
|
var ID = 'builtin';
|
|
var CLASS = 'qualifier';
|
|
|
|
var ATTRS_NEST = {
|
|
'{': '}',
|
|
'(': ')',
|
|
'[': ']'
|
|
};
|
|
|
|
var jsMode = CodeMirror.getMode(config, 'javascript');
|
|
|
|
function State() {
|
|
this.javaScriptLine = false;
|
|
this.javaScriptLineExcludesColon = false;
|
|
|
|
this.javaScriptArguments = false;
|
|
this.javaScriptArgumentsDepth = 0;
|
|
|
|
this.isInterpolating = false;
|
|
this.interpolationNesting = 0;
|
|
|
|
this.jsState = jsMode.startState();
|
|
|
|
this.restOfLine = '';
|
|
|
|
this.isIncludeFiltered = false;
|
|
this.isEach = false;
|
|
|
|
this.lastTag = '';
|
|
this.scriptType = '';
|
|
|
|
// Attributes Mode
|
|
this.isAttrs = false;
|
|
this.attrsNest = [];
|
|
this.inAttributeName = true;
|
|
this.attributeIsType = false;
|
|
this.attrValue = '';
|
|
|
|
// Indented Mode
|
|
this.indentOf = Infinity;
|
|
this.indentToken = '';
|
|
|
|
this.innerMode = null;
|
|
this.innerState = null;
|
|
|
|
this.innerModeForLine = false;
|
|
}
|
|
/**
|
|
* Safely copy a state
|
|
*
|
|
* @return {State}
|
|
*/
|
|
State.prototype.copy = function () {
|
|
var res = new State();
|
|
res.javaScriptLine = this.javaScriptLine;
|
|
res.javaScriptLineExcludesColon = this.javaScriptLineExcludesColon;
|
|
res.javaScriptArguments = this.javaScriptArguments;
|
|
res.javaScriptArgumentsDepth = this.javaScriptArgumentsDepth;
|
|
res.isInterpolating = this.isInterpolating;
|
|
res.interpolationNesting = this.intpolationNesting;
|
|
|
|
res.jsState = CodeMirror.copyState(jsMode, this.jsState);
|
|
|
|
res.innerMode = this.innerMode;
|
|
if (this.innerMode && this.innerState) {
|
|
res.innerState = CodeMirror.copyState(this.innerMode, this.innerState);
|
|
}
|
|
|
|
res.restOfLine = this.restOfLine;
|
|
|
|
res.isIncludeFiltered = this.isIncludeFiltered;
|
|
res.isEach = this.isEach;
|
|
res.lastTag = this.lastTag;
|
|
res.scriptType = this.scriptType;
|
|
res.isAttrs = this.isAttrs;
|
|
res.attrsNest = this.attrsNest.slice();
|
|
res.inAttributeName = this.inAttributeName;
|
|
res.attributeIsType = this.attributeIsType;
|
|
res.attrValue = this.attrValue;
|
|
res.indentOf = this.indentOf;
|
|
res.indentToken = this.indentToken;
|
|
|
|
res.innerModeForLine = this.innerModeForLine;
|
|
|
|
return res;
|
|
};
|
|
|
|
function javaScript(stream, state) {
|
|
if (stream.sol()) {
|
|
// if javaScriptLine was set at end of line, ignore it
|
|
state.javaScriptLine = false;
|
|
state.javaScriptLineExcludesColon = false;
|
|
}
|
|
if (state.javaScriptLine) {
|
|
if (state.javaScriptLineExcludesColon && stream.peek() === ':') {
|
|
state.javaScriptLine = false;
|
|
state.javaScriptLineExcludesColon = false;
|
|
return;
|
|
}
|
|
var tok = jsMode.token(stream, state.jsState);
|
|
if (stream.eol()) state.javaScriptLine = false;
|
|
return tok || true;
|
|
}
|
|
}
|
|
function javaScriptArguments(stream, state) {
|
|
if (state.javaScriptArguments) {
|
|
if (state.javaScriptArgumentsDepth === 0 && stream.peek() !== '(') {
|
|
state.javaScriptArguments = false;
|
|
return;
|
|
}
|
|
if (stream.peek() === '(') {
|
|
state.javaScriptArgumentsDepth++;
|
|
} else if (stream.peek() === ')') {
|
|
state.javaScriptArgumentsDepth--;
|
|
}
|
|
if (state.javaScriptArgumentsDepth === 0) {
|
|
state.javaScriptArguments = false;
|
|
return;
|
|
}
|
|
|
|
var tok = jsMode.token(stream, state.jsState);
|
|
return tok || true;
|
|
}
|
|
}
|
|
|
|
function yieldStatement(stream) {
|
|
if (stream.match(/^yield\b/)) {
|
|
return 'keyword';
|
|
}
|
|
}
|
|
|
|
function doctype(stream) {
|
|
if (stream.match(/^(?:doctype) *([^\n]+)?/)) {
|
|
return DOCTYPE;
|
|
}
|
|
}
|
|
|
|
function interpolation(stream, state) {
|
|
if (stream.match('#{')) {
|
|
state.isInterpolating = true;
|
|
state.interpolationNesting = 0;
|
|
return 'punctuation';
|
|
}
|
|
}
|
|
|
|
function interpolationContinued(stream, state) {
|
|
if (state.isInterpolating) {
|
|
if (stream.peek() === '}') {
|
|
state.interpolationNesting--;
|
|
if (state.interpolationNesting < 0) {
|
|
stream.next();
|
|
state.isInterpolating = false;
|
|
return 'puncutation';
|
|
}
|
|
} else if (stream.peek() === '{') {
|
|
state.interpolationNesting++;
|
|
}
|
|
return jsMode.token(stream, state.jsState) || true;
|
|
}
|
|
}
|
|
|
|
function caseStatement(stream, state) {
|
|
if (stream.match(/^case\b/)) {
|
|
state.javaScriptLine = true;
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function when(stream, state) {
|
|
if (stream.match(/^when\b/)) {
|
|
state.javaScriptLine = true;
|
|
state.javaScriptLineExcludesColon = true;
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function defaultStatement(stream) {
|
|
if (stream.match(/^default\b/)) {
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function extendsStatement(stream, state) {
|
|
if (stream.match(/^extends?\b/)) {
|
|
state.restOfLine = 'string';
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function append(stream, state) {
|
|
if (stream.match(/^append\b/)) {
|
|
state.restOfLine = 'variable';
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
function prepend(stream, state) {
|
|
if (stream.match(/^prepend\b/)) {
|
|
state.restOfLine = 'variable';
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
function block(stream, state) {
|
|
if (stream.match(/^block\b *(?:(prepend|append)\b)?/)) {
|
|
state.restOfLine = 'variable';
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function include(stream, state) {
|
|
if (stream.match(/^include\b/)) {
|
|
state.restOfLine = 'string';
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function includeFiltered(stream, state) {
|
|
if (stream.match(/^include:([a-zA-Z0-9\-]+)/, false) && stream.match('include')) {
|
|
state.isIncludeFiltered = true;
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function includeFilteredContinued(stream, state) {
|
|
if (state.isIncludeFiltered) {
|
|
var tok = filter(stream, state);
|
|
state.isIncludeFiltered = false;
|
|
state.restOfLine = 'string';
|
|
return tok;
|
|
}
|
|
}
|
|
|
|
function mixin(stream, state) {
|
|
if (stream.match(/^mixin\b/)) {
|
|
state.javaScriptLine = true;
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function call(stream, state) {
|
|
if (stream.match(/^\+([-\w]+)/)) {
|
|
if (!stream.match(/^\( *[-\w]+ *=/, false)) {
|
|
state.javaScriptArguments = true;
|
|
state.javaScriptArgumentsDepth = 0;
|
|
}
|
|
return 'variable';
|
|
}
|
|
if (stream.match(/^\+#{/, false)) {
|
|
stream.next();
|
|
state.mixinCallAfter = true;
|
|
return interpolation(stream, state);
|
|
}
|
|
}
|
|
function callArguments(stream, state) {
|
|
if (state.mixinCallAfter) {
|
|
state.mixinCallAfter = false;
|
|
if (!stream.match(/^\( *[-\w]+ *=/, false)) {
|
|
state.javaScriptArguments = true;
|
|
state.javaScriptArgumentsDepth = 0;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function conditional(stream, state) {
|
|
if (stream.match(/^(if|unless|else if|else)\b/)) {
|
|
state.javaScriptLine = true;
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function each(stream, state) {
|
|
if (stream.match(/^(- *)?(each|for)\b/)) {
|
|
state.isEach = true;
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
function eachContinued(stream, state) {
|
|
if (state.isEach) {
|
|
if (stream.match(/^ in\b/)) {
|
|
state.javaScriptLine = true;
|
|
state.isEach = false;
|
|
return KEYWORD;
|
|
} else if (stream.sol() || stream.eol()) {
|
|
state.isEach = false;
|
|
} else if (stream.next()) {
|
|
while (!stream.match(/^ in\b/, false) && stream.next());
|
|
return 'variable';
|
|
}
|
|
}
|
|
}
|
|
|
|
function whileStatement(stream, state) {
|
|
if (stream.match(/^while\b/)) {
|
|
state.javaScriptLine = true;
|
|
return KEYWORD;
|
|
}
|
|
}
|
|
|
|
function tag(stream, state) {
|
|
var captures;
|
|
if (captures = stream.match(/^(\w(?:[-:\w]*\w)?)\/?/)) {
|
|
state.lastTag = captures[1].toLowerCase();
|
|
if (state.lastTag === 'script') {
|
|
state.scriptType = 'application/javascript';
|
|
}
|
|
return 'tag';
|
|
}
|
|
}
|
|
|
|
function filter(stream, state) {
|
|
if (stream.match(/^:([\w\-]+)/)) {
|
|
var innerMode;
|
|
if (config && config.innerModes) {
|
|
innerMode = config.innerModes(stream.current().substring(1));
|
|
}
|
|
if (!innerMode) {
|
|
innerMode = stream.current().substring(1);
|
|
}
|
|
if (typeof innerMode === 'string') {
|
|
innerMode = CodeMirror.getMode(config, innerMode);
|
|
}
|
|
setInnerMode(stream, state, innerMode);
|
|
return 'atom';
|
|
}
|
|
}
|
|
|
|
function code(stream, state) {
|
|
if (stream.match(/^(!?=|-)/)) {
|
|
state.javaScriptLine = true;
|
|
return 'punctuation';
|
|
}
|
|
}
|
|
|
|
function id(stream) {
|
|
if (stream.match(/^#([\w-]+)/)) {
|
|
return ID;
|
|
}
|
|
}
|
|
|
|
function className(stream) {
|
|
if (stream.match(/^\.([\w-]+)/)) {
|
|
return CLASS;
|
|
}
|
|
}
|
|
|
|
function attrs(stream, state) {
|
|
if (stream.peek() == '(') {
|
|
stream.next();
|
|
state.isAttrs = true;
|
|
state.attrsNest = [];
|
|
state.inAttributeName = true;
|
|
state.attrValue = '';
|
|
state.attributeIsType = false;
|
|
return 'punctuation';
|
|
}
|
|
}
|
|
|
|
function attrsContinued(stream, state) {
|
|
if (state.isAttrs) {
|
|
if (ATTRS_NEST[stream.peek()]) {
|
|
state.attrsNest.push(ATTRS_NEST[stream.peek()]);
|
|
}
|
|
if (state.attrsNest[state.attrsNest.length - 1] === stream.peek()) {
|
|
state.attrsNest.pop();
|
|
} else if (stream.eat(')')) {
|
|
state.isAttrs = false;
|
|
return 'punctuation';
|
|
}
|
|
if (state.inAttributeName && stream.match(/^[^=,\)!]+/)) {
|
|
if (stream.peek() === '=' || stream.peek() === '!') {
|
|
state.inAttributeName = false;
|
|
state.jsState = jsMode.startState();
|
|
if (state.lastTag === 'script' && stream.current().trim().toLowerCase() === 'type') {
|
|
state.attributeIsType = true;
|
|
} else {
|
|
state.attributeIsType = false;
|
|
}
|
|
}
|
|
return 'attribute';
|
|
}
|
|
|
|
var tok = jsMode.token(stream, state.jsState);
|
|
if (state.attributeIsType && tok === 'string') {
|
|
state.scriptType = stream.current().toString();
|
|
}
|
|
if (state.attrsNest.length === 0 && (tok === 'string' || tok === 'variable' || tok === 'keyword')) {
|
|
try {
|
|
Function('', 'var x ' + state.attrValue.replace(/,\s*$/, '').replace(/^!/, ''));
|
|
state.inAttributeName = true;
|
|
state.attrValue = '';
|
|
stream.backUp(stream.current().length);
|
|
return attrsContinued(stream, state);
|
|
} catch (ex) {
|
|
//not the end of an attribute
|
|
}
|
|
}
|
|
state.attrValue += stream.current();
|
|
return tok || true;
|
|
}
|
|
}
|
|
|
|
function attributesBlock(stream, state) {
|
|
if (stream.match(/^&attributes\b/)) {
|
|
state.javaScriptArguments = true;
|
|
state.javaScriptArgumentsDepth = 0;
|
|
return 'keyword';
|
|
}
|
|
}
|
|
|
|
function indent(stream) {
|
|
if (stream.sol() && stream.eatSpace()) {
|
|
return 'indent';
|
|
}
|
|
}
|
|
|
|
function comment(stream, state) {
|
|
if (stream.match(/^ *\/\/(-)?([^\n]*)/)) {
|
|
state.indentOf = stream.indentation();
|
|
state.indentToken = 'comment';
|
|
return 'comment';
|
|
}
|
|
}
|
|
|
|
function colon(stream) {
|
|
if (stream.match(/^: */)) {
|
|
return 'colon';
|
|
}
|
|
}
|
|
|
|
function text(stream, state) {
|
|
if (stream.match(/^(?:\| ?| )([^\n]+)/)) {
|
|
return 'string';
|
|
}
|
|
if (stream.match(/^(<[^\n]*)/, false)) {
|
|
// html string
|
|
setInnerMode(stream, state, 'htmlmixed');
|
|
state.innerModeForLine = true;
|
|
return innerMode(stream, state, true);
|
|
}
|
|
}
|
|
|
|
function dot(stream, state) {
|
|
if (stream.eat('.')) {
|
|
var innerMode = null;
|
|
if (state.lastTag === 'script' && state.scriptType.toLowerCase().indexOf('javascript') != -1) {
|
|
innerMode = state.scriptType.toLowerCase().replace(/"|'/g, '');
|
|
} else if (state.lastTag === 'style') {
|
|
innerMode = 'css';
|
|
}
|
|
setInnerMode(stream, state, innerMode);
|
|
return 'dot';
|
|
}
|
|
}
|
|
|
|
function fail(stream) {
|
|
stream.next();
|
|
return null;
|
|
}
|
|
|
|
|
|
function setInnerMode(stream, state, mode) {
|
|
mode = CodeMirror.mimeModes[mode] || mode;
|
|
mode = config.innerModes ? config.innerModes(mode) || mode : mode;
|
|
mode = CodeMirror.mimeModes[mode] || mode;
|
|
mode = CodeMirror.getMode(config, mode);
|
|
state.indentOf = stream.indentation();
|
|
|
|
if (mode && mode.name !== 'null') {
|
|
state.innerMode = mode;
|
|
} else {
|
|
state.indentToken = 'string';
|
|
}
|
|
}
|
|
function innerMode(stream, state, force) {
|
|
if (stream.indentation() > state.indentOf || (state.innerModeForLine && !stream.sol()) || force) {
|
|
if (state.innerMode) {
|
|
if (!state.innerState) {
|
|
state.innerState = state.innerMode.startState ? state.innerMode.startState(stream.indentation()) : {};
|
|
}
|
|
return stream.hideFirstChars(state.indentOf + 2, function () {
|
|
return state.innerMode.token(stream, state.innerState) || true;
|
|
});
|
|
} else {
|
|
stream.skipToEnd();
|
|
return state.indentToken;
|
|
}
|
|
} else if (stream.sol()) {
|
|
state.indentOf = Infinity;
|
|
state.indentToken = null;
|
|
state.innerMode = null;
|
|
state.innerState = null;
|
|
}
|
|
}
|
|
function restOfLine(stream, state) {
|
|
if (stream.sol()) {
|
|
// if restOfLine was set at end of line, ignore it
|
|
state.restOfLine = '';
|
|
}
|
|
if (state.restOfLine) {
|
|
stream.skipToEnd();
|
|
var tok = state.restOfLine;
|
|
state.restOfLine = '';
|
|
return tok;
|
|
}
|
|
}
|
|
|
|
|
|
function startState() {
|
|
return new State();
|
|
}
|
|
function copyState(state) {
|
|
return state.copy();
|
|
}
|
|
/**
|
|
* Get the next token in the stream
|
|
*
|
|
* @param {Stream} stream
|
|
* @param {State} state
|
|
*/
|
|
function nextToken(stream, state) {
|
|
var tok = innerMode(stream, state)
|
|
|| restOfLine(stream, state)
|
|
|| interpolationContinued(stream, state)
|
|
|| includeFilteredContinued(stream, state)
|
|
|| eachContinued(stream, state)
|
|
|| attrsContinued(stream, state)
|
|
|| javaScript(stream, state)
|
|
|| javaScriptArguments(stream, state)
|
|
|| callArguments(stream, state)
|
|
|
|
|| yieldStatement(stream, state)
|
|
|| doctype(stream, state)
|
|
|| interpolation(stream, state)
|
|
|| caseStatement(stream, state)
|
|
|| when(stream, state)
|
|
|| defaultStatement(stream, state)
|
|
|| extendsStatement(stream, state)
|
|
|| append(stream, state)
|
|
|| prepend(stream, state)
|
|
|| block(stream, state)
|
|
|| include(stream, state)
|
|
|| includeFiltered(stream, state)
|
|
|| mixin(stream, state)
|
|
|| call(stream, state)
|
|
|| conditional(stream, state)
|
|
|| each(stream, state)
|
|
|| whileStatement(stream, state)
|
|
|| tag(stream, state)
|
|
|| filter(stream, state)
|
|
|| code(stream, state)
|
|
|| id(stream, state)
|
|
|| className(stream, state)
|
|
|| attrs(stream, state)
|
|
|| attributesBlock(stream, state)
|
|
|| indent(stream, state)
|
|
|| text(stream, state)
|
|
|| comment(stream, state)
|
|
|| colon(stream, state)
|
|
|| dot(stream, state)
|
|
|| fail(stream, state);
|
|
|
|
return tok === true ? null : tok;
|
|
}
|
|
return {
|
|
startState: startState,
|
|
copyState: copyState,
|
|
token: nextToken
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME('text/x-jade', 'jade');
|
|
|
|
});
|