mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 23:16:18 +08:00
修复 php 输入问题
This commit is contained in:
parent
6e437d2e64
commit
ab5dd69db3
935
codemirror/mode/clike/clike.js
vendored
Normal file
935
codemirror/mode/clike/clike.js
vendored
Normal file
@ -0,0 +1,935 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://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 Context(indented, column, type, info, align, prev) {
|
||||||
|
this.indented = indented;
|
||||||
|
this.column = column;
|
||||||
|
this.type = type;
|
||||||
|
this.info = info;
|
||||||
|
this.align = align;
|
||||||
|
this.prev = prev;
|
||||||
|
}
|
||||||
|
function pushContext(state, col, type, info) {
|
||||||
|
var indent = state.indented;
|
||||||
|
if (state.context && state.context.type == "statement" && type != "statement")
|
||||||
|
indent = state.context.indented;
|
||||||
|
return state.context = new Context(indent, col, type, info, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function typeBefore(stream, state, pos) {
|
||||||
|
if (state.prevToken == "variable" || state.prevToken == "type") return true;
|
||||||
|
if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, pos))) return true;
|
||||||
|
if (state.typeAtEndOfLine && stream.column() == stream.indentation()) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isTopScope(context) {
|
||||||
|
for (;;) {
|
||||||
|
if (!context || context.type == "top") return true;
|
||||||
|
if (context.type == "}" && context.prev.info != "namespace") return false;
|
||||||
|
context = context.prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.defineMode("clike", function(config, parserConfig) {
|
||||||
|
var indentUnit = config.indentUnit,
|
||||||
|
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
|
||||||
|
dontAlignCalls = parserConfig.dontAlignCalls,
|
||||||
|
keywords = parserConfig.keywords || {},
|
||||||
|
types = parserConfig.types || {},
|
||||||
|
builtin = parserConfig.builtin || {},
|
||||||
|
blockKeywords = parserConfig.blockKeywords || {},
|
||||||
|
defKeywords = parserConfig.defKeywords || {},
|
||||||
|
atoms = parserConfig.atoms || {},
|
||||||
|
hooks = parserConfig.hooks || {},
|
||||||
|
multiLineStrings = parserConfig.multiLineStrings,
|
||||||
|
indentStatements = parserConfig.indentStatements !== false,
|
||||||
|
indentSwitch = parserConfig.indentSwitch !== false,
|
||||||
|
namespaceSeparator = parserConfig.namespaceSeparator,
|
||||||
|
isPunctuationChar = parserConfig.isPunctuationChar || /[\[\]{}\(\),;\:\.]/,
|
||||||
|
numberStart = parserConfig.numberStart || /[\d\.]/,
|
||||||
|
number = parserConfig.number || /^(?:0x[a-f\d]+|0b[01]+|(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)(u|ll?|l|f)?/i,
|
||||||
|
isOperatorChar = parserConfig.isOperatorChar || /[+\-*&%=<>!?|\/]/,
|
||||||
|
isIdentifierChar = parserConfig.isIdentifierChar || /[\w\$_\xa1-\uffff]/,
|
||||||
|
// An optional function that takes a {string} token and returns true if it
|
||||||
|
// should be treated as a builtin.
|
||||||
|
isReservedIdentifier = parserConfig.isReservedIdentifier || false;
|
||||||
|
|
||||||
|
var curPunc, isDefKeyword;
|
||||||
|
|
||||||
|
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 (isPunctuationChar.test(ch)) {
|
||||||
|
curPunc = ch;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (numberStart.test(ch)) {
|
||||||
|
stream.backUp(1)
|
||||||
|
if (stream.match(number)) return "number"
|
||||||
|
stream.next()
|
||||||
|
}
|
||||||
|
if (ch == "/") {
|
||||||
|
if (stream.eat("*")) {
|
||||||
|
state.tokenize = tokenComment;
|
||||||
|
return tokenComment(stream, state);
|
||||||
|
}
|
||||||
|
if (stream.eat("/")) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return "comment";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isOperatorChar.test(ch)) {
|
||||||
|
while (!stream.match(/^\/[\/*]/, false) && stream.eat(isOperatorChar)) {}
|
||||||
|
return "operator";
|
||||||
|
}
|
||||||
|
stream.eatWhile(isIdentifierChar);
|
||||||
|
if (namespaceSeparator) while (stream.match(namespaceSeparator))
|
||||||
|
stream.eatWhile(isIdentifierChar);
|
||||||
|
|
||||||
|
var cur = stream.current();
|
||||||
|
if (contains(keywords, cur)) {
|
||||||
|
if (contains(blockKeywords, cur)) curPunc = "newstatement";
|
||||||
|
if (contains(defKeywords, cur)) isDefKeyword = true;
|
||||||
|
return "keyword";
|
||||||
|
}
|
||||||
|
if (contains(types, cur)) return "type";
|
||||||
|
if (contains(builtin, cur)
|
||||||
|
|| (isReservedIdentifier && isReservedIdentifier(cur))) {
|
||||||
|
if (contains(blockKeywords, cur)) curPunc = "newstatement";
|
||||||
|
return "builtin";
|
||||||
|
}
|
||||||
|
if (contains(atoms, 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 maybeEOL(stream, state) {
|
||||||
|
if (parserConfig.typeFirstDefinitions && stream.eol() && isTopScope(state.context))
|
||||||
|
state.typeAtEndOfLine = typeBefore(stream, state, stream.pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface
|
||||||
|
|
||||||
|
return {
|
||||||
|
startState: function(basecolumn) {
|
||||||
|
return {
|
||||||
|
tokenize: null,
|
||||||
|
context: new Context((basecolumn || 0) - indentUnit, 0, "top", null, false),
|
||||||
|
indented: 0,
|
||||||
|
startOfLine: true,
|
||||||
|
prevToken: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
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()) { maybeEOL(stream, state); return null; }
|
||||||
|
curPunc = isDefKeyword = 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 == "," && stream.match(/^\s*(?:\/\/.*)?$/, false)))
|
||||||
|
while (state.context.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", stream.current());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (style == "variable" &&
|
||||||
|
((state.prevToken == "def" ||
|
||||||
|
(parserConfig.typeFirstDefinitions && typeBefore(stream, state, stream.start) &&
|
||||||
|
isTopScope(state.context) && stream.match(/^\s*\(/, false)))))
|
||||||
|
style = "def";
|
||||||
|
|
||||||
|
if (hooks.token) {
|
||||||
|
var result = hooks.token(stream, state, style);
|
||||||
|
if (result !== undefined) style = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (style == "def" && parserConfig.styleDefs === false) style = "variable";
|
||||||
|
|
||||||
|
state.startOfLine = false;
|
||||||
|
state.prevToken = isDefKeyword ? "def" : style || curPunc;
|
||||||
|
maybeEOL(stream, state);
|
||||||
|
return style;
|
||||||
|
},
|
||||||
|
|
||||||
|
indent: function(state, textAfter) {
|
||||||
|
if (state.tokenize != tokenBase && state.tokenize != null || state.typeAtEndOfLine) return CodeMirror.Pass;
|
||||||
|
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
||||||
|
var closing = firstChar == ctx.type;
|
||||||
|
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
||||||
|
if (parserConfig.dontIndentStatements)
|
||||||
|
while (ctx.type == "statement" && parserConfig.dontIndentStatements.test(ctx.info))
|
||||||
|
ctx = ctx.prev
|
||||||
|
if (hooks.indent) {
|
||||||
|
var hook = hooks.indent(state, ctx, textAfter, indentUnit);
|
||||||
|
if (typeof hook == "number") return hook
|
||||||
|
}
|
||||||
|
var switchBlock = ctx.prev && ctx.prev.info == "switch";
|
||||||
|
if (parserConfig.allmanIndentation && /[{(]/.test(firstChar)) {
|
||||||
|
while (ctx.type != "top" && ctx.type != "}") ctx = ctx.prev
|
||||||
|
return ctx.indented
|
||||||
|
}
|
||||||
|
if (ctx.type == "statement")
|
||||||
|
return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
|
||||||
|
if (ctx.align && (!dontAlignCalls || ctx.type != ")"))
|
||||||
|
return ctx.column + (closing ? 0 : 1);
|
||||||
|
if (ctx.type == ")" && !closing)
|
||||||
|
return ctx.indented + statementIndentUnit;
|
||||||
|
|
||||||
|
return ctx.indented + (closing ? 0 : indentUnit) +
|
||||||
|
(!closing && switchBlock && !/^(?:case|default)\b/.test(textAfter) ? indentUnit : 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
electricInput: indentSwitch ? /^\s*(?:case .*?:|default:|\{\}?|\})$/ : /^\s*[{}]$/,
|
||||||
|
blockCommentStart: "/*",
|
||||||
|
blockCommentEnd: "*/",
|
||||||
|
blockCommentContinue: " * ",
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
function contains(words, word) {
|
||||||
|
if (typeof words === "function") {
|
||||||
|
return words(word);
|
||||||
|
} else {
|
||||||
|
return words.propertyIsEnumerable(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var cKeywords = "auto if break case register continue return default do sizeof " +
|
||||||
|
"static else struct switch extern typedef union for goto while enum const " +
|
||||||
|
"volatile inline restrict asm fortran";
|
||||||
|
|
||||||
|
// Keywords from https://en.cppreference.com/w/cpp/keyword includes C++20.
|
||||||
|
var cppKeywords = "alignas alignof and and_eq audit axiom bitand bitor catch " +
|
||||||
|
"class compl concept constexpr const_cast decltype delete dynamic_cast " +
|
||||||
|
"explicit export final friend import module mutable namespace new noexcept " +
|
||||||
|
"not not_eq operator or or_eq override private protected public " +
|
||||||
|
"reinterpret_cast requires static_assert static_cast template this " +
|
||||||
|
"thread_local throw try typeid typename using virtual xor xor_eq";
|
||||||
|
|
||||||
|
var objCKeywords = "bycopy byref in inout oneway out self super atomic nonatomic retain copy " +
|
||||||
|
"readwrite readonly strong weak assign typeof nullable nonnull null_resettable _cmd " +
|
||||||
|
"@interface @implementation @end @protocol @encode @property @synthesize @dynamic @class " +
|
||||||
|
"@public @package @private @protected @required @optional @try @catch @finally @import " +
|
||||||
|
"@selector @encode @defs @synchronized @autoreleasepool @compatibility_alias @available";
|
||||||
|
|
||||||
|
var objCBuiltins = "FOUNDATION_EXPORT FOUNDATION_EXTERN NS_INLINE NS_FORMAT_FUNCTION " +
|
||||||
|
" NS_RETURNS_RETAINEDNS_ERROR_ENUM NS_RETURNS_NOT_RETAINED NS_RETURNS_INNER_POINTER " +
|
||||||
|
"NS_DESIGNATED_INITIALIZER NS_ENUM NS_OPTIONS NS_REQUIRES_NIL_TERMINATION " +
|
||||||
|
"NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END NS_SWIFT_NAME NS_REFINED_FOR_SWIFT"
|
||||||
|
|
||||||
|
// Do not use this. Use the cTypes function below. This is global just to avoid
|
||||||
|
// excessive calls when cTypes is being called multiple times during a parse.
|
||||||
|
var basicCTypes = words("int long char short double float unsigned signed " +
|
||||||
|
"void bool");
|
||||||
|
|
||||||
|
// Do not use this. Use the objCTypes function below. This is global just to avoid
|
||||||
|
// excessive calls when objCTypes is being called multiple times during a parse.
|
||||||
|
var basicObjCTypes = words("SEL instancetype id Class Protocol BOOL");
|
||||||
|
|
||||||
|
// Returns true if identifier is a "C" type.
|
||||||
|
// C type is defined as those that are reserved by the compiler (basicTypes),
|
||||||
|
// and those that end in _t (Reserved by POSIX for types)
|
||||||
|
// http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
|
||||||
|
function cTypes(identifier) {
|
||||||
|
return contains(basicCTypes, identifier) || /.+_t$/.test(identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true if identifier is a "Objective C" type.
|
||||||
|
function objCTypes(identifier) {
|
||||||
|
return cTypes(identifier) || contains(basicObjCTypes, identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
var cBlockKeywords = "case do else for if switch while struct enum union";
|
||||||
|
var cDefKeywords = "struct enum union";
|
||||||
|
|
||||||
|
function cppHook(stream, state) {
|
||||||
|
if (!state.startOfLine) return false
|
||||||
|
for (var ch, next = null; ch = stream.peek();) {
|
||||||
|
if (ch == "\\" && stream.match(/^.$/)) {
|
||||||
|
next = cppHook
|
||||||
|
break
|
||||||
|
} else if (ch == "/" && stream.match(/^\/[\/\*]/, false)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
stream.next()
|
||||||
|
}
|
||||||
|
state.tokenize = next
|
||||||
|
return "meta"
|
||||||
|
}
|
||||||
|
|
||||||
|
function pointerHook(_stream, state) {
|
||||||
|
if (state.prevToken == "type") return "type";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For C and C++ (and ObjC): identifiers starting with __
|
||||||
|
// or _ followed by a capital letter are reserved for the compiler.
|
||||||
|
function cIsReservedIdentifier(token) {
|
||||||
|
if (!token || token.length < 2) return false;
|
||||||
|
if (token[0] != '_') return false;
|
||||||
|
return (token[1] == '_') || (token[1] !== token[1].toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
function cpp14Literal(stream) {
|
||||||
|
stream.eatWhile(/[\w\.']/);
|
||||||
|
return "number";
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cppLooksLikeConstructor(word) {
|
||||||
|
var lastTwo = /(\w+)::~?(\w+)$/.exec(word);
|
||||||
|
return lastTwo && lastTwo[1] == lastTwo[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.types);
|
||||||
|
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),
|
||||||
|
types: cTypes,
|
||||||
|
blockKeywords: words(cBlockKeywords),
|
||||||
|
defKeywords: words(cDefKeywords),
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
atoms: words("NULL true false"),
|
||||||
|
isReservedIdentifier: cIsReservedIdentifier,
|
||||||
|
hooks: {
|
||||||
|
"#": cppHook,
|
||||||
|
"*": pointerHook,
|
||||||
|
},
|
||||||
|
modeProps: {fold: ["brace", "include"]}
|
||||||
|
});
|
||||||
|
|
||||||
|
def(["text/x-c++src", "text/x-c++hdr"], {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words(cKeywords + " " + cppKeywords),
|
||||||
|
types: cTypes,
|
||||||
|
blockKeywords: words(cBlockKeywords + " class try catch"),
|
||||||
|
defKeywords: words(cDefKeywords + " class namespace"),
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
atoms: words("true false NULL nullptr"),
|
||||||
|
dontIndentStatements: /^template$/,
|
||||||
|
isIdentifierChar: /[\w\$_~\xa1-\uffff]/,
|
||||||
|
isReservedIdentifier: cIsReservedIdentifier,
|
||||||
|
hooks: {
|
||||||
|
"#": cppHook,
|
||||||
|
"*": pointerHook,
|
||||||
|
"u": cpp11StringHook,
|
||||||
|
"U": cpp11StringHook,
|
||||||
|
"L": cpp11StringHook,
|
||||||
|
"R": cpp11StringHook,
|
||||||
|
"0": cpp14Literal,
|
||||||
|
"1": cpp14Literal,
|
||||||
|
"2": cpp14Literal,
|
||||||
|
"3": cpp14Literal,
|
||||||
|
"4": cpp14Literal,
|
||||||
|
"5": cpp14Literal,
|
||||||
|
"6": cpp14Literal,
|
||||||
|
"7": cpp14Literal,
|
||||||
|
"8": cpp14Literal,
|
||||||
|
"9": cpp14Literal,
|
||||||
|
token: function(stream, state, style) {
|
||||||
|
if (style == "variable" && stream.peek() == "(" &&
|
||||||
|
(state.prevToken == ";" || state.prevToken == null ||
|
||||||
|
state.prevToken == "}") &&
|
||||||
|
cppLooksLikeConstructor(stream.current()))
|
||||||
|
return "def";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
namespaceSeparator: "::",
|
||||||
|
modeProps: {fold: ["brace", "include"]}
|
||||||
|
});
|
||||||
|
|
||||||
|
def("text/x-java", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words("abstract assert break case catch class const continue default " +
|
||||||
|
"do else enum extends final finally for goto if implements import " +
|
||||||
|
"instanceof interface native new package private protected public " +
|
||||||
|
"return static strictfp super switch synchronized this throw throws transient " +
|
||||||
|
"try volatile while @interface"),
|
||||||
|
types: words("byte short int long float double boolean char void Boolean Byte Character Double Float " +
|
||||||
|
"Integer Long Number Object Short String StringBuffer StringBuilder Void"),
|
||||||
|
blockKeywords: words("catch class do else finally for if switch try while"),
|
||||||
|
defKeywords: words("class interface enum @interface"),
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
atoms: words("true false null"),
|
||||||
|
number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
|
||||||
|
hooks: {
|
||||||
|
"@": function(stream) {
|
||||||
|
// Don't match the @interface keyword.
|
||||||
|
if (stream.match('interface', false)) return false;
|
||||||
|
|
||||||
|
stream.eatWhile(/[\w\$_]/);
|
||||||
|
return "meta";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modeProps: {fold: ["brace", "import"]}
|
||||||
|
});
|
||||||
|
|
||||||
|
def("text/x-csharp", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words("abstract as async await 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"),
|
||||||
|
types: words("Action Boolean Byte Char DateTime DateTimeOffset Decimal Double Func" +
|
||||||
|
" Guid Int16 Int32 Int64 Object SByte Single String Task TimeSpan UInt16 UInt32" +
|
||||||
|
" UInt64 bool byte char decimal double short int long object" +
|
||||||
|
" sbyte float string ushort uint ulong"),
|
||||||
|
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
|
||||||
|
defKeywords: words("class interface namespace struct var"),
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenNestedComment(depth) {
|
||||||
|
return function (stream, state) {
|
||||||
|
var ch
|
||||||
|
while (ch = stream.next()) {
|
||||||
|
if (ch == "*" && stream.eat("/")) {
|
||||||
|
if (depth == 1) {
|
||||||
|
state.tokenize = null
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
state.tokenize = tokenNestedComment(depth - 1)
|
||||||
|
return state.tokenize(stream, state)
|
||||||
|
}
|
||||||
|
} else if (ch == "/" && stream.eat("*")) {
|
||||||
|
state.tokenize = tokenNestedComment(depth + 1)
|
||||||
|
return state.tokenize(stream, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "comment"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def("text/x-scala", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words(
|
||||||
|
/* scala */
|
||||||
|
"abstract case catch class def do else extends final finally for forSome if " +
|
||||||
|
"implicit import lazy match new null object override package private protected return " +
|
||||||
|
"sealed super this throw trait try type val var while with yield _ " +
|
||||||
|
|
||||||
|
/* package scala */
|
||||||
|
"assert assume require print println printf readLine readBoolean readByte readShort " +
|
||||||
|
"readChar readInt readLong readFloat readDouble"
|
||||||
|
),
|
||||||
|
types: words(
|
||||||
|
"AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
|
||||||
|
"Enumeration Equiv Error Exception Fractional Function IndexedSeq Int 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 enum do else finally for forSome if match switch try while"),
|
||||||
|
defKeywords: words("class enum def object package trait type val var"),
|
||||||
|
atoms: words("true false null"),
|
||||||
|
indentStatements: false,
|
||||||
|
indentSwitch: false,
|
||||||
|
isOperatorChar: /[+\-*&%=<>!?|\/#:@]/,
|
||||||
|
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";
|
||||||
|
},
|
||||||
|
"=": function(stream, state) {
|
||||||
|
var cx = state.context
|
||||||
|
if (cx.type == "}" && cx.align && stream.eat(">")) {
|
||||||
|
state.context = new Context(cx.indented, cx.column, cx.type, cx.info, null, cx.prev)
|
||||||
|
return "operator"
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"/": function(stream, state) {
|
||||||
|
if (!stream.eat("*")) return false
|
||||||
|
state.tokenize = tokenNestedComment(1)
|
||||||
|
return state.tokenize(stream, state)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modeProps: {closeBrackets: {pairs: '()[]{}""', triples: '"'}}
|
||||||
|
});
|
||||||
|
|
||||||
|
function tokenKotlinString(tripleString){
|
||||||
|
return function (stream, state) {
|
||||||
|
var escaped = false, next, end = false;
|
||||||
|
while (!stream.eol()) {
|
||||||
|
if (!tripleString && !escaped && stream.match('"') ) {end = true; break;}
|
||||||
|
if (tripleString && stream.match('"""')) {end = true; break;}
|
||||||
|
next = stream.next();
|
||||||
|
if(!escaped && next == "$" && stream.match('{'))
|
||||||
|
stream.skipTo("}");
|
||||||
|
escaped = !escaped && next == "\\" && !tripleString;
|
||||||
|
}
|
||||||
|
if (end || !tripleString)
|
||||||
|
state.tokenize = null;
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def("text/x-kotlin", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words(
|
||||||
|
/*keywords*/
|
||||||
|
"package as typealias class interface this super val operator " +
|
||||||
|
"var fun for is in This throw return annotation " +
|
||||||
|
"break continue object if else while do try when !in !is as? " +
|
||||||
|
|
||||||
|
/*soft keywords*/
|
||||||
|
"file import where by get set abstract enum open inner override private public internal " +
|
||||||
|
"protected catch finally out final vararg reified dynamic companion constructor init " +
|
||||||
|
"sealed field property receiver param sparam lateinit data inline noinline tailrec " +
|
||||||
|
"external annotation crossinline const operator infix suspend actual expect setparam"
|
||||||
|
),
|
||||||
|
types: words(
|
||||||
|
/* 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 Annotation Any BooleanArray " +
|
||||||
|
"ByteArray Char CharArray DeprecationLevel DoubleArray Enum FloatArray Function Int IntArray Lazy " +
|
||||||
|
"LazyThreadSafetyMode LongArray Nothing ShortArray Unit"
|
||||||
|
),
|
||||||
|
intendSwitch: false,
|
||||||
|
indentStatements: false,
|
||||||
|
multiLineStrings: true,
|
||||||
|
number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+(\.\d+)?|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
|
||||||
|
blockKeywords: words("catch class do else finally for if where try while enum"),
|
||||||
|
defKeywords: words("class val var object interface fun"),
|
||||||
|
atoms: words("true false null this"),
|
||||||
|
hooks: {
|
||||||
|
"@": function(stream) {
|
||||||
|
stream.eatWhile(/[\w\$_]/);
|
||||||
|
return "meta";
|
||||||
|
},
|
||||||
|
'*': function(_stream, state) {
|
||||||
|
return state.prevToken == '.' ? 'variable' : 'operator';
|
||||||
|
},
|
||||||
|
'"': function(stream, state) {
|
||||||
|
state.tokenize = tokenKotlinString(stream.match('""'));
|
||||||
|
return state.tokenize(stream, state);
|
||||||
|
},
|
||||||
|
"/": function(stream, state) {
|
||||||
|
if (!stream.eat("*")) return false;
|
||||||
|
state.tokenize = tokenNestedComment(1);
|
||||||
|
return state.tokenize(stream, state)
|
||||||
|
},
|
||||||
|
indent: function(state, ctx, textAfter, indentUnit) {
|
||||||
|
var firstChar = textAfter && textAfter.charAt(0);
|
||||||
|
if ((state.prevToken == "}" || state.prevToken == ")") && textAfter == "")
|
||||||
|
return state.indented;
|
||||||
|
if ((state.prevToken == "operator" && textAfter != "}" && state.context.type != "}") ||
|
||||||
|
state.prevToken == "variable" && firstChar == "." ||
|
||||||
|
(state.prevToken == "}" || state.prevToken == ")") && firstChar == ".")
|
||||||
|
return indentUnit * 2 + ctx.indented;
|
||||||
|
if (ctx.align && ctx.type == "}")
|
||||||
|
return ctx.indented + (state.context.type == (textAfter || "").charAt(0) ? 0 : indentUnit);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modeProps: {closeBrackets: {triples: '"'}}
|
||||||
|
});
|
||||||
|
|
||||||
|
def(["x-shader/x-vertex", "x-shader/x-fragment"], {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words("sampler1D sampler2D sampler3D samplerCube " +
|
||||||
|
"sampler1DShadow sampler2DShadow " +
|
||||||
|
"const attribute uniform varying " +
|
||||||
|
"break continue discard return " +
|
||||||
|
"for while do if else struct " +
|
||||||
|
"in out inout"),
|
||||||
|
types: words("float int bool void " +
|
||||||
|
"vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
|
||||||
|
"mat2 mat3 mat4"),
|
||||||
|
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"),
|
||||||
|
indentSwitch: false,
|
||||||
|
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"),
|
||||||
|
types: cTypes,
|
||||||
|
blockKeywords: words(cBlockKeywords),
|
||||||
|
atoms: words("null true false"),
|
||||||
|
hooks: {"#": cppHook},
|
||||||
|
modeProps: {fold: ["brace", "include"]}
|
||||||
|
});
|
||||||
|
|
||||||
|
def("text/x-objectivec", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words(cKeywords + " " + objCKeywords),
|
||||||
|
types: objCTypes,
|
||||||
|
builtin: words(objCBuiltins),
|
||||||
|
blockKeywords: words(cBlockKeywords + " @synthesize @try @catch @finally @autoreleasepool @synchronized"),
|
||||||
|
defKeywords: words(cDefKeywords + " @interface @implementation @protocol @class"),
|
||||||
|
dontIndentStatements: /^@.*$/,
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
atoms: words("YES NO NULL Nil nil true false nullptr"),
|
||||||
|
isReservedIdentifier: cIsReservedIdentifier,
|
||||||
|
hooks: {
|
||||||
|
"#": cppHook,
|
||||||
|
"*": pointerHook,
|
||||||
|
},
|
||||||
|
modeProps: {fold: ["brace", "include"]}
|
||||||
|
});
|
||||||
|
|
||||||
|
def("text/x-objectivec++", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words(cKeywords + " " + objCKeywords + " " + cppKeywords),
|
||||||
|
types: objCTypes,
|
||||||
|
builtin: words(objCBuiltins),
|
||||||
|
blockKeywords: words(cBlockKeywords + " @synthesize @try @catch @finally @autoreleasepool @synchronized class try catch"),
|
||||||
|
defKeywords: words(cDefKeywords + " @interface @implementation @protocol @class class namespace"),
|
||||||
|
dontIndentStatements: /^@.*$|^template$/,
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
atoms: words("YES NO NULL Nil nil true false nullptr"),
|
||||||
|
isReservedIdentifier: cIsReservedIdentifier,
|
||||||
|
hooks: {
|
||||||
|
"#": cppHook,
|
||||||
|
"*": pointerHook,
|
||||||
|
"u": cpp11StringHook,
|
||||||
|
"U": cpp11StringHook,
|
||||||
|
"L": cpp11StringHook,
|
||||||
|
"R": cpp11StringHook,
|
||||||
|
"0": cpp14Literal,
|
||||||
|
"1": cpp14Literal,
|
||||||
|
"2": cpp14Literal,
|
||||||
|
"3": cpp14Literal,
|
||||||
|
"4": cpp14Literal,
|
||||||
|
"5": cpp14Literal,
|
||||||
|
"6": cpp14Literal,
|
||||||
|
"7": cpp14Literal,
|
||||||
|
"8": cpp14Literal,
|
||||||
|
"9": cpp14Literal,
|
||||||
|
token: function(stream, state, style) {
|
||||||
|
if (style == "variable" && stream.peek() == "(" &&
|
||||||
|
(state.prevToken == ";" || state.prevToken == null ||
|
||||||
|
state.prevToken == "}") &&
|
||||||
|
cppLooksLikeConstructor(stream.current()))
|
||||||
|
return "def";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
namespaceSeparator: "::",
|
||||||
|
modeProps: {fold: ["brace", "include"]}
|
||||||
|
});
|
||||||
|
|
||||||
|
def("text/x-squirrel", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words("base break clone continue const default delete enum extends function in class" +
|
||||||
|
" foreach local resume return this throw typeof yield constructor instanceof static"),
|
||||||
|
types: cTypes,
|
||||||
|
blockKeywords: words("case catch class else for foreach if switch try while"),
|
||||||
|
defKeywords: words("function local class"),
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
atoms: words("true false null"),
|
||||||
|
hooks: {"#": cppHook},
|
||||||
|
modeProps: {fold: ["brace", "include"]}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ceylon Strings need to deal with interpolation
|
||||||
|
var stringTokenizer = null;
|
||||||
|
function tokenCeylonString(type) {
|
||||||
|
return function(stream, state) {
|
||||||
|
var escaped = false, next, end = false;
|
||||||
|
while (!stream.eol()) {
|
||||||
|
if (!escaped && stream.match('"') &&
|
||||||
|
(type == "single" || stream.match('""'))) {
|
||||||
|
end = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!escaped && stream.match('``')) {
|
||||||
|
stringTokenizer = tokenCeylonString(type);
|
||||||
|
end = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
next = stream.next();
|
||||||
|
escaped = type == "single" && !escaped && next == "\\";
|
||||||
|
}
|
||||||
|
if (end)
|
||||||
|
state.tokenize = null;
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def("text/x-ceylon", {
|
||||||
|
name: "clike",
|
||||||
|
keywords: words("abstracts alias assembly assert assign break case catch class continue dynamic else" +
|
||||||
|
" exists extends finally for function given if import in interface is let module new" +
|
||||||
|
" nonempty object of out outer package return satisfies super switch then this throw" +
|
||||||
|
" try value void while"),
|
||||||
|
types: function(word) {
|
||||||
|
// In Ceylon all identifiers that start with an uppercase are types
|
||||||
|
var first = word.charAt(0);
|
||||||
|
return (first === first.toUpperCase() && first !== first.toLowerCase());
|
||||||
|
},
|
||||||
|
blockKeywords: words("case catch class dynamic else finally for function if interface module new object switch try while"),
|
||||||
|
defKeywords: words("class dynamic function interface module object package value"),
|
||||||
|
builtin: words("abstract actual aliased annotation by default deprecated doc final formal late license" +
|
||||||
|
" native optional sealed see serializable shared suppressWarnings tagged throws variable"),
|
||||||
|
isPunctuationChar: /[\[\]{}\(\),;\:\.`]/,
|
||||||
|
isOperatorChar: /[+\-*&%=<>!?|^~:\/]/,
|
||||||
|
numberStart: /[\d#$]/,
|
||||||
|
number: /^(?:#[\da-fA-F_]+|\$[01_]+|[\d_]+[kMGTPmunpf]?|[\d_]+\.[\d_]+(?:[eE][-+]?\d+|[kMGTPmunpf]|)|)/i,
|
||||||
|
multiLineStrings: true,
|
||||||
|
typeFirstDefinitions: true,
|
||||||
|
atoms: words("true false null larger smaller equal empty finished"),
|
||||||
|
indentSwitch: false,
|
||||||
|
styleDefs: false,
|
||||||
|
hooks: {
|
||||||
|
"@": function(stream) {
|
||||||
|
stream.eatWhile(/[\w\$_]/);
|
||||||
|
return "meta";
|
||||||
|
},
|
||||||
|
'"': function(stream, state) {
|
||||||
|
state.tokenize = tokenCeylonString(stream.match('""') ? "triple" : "single");
|
||||||
|
return state.tokenize(stream, state);
|
||||||
|
},
|
||||||
|
'`': function(stream, state) {
|
||||||
|
if (!stringTokenizer || !stream.match('`')) return false;
|
||||||
|
state.tokenize = stringTokenizer;
|
||||||
|
stringTokenizer = null;
|
||||||
|
return state.tokenize(stream, state);
|
||||||
|
},
|
||||||
|
"'": function(stream) {
|
||||||
|
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
|
||||||
|
return "atom";
|
||||||
|
},
|
||||||
|
token: function(_stream, state, style) {
|
||||||
|
if ((style == "variable" || style == "type") &&
|
||||||
|
state.prevToken == ".") {
|
||||||
|
return "variable-2";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modeProps: {
|
||||||
|
fold: ["brace", "import"],
|
||||||
|
closeBrackets: {triples: '"'}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
380
codemirror/mode/clike/index.html
vendored
Normal file
380
codemirror/mode/clike/index.html
vendored
Normal file
@ -0,0 +1,380 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: C-like mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||||
|
<link rel="stylesheet" href="../../addon/hint/show-hint.css">
|
||||||
|
<script src="../../addon/hint/show-hint.js"></script>
|
||||||
|
<script src="clike.js"></script>
|
||||||
|
<style>.CodeMirror {border: 2px inset #dee;}</style>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">C-like</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>C-like mode</h2>
|
||||||
|
|
||||||
|
<div><textarea id="c-code">
|
||||||
|
/* C demo code */
|
||||||
|
|
||||||
|
#include <zmq.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void* arg_socket;
|
||||||
|
zmq_msg_t* arg_msg;
|
||||||
|
char* arg_string;
|
||||||
|
unsigned long arg_len;
|
||||||
|
int arg_int, arg_command;
|
||||||
|
|
||||||
|
int signal_fd;
|
||||||
|
int pad;
|
||||||
|
void* context;
|
||||||
|
sem_t sem;
|
||||||
|
} acl_zmq_context;
|
||||||
|
|
||||||
|
#define p(X) (context->arg_##X)
|
||||||
|
|
||||||
|
void* zmq_thread(void* context_pointer) {
|
||||||
|
acl_zmq_context* context = (acl_zmq_context*)context_pointer;
|
||||||
|
char ok = 'K', err = 'X';
|
||||||
|
int res;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
while ((res = sem_wait(&context->sem)) == EINTR);
|
||||||
|
if (res) {write(context->signal_fd, &err, 1); goto cleanup;}
|
||||||
|
switch(p(command)) {
|
||||||
|
case 0: goto cleanup;
|
||||||
|
case 1: p(socket) = zmq_socket(context->context, p(int)); break;
|
||||||
|
case 2: p(int) = zmq_close(p(socket)); break;
|
||||||
|
case 3: p(int) = zmq_bind(p(socket), p(string)); break;
|
||||||
|
case 4: p(int) = zmq_connect(p(socket), p(string)); break;
|
||||||
|
case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break;
|
||||||
|
case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
|
||||||
|
case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
|
||||||
|
case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
|
||||||
|
case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
|
||||||
|
}
|
||||||
|
p(command) = errno;
|
||||||
|
write(context->signal_fd, &ok, 1);
|
||||||
|
}
|
||||||
|
cleanup:
|
||||||
|
close(context->signal_fd);
|
||||||
|
free(context_pointer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* zmq_thread_init(void* zmq_context, int signal_fd) {
|
||||||
|
acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
|
||||||
|
pthread_t thread;
|
||||||
|
|
||||||
|
context->context = zmq_context;
|
||||||
|
context->signal_fd = signal_fd;
|
||||||
|
sem_init(&context->sem, 1, 0);
|
||||||
|
pthread_create(&thread, 0, &zmq_thread, context);
|
||||||
|
pthread_detach(thread);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
</textarea></div>
|
||||||
|
|
||||||
|
<h2>C++ example</h2>
|
||||||
|
|
||||||
|
<div><textarea id="cpp-code">
|
||||||
|
#include <iostream>
|
||||||
|
#include "mystuff/util.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
enum Enum {
|
||||||
|
VAL1, VAL2, VAL3
|
||||||
|
};
|
||||||
|
|
||||||
|
char32_t unicode_string = U"\U0010FFFF";
|
||||||
|
string raw_string = R"delim(anything
|
||||||
|
you
|
||||||
|
want)delim";
|
||||||
|
|
||||||
|
int Helper(const MyType& param) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
class ForwardDec;
|
||||||
|
|
||||||
|
template <class T, class V>
|
||||||
|
class Class : public BaseClass {
|
||||||
|
const MyType<T, V> member_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const MyType<T, V>& Method() const {
|
||||||
|
return member_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Method2(MyType<T, V>* value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T, class V>
|
||||||
|
void Class::Method2(MyType<T, V>* value) {
|
||||||
|
std::out << 1 >> method();
|
||||||
|
value->Method3(member_);
|
||||||
|
member_ = value;
|
||||||
|
}
|
||||||
|
</textarea></div>
|
||||||
|
|
||||||
|
<h2>Objective-C example</h2>
|
||||||
|
|
||||||
|
<div><textarea id="objectivec-code">
|
||||||
|
/*
|
||||||
|
This is a longer comment
|
||||||
|
That spans two lines
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "MyClass.h"
|
||||||
|
#import <AFramework/AFrameork.h>
|
||||||
|
@import BFrameworkModule;
|
||||||
|
|
||||||
|
NS_ENUM(SomeValues) {
|
||||||
|
aValue = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
// A Class Extension with some properties
|
||||||
|
@interface MyClass ()<AProtocol>
|
||||||
|
@property(atomic, readwrite, assign) NSInteger anInt;
|
||||||
|
@property(nonatomic, strong, nullable) NSString *aString;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation YourAppDelegate
|
||||||
|
|
||||||
|
- (instancetype)initWithString:(NSString *)aStringVar {
|
||||||
|
if ((self = [super init])) {
|
||||||
|
aString = aStringVar;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)doSomething:(float)progress {
|
||||||
|
NSString *myString = @"This is a ObjC string %f ";
|
||||||
|
myString = [[NSString stringWithFormat:myString, progress] stringByAppendingString:self.aString];
|
||||||
|
return myString.length > 100 ? NO : YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
</textarea></div>
|
||||||
|
|
||||||
|
<h2>Java example</h2>
|
||||||
|
|
||||||
|
<div><textarea id="java-code">
|
||||||
|
import com.demo.util.MyType;
|
||||||
|
import com.demo.util.MyInterface;
|
||||||
|
|
||||||
|
public enum Enum {
|
||||||
|
VAL1, VAL2, VAL3
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Class<T, V> implements MyInterface {
|
||||||
|
public static final MyType<T, V> member;
|
||||||
|
|
||||||
|
private class InnerClass {
|
||||||
|
public int zero() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MyType method() {
|
||||||
|
return member;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void method2(MyType<T, V> value) {
|
||||||
|
method();
|
||||||
|
value.method3();
|
||||||
|
member = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</textarea></div>
|
||||||
|
|
||||||
|
<h2>Scala example</h2>
|
||||||
|
|
||||||
|
<div><textarea id="scala-code">
|
||||||
|
object FilterTest extends App {
|
||||||
|
def filter(xs: List[Int], threshold: Int) = {
|
||||||
|
def process(ys: List[Int]): List[Int] =
|
||||||
|
if (ys.isEmpty) ys
|
||||||
|
else if (ys.head < threshold) ys.head :: process(ys.tail)
|
||||||
|
else process(ys.tail)
|
||||||
|
process(xs)
|
||||||
|
}
|
||||||
|
println(filter(List(1, 9, 2, 8, 3, 7, 4), 5))
|
||||||
|
}
|
||||||
|
</textarea></div>
|
||||||
|
|
||||||
|
<h2>Kotlin mode</h2>
|
||||||
|
|
||||||
|
<div><textarea id="kotlin-code">
|
||||||
|
package org.wasabi.http
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import java.net.InetSocketAddress
|
||||||
|
import org.wasabi.app.AppConfiguration
|
||||||
|
import io.netty.bootstrap.ServerBootstrap
|
||||||
|
import io.netty.channel.nio.NioEventLoopGroup
|
||||||
|
import io.netty.channel.socket.nio.NioServerSocketChannel
|
||||||
|
import org.wasabi.app.AppServer
|
||||||
|
|
||||||
|
public class HttpServer(private val appServer: AppServer) {
|
||||||
|
|
||||||
|
val bootstrap: ServerBootstrap
|
||||||
|
val primaryGroup: NioEventLoopGroup
|
||||||
|
val workerGroup: NioEventLoopGroup
|
||||||
|
|
||||||
|
init {
|
||||||
|
// Define worker groups
|
||||||
|
primaryGroup = NioEventLoopGroup()
|
||||||
|
workerGroup = NioEventLoopGroup()
|
||||||
|
|
||||||
|
// Initialize bootstrap of server
|
||||||
|
bootstrap = ServerBootstrap()
|
||||||
|
|
||||||
|
bootstrap.group(primaryGroup, workerGroup)
|
||||||
|
bootstrap.channel(javaClass<NioServerSocketChannel>())
|
||||||
|
bootstrap.childHandler(NettyPipelineInitializer(appServer))
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun start(wait: Boolean = true) {
|
||||||
|
val channel = bootstrap.bind(appServer.configuration.port)?.sync()?.channel()
|
||||||
|
|
||||||
|
if (wait) {
|
||||||
|
channel?.closeFuture()?.sync()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun stop() {
|
||||||
|
// Shutdown all event loops
|
||||||
|
primaryGroup.shutdownGracefully()
|
||||||
|
workerGroup.shutdownGracefully()
|
||||||
|
|
||||||
|
// Wait till all threads are terminated
|
||||||
|
primaryGroup.terminationFuture().sync()
|
||||||
|
workerGroup.terminationFuture().sync()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</textarea></div>
|
||||||
|
|
||||||
|
<h2>Ceylon mode</h2>
|
||||||
|
|
||||||
|
<div><textarea id="ceylon-code">
|
||||||
|
"Produces the [[stream|Iterable]] that results from repeated
|
||||||
|
application of the given [[function|next]] to the given
|
||||||
|
[[first]] element of the stream, until the function first
|
||||||
|
returns [[finished]]. If the given function never returns
|
||||||
|
`finished`, the resulting stream is infinite.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
loop(0)(2.plus).takeWhile(10.largerThan)
|
||||||
|
|
||||||
|
produces the stream `{ 0, 2, 4, 6, 8 }`."
|
||||||
|
tagged("Streams")
|
||||||
|
shared {Element+} loop<Element>(
|
||||||
|
"The first element of the resulting stream."
|
||||||
|
Element first)(
|
||||||
|
"The function that produces the next element of the
|
||||||
|
stream, given the current element. The function may
|
||||||
|
return [[finished]] to indicate the end of the
|
||||||
|
stream."
|
||||||
|
Element|Finished next(Element element))
|
||||||
|
=> let (start = first)
|
||||||
|
object satisfies {Element+} {
|
||||||
|
first => start;
|
||||||
|
empty => false;
|
||||||
|
function nextElement(Element element)
|
||||||
|
=> next(element);
|
||||||
|
iterator()
|
||||||
|
=> object satisfies Iterator<Element> {
|
||||||
|
variable Element|Finished current = start;
|
||||||
|
shared actual Element|Finished next() {
|
||||||
|
if (!is Finished result = current) {
|
||||||
|
current = nextElement(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
</textarea></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var cEditor = CodeMirror.fromTextArea(document.getElementById("c-code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-csrc"
|
||||||
|
});
|
||||||
|
var cppEditor = CodeMirror.fromTextArea(document.getElementById("cpp-code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-c++src"
|
||||||
|
});
|
||||||
|
var javaEditor = CodeMirror.fromTextArea(document.getElementById("java-code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-java"
|
||||||
|
});
|
||||||
|
var objectivecEditor = CodeMirror.fromTextArea(document.getElementById("objectivec-code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-objectivec"
|
||||||
|
});
|
||||||
|
var scalaEditor = CodeMirror.fromTextArea(document.getElementById("scala-code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-scala"
|
||||||
|
});
|
||||||
|
var kotlinEditor = CodeMirror.fromTextArea(document.getElementById("kotlin-code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-kotlin"
|
||||||
|
});
|
||||||
|
var ceylonEditor = CodeMirror.fromTextArea(document.getElementById("ceylon-code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-ceylon"
|
||||||
|
});
|
||||||
|
var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault;
|
||||||
|
CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>Simple mode that tries to handle C-like languages as well as it
|
||||||
|
can. Takes two configuration parameters: <code>keywords</code>, an
|
||||||
|
object whose property names are the keywords in the language,
|
||||||
|
and <code>useCPP</code>, which determines whether C preprocessor
|
||||||
|
directives are recognized.</p>
|
||||||
|
|
||||||
|
<p><strong>MIME types defined:</strong> <code>text/x-csrc</code>
|
||||||
|
(C), <code>text/x-c++src</code> (C++), <code>text/x-java</code>
|
||||||
|
(Java), <code>text/x-csharp</code> (C#),
|
||||||
|
<code>text/x-objectivec</code> (Objective-C),
|
||||||
|
<code>text/x-scala</code> (Scala), <code>text/x-vertex</code>
|
||||||
|
<code>x-shader/x-fragment</code> (shader programs),
|
||||||
|
<code>text/x-squirrel</code> (Squirrel) and
|
||||||
|
<code>text/x-ceylon</code> (Ceylon)</p>
|
||||||
|
</article>
|
767
codemirror/mode/clike/scala.html
vendored
Normal file
767
codemirror/mode/clike/scala.html
vendored
Normal file
@ -0,0 +1,767 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: Scala mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<link rel="stylesheet" href="../../theme/ambiance.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||||
|
<script src="clike.js"></script>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">Scala</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>Scala mode</h2>
|
||||||
|
<form>
|
||||||
|
<textarea id="code" name="code">
|
||||||
|
|
||||||
|
/* __ *\
|
||||||
|
** ________ ___ / / ___ Scala API **
|
||||||
|
** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
|
||||||
|
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||||
|
** /____/\___/_/ |_/____/_/ | | **
|
||||||
|
** |/ **
|
||||||
|
\* */
|
||||||
|
|
||||||
|
package scala.collection
|
||||||
|
|
||||||
|
import generic._
|
||||||
|
import mutable.{ Builder, ListBuffer }
|
||||||
|
import annotation.{tailrec, migration, bridge}
|
||||||
|
import annotation.unchecked.{ uncheckedVariance => uV }
|
||||||
|
import parallel.ParIterable
|
||||||
|
|
||||||
|
/** A template trait for traversable collections of type `Traversable[A]`.
|
||||||
|
*
|
||||||
|
* $traversableInfo
|
||||||
|
* @define mutability
|
||||||
|
* @define traversableInfo
|
||||||
|
* This is a base trait of all kinds of $mutability Scala collections. It
|
||||||
|
* implements the behavior common to all collections, in terms of a method
|
||||||
|
* `foreach` with signature:
|
||||||
|
* {{{
|
||||||
|
* def foreach[U](f: Elem => U): Unit
|
||||||
|
* }}}
|
||||||
|
* Collection classes mixing in this trait provide a concrete
|
||||||
|
* `foreach` method which traverses all the
|
||||||
|
* elements contained in the collection, applying a given function to each.
|
||||||
|
* They also need to provide a method `newBuilder`
|
||||||
|
* which creates a builder for collections of the same kind.
|
||||||
|
*
|
||||||
|
* A traversable class might or might not have two properties: strictness
|
||||||
|
* and orderedness. Neither is represented as a type.
|
||||||
|
*
|
||||||
|
* The instances of a strict collection class have all their elements
|
||||||
|
* computed before they can be used as values. By contrast, instances of
|
||||||
|
* a non-strict collection class may defer computation of some of their
|
||||||
|
* elements until after the instance is available as a value.
|
||||||
|
* A typical example of a non-strict collection class is a
|
||||||
|
* <a href="../immutable/Stream.html" target="ContentFrame">
|
||||||
|
* `scala.collection.immutable.Stream`</a>.
|
||||||
|
* A more general class of examples are `TraversableViews`.
|
||||||
|
*
|
||||||
|
* If a collection is an instance of an ordered collection class, traversing
|
||||||
|
* its elements with `foreach` will always visit elements in the
|
||||||
|
* same order, even for different runs of the program. If the class is not
|
||||||
|
* ordered, `foreach` can visit elements in different orders for
|
||||||
|
* different runs (but it will keep the same order in the same run).'
|
||||||
|
*
|
||||||
|
* A typical example of a collection class which is not ordered is a
|
||||||
|
* `HashMap` of objects. The traversal order for hash maps will
|
||||||
|
* depend on the hash codes of its elements, and these hash codes might
|
||||||
|
* differ from one run to the next. By contrast, a `LinkedHashMap`
|
||||||
|
* is ordered because it's `foreach` method visits elements in the
|
||||||
|
* order they were inserted into the `HashMap`.
|
||||||
|
*
|
||||||
|
* @author Martin Odersky
|
||||||
|
* @version 2.8
|
||||||
|
* @since 2.8
|
||||||
|
* @tparam A the element type of the collection
|
||||||
|
* @tparam Repr the type of the actual collection containing the elements.
|
||||||
|
*
|
||||||
|
* @define Coll Traversable
|
||||||
|
* @define coll traversable collection
|
||||||
|
*/
|
||||||
|
trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr]
|
||||||
|
with FilterMonadic[A, Repr]
|
||||||
|
with TraversableOnce[A]
|
||||||
|
with GenTraversableLike[A, Repr]
|
||||||
|
with Parallelizable[A, ParIterable[A]]
|
||||||
|
{
|
||||||
|
self =>
|
||||||
|
|
||||||
|
import Traversable.breaks._
|
||||||
|
|
||||||
|
/** The type implementing this traversable */
|
||||||
|
protected type Self = Repr
|
||||||
|
|
||||||
|
/** The collection of type $coll underlying this `TraversableLike` object.
|
||||||
|
* By default this is implemented as the `TraversableLike` object itself,
|
||||||
|
* but this can be overridden.
|
||||||
|
*/
|
||||||
|
def repr: Repr = this.asInstanceOf[Repr]
|
||||||
|
|
||||||
|
/** The underlying collection seen as an instance of `$Coll`.
|
||||||
|
* By default this is implemented as the current collection object itself,
|
||||||
|
* but this can be overridden.
|
||||||
|
*/
|
||||||
|
protected[this] def thisCollection: Traversable[A] = this.asInstanceOf[Traversable[A]]
|
||||||
|
|
||||||
|
/** A conversion from collections of type `Repr` to `$Coll` objects.
|
||||||
|
* By default this is implemented as just a cast, but this can be overridden.
|
||||||
|
*/
|
||||||
|
protected[this] def toCollection(repr: Repr): Traversable[A] = repr.asInstanceOf[Traversable[A]]
|
||||||
|
|
||||||
|
/** Creates a new builder for this collection type.
|
||||||
|
*/
|
||||||
|
protected[this] def newBuilder: Builder[A, Repr]
|
||||||
|
|
||||||
|
protected[this] def parCombiner = ParIterable.newCombiner[A]
|
||||||
|
|
||||||
|
/** Applies a function `f` to all elements of this $coll.
|
||||||
|
*
|
||||||
|
* Note: this method underlies the implementation of most other bulk operations.
|
||||||
|
* It's important to implement this method in an efficient way.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param f the function that is applied for its side-effect to every element.
|
||||||
|
* The result of function `f` is discarded.
|
||||||
|
*
|
||||||
|
* @tparam U the type parameter describing the result of function `f`.
|
||||||
|
* This result will always be ignored. Typically `U` is `Unit`,
|
||||||
|
* but this is not necessary.
|
||||||
|
*
|
||||||
|
* @usecase def foreach(f: A => Unit): Unit
|
||||||
|
*/
|
||||||
|
def foreach[U](f: A => U): Unit
|
||||||
|
|
||||||
|
/** Tests whether this $coll is empty.
|
||||||
|
*
|
||||||
|
* @return `true` if the $coll contain no elements, `false` otherwise.
|
||||||
|
*/
|
||||||
|
def isEmpty: Boolean = {
|
||||||
|
var result = true
|
||||||
|
breakable {
|
||||||
|
for (x <- this) {
|
||||||
|
result = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tests whether this $coll is known to have a finite size.
|
||||||
|
* All strict collections are known to have finite size. For a non-strict collection
|
||||||
|
* such as `Stream`, the predicate returns `true` if all elements have been computed.
|
||||||
|
* It returns `false` if the stream is not yet evaluated to the end.
|
||||||
|
*
|
||||||
|
* Note: many collection methods will not work on collections of infinite sizes.
|
||||||
|
*
|
||||||
|
* @return `true` if this collection is known to have finite size, `false` otherwise.
|
||||||
|
*/
|
||||||
|
def hasDefiniteSize = true
|
||||||
|
|
||||||
|
def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.seq.size)
|
||||||
|
b ++= thisCollection
|
||||||
|
b ++= that.seq
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
@bridge
|
||||||
|
def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That =
|
||||||
|
++(that: GenTraversableOnce[B])(bf)
|
||||||
|
|
||||||
|
/** Concatenates this $coll with the elements of a traversable collection.
|
||||||
|
* It differs from ++ in that the right operand determines the type of the
|
||||||
|
* resulting collection rather than the left one.
|
||||||
|
*
|
||||||
|
* @param that the traversable to append.
|
||||||
|
* @tparam B the element type of the returned collection.
|
||||||
|
* @tparam That $thatinfo
|
||||||
|
* @param bf $bfinfo
|
||||||
|
* @return a new collection of type `That` which contains all elements
|
||||||
|
* of this $coll followed by all elements of `that`.
|
||||||
|
*
|
||||||
|
* @usecase def ++:[B](that: TraversableOnce[B]): $Coll[B]
|
||||||
|
*
|
||||||
|
* @return a new $coll which contains all elements of this $coll
|
||||||
|
* followed by all elements of `that`.
|
||||||
|
*/
|
||||||
|
def ++:[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.size)
|
||||||
|
b ++= that
|
||||||
|
b ++= thisCollection
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This overload exists because: for the implementation of ++: we should reuse
|
||||||
|
* that of ++ because many collections override it with more efficient versions.
|
||||||
|
* Since TraversableOnce has no '++' method, we have to implement that directly,
|
||||||
|
* but Traversable and down can use the overload.
|
||||||
|
*/
|
||||||
|
def ++:[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That =
|
||||||
|
(that ++ seq)(breakOut)
|
||||||
|
|
||||||
|
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
b.sizeHint(this)
|
||||||
|
for (x <- this) b += f(x)
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
for (x <- this) b ++= f(x).seq
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Selects all elements of this $coll which satisfy a predicate.
|
||||||
|
*
|
||||||
|
* @param p the predicate used to test elements.
|
||||||
|
* @return a new $coll consisting of all elements of this $coll that satisfy the given
|
||||||
|
* predicate `p`. The order of the elements is preserved.
|
||||||
|
*/
|
||||||
|
def filter(p: A => Boolean): Repr = {
|
||||||
|
val b = newBuilder
|
||||||
|
for (x <- this)
|
||||||
|
if (p(x)) b += x
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Selects all elements of this $coll which do not satisfy a predicate.
|
||||||
|
*
|
||||||
|
* @param p the predicate used to test elements.
|
||||||
|
* @return a new $coll consisting of all elements of this $coll that do not satisfy the given
|
||||||
|
* predicate `p`. The order of the elements is preserved.
|
||||||
|
*/
|
||||||
|
def filterNot(p: A => Boolean): Repr = filter(!p(_))
|
||||||
|
|
||||||
|
def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
for (x <- this) if (pf.isDefinedAt(x)) b += pf(x)
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Builds a new collection by applying an option-valued function to all
|
||||||
|
* elements of this $coll on which the function is defined.
|
||||||
|
*
|
||||||
|
* @param f the option-valued function which filters and maps the $coll.
|
||||||
|
* @tparam B the element type of the returned collection.
|
||||||
|
* @tparam That $thatinfo
|
||||||
|
* @param bf $bfinfo
|
||||||
|
* @return a new collection of type `That` resulting from applying the option-valued function
|
||||||
|
* `f` to each element and collecting all defined results.
|
||||||
|
* The order of the elements is preserved.
|
||||||
|
*
|
||||||
|
* @usecase def filterMap[B](f: A => Option[B]): $Coll[B]
|
||||||
|
*
|
||||||
|
* @param pf the partial function which filters and maps the $coll.
|
||||||
|
* @return a new $coll resulting from applying the given option-valued function
|
||||||
|
* `f` to each element and collecting all defined results.
|
||||||
|
* The order of the elements is preserved.
|
||||||
|
def filterMap[B, That](f: A => Option[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
for (x <- this)
|
||||||
|
f(x) match {
|
||||||
|
case Some(y) => b += y
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Partitions this $coll in two ${coll}s according to a predicate.
|
||||||
|
*
|
||||||
|
* @param p the predicate on which to partition.
|
||||||
|
* @return a pair of ${coll}s: the first $coll consists of all elements that
|
||||||
|
* satisfy the predicate `p` and the second $coll consists of all elements
|
||||||
|
* that don't. The relative order of the elements in the resulting ${coll}s
|
||||||
|
* is the same as in the original $coll.
|
||||||
|
*/
|
||||||
|
def partition(p: A => Boolean): (Repr, Repr) = {
|
||||||
|
val l, r = newBuilder
|
||||||
|
for (x <- this) (if (p(x)) l else r) += x
|
||||||
|
(l.result, r.result)
|
||||||
|
}
|
||||||
|
|
||||||
|
def groupBy[K](f: A => K): immutable.Map[K, Repr] = {
|
||||||
|
val m = mutable.Map.empty[K, Builder[A, Repr]]
|
||||||
|
for (elem <- this) {
|
||||||
|
val key = f(elem)
|
||||||
|
val bldr = m.getOrElseUpdate(key, newBuilder)
|
||||||
|
bldr += elem
|
||||||
|
}
|
||||||
|
val b = immutable.Map.newBuilder[K, Repr]
|
||||||
|
for ((k, v) <- m)
|
||||||
|
b += ((k, v.result))
|
||||||
|
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tests whether a predicate holds for all elements of this $coll.
|
||||||
|
*
|
||||||
|
* $mayNotTerminateInf
|
||||||
|
*
|
||||||
|
* @param p the predicate used to test elements.
|
||||||
|
* @return `true` if the given predicate `p` holds for all elements
|
||||||
|
* of this $coll, otherwise `false`.
|
||||||
|
*/
|
||||||
|
def forall(p: A => Boolean): Boolean = {
|
||||||
|
var result = true
|
||||||
|
breakable {
|
||||||
|
for (x <- this)
|
||||||
|
if (!p(x)) { result = false; break }
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tests whether a predicate holds for some of the elements of this $coll.
|
||||||
|
*
|
||||||
|
* $mayNotTerminateInf
|
||||||
|
*
|
||||||
|
* @param p the predicate used to test elements.
|
||||||
|
* @return `true` if the given predicate `p` holds for some of the
|
||||||
|
* elements of this $coll, otherwise `false`.
|
||||||
|
*/
|
||||||
|
def exists(p: A => Boolean): Boolean = {
|
||||||
|
var result = false
|
||||||
|
breakable {
|
||||||
|
for (x <- this)
|
||||||
|
if (p(x)) { result = true; break }
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Finds the first element of the $coll satisfying a predicate, if any.
|
||||||
|
*
|
||||||
|
* $mayNotTerminateInf
|
||||||
|
* $orderDependent
|
||||||
|
*
|
||||||
|
* @param p the predicate used to test elements.
|
||||||
|
* @return an option value containing the first element in the $coll
|
||||||
|
* that satisfies `p`, or `None` if none exists.
|
||||||
|
*/
|
||||||
|
def find(p: A => Boolean): Option[A] = {
|
||||||
|
var result: Option[A] = None
|
||||||
|
breakable {
|
||||||
|
for (x <- this)
|
||||||
|
if (p(x)) { result = Some(x); break }
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
def scan[B >: A, That](z: B)(op: (B, B) => B)(implicit cbf: CanBuildFrom[Repr, B, That]): That = scanLeft(z)(op)
|
||||||
|
|
||||||
|
def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
b.sizeHint(this, 1)
|
||||||
|
var acc = z
|
||||||
|
b += acc
|
||||||
|
for (x <- this) { acc = op(acc, x); b += acc }
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
@migration(2, 9,
|
||||||
|
"This scanRight definition has changed in 2.9.\n" +
|
||||||
|
"The previous behavior can be reproduced with scanRight.reverse."
|
||||||
|
)
|
||||||
|
def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
var scanned = List(z)
|
||||||
|
var acc = z
|
||||||
|
for (x <- reversed) {
|
||||||
|
acc = op(x, acc)
|
||||||
|
scanned ::= acc
|
||||||
|
}
|
||||||
|
val b = bf(repr)
|
||||||
|
for (elem <- scanned) b += elem
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Selects the first element of this $coll.
|
||||||
|
* $orderDependent
|
||||||
|
* @return the first element of this $coll.
|
||||||
|
* @throws `NoSuchElementException` if the $coll is empty.
|
||||||
|
*/
|
||||||
|
def head: A = {
|
||||||
|
var result: () => A = () => throw new NoSuchElementException
|
||||||
|
breakable {
|
||||||
|
for (x <- this) {
|
||||||
|
result = () => x
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Optionally selects the first element.
|
||||||
|
* $orderDependent
|
||||||
|
* @return the first element of this $coll if it is nonempty, `None` if it is empty.
|
||||||
|
*/
|
||||||
|
def headOption: Option[A] = if (isEmpty) None else Some(head)
|
||||||
|
|
||||||
|
/** Selects all elements except the first.
|
||||||
|
* $orderDependent
|
||||||
|
* @return a $coll consisting of all elements of this $coll
|
||||||
|
* except the first one.
|
||||||
|
* @throws `UnsupportedOperationException` if the $coll is empty.
|
||||||
|
*/
|
||||||
|
override def tail: Repr = {
|
||||||
|
if (isEmpty) throw new UnsupportedOperationException("empty.tail")
|
||||||
|
drop(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Selects the last element.
|
||||||
|
* $orderDependent
|
||||||
|
* @return The last element of this $coll.
|
||||||
|
* @throws NoSuchElementException If the $coll is empty.
|
||||||
|
*/
|
||||||
|
def last: A = {
|
||||||
|
var lst = head
|
||||||
|
for (x <- this)
|
||||||
|
lst = x
|
||||||
|
lst
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Optionally selects the last element.
|
||||||
|
* $orderDependent
|
||||||
|
* @return the last element of this $coll$ if it is nonempty, `None` if it is empty.
|
||||||
|
*/
|
||||||
|
def lastOption: Option[A] = if (isEmpty) None else Some(last)
|
||||||
|
|
||||||
|
/** Selects all elements except the last.
|
||||||
|
* $orderDependent
|
||||||
|
* @return a $coll consisting of all elements of this $coll
|
||||||
|
* except the last one.
|
||||||
|
* @throws `UnsupportedOperationException` if the $coll is empty.
|
||||||
|
*/
|
||||||
|
def init: Repr = {
|
||||||
|
if (isEmpty) throw new UnsupportedOperationException("empty.init")
|
||||||
|
var lst = head
|
||||||
|
var follow = false
|
||||||
|
val b = newBuilder
|
||||||
|
b.sizeHint(this, -1)
|
||||||
|
for (x <- this.seq) {
|
||||||
|
if (follow) b += lst
|
||||||
|
else follow = true
|
||||||
|
lst = x
|
||||||
|
}
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
def take(n: Int): Repr = slice(0, n)
|
||||||
|
|
||||||
|
def drop(n: Int): Repr =
|
||||||
|
if (n <= 0) {
|
||||||
|
val b = newBuilder
|
||||||
|
b.sizeHint(this)
|
||||||
|
b ++= thisCollection result
|
||||||
|
}
|
||||||
|
else sliceWithKnownDelta(n, Int.MaxValue, -n)
|
||||||
|
|
||||||
|
def slice(from: Int, until: Int): Repr = sliceWithKnownBound(math.max(from, 0), until)
|
||||||
|
|
||||||
|
// Precondition: from >= 0, until > 0, builder already configured for building.
|
||||||
|
private[this] def sliceInternal(from: Int, until: Int, b: Builder[A, Repr]): Repr = {
|
||||||
|
var i = 0
|
||||||
|
breakable {
|
||||||
|
for (x <- this.seq) {
|
||||||
|
if (i >= from) b += x
|
||||||
|
i += 1
|
||||||
|
if (i >= until) break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
// Precondition: from >= 0
|
||||||
|
private[scala] def sliceWithKnownDelta(from: Int, until: Int, delta: Int): Repr = {
|
||||||
|
val b = newBuilder
|
||||||
|
if (until <= from) b.result
|
||||||
|
else {
|
||||||
|
b.sizeHint(this, delta)
|
||||||
|
sliceInternal(from, until, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Precondition: from >= 0
|
||||||
|
private[scala] def sliceWithKnownBound(from: Int, until: Int): Repr = {
|
||||||
|
val b = newBuilder
|
||||||
|
if (until <= from) b.result
|
||||||
|
else {
|
||||||
|
b.sizeHintBounded(until - from, this)
|
||||||
|
sliceInternal(from, until, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def takeWhile(p: A => Boolean): Repr = {
|
||||||
|
val b = newBuilder
|
||||||
|
breakable {
|
||||||
|
for (x <- this) {
|
||||||
|
if (!p(x)) break
|
||||||
|
b += x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
def dropWhile(p: A => Boolean): Repr = {
|
||||||
|
val b = newBuilder
|
||||||
|
var go = false
|
||||||
|
for (x <- this) {
|
||||||
|
if (!p(x)) go = true
|
||||||
|
if (go) b += x
|
||||||
|
}
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
def span(p: A => Boolean): (Repr, Repr) = {
|
||||||
|
val l, r = newBuilder
|
||||||
|
var toLeft = true
|
||||||
|
for (x <- this) {
|
||||||
|
toLeft = toLeft && p(x)
|
||||||
|
(if (toLeft) l else r) += x
|
||||||
|
}
|
||||||
|
(l.result, r.result)
|
||||||
|
}
|
||||||
|
|
||||||
|
def splitAt(n: Int): (Repr, Repr) = {
|
||||||
|
val l, r = newBuilder
|
||||||
|
l.sizeHintBounded(n, this)
|
||||||
|
if (n >= 0) r.sizeHint(this, -n)
|
||||||
|
var i = 0
|
||||||
|
for (x <- this) {
|
||||||
|
(if (i < n) l else r) += x
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
(l.result, r.result)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Iterates over the tails of this $coll. The first value will be this
|
||||||
|
* $coll and the final one will be an empty $coll, with the intervening
|
||||||
|
* values the results of successive applications of `tail`.
|
||||||
|
*
|
||||||
|
* @return an iterator over all the tails of this $coll
|
||||||
|
* @example `List(1,2,3).tails = Iterator(List(1,2,3), List(2,3), List(3), Nil)`
|
||||||
|
*/
|
||||||
|
def tails: Iterator[Repr] = iterateUntilEmpty(_.tail)
|
||||||
|
|
||||||
|
/** Iterates over the inits of this $coll. The first value will be this
|
||||||
|
* $coll and the final one will be an empty $coll, with the intervening
|
||||||
|
* values the results of successive applications of `init`.
|
||||||
|
*
|
||||||
|
* @return an iterator over all the inits of this $coll
|
||||||
|
* @example `List(1,2,3).inits = Iterator(List(1,2,3), List(1,2), List(1), Nil)`
|
||||||
|
*/
|
||||||
|
def inits: Iterator[Repr] = iterateUntilEmpty(_.init)
|
||||||
|
|
||||||
|
/** Copies elements of this $coll to an array.
|
||||||
|
* Fills the given array `xs` with at most `len` elements of
|
||||||
|
* this $coll, starting at position `start`.
|
||||||
|
* Copying will stop once either the end of the current $coll is reached,
|
||||||
|
* or the end of the array is reached, or `len` elements have been copied.
|
||||||
|
*
|
||||||
|
* $willNotTerminateInf
|
||||||
|
*
|
||||||
|
* @param xs the array to fill.
|
||||||
|
* @param start the starting index.
|
||||||
|
* @param len the maximal number of elements to copy.
|
||||||
|
* @tparam B the type of the elements of the array.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit
|
||||||
|
*/
|
||||||
|
def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) {
|
||||||
|
var i = start
|
||||||
|
val end = (start + len) min xs.length
|
||||||
|
breakable {
|
||||||
|
for (x <- this) {
|
||||||
|
if (i >= end) break
|
||||||
|
xs(i) = x
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def toTraversable: Traversable[A] = thisCollection
|
||||||
|
def toIterator: Iterator[A] = toStream.iterator
|
||||||
|
def toStream: Stream[A] = toBuffer.toStream
|
||||||
|
|
||||||
|
/** Converts this $coll to a string.
|
||||||
|
*
|
||||||
|
* @return a string representation of this collection. By default this
|
||||||
|
* string consists of the `stringPrefix` of this $coll,
|
||||||
|
* followed by all elements separated by commas and enclosed in parentheses.
|
||||||
|
*/
|
||||||
|
override def toString = mkString(stringPrefix + "(", ", ", ")")
|
||||||
|
|
||||||
|
/** Defines the prefix of this object's `toString` representation.
|
||||||
|
*
|
||||||
|
* @return a string representation which starts the result of `toString`
|
||||||
|
* applied to this $coll. By default the string prefix is the
|
||||||
|
* simple name of the collection class $coll.
|
||||||
|
*/
|
||||||
|
def stringPrefix : String = {
|
||||||
|
var string = repr.asInstanceOf[AnyRef].getClass.getName
|
||||||
|
val idx1 = string.lastIndexOf('.' : Int)
|
||||||
|
if (idx1 != -1) string = string.substring(idx1 + 1)
|
||||||
|
val idx2 = string.indexOf('$')
|
||||||
|
if (idx2 != -1) string = string.substring(0, idx2)
|
||||||
|
string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a non-strict view of this $coll.
|
||||||
|
*
|
||||||
|
* @return a non-strict view of this $coll.
|
||||||
|
*/
|
||||||
|
def view = new TraversableView[A, Repr] {
|
||||||
|
protected lazy val underlying = self.repr
|
||||||
|
override def foreach[U](f: A => U) = self foreach f
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a non-strict view of a slice of this $coll.
|
||||||
|
*
|
||||||
|
* Note: the difference between `view` and `slice` is that `view` produces
|
||||||
|
* a view of the current $coll, whereas `slice` produces a new $coll.
|
||||||
|
*
|
||||||
|
* Note: `view(from, to)` is equivalent to `view.slice(from, to)`
|
||||||
|
* $orderDependent
|
||||||
|
*
|
||||||
|
* @param from the index of the first element of the view
|
||||||
|
* @param until the index of the element following the view
|
||||||
|
* @return a non-strict view of a slice of this $coll, starting at index `from`
|
||||||
|
* and extending up to (but not including) index `until`.
|
||||||
|
*/
|
||||||
|
def view(from: Int, until: Int): TraversableView[A, Repr] = view.slice(from, until)
|
||||||
|
|
||||||
|
/** Creates a non-strict filter of this $coll.
|
||||||
|
*
|
||||||
|
* Note: the difference between `c filter p` and `c withFilter p` is that
|
||||||
|
* the former creates a new collection, whereas the latter only
|
||||||
|
* restricts the domain of subsequent `map`, `flatMap`, `foreach`,
|
||||||
|
* and `withFilter` operations.
|
||||||
|
* $orderDependent
|
||||||
|
*
|
||||||
|
* @param p the predicate used to test elements.
|
||||||
|
* @return an object of class `WithFilter`, which supports
|
||||||
|
* `map`, `flatMap`, `foreach`, and `withFilter` operations.
|
||||||
|
* All these operations apply to those elements of this $coll which
|
||||||
|
* satisfy the predicate `p`.
|
||||||
|
*/
|
||||||
|
def withFilter(p: A => Boolean): FilterMonadic[A, Repr] = new WithFilter(p)
|
||||||
|
|
||||||
|
/** A class supporting filtered operations. Instances of this class are
|
||||||
|
* returned by method `withFilter`.
|
||||||
|
*/
|
||||||
|
class WithFilter(p: A => Boolean) extends FilterMonadic[A, Repr] {
|
||||||
|
|
||||||
|
/** Builds a new collection by applying a function to all elements of the
|
||||||
|
* outer $coll containing this `WithFilter` instance that satisfy predicate `p`.
|
||||||
|
*
|
||||||
|
* @param f the function to apply to each element.
|
||||||
|
* @tparam B the element type of the returned collection.
|
||||||
|
* @tparam That $thatinfo
|
||||||
|
* @param bf $bfinfo
|
||||||
|
* @return a new collection of type `That` resulting from applying
|
||||||
|
* the given function `f` to each element of the outer $coll
|
||||||
|
* that satisfies predicate `p` and collecting the results.
|
||||||
|
*
|
||||||
|
* @usecase def map[B](f: A => B): $Coll[B]
|
||||||
|
*
|
||||||
|
* @return a new $coll resulting from applying the given function
|
||||||
|
* `f` to each element of the outer $coll that satisfies
|
||||||
|
* predicate `p` and collecting the results.
|
||||||
|
*/
|
||||||
|
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
for (x <- self)
|
||||||
|
if (p(x)) b += f(x)
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Builds a new collection by applying a function to all elements of the
|
||||||
|
* outer $coll containing this `WithFilter` instance that satisfy
|
||||||
|
* predicate `p` and concatenating the results.
|
||||||
|
*
|
||||||
|
* @param f the function to apply to each element.
|
||||||
|
* @tparam B the element type of the returned collection.
|
||||||
|
* @tparam That $thatinfo
|
||||||
|
* @param bf $bfinfo
|
||||||
|
* @return a new collection of type `That` resulting from applying
|
||||||
|
* the given collection-valued function `f` to each element
|
||||||
|
* of the outer $coll that satisfies predicate `p` and
|
||||||
|
* concatenating the results.
|
||||||
|
*
|
||||||
|
* @usecase def flatMap[B](f: A => TraversableOnce[B]): $Coll[B]
|
||||||
|
*
|
||||||
|
* @return a new $coll resulting from applying the given collection-valued function
|
||||||
|
* `f` to each element of the outer $coll that satisfies predicate `p` and concatenating the results.
|
||||||
|
*/
|
||||||
|
def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
||||||
|
val b = bf(repr)
|
||||||
|
for (x <- self)
|
||||||
|
if (p(x)) b ++= f(x).seq
|
||||||
|
b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Applies a function `f` to all elements of the outer $coll containing
|
||||||
|
* this `WithFilter` instance that satisfy predicate `p`.
|
||||||
|
*
|
||||||
|
* @param f the function that is applied for its side-effect to every element.
|
||||||
|
* The result of function `f` is discarded.
|
||||||
|
*
|
||||||
|
* @tparam U the type parameter describing the result of function `f`.
|
||||||
|
* This result will always be ignored. Typically `U` is `Unit`,
|
||||||
|
* but this is not necessary.
|
||||||
|
*
|
||||||
|
* @usecase def foreach(f: A => Unit): Unit
|
||||||
|
*/
|
||||||
|
def foreach[U](f: A => U): Unit =
|
||||||
|
for (x <- self)
|
||||||
|
if (p(x)) f(x)
|
||||||
|
|
||||||
|
/** Further refines the filter for this $coll.
|
||||||
|
*
|
||||||
|
* @param q the predicate used to test elements.
|
||||||
|
* @return an object of class `WithFilter`, which supports
|
||||||
|
* `map`, `flatMap`, `foreach`, and `withFilter` operations.
|
||||||
|
* All these operations apply to those elements of this $coll which
|
||||||
|
* satisfy the predicate `q` in addition to the predicate `p`.
|
||||||
|
*/
|
||||||
|
def withFilter(q: A => Boolean): WithFilter =
|
||||||
|
new WithFilter(x => p(x) && q(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
// A helper for tails and inits.
|
||||||
|
private def iterateUntilEmpty(f: Traversable[A @uV] => Traversable[A @uV]): Iterator[Repr] = {
|
||||||
|
val it = Iterator.iterate(thisCollection)(f) takeWhile (x => !x.isEmpty)
|
||||||
|
it ++ Iterator(Nil) map (newBuilder ++= _ result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</textarea>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
theme: "ambiance",
|
||||||
|
mode: "text/x-scala"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</article>
|
165
codemirror/mode/clike/test.js
vendored
Normal file
165
codemirror/mode/clike/test.js
vendored
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-c");
|
||||||
|
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
|
||||||
|
|
||||||
|
MT("indent",
|
||||||
|
"[type void] [def foo]([type void*] [variable a], [type int] [variable b]) {",
|
||||||
|
" [type int] [variable c] [operator =] [variable b] [operator +]",
|
||||||
|
" [number 1];",
|
||||||
|
" [keyword return] [operator *][variable a];",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("indent_switch",
|
||||||
|
"[keyword switch] ([variable x]) {",
|
||||||
|
" [keyword case] [number 10]:",
|
||||||
|
" [keyword return] [number 20];",
|
||||||
|
" [keyword default]:",
|
||||||
|
" [variable printf]([string \"foo %c\"], [variable x]);",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("def",
|
||||||
|
"[type void] [def foo]() {}",
|
||||||
|
"[keyword struct] [def bar]{}",
|
||||||
|
"[keyword enum] [def zot]{}",
|
||||||
|
"[keyword union] [def ugh]{}",
|
||||||
|
"[type int] [type *][def baz]() {}");
|
||||||
|
|
||||||
|
MT("def_new_line",
|
||||||
|
"::[variable std]::[variable SomeTerribleType][operator <][variable T][operator >]",
|
||||||
|
"[def SomeLongMethodNameThatDoesntFitIntoOneLine]([keyword const] [variable MyType][operator &] [variable param]) {}")
|
||||||
|
|
||||||
|
MT("double_block",
|
||||||
|
"[keyword for] (;;)",
|
||||||
|
" [keyword for] (;;)",
|
||||||
|
" [variable x][operator ++];",
|
||||||
|
"[keyword return];");
|
||||||
|
|
||||||
|
MT("preprocessor",
|
||||||
|
"[meta #define FOO 3]",
|
||||||
|
"[type int] [variable foo];",
|
||||||
|
"[meta #define BAR\\]",
|
||||||
|
"[meta 4]",
|
||||||
|
"[type unsigned] [type int] [variable bar] [operator =] [number 8];",
|
||||||
|
"[meta #include <baz> ][comment // comment]")
|
||||||
|
|
||||||
|
MT("c_underscores",
|
||||||
|
"[builtin __FOO];",
|
||||||
|
"[builtin _Complex];",
|
||||||
|
"[builtin __aName];",
|
||||||
|
"[variable _aName];");
|
||||||
|
|
||||||
|
MT("c_types",
|
||||||
|
"[type int];",
|
||||||
|
"[type long];",
|
||||||
|
"[type char];",
|
||||||
|
"[type short];",
|
||||||
|
"[type double];",
|
||||||
|
"[type float];",
|
||||||
|
"[type unsigned];",
|
||||||
|
"[type signed];",
|
||||||
|
"[type void];",
|
||||||
|
"[type bool];",
|
||||||
|
"[type foo_t];",
|
||||||
|
"[variable foo_T];",
|
||||||
|
"[variable _t];");
|
||||||
|
|
||||||
|
var mode_cpp = CodeMirror.getMode({indentUnit: 2}, "text/x-c++src");
|
||||||
|
function MTCPP(name) { test.mode(name, mode_cpp, Array.prototype.slice.call(arguments, 1)); }
|
||||||
|
|
||||||
|
MTCPP("cpp14_literal",
|
||||||
|
"[number 10'000];",
|
||||||
|
"[number 0b10'000];",
|
||||||
|
"[number 0x10'000];",
|
||||||
|
"[string '100000'];");
|
||||||
|
|
||||||
|
MTCPP("ctor_dtor",
|
||||||
|
"[def Foo::Foo]() {}",
|
||||||
|
"[def Foo::~Foo]() {}");
|
||||||
|
|
||||||
|
MTCPP("cpp_underscores",
|
||||||
|
"[builtin __FOO];",
|
||||||
|
"[builtin _Complex];",
|
||||||
|
"[builtin __aName];",
|
||||||
|
"[variable _aName];");
|
||||||
|
|
||||||
|
var mode_objc = CodeMirror.getMode({indentUnit: 2}, "text/x-objectivec");
|
||||||
|
function MTOBJC(name) { test.mode(name, mode_objc, Array.prototype.slice.call(arguments, 1)); }
|
||||||
|
|
||||||
|
MTOBJC("objc_underscores",
|
||||||
|
"[builtin __FOO];",
|
||||||
|
"[builtin _Complex];",
|
||||||
|
"[builtin __aName];",
|
||||||
|
"[variable _aName];");
|
||||||
|
|
||||||
|
MTOBJC("objc_interface",
|
||||||
|
"[keyword @interface] [def foo] {",
|
||||||
|
" [type int] [variable bar];",
|
||||||
|
"}",
|
||||||
|
"[keyword @property] ([keyword atomic], [keyword nullable]) [variable NSString][operator *] [variable a];",
|
||||||
|
"[keyword @property] ([keyword nonatomic], [keyword assign]) [type int] [variable b];",
|
||||||
|
"[operator -]([type instancetype])[variable initWithFoo]:([type int])[variable a] " +
|
||||||
|
"[builtin NS_DESIGNATED_INITIALIZER];",
|
||||||
|
"[keyword @end]");
|
||||||
|
|
||||||
|
MTOBJC("objc_implementation",
|
||||||
|
"[keyword @implementation] [def foo] {",
|
||||||
|
" [type int] [variable bar];",
|
||||||
|
"}",
|
||||||
|
"[keyword @property] ([keyword readwrite]) [type SEL] [variable a];",
|
||||||
|
"[operator -]([type instancetype])[variable initWithFoo]:([type int])[variable a] {",
|
||||||
|
" [keyword if](([keyword self] [operator =] [[[keyword super] [variable init] ]])) {}",
|
||||||
|
" [keyword return] [keyword self];",
|
||||||
|
"}",
|
||||||
|
"[keyword @end]");
|
||||||
|
|
||||||
|
MTOBJC("objc_types",
|
||||||
|
"[type int];",
|
||||||
|
"[type foo_t];",
|
||||||
|
"[variable foo_T];",
|
||||||
|
"[type id];",
|
||||||
|
"[type SEL];",
|
||||||
|
"[type instancetype];",
|
||||||
|
"[type Class];",
|
||||||
|
"[type Protocol];",
|
||||||
|
"[type BOOL];"
|
||||||
|
);
|
||||||
|
|
||||||
|
var mode_scala = CodeMirror.getMode({indentUnit: 2}, "text/x-scala");
|
||||||
|
function MTSCALA(name) { test.mode("scala_" + name, mode_scala, Array.prototype.slice.call(arguments, 1)); }
|
||||||
|
MTSCALA("nested_comments",
|
||||||
|
"[comment /*]",
|
||||||
|
"[comment But wait /* this is a nested comment */ for real]",
|
||||||
|
"[comment /**** let * me * show * you ****/]",
|
||||||
|
"[comment ///// let / me / show / you /////]",
|
||||||
|
"[comment */]");
|
||||||
|
|
||||||
|
var mode_java = CodeMirror.getMode({indentUnit: 2}, "text/x-java");
|
||||||
|
function MTJAVA(name) { test.mode("java_" + name, mode_java, Array.prototype.slice.call(arguments, 1)); }
|
||||||
|
MTJAVA("types",
|
||||||
|
"[type byte];",
|
||||||
|
"[type short];",
|
||||||
|
"[type int];",
|
||||||
|
"[type long];",
|
||||||
|
"[type float];",
|
||||||
|
"[type double];",
|
||||||
|
"[type boolean];",
|
||||||
|
"[type char];",
|
||||||
|
"[type void];",
|
||||||
|
"[type Boolean];",
|
||||||
|
"[type Byte];",
|
||||||
|
"[type Character];",
|
||||||
|
"[type Double];",
|
||||||
|
"[type Float];",
|
||||||
|
"[type Integer];",
|
||||||
|
"[type Long];",
|
||||||
|
"[type Number];",
|
||||||
|
"[type Object];",
|
||||||
|
"[type Short];",
|
||||||
|
"[type String];",
|
||||||
|
"[type StringBuffer];",
|
||||||
|
"[type StringBuilder];",
|
||||||
|
"[type Void];");
|
||||||
|
})();
|
831
codemirror/mode/css/css.js
vendored
Normal file
831
codemirror/mode/css/css.js
vendored
Normal file
@ -0,0 +1,831 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://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) {
|
||||||
|
var inline = parserConfig.inline
|
||||||
|
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
|
||||||
|
|
||||||
|
var indentUnit = config.indentUnit,
|
||||||
|
tokenHooks = parserConfig.tokenHooks,
|
||||||
|
documentTypes = parserConfig.documentTypes || {},
|
||||||
|
mediaTypes = parserConfig.mediaTypes || {},
|
||||||
|
mediaFeatures = parserConfig.mediaFeatures || {},
|
||||||
|
mediaValueKeywords = parserConfig.mediaValueKeywords || {},
|
||||||
|
propertyKeywords = parserConfig.propertyKeywords || {},
|
||||||
|
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
|
||||||
|
fontProperties = parserConfig.fontProperties || {},
|
||||||
|
counterDescriptors = parserConfig.counterDescriptors || {},
|
||||||
|
colorKeywords = parserConfig.colorKeywords || {},
|
||||||
|
valueKeywords = parserConfig.valueKeywords || {},
|
||||||
|
allowNested = parserConfig.allowNested,
|
||||||
|
lineComment = parserConfig.lineComment,
|
||||||
|
supportsAtComponent = parserConfig.supportsAtComponent === true;
|
||||||
|
|
||||||
|
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 (stream.match(/[\w-.]+(?=\()/)) {
|
||||||
|
if (/^(url(-prefix)?|domain|regexp)$/.test(stream.current().toLowerCase())) {
|
||||||
|
state.tokenize = tokenParenthesized;
|
||||||
|
}
|
||||||
|
return ret("variable callee", "variable");
|
||||||
|
} 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, indent) {
|
||||||
|
state.context = new Context(type, stream.indentation() + (indent === false ? 0 : indentUnit), state.context);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
function popContext(state) {
|
||||||
|
if (state.context.prev)
|
||||||
|
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 (supportsAtComponent && /@component/i.test(type)) {
|
||||||
|
return pushContext(state, stream, "atComponentBlock");
|
||||||
|
} else if (/^@(-moz-)?document$/i.test(type)) {
|
||||||
|
return pushContext(state, stream, "documentTypes");
|
||||||
|
} else if (/^@(media|supports|(-moz-)?document|import)$/i.test(type)) {
|
||||||
|
return pushContext(state, stream, "atBlock");
|
||||||
|
} else if (/^@(font-face|counter-style)/i.test(type)) {
|
||||||
|
state.stateArg = type;
|
||||||
|
return "restricted_atBlock_before";
|
||||||
|
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/i.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,4}|[0-9a-fA-f]{6}|[0-9a-fA-f]{8})$/.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 == "interpolation") return pushContext(state, stream, "interpolation");
|
||||||
|
if (type == "word") wordAsValue(stream);
|
||||||
|
return "parens";
|
||||||
|
};
|
||||||
|
|
||||||
|
states.pseudo = function(type, stream, state) {
|
||||||
|
if (type == "meta") return "pseudo";
|
||||||
|
|
||||||
|
if (type == "word") {
|
||||||
|
override = "variable-3";
|
||||||
|
return state.context.type;
|
||||||
|
}
|
||||||
|
return pass(type, stream, state);
|
||||||
|
};
|
||||||
|
|
||||||
|
states.documentTypes = function(type, stream, state) {
|
||||||
|
if (type == "word" && documentTypes.hasOwnProperty(stream.current())) {
|
||||||
|
override = "tag";
|
||||||
|
return state.context.type;
|
||||||
|
} else {
|
||||||
|
return states.atBlock(type, stream, state);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
states.atBlock = function(type, stream, state) {
|
||||||
|
if (type == "(") return pushContext(state, stream, "atBlock_parens");
|
||||||
|
if (type == "}" || type == ";") return popAndPass(type, stream, state);
|
||||||
|
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
|
||||||
|
|
||||||
|
if (type == "interpolation") return pushContext(state, stream, "interpolation");
|
||||||
|
|
||||||
|
if (type == "word") {
|
||||||
|
var word = stream.current().toLowerCase();
|
||||||
|
if (word == "only" || word == "not" || word == "and" || word == "or")
|
||||||
|
override = "keyword";
|
||||||
|
else if (mediaTypes.hasOwnProperty(word))
|
||||||
|
override = "attribute";
|
||||||
|
else if (mediaFeatures.hasOwnProperty(word))
|
||||||
|
override = "property";
|
||||||
|
else if (mediaValueKeywords.hasOwnProperty(word))
|
||||||
|
override = "keyword";
|
||||||
|
else if (propertyKeywords.hasOwnProperty(word))
|
||||||
|
override = "property";
|
||||||
|
else if (nonStandardPropertyKeywords.hasOwnProperty(word))
|
||||||
|
override = "string-2";
|
||||||
|
else if (valueKeywords.hasOwnProperty(word))
|
||||||
|
override = "atom";
|
||||||
|
else if (colorKeywords.hasOwnProperty(word))
|
||||||
|
override = "keyword";
|
||||||
|
else
|
||||||
|
override = "error";
|
||||||
|
}
|
||||||
|
return state.context.type;
|
||||||
|
};
|
||||||
|
|
||||||
|
states.atComponentBlock = function(type, stream, state) {
|
||||||
|
if (type == "}")
|
||||||
|
return popAndPass(type, stream, state);
|
||||||
|
if (type == "{")
|
||||||
|
return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top", false);
|
||||||
|
if (type == "word")
|
||||||
|
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 == "word") override = "variable";
|
||||||
|
else if (type != "variable" && type != "(" && type != ")") override = "error";
|
||||||
|
return "interpolation";
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
startState: function(base) {
|
||||||
|
return {tokenize: null,
|
||||||
|
state: inline ? "block" : "top",
|
||||||
|
stateArg: null,
|
||||||
|
context: new Context(inline ? "block" : "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;
|
||||||
|
if (type != "comment")
|
||||||
|
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) {
|
||||||
|
if (ch == "}" && (cx.type == "block" || cx.type == "top" ||
|
||||||
|
cx.type == "interpolation" || cx.type == "restricted_atBlock")) {
|
||||||
|
// Resume indentation from parent context.
|
||||||
|
cx = cx.prev;
|
||||||
|
indent = cx.indent;
|
||||||
|
} else if (ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") ||
|
||||||
|
ch == "{" && (cx.type == "at" || cx.type == "atBlock")) {
|
||||||
|
// Dedent relative to current context.
|
||||||
|
indent = Math.max(0, cx.indent - indentUnit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return indent;
|
||||||
|
},
|
||||||
|
|
||||||
|
electricChars: "}",
|
||||||
|
blockCommentStart: "/*",
|
||||||
|
blockCommentEnd: "*/",
|
||||||
|
blockCommentContinue: " * ",
|
||||||
|
lineComment: lineComment,
|
||||||
|
fold: "brace"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
function keySet(array) {
|
||||||
|
var keys = {};
|
||||||
|
for (var i = 0; i < array.length; ++i) {
|
||||||
|
keys[array[i].toLowerCase()] = 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", "orientation",
|
||||||
|
"device-pixel-ratio", "min-device-pixel-ratio", "max-device-pixel-ratio",
|
||||||
|
"pointer", "any-pointer", "hover", "any-hover"
|
||||||
|
], mediaFeatures = keySet(mediaFeatures_);
|
||||||
|
|
||||||
|
var mediaValueKeywords_ = [
|
||||||
|
"landscape", "portrait", "none", "coarse", "fine", "on-demand", "hover",
|
||||||
|
"interlace", "progressive"
|
||||||
|
], mediaValueKeywords = keySet(mediaValueKeywords_);
|
||||||
|
|
||||||
|
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-blend-mode", "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", "caret-color", "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-rows", "grid-column", "grid-column-end", "grid-column-gap",
|
||||||
|
"grid-column-start", "grid-gap", "grid-row", "grid-row-end", "grid-row-gap",
|
||||||
|
"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", "justify-items", "justify-self", "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",
|
||||||
|
"marks", "marquee-direction", "marquee-loop",
|
||||||
|
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
|
||||||
|
"max-width", "min-height", "min-width", "mix-blend-mode", "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", "place-content", "place-items", "place-self", "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",
|
||||||
|
"user-select", "vertical-align", "visibility", "voice-balance", "voice-duration",
|
||||||
|
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
|
||||||
|
"voice-volume", "volume", "white-space", "widows", "width", "will-change", "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", "auto-flow", "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", "color", "color-burn", "color-dodge", "column", "column-reverse",
|
||||||
|
"compact", "condensed", "contain", "content", "contents",
|
||||||
|
"content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
|
||||||
|
"cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal",
|
||||||
|
"decimal-leading-zero", "default", "default-button", "dense", "destination-atop",
|
||||||
|
"destination-in", "destination-out", "destination-over", "devanagari", "difference",
|
||||||
|
"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", "exclusion", "expanded", "extends", "extra-condensed",
|
||||||
|
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes",
|
||||||
|
"forwards", "from", "geometricPrecision", "georgian", "graytext", "grid", "groove",
|
||||||
|
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew",
|
||||||
|
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
|
||||||
|
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore",
|
||||||
|
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
|
||||||
|
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
|
||||||
|
"inline-block", "inline-flex", "inline-grid", "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", "lighten",
|
||||||
|
"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", "luminosity", "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", "multiply", "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", "opacity", "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", "row-resize", "row-reverse", "rtl", "run-in", "running",
|
||||||
|
"s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen",
|
||||||
|
"scroll", "scrollbar", "scroll-position", "se-resize", "searchfield",
|
||||||
|
"searchfield-cancel-button", "searchfield-decoration",
|
||||||
|
"searchfield-results-button", "searchfield-results-decoration", "self-start", "self-end",
|
||||||
|
"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", "soft-light", "solid", "somali",
|
||||||
|
"source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "space-evenly", "spell-out", "square",
|
||||||
|
"square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
|
||||||
|
"subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "system-ui", "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", "transform",
|
||||||
|
"translate", "translate3d", "translateX", "translateY", "translateZ",
|
||||||
|
"transparent", "ultra-condensed", "ultra-expanded", "underline", "unset", "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", "wrap", "wrap-reverse", "x-large", "x-small", "xor",
|
||||||
|
"xx-large", "xx-small"
|
||||||
|
], valueKeywords = keySet(valueKeywords_);
|
||||||
|
|
||||||
|
var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(mediaValueKeywords_)
|
||||||
|
.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"];
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.defineMIME("text/css", {
|
||||||
|
documentTypes: documentTypes,
|
||||||
|
mediaTypes: mediaTypes,
|
||||||
|
mediaFeatures: mediaFeatures,
|
||||||
|
mediaValueKeywords: mediaValueKeywords,
|
||||||
|
propertyKeywords: propertyKeywords,
|
||||||
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
||||||
|
fontProperties: fontProperties,
|
||||||
|
counterDescriptors: counterDescriptors,
|
||||||
|
colorKeywords: colorKeywords,
|
||||||
|
valueKeywords: valueKeywords,
|
||||||
|
tokenHooks: {
|
||||||
|
"/": 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,
|
||||||
|
mediaValueKeywords: mediaValueKeywords,
|
||||||
|
propertyKeywords: propertyKeywords,
|
||||||
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
||||||
|
colorKeywords: colorKeywords,
|
||||||
|
valueKeywords: valueKeywords,
|
||||||
|
fontProperties: fontProperties,
|
||||||
|
allowNested: true,
|
||||||
|
lineComment: "//",
|
||||||
|
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*\{/, false))
|
||||||
|
return [null, 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,
|
||||||
|
mediaValueKeywords: mediaValueKeywords,
|
||||||
|
propertyKeywords: propertyKeywords,
|
||||||
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
||||||
|
colorKeywords: colorKeywords,
|
||||||
|
valueKeywords: valueKeywords,
|
||||||
|
fontProperties: fontProperties,
|
||||||
|
allowNested: true,
|
||||||
|
lineComment: "//",
|
||||||
|
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.eat("{")) return [null, "interpolation"];
|
||||||
|
if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/i, 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.defineMIME("text/x-gss", {
|
||||||
|
documentTypes: documentTypes,
|
||||||
|
mediaTypes: mediaTypes,
|
||||||
|
mediaFeatures: mediaFeatures,
|
||||||
|
propertyKeywords: propertyKeywords,
|
||||||
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
||||||
|
fontProperties: fontProperties,
|
||||||
|
counterDescriptors: counterDescriptors,
|
||||||
|
colorKeywords: colorKeywords,
|
||||||
|
valueKeywords: valueKeywords,
|
||||||
|
supportsAtComponent: true,
|
||||||
|
tokenHooks: {
|
||||||
|
"/": function(stream, state) {
|
||||||
|
if (!stream.eat("*")) return false;
|
||||||
|
state.tokenize = tokenCComment;
|
||||||
|
return tokenCComment(stream, state);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
name: "css",
|
||||||
|
helperType: "gss"
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
104
codemirror/mode/css/gss.html
vendored
Normal file
104
codemirror/mode/css/gss.html
vendored
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: Closure Stylesheets (GSS) mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<link rel="stylesheet" href="../../addon/hint/show-hint.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="css.js"></script>
|
||||||
|
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||||
|
<script src="../../addon/hint/show-hint.js"></script>
|
||||||
|
<script src="../../addon/hint/css-hint.js"></script>
|
||||||
|
<style>.CodeMirror {background: #f8f8f8;}</style>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">Closure Stylesheets (GSS)</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>Closure Stylesheets (GSS) mode</h2>
|
||||||
|
<form><textarea id="code" name="code">
|
||||||
|
/* Some example Closure Stylesheets */
|
||||||
|
|
||||||
|
@provide 'some.styles';
|
||||||
|
|
||||||
|
@require 'other.styles';
|
||||||
|
|
||||||
|
@component {
|
||||||
|
|
||||||
|
@def FONT_FAMILY "Times New Roman", Georgia, Serif;
|
||||||
|
@def FONT_SIZE_NORMAL 15px;
|
||||||
|
@def FONT_NORMAL normal FONT_SIZE_NORMAL FONT_FAMILY;
|
||||||
|
|
||||||
|
@def BG_COLOR rgb(235, 239, 249);
|
||||||
|
|
||||||
|
@def DIALOG_BORDER_COLOR rgb(107, 144, 218);
|
||||||
|
@def DIALOG_BG_COLOR BG_COLOR;
|
||||||
|
|
||||||
|
@def LEFT_HAND_NAV_WIDTH 180px;
|
||||||
|
@def LEFT_HAND_NAV_PADDING 3px;
|
||||||
|
|
||||||
|
@defmixin size(WIDTH, HEIGHT) {
|
||||||
|
width: WIDTH;
|
||||||
|
height: HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: BG_COLOR;
|
||||||
|
margin: 0;
|
||||||
|
padding: 3em 6em;
|
||||||
|
font: FONT_NORMAL;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation a {
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog {
|
||||||
|
background-color: DIALOG_BG_COLOR;
|
||||||
|
border: 1px solid DIALOG_BORDER_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
position: absolute;
|
||||||
|
margin-left: add(LEFT_HAND_NAV_PADDING, /* padding left */
|
||||||
|
LEFT_HAND_NAV_WIDTH,
|
||||||
|
LEFT_HAND_NAV_PADDING); /* padding right */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
@mixin size(150px, 55px);
|
||||||
|
background-image: url('http://www.google.com/images/logo_sm.gif');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</textarea></form>
|
||||||
|
<script>
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||||
|
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-gss"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>A mode for <a href="https://github.com/google/closure-stylesheets">Closure Stylesheets</a> (GSS).</p>
|
||||||
|
<p><strong>MIME type defined:</strong> <code>text/x-gss</code>.</p>
|
||||||
|
|
||||||
|
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#gss_*">normal</a>, <a href="../../test/index.html#verbose,gss_*">verbose</a>.</p>
|
||||||
|
|
||||||
|
</article>
|
17
codemirror/mode/css/gss_test.js
vendored
Normal file
17
codemirror/mode/css/gss_test.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-gss");
|
||||||
|
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), "gss"); }
|
||||||
|
|
||||||
|
MT("atComponent",
|
||||||
|
"[def @component] {",
|
||||||
|
"[tag foo] {",
|
||||||
|
" [property color]: [keyword black];",
|
||||||
|
"}",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
})();
|
75
codemirror/mode/css/index.html
vendored
Normal file
75
codemirror/mode/css/index.html
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: CSS mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<link rel="stylesheet" href="../../addon/hint/show-hint.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="css.js"></script>
|
||||||
|
<script src="../../addon/hint/show-hint.js"></script>
|
||||||
|
<script src="../../addon/hint/css-hint.js"></script>
|
||||||
|
<style>.CodeMirror {background: #f8f8f8;}</style>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">CSS</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>CSS mode</h2>
|
||||||
|
<form><textarea id="code" name="code">
|
||||||
|
/* Some example CSS */
|
||||||
|
|
||||||
|
@import url("something.css");
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 3em 6em;
|
||||||
|
font-family: tahoma, arial, sans-serif;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation a {
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.7em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1:before, h2:before {
|
||||||
|
content: "::";
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: courier, monospace;
|
||||||
|
font-size: 80%;
|
||||||
|
color: #418A8A;
|
||||||
|
}
|
||||||
|
</textarea></form>
|
||||||
|
<script>
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||||
|
extraKeys: {"Ctrl-Space": "autocomplete"}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p><strong>MIME types defined:</strong> <code>text/css</code>, <code>text/x-scss</code> (<a href="scss.html">demo</a>), <code>text/x-less</code> (<a href="less.html">demo</a>).</p>
|
||||||
|
|
||||||
|
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#css_*">normal</a>, <a href="../../test/index.html#verbose,css_*">verbose</a>.</p>
|
||||||
|
|
||||||
|
</article>
|
152
codemirror/mode/css/less.html
vendored
Normal file
152
codemirror/mode/css/less.html
vendored
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: LESS mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||||
|
<script src="css.js"></script>
|
||||||
|
<style>.CodeMirror {border: 1px solid #ddd; line-height: 1.2;}</style>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">LESS</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>LESS mode</h2>
|
||||||
|
<form><textarea id="code" name="code">@media screen and (device-aspect-ratio: 16/9) { … }
|
||||||
|
@media screen and (device-aspect-ratio: 1280/720) { … }
|
||||||
|
@media screen and (device-aspect-ratio: 2560/1440) { … }
|
||||||
|
|
||||||
|
html:lang(fr-be)
|
||||||
|
|
||||||
|
tr:nth-child(2n+1) /* represents every odd row of an HTML table */
|
||||||
|
|
||||||
|
img:nth-of-type(2n+1) { float: right; }
|
||||||
|
img:nth-of-type(2n) { float: left; }
|
||||||
|
|
||||||
|
body > h2:not(:first-of-type):not(:last-of-type)
|
||||||
|
|
||||||
|
html|*:not(:link):not(:visited)
|
||||||
|
*|*:not(:hover)
|
||||||
|
p::first-line { text-transform: uppercase }
|
||||||
|
|
||||||
|
@namespace foo url(http://www.example.com);
|
||||||
|
foo|h1 { color: blue } /* first rule */
|
||||||
|
|
||||||
|
span[hello="Ocean"][goodbye="Land"]
|
||||||
|
|
||||||
|
E[foo]{
|
||||||
|
padding:65px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="search"]::-webkit-search-decoration,
|
||||||
|
input[type="search"]::-webkit-search-cancel-button {
|
||||||
|
-webkit-appearance: none; // Inner-padding issues in Chrome OSX, Safari 5
|
||||||
|
}
|
||||||
|
button::-moz-focus-inner,
|
||||||
|
input::-moz-focus-inner { // Inner padding and border oddities in FF3/4
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
.btn {
|
||||||
|
// reset here as of 2.0.3 due to Recess property order
|
||||||
|
border-color: #ccc;
|
||||||
|
border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);
|
||||||
|
}
|
||||||
|
fieldset span button, fieldset span input[type="file"] {
|
||||||
|
font-size:12px;
|
||||||
|
font-family:Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rounded-corners (@radius: 5px) {
|
||||||
|
border-radius: @radius;
|
||||||
|
-webkit-border-radius: @radius;
|
||||||
|
-moz-border-radius: @radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
@import url("something.css");
|
||||||
|
|
||||||
|
@light-blue: hsl(190, 50%, 65%);
|
||||||
|
|
||||||
|
#menu {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
z-index: 3;
|
||||||
|
clear: both;
|
||||||
|
display: block;
|
||||||
|
background-color: @blue;
|
||||||
|
height: 42px;
|
||||||
|
border-top: 2px solid lighten(@alpha-blue, 20%);
|
||||||
|
border-bottom: 2px solid darken(@alpha-blue, 25%);
|
||||||
|
.box-shadow(0, 1px, 8px, 0.6);
|
||||||
|
-moz-box-shadow: 0 0 0 #000; // Because firefox sucks.
|
||||||
|
|
||||||
|
&.docked {
|
||||||
|
background-color: hsla(210, 60%, 40%, 0.4);
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
background-color: @blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#dropdown {
|
||||||
|
margin: 0 0 0 117px;
|
||||||
|
padding: 0;
|
||||||
|
padding-top: 5px;
|
||||||
|
display: none;
|
||||||
|
width: 190px;
|
||||||
|
border-top: 2px solid @medium;
|
||||||
|
color: @highlight;
|
||||||
|
border: 2px solid darken(@medium, 25%);
|
||||||
|
border-left-color: darken(@medium, 15%);
|
||||||
|
border-right-color: darken(@medium, 15%);
|
||||||
|
border-top-width: 0;
|
||||||
|
background-color: darken(@medium, 10%);
|
||||||
|
ul {
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
font-size: 14px;
|
||||||
|
display: block;
|
||||||
|
text-align: left;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
a {
|
||||||
|
display: block;
|
||||||
|
padding: 0px 15px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: white;
|
||||||
|
&:hover {
|
||||||
|
background-color: darken(@medium, 15%);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.border-radius(5px, bottom);
|
||||||
|
.box-shadow(0, 6px, 8px, 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</textarea></form>
|
||||||
|
<script>
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-less"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>The LESS mode is a sub-mode of the <a href="index.html">CSS mode</a> (defined in <code>css.js</code>).</p>
|
||||||
|
|
||||||
|
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#less_*">normal</a>, <a href="../../test/index.html#verbose,less_*">verbose</a>.</p>
|
||||||
|
</article>
|
54
codemirror/mode/css/less_test.js
vendored
Normal file
54
codemirror/mode/css/less_test.js
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-less");
|
||||||
|
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), "less"); }
|
||||||
|
|
||||||
|
MT("variable",
|
||||||
|
"[variable-2 @base]: [atom #f04615];",
|
||||||
|
"[qualifier .class] {",
|
||||||
|
" [property width]: [variable&callee percentage]([number 0.5]); [comment // returns `50%`]",
|
||||||
|
" [property color]: [variable&callee saturate]([variable-2 @base], [number 5%]);",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("amp",
|
||||||
|
"[qualifier .child], [qualifier .sibling] {",
|
||||||
|
" [qualifier .parent] [atom &] {",
|
||||||
|
" [property color]: [keyword black];",
|
||||||
|
" }",
|
||||||
|
" [atom &] + [atom &] {",
|
||||||
|
" [property color]: [keyword red];",
|
||||||
|
" }",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("mixin",
|
||||||
|
"[qualifier .mixin] ([variable dark]; [variable-2 @color]) {",
|
||||||
|
" [property color]: [variable&callee darken]([variable-2 @color], [number 10%]);",
|
||||||
|
"}",
|
||||||
|
"[qualifier .mixin] ([variable light]; [variable-2 @color]) {",
|
||||||
|
" [property color]: [variable&callee lighten]([variable-2 @color], [number 10%]);",
|
||||||
|
"}",
|
||||||
|
"[qualifier .mixin] ([variable-2 @_]; [variable-2 @color]) {",
|
||||||
|
" [property display]: [atom block];",
|
||||||
|
"}",
|
||||||
|
"[variable-2 @switch]: [variable light];",
|
||||||
|
"[qualifier .class] {",
|
||||||
|
" [qualifier .mixin]([variable-2 @switch]; [atom #888]);",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("nest",
|
||||||
|
"[qualifier .one] {",
|
||||||
|
" [def @media] ([property width]: [number 400px]) {",
|
||||||
|
" [property font-size]: [number 1.2em];",
|
||||||
|
" [def @media] [attribute print] [keyword and] [property color] {",
|
||||||
|
" [property color]: [keyword blue];",
|
||||||
|
" }",
|
||||||
|
" }",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
|
||||||
|
MT("interpolation", ".@{[variable foo]} { [property font-weight]: [atom bold]; }");
|
||||||
|
})();
|
158
codemirror/mode/css/scss.html
vendored
Normal file
158
codemirror/mode/css/scss.html
vendored
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: SCSS mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||||
|
<script src="css.js"></script>
|
||||||
|
<style>.CodeMirror {background: #f8f8f8;}</style>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">SCSS</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>SCSS mode</h2>
|
||||||
|
<form><textarea id="code" name="code">
|
||||||
|
/* Some example SCSS */
|
||||||
|
|
||||||
|
@import "compass/css3";
|
||||||
|
$variable: #333;
|
||||||
|
|
||||||
|
$blue: #3bbfce;
|
||||||
|
$margin: 16px;
|
||||||
|
|
||||||
|
.content-navigation {
|
||||||
|
#nested {
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
border-color: $blue;
|
||||||
|
color:
|
||||||
|
darken($blue, 9%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.border {
|
||||||
|
padding: $margin / 2;
|
||||||
|
margin: $margin / 2;
|
||||||
|
border-color: $blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin table-base {
|
||||||
|
th {
|
||||||
|
text-align: center;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
td, th {padding: 2px}
|
||||||
|
}
|
||||||
|
|
||||||
|
table.hl {
|
||||||
|
margin: 2em 0;
|
||||||
|
td.ln {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
font: {
|
||||||
|
family: serif;
|
||||||
|
weight: bold;
|
||||||
|
size: 1.2em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin left($dist) {
|
||||||
|
float: left;
|
||||||
|
margin-left: $dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
#data {
|
||||||
|
@include left(10px);
|
||||||
|
@include table-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.source {
|
||||||
|
@include flow-into(target);
|
||||||
|
border: 10px solid green;
|
||||||
|
margin: 20px;
|
||||||
|
width: 200px; }
|
||||||
|
|
||||||
|
.new-container {
|
||||||
|
@include flow-from(target);
|
||||||
|
border: 10px solid red;
|
||||||
|
margin: 20px;
|
||||||
|
width: 200px; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 3em 6em;
|
||||||
|
font-family: tahoma, arial, sans-serif;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin yellow() {
|
||||||
|
background: yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nested {
|
||||||
|
@include border-radius(3px);
|
||||||
|
@extend .big;
|
||||||
|
p {
|
||||||
|
background: whitesmoke;
|
||||||
|
a {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation a {
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.7em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1:before, h2:before {
|
||||||
|
content: "::";
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: courier, monospace;
|
||||||
|
font-size: 80%;
|
||||||
|
color: #418A8A;
|
||||||
|
}
|
||||||
|
</textarea></form>
|
||||||
|
<script>
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-scss"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>The SCSS mode is a sub-mode of the <a href="index.html">CSS mode</a> (defined in <code>css.js</code>).</p>
|
||||||
|
|
||||||
|
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#scss_*">normal</a>, <a href="../../test/index.html#verbose,scss_*">verbose</a>.</p>
|
||||||
|
|
||||||
|
</article>
|
110
codemirror/mode/css/scss_test.js
vendored
Normal file
110
codemirror/mode/css/scss_test.js
vendored
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-scss");
|
||||||
|
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), "scss"); }
|
||||||
|
|
||||||
|
MT('url_with_quotation',
|
||||||
|
"[tag foo] { [property background]:[variable&callee url]([string test.jpg]) }");
|
||||||
|
|
||||||
|
MT('url_with_double_quotes',
|
||||||
|
"[tag foo] { [property background]:[variable&callee url]([string \"test.jpg\"]) }");
|
||||||
|
|
||||||
|
MT('url_with_single_quotes',
|
||||||
|
"[tag foo] { [property background]:[variable&callee url]([string \'test.jpg\']) }");
|
||||||
|
|
||||||
|
MT('string',
|
||||||
|
"[def @import] [string \"compass/css3\"]");
|
||||||
|
|
||||||
|
MT('important_keyword',
|
||||||
|
"[tag foo] { [property background]:[variable&callee url]([string \'test.jpg\']) [keyword !important] }");
|
||||||
|
|
||||||
|
MT('variable',
|
||||||
|
"[variable-2 $blue]:[atom #333]");
|
||||||
|
|
||||||
|
MT('variable_as_attribute',
|
||||||
|
"[tag foo] { [property color]:[variable-2 $blue] }");
|
||||||
|
|
||||||
|
MT('numbers',
|
||||||
|
"[tag foo] { [property padding]:[number 10px] [number 10] [number 10em] [number 8in] }");
|
||||||
|
|
||||||
|
MT('number_percentage',
|
||||||
|
"[tag foo] { [property width]:[number 80%] }");
|
||||||
|
|
||||||
|
MT('selector',
|
||||||
|
"[builtin #hello][qualifier .world]{}");
|
||||||
|
|
||||||
|
MT('singleline_comment',
|
||||||
|
"[comment // this is a comment]");
|
||||||
|
|
||||||
|
MT('multiline_comment',
|
||||||
|
"[comment /*foobar*/]");
|
||||||
|
|
||||||
|
MT('attribute_with_hyphen',
|
||||||
|
"[tag foo] { [property font-size]:[number 10px] }");
|
||||||
|
|
||||||
|
MT('string_after_attribute',
|
||||||
|
"[tag foo] { [property content]:[string \"::\"] }");
|
||||||
|
|
||||||
|
MT('directives',
|
||||||
|
"[def @include] [qualifier .mixin]");
|
||||||
|
|
||||||
|
MT('basic_structure',
|
||||||
|
"[tag p] { [property background]:[keyword red]; }");
|
||||||
|
|
||||||
|
MT('nested_structure',
|
||||||
|
"[tag p] { [tag a] { [property color]:[keyword red]; } }");
|
||||||
|
|
||||||
|
MT('mixin',
|
||||||
|
"[def @mixin] [tag table-base] {}");
|
||||||
|
|
||||||
|
MT('number_without_semicolon',
|
||||||
|
"[tag p] {[property width]:[number 12]}",
|
||||||
|
"[tag a] {[property color]:[keyword red];}");
|
||||||
|
|
||||||
|
MT('atom_in_nested_block',
|
||||||
|
"[tag p] { [tag a] { [property color]:[atom #000]; } }");
|
||||||
|
|
||||||
|
MT('interpolation_in_property',
|
||||||
|
"[tag foo] { #{[variable-2 $hello]}:[number 2]; }");
|
||||||
|
|
||||||
|
MT('interpolation_in_selector',
|
||||||
|
"[tag foo]#{[variable-2 $hello]} { [property color]:[atom #000]; }");
|
||||||
|
|
||||||
|
MT('interpolation_error',
|
||||||
|
"[tag foo]#{[variable foo]} { [property color]:[atom #000]; }");
|
||||||
|
|
||||||
|
MT("divide_operator",
|
||||||
|
"[tag foo] { [property width]:[number 4] [operator /] [number 2] }");
|
||||||
|
|
||||||
|
MT('nested_structure_with_id_selector',
|
||||||
|
"[tag p] { [builtin #hello] { [property color]:[keyword red]; } }");
|
||||||
|
|
||||||
|
MT('indent_mixin',
|
||||||
|
"[def @mixin] [tag container] (",
|
||||||
|
" [variable-2 $a]: [number 10],",
|
||||||
|
" [variable-2 $b]: [number 10])",
|
||||||
|
"{}");
|
||||||
|
|
||||||
|
MT('indent_nested',
|
||||||
|
"[tag foo] {",
|
||||||
|
" [tag bar] {",
|
||||||
|
" }",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT('indent_parentheses',
|
||||||
|
"[tag foo] {",
|
||||||
|
" [property color]: [variable&callee darken]([variable-2 $blue],",
|
||||||
|
" [number 9%]);",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT('indent_vardef',
|
||||||
|
"[variable-2 $name]:",
|
||||||
|
" [string 'val'];",
|
||||||
|
"[tag tag] {",
|
||||||
|
" [tag inner] {",
|
||||||
|
" [property margin]: [number 3px];",
|
||||||
|
" }",
|
||||||
|
"}");
|
||||||
|
})();
|
217
codemirror/mode/css/test.js
vendored
Normal file
217
codemirror/mode/css/test.js
vendored
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var mode = CodeMirror.getMode({indentUnit: 2}, "css");
|
||||||
|
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
|
||||||
|
|
||||||
|
// Error, because "foobarhello" is neither a known type or property, but
|
||||||
|
// property was expected (after "and"), and it should be in parentheses.
|
||||||
|
MT("atMediaUnknownType",
|
||||||
|
"[def @media] [attribute screen] [keyword and] [error foobarhello] { }");
|
||||||
|
|
||||||
|
// Soft error, because "foobarhello" is not a known property or type.
|
||||||
|
MT("atMediaUnknownProperty",
|
||||||
|
"[def @media] [attribute screen] [keyword and] ([error foobarhello]) { }");
|
||||||
|
|
||||||
|
// Make sure nesting works with media queries
|
||||||
|
MT("atMediaMaxWidthNested",
|
||||||
|
"[def @media] [attribute screen] [keyword and] ([property max-width]: [number 25px]) { [tag foo] { } }");
|
||||||
|
|
||||||
|
MT("atMediaFeatureValueKeyword",
|
||||||
|
"[def @media] ([property orientation]: [keyword landscape]) { }");
|
||||||
|
|
||||||
|
MT("atMediaUnknownFeatureValueKeyword",
|
||||||
|
"[def @media] ([property orientation]: [error upsidedown]) { }");
|
||||||
|
|
||||||
|
MT("atMediaUppercase",
|
||||||
|
"[def @MEDIA] ([property orienTAtion]: [keyword landScape]) { }");
|
||||||
|
|
||||||
|
MT("tagSelector",
|
||||||
|
"[tag foo] { }");
|
||||||
|
|
||||||
|
MT("classSelector",
|
||||||
|
"[qualifier .foo-bar_hello] { }");
|
||||||
|
|
||||||
|
MT("idSelector",
|
||||||
|
"[builtin #foo] { [error #foo] }");
|
||||||
|
|
||||||
|
MT("tagSelectorUnclosed",
|
||||||
|
"[tag foo] { [property margin]: [number 0] } [tag bar] { }");
|
||||||
|
|
||||||
|
MT("tagStringNoQuotes",
|
||||||
|
"[tag foo] { [property font-family]: [variable hello] [variable world]; }");
|
||||||
|
|
||||||
|
MT("tagStringDouble",
|
||||||
|
"[tag foo] { [property font-family]: [string \"hello world\"]; }");
|
||||||
|
|
||||||
|
MT("tagStringSingle",
|
||||||
|
"[tag foo] { [property font-family]: [string 'hello world']; }");
|
||||||
|
|
||||||
|
MT("tagColorKeyword",
|
||||||
|
"[tag foo] {",
|
||||||
|
" [property color]: [keyword black];",
|
||||||
|
" [property color]: [keyword navy];",
|
||||||
|
" [property color]: [keyword yellow];",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("tagColorHex3",
|
||||||
|
"[tag foo] { [property background]: [atom #fff]; }");
|
||||||
|
|
||||||
|
MT("tagColorHex4",
|
||||||
|
"[tag foo] { [property background]: [atom #ffff]; }");
|
||||||
|
|
||||||
|
MT("tagColorHex6",
|
||||||
|
"[tag foo] { [property background]: [atom #ffffff]; }");
|
||||||
|
|
||||||
|
MT("tagColorHex8",
|
||||||
|
"[tag foo] { [property background]: [atom #ffffffff]; }");
|
||||||
|
|
||||||
|
MT("tagColorHex5Invalid",
|
||||||
|
"[tag foo] { [property background]: [atom&error #fffff]; }");
|
||||||
|
|
||||||
|
MT("tagColorHexInvalid",
|
||||||
|
"[tag foo] { [property background]: [atom&error #ffg]; }");
|
||||||
|
|
||||||
|
MT("tagNegativeNumber",
|
||||||
|
"[tag foo] { [property margin]: [number -5px]; }");
|
||||||
|
|
||||||
|
MT("tagPositiveNumber",
|
||||||
|
"[tag foo] { [property padding]: [number 5px]; }");
|
||||||
|
|
||||||
|
MT("tagVendor",
|
||||||
|
"[tag foo] { [meta -foo-][property box-sizing]: [meta -foo-][atom border-box]; }");
|
||||||
|
|
||||||
|
MT("tagBogusProperty",
|
||||||
|
"[tag foo] { [property&error barhelloworld]: [number 0]; }");
|
||||||
|
|
||||||
|
MT("tagTwoProperties",
|
||||||
|
"[tag foo] { [property margin]: [number 0]; [property padding]: [number 0]; }");
|
||||||
|
|
||||||
|
MT("tagTwoPropertiesURL",
|
||||||
|
"[tag foo] { [property background]: [variable&callee url]([string //example.com/foo.png]); [property padding]: [number 0]; }");
|
||||||
|
|
||||||
|
MT("indent_tagSelector",
|
||||||
|
"[tag strong], [tag em] {",
|
||||||
|
" [property background]: [variable&callee rgba](",
|
||||||
|
" [number 255], [number 255], [number 0], [number .2]",
|
||||||
|
" );",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("indent_atMedia",
|
||||||
|
"[def @media] {",
|
||||||
|
" [tag foo] {",
|
||||||
|
" [property color]:",
|
||||||
|
" [keyword yellow];",
|
||||||
|
" }",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("indent_comma",
|
||||||
|
"[tag foo] {",
|
||||||
|
" [property font-family]: [variable verdana],",
|
||||||
|
" [atom sans-serif];",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("indent_parentheses",
|
||||||
|
"[tag foo]:[variable-3 before] {",
|
||||||
|
" [property background]: [variable&callee url](",
|
||||||
|
"[string blahblah]",
|
||||||
|
"[string etc]",
|
||||||
|
"[string ]) [keyword !important];",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("font_face",
|
||||||
|
"[def @font-face] {",
|
||||||
|
" [property font-family]: [string 'myfont'];",
|
||||||
|
" [error nonsense]: [string 'abc'];",
|
||||||
|
" [property src]: [variable&callee url]([string http://blah]),",
|
||||||
|
" [variable&callee url]([string http://foo]);",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("empty_url",
|
||||||
|
"[def @import] [variable&callee url]() [attribute screen];");
|
||||||
|
|
||||||
|
MT("parens",
|
||||||
|
"[qualifier .foo] {",
|
||||||
|
" [property background-image]: [variable&callee fade]([atom #000], [number 20%]);",
|
||||||
|
" [property border-image]: [variable&callee linear-gradient](",
|
||||||
|
" [atom to] [atom bottom],",
|
||||||
|
" [variable&callee fade]([atom #000], [number 20%]) [number 0%],",
|
||||||
|
" [variable&callee fade]([atom #000], [number 20%]) [number 100%]",
|
||||||
|
" );",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("css_variable",
|
||||||
|
":[variable-3 root] {",
|
||||||
|
" [variable-2 --main-color]: [atom #06c];",
|
||||||
|
"}",
|
||||||
|
"[tag h1][builtin #foo] {",
|
||||||
|
" [property color]: [variable&callee var]([variable-2 --main-color]);",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("blank_css_variable",
|
||||||
|
":[variable-3 root] {",
|
||||||
|
" [variable-2 --]: [atom #06c];",
|
||||||
|
"}",
|
||||||
|
"[tag h1][builtin #foo] {",
|
||||||
|
" [property color]: [variable&callee var]([variable-2 --]);",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("supports",
|
||||||
|
"[def @supports] ([keyword not] (([property text-align-last]: [atom justify]) [keyword or] ([meta -moz-][property text-align-last]: [atom justify])) {",
|
||||||
|
" [property text-align-last]: [atom justify];",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("document",
|
||||||
|
"[def @document] [variable&callee url]([string http://blah]),",
|
||||||
|
" [variable&callee url-prefix]([string https://]),",
|
||||||
|
" [variable&callee domain]([string blah.com]),",
|
||||||
|
" [variable&callee regexp]([string \".*blah.+\"]) {",
|
||||||
|
" [builtin #id] {",
|
||||||
|
" [property background-color]: [keyword white];",
|
||||||
|
" }",
|
||||||
|
" [tag foo] {",
|
||||||
|
" [property font-family]: [variable Verdana], [atom sans-serif];",
|
||||||
|
" }",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("document_url",
|
||||||
|
"[def @document] [variable&callee url]([string http://blah]) { [qualifier .class] { } }");
|
||||||
|
|
||||||
|
MT("document_urlPrefix",
|
||||||
|
"[def @document] [variable&callee url-prefix]([string https://]) { [builtin #id] { } }");
|
||||||
|
|
||||||
|
MT("document_domain",
|
||||||
|
"[def @document] [variable&callee domain]([string blah.com]) { [tag foo] { } }");
|
||||||
|
|
||||||
|
MT("document_regexp",
|
||||||
|
"[def @document] [variable&callee regexp]([string \".*blah.+\"]) { [builtin #id] { } }");
|
||||||
|
|
||||||
|
MT("counter-style",
|
||||||
|
"[def @counter-style] [variable binary] {",
|
||||||
|
" [property system]: [atom numeric];",
|
||||||
|
" [property symbols]: [number 0] [number 1];",
|
||||||
|
" [property suffix]: [string \".\"];",
|
||||||
|
" [property range]: [atom infinite];",
|
||||||
|
" [property speak-as]: [atom numeric];",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("counter-style-additive-symbols",
|
||||||
|
"[def @counter-style] [variable simple-roman] {",
|
||||||
|
" [property system]: [atom additive];",
|
||||||
|
" [property additive-symbols]: [number 10] [variable X], [number 5] [variable V], [number 1] [variable I];",
|
||||||
|
" [property range]: [number 1] [number 49];",
|
||||||
|
"}");
|
||||||
|
|
||||||
|
MT("counter-style-use",
|
||||||
|
"[tag ol][qualifier .roman] { [property list-style]: [variable simple-roman]; }");
|
||||||
|
|
||||||
|
MT("counter-style-symbols",
|
||||||
|
"[tag ol] { [property list-style]: [variable&callee symbols]([atom cyclic] [string \"*\"] [string \"\\2020\"] [string \"\\2021\"] [string \"\\A7\"]); }");
|
||||||
|
|
||||||
|
MT("comment-does-not-disrupt",
|
||||||
|
"[def @font-face] [comment /* foo */] {",
|
||||||
|
" [property src]: [variable&callee url]([string x]);",
|
||||||
|
" [property font-family]: [variable One];",
|
||||||
|
"}")
|
||||||
|
})();
|
152
codemirror/mode/htmlmixed/htmlmixed.js
vendored
Normal file
152
codemirror/mode/htmlmixed/htmlmixed.js
vendored
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://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";
|
||||||
|
|
||||||
|
var defaultTags = {
|
||||||
|
script: [
|
||||||
|
["lang", /(javascript|babel)/i, "javascript"],
|
||||||
|
["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i, "javascript"],
|
||||||
|
["type", /./, "text/plain"],
|
||||||
|
[null, null, "javascript"]
|
||||||
|
],
|
||||||
|
style: [
|
||||||
|
["lang", /^css$/i, "css"],
|
||||||
|
["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"],
|
||||||
|
["type", /./, "text/plain"],
|
||||||
|
[null, null, "css"]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
function maybeBackup(stream, pat, style) {
|
||||||
|
var cur = stream.current(), close = cur.search(pat);
|
||||||
|
if (close > -1) {
|
||||||
|
stream.backUp(cur.length - close);
|
||||||
|
} else if (cur.match(/<\/?$/)) {
|
||||||
|
stream.backUp(cur.length);
|
||||||
|
if (!stream.match(pat, false)) stream.match(cur);
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
var attrRegexpCache = {};
|
||||||
|
function getAttrRegexp(attr) {
|
||||||
|
var regexp = attrRegexpCache[attr];
|
||||||
|
if (regexp) return regexp;
|
||||||
|
return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAttrValue(text, attr) {
|
||||||
|
var match = text.match(getAttrRegexp(attr))
|
||||||
|
return match ? /^\s*(.*?)\s*$/.exec(match[2])[1] : ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTagRegexp(tagName, anchored) {
|
||||||
|
return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i");
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTags(from, to) {
|
||||||
|
for (var tag in from) {
|
||||||
|
var dest = to[tag] || (to[tag] = []);
|
||||||
|
var source = from[tag];
|
||||||
|
for (var i = source.length - 1; i >= 0; i--)
|
||||||
|
dest.unshift(source[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findMatchingMode(tagInfo, tagText) {
|
||||||
|
for (var i = 0; i < tagInfo.length; i++) {
|
||||||
|
var spec = tagInfo[i];
|
||||||
|
if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.defineMode("htmlmixed", function (config, parserConfig) {
|
||||||
|
var htmlMode = CodeMirror.getMode(config, {
|
||||||
|
name: "xml",
|
||||||
|
htmlMode: true,
|
||||||
|
multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
|
||||||
|
multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag
|
||||||
|
});
|
||||||
|
|
||||||
|
var tags = {};
|
||||||
|
var configTags = parserConfig && parserConfig.tags, configScript = parserConfig && parserConfig.scriptTypes;
|
||||||
|
addTags(defaultTags, tags);
|
||||||
|
if (configTags) addTags(configTags, tags);
|
||||||
|
if (configScript) for (var i = configScript.length - 1; i >= 0; i--)
|
||||||
|
tags.script.unshift(["type", configScript[i].matches, configScript[i].mode])
|
||||||
|
|
||||||
|
function html(stream, state) {
|
||||||
|
var style = htmlMode.token(stream, state.htmlState), tag = /\btag\b/.test(style), tagName
|
||||||
|
if (tag && !/[<>\s\/]/.test(stream.current()) &&
|
||||||
|
(tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) &&
|
||||||
|
tags.hasOwnProperty(tagName)) {
|
||||||
|
state.inTag = tagName + " "
|
||||||
|
} else if (state.inTag && tag && />$/.test(stream.current())) {
|
||||||
|
var inTag = /^([\S]+) (.*)/.exec(state.inTag)
|
||||||
|
state.inTag = null
|
||||||
|
var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2])
|
||||||
|
var mode = CodeMirror.getMode(config, modeSpec)
|
||||||
|
var endTagA = getTagRegexp(inTag[1], true), endTag = getTagRegexp(inTag[1], false);
|
||||||
|
state.token = function (stream, state) {
|
||||||
|
if (stream.match(endTagA, false)) {
|
||||||
|
state.token = html;
|
||||||
|
state.localState = state.localMode = null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState));
|
||||||
|
};
|
||||||
|
state.localMode = mode;
|
||||||
|
state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, "", ""));
|
||||||
|
} else if (state.inTag) {
|
||||||
|
state.inTag += stream.current()
|
||||||
|
if (stream.eol()) state.inTag += " "
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
startState: function () {
|
||||||
|
var state = CodeMirror.startState(htmlMode);
|
||||||
|
return {token: html, inTag: null, localMode: null, localState: null, htmlState: state};
|
||||||
|
},
|
||||||
|
|
||||||
|
copyState: function (state) {
|
||||||
|
var local;
|
||||||
|
if (state.localState) {
|
||||||
|
local = CodeMirror.copyState(state.localMode, state.localState);
|
||||||
|
}
|
||||||
|
return {token: state.token, inTag: state.inTag,
|
||||||
|
localMode: state.localMode, localState: local,
|
||||||
|
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
|
||||||
|
},
|
||||||
|
|
||||||
|
token: function (stream, state) {
|
||||||
|
return state.token(stream, state);
|
||||||
|
},
|
||||||
|
|
||||||
|
indent: function (state, textAfter, line) {
|
||||||
|
if (!state.localMode || /^\s*<\//.test(textAfter))
|
||||||
|
return htmlMode.indent(state.htmlState, textAfter, line);
|
||||||
|
else if (state.localMode.indent)
|
||||||
|
return state.localMode.indent(state.localState, textAfter, line);
|
||||||
|
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");
|
||||||
|
});
|
100
codemirror/mode/htmlmixed/index.html
vendored
Normal file
100
codemirror/mode/htmlmixed/index.html
vendored
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: HTML mixed mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="../../addon/selection/selection-pointer.js"></script>
|
||||||
|
<script src="../xml/xml.js"></script>
|
||||||
|
<script src="../javascript/javascript.js"></script>
|
||||||
|
<script src="../css/css.js"></script>
|
||||||
|
<script src="../vbscript/vbscript.js"></script>
|
||||||
|
<script src="htmlmixed.js"></script>
|
||||||
|
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">HTML mixed</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>HTML mixed mode</h2>
|
||||||
|
<form><textarea id="code" name="code">
|
||||||
|
<html style="color: green">
|
||||||
|
<!-- this is a comment -->
|
||||||
|
<head>
|
||||||
|
<title>Mixed HTML Example</title>
|
||||||
|
<style>
|
||||||
|
h1 {font-family: comic sans; color: #f0f;}
|
||||||
|
div {background: yellow !important;}
|
||||||
|
body {
|
||||||
|
max-width: 50em;
|
||||||
|
margin: 1em 2em 1em 5em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Mixed HTML Example</h1>
|
||||||
|
<script>
|
||||||
|
function jsFunc(arg1, arg2) {
|
||||||
|
if (arg1 && arg2) document.body.innerHTML = "achoo";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</textarea></form>
|
||||||
|
<script>
|
||||||
|
// Define an extended mixed-mode that understands vbscript and
|
||||||
|
// leaves mustache/handlebars embedded templates in html mode
|
||||||
|
var mixedMode = {
|
||||||
|
name: "htmlmixed",
|
||||||
|
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
|
||||||
|
mode: null},
|
||||||
|
{matches: /(text|application)\/(x-)?vb(a|script)/i,
|
||||||
|
mode: "vbscript"}]
|
||||||
|
};
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||||
|
mode: mixedMode,
|
||||||
|
selectionPointer: true
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>The HTML mixed mode depends on the XML, JavaScript, and CSS modes.</p>
|
||||||
|
|
||||||
|
<p>It takes an optional mode configuration
|
||||||
|
option, <code>tags</code>, which can be used to add custom
|
||||||
|
behavior for specific tags. When given, it should be an object
|
||||||
|
mapping tag names (for example <code>script</code>) to arrays or
|
||||||
|
three-element arrays. Those inner arrays indicate [attributeName,
|
||||||
|
valueRegexp, <a href="../../doc/manual.html#option_mode">modeSpec</a>]
|
||||||
|
specifications. For example, you could use <code>["type", /^foo$/,
|
||||||
|
"foo"]</code> to map the attribute <code>type="foo"</code> to
|
||||||
|
the <code>foo</code> mode. When the first two fields are null
|
||||||
|
(<code>[null, null, "mode"]</code>), the given mode is used for
|
||||||
|
any such tag that doesn't match any of the previously given
|
||||||
|
attributes. For example:</p>
|
||||||
|
|
||||||
|
<pre>var myModeSpec = {
|
||||||
|
name: "htmlmixed",
|
||||||
|
tags: {
|
||||||
|
style: [["type", /^text\/(x-)?scss$/, "text/x-scss"],
|
||||||
|
[null, null, "css"]],
|
||||||
|
custom: [[null, null, "customMode"]]
|
||||||
|
}
|
||||||
|
}</pre>
|
||||||
|
|
||||||
|
<p><strong>MIME types defined:</strong> <code>text/html</code>
|
||||||
|
(redefined, only takes effect if you load this parser after the
|
||||||
|
XML parser).</p>
|
||||||
|
|
||||||
|
</article>
|
61
codemirror/mode/xml/index.html
vendored
Normal file
61
codemirror/mode/xml/index.html
vendored
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<title>CodeMirror: XML mode</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<link rel=stylesheet href="../../doc/docs.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||||
|
<script src="../../lib/codemirror.js"></script>
|
||||||
|
<script src="xml.js"></script>
|
||||||
|
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||||
|
<div id=nav>
|
||||||
|
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="../../index.html">Home</a>
|
||||||
|
<li><a href="../../doc/manual.html">Manual</a>
|
||||||
|
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="../index.html">Language modes</a>
|
||||||
|
<li><a class=active href="#">XML</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>XML mode</h2>
|
||||||
|
<form><textarea id="code" name="code">
|
||||||
|
<html style="color: green">
|
||||||
|
<!-- this is a comment -->
|
||||||
|
<head>
|
||||||
|
<title>HTML Example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
The indentation tries to be <em>somewhat &quot;do what
|
||||||
|
I mean&quot;</em>... but might not match your style.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</textarea></form>
|
||||||
|
<script>
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||||
|
mode: "text/html",
|
||||||
|
lineNumbers: true
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<p>The XML mode supports these configuration parameters:</p>
|
||||||
|
<dl>
|
||||||
|
<dt><code>htmlMode (boolean)</code></dt>
|
||||||
|
<dd>This switches the mode to parse HTML instead of XML. This
|
||||||
|
means attributes do not have to be quoted, and some elements
|
||||||
|
(such as <code>br</code>) do not require a closing tag.</dd>
|
||||||
|
<dt><code>matchClosing (boolean)</code></dt>
|
||||||
|
<dd>Controls whether the mode checks that close tags match the
|
||||||
|
corresponding opening tag, and highlights mismatches as errors.
|
||||||
|
Defaults to true.</dd>
|
||||||
|
<dt><code>alignCDATA (boolean)</code></dt>
|
||||||
|
<dd>Setting this to true will force the opening tag of CDATA
|
||||||
|
blocks to not be indented.</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<p><strong>MIME types defined:</strong> <code>application/xml</code>, <code>text/html</code>.</p>
|
||||||
|
</article>
|
51
codemirror/mode/xml/test.js
vendored
Normal file
51
codemirror/mode/xml/test.js
vendored
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var mode = CodeMirror.getMode({indentUnit: 2}, "xml"), mname = "xml";
|
||||||
|
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), mname); }
|
||||||
|
|
||||||
|
MT("matching",
|
||||||
|
"[tag&bracket <][tag top][tag&bracket >]",
|
||||||
|
" text",
|
||||||
|
" [tag&bracket <][tag inner][tag&bracket />]",
|
||||||
|
"[tag&bracket </][tag top][tag&bracket >]");
|
||||||
|
|
||||||
|
MT("nonmatching",
|
||||||
|
"[tag&bracket <][tag top][tag&bracket >]",
|
||||||
|
" [tag&bracket <][tag inner][tag&bracket />]",
|
||||||
|
" [tag&bracket </][tag&error tip][tag&bracket&error >]");
|
||||||
|
|
||||||
|
MT("doctype",
|
||||||
|
"[meta <!doctype foobar>]",
|
||||||
|
"[tag&bracket <][tag top][tag&bracket />]");
|
||||||
|
|
||||||
|
MT("cdata",
|
||||||
|
"[tag&bracket <][tag top][tag&bracket >]",
|
||||||
|
" [atom <![CDATA[foo]",
|
||||||
|
"[atom barbazguh]]]]>]",
|
||||||
|
"[tag&bracket </][tag top][tag&bracket >]");
|
||||||
|
|
||||||
|
// HTML tests
|
||||||
|
mode = CodeMirror.getMode({indentUnit: 2}, "text/html");
|
||||||
|
|
||||||
|
MT("selfclose",
|
||||||
|
"[tag&bracket <][tag html][tag&bracket >]",
|
||||||
|
" [tag&bracket <][tag link] [attribute rel]=[string stylesheet] [attribute href]=[string \"/foobar\"][tag&bracket >]",
|
||||||
|
"[tag&bracket </][tag html][tag&bracket >]");
|
||||||
|
|
||||||
|
MT("list",
|
||||||
|
"[tag&bracket <][tag ol][tag&bracket >]",
|
||||||
|
" [tag&bracket <][tag li][tag&bracket >]one",
|
||||||
|
" [tag&bracket <][tag li][tag&bracket >]two",
|
||||||
|
"[tag&bracket </][tag ol][tag&bracket >]");
|
||||||
|
|
||||||
|
MT("valueless",
|
||||||
|
"[tag&bracket <][tag input] [attribute type]=[string checkbox] [attribute checked][tag&bracket />]");
|
||||||
|
|
||||||
|
MT("pThenArticle",
|
||||||
|
"[tag&bracket <][tag p][tag&bracket >]",
|
||||||
|
" foo",
|
||||||
|
"[tag&bracket <][tag article][tag&bracket >]bar");
|
||||||
|
|
||||||
|
})();
|
413
codemirror/mode/xml/xml.js
vendored
Normal file
413
codemirror/mode/xml/xml.js
vendored
Normal file
@ -0,0 +1,413 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://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";
|
||||||
|
|
||||||
|
var htmlConfig = {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
var xmlConfig = {
|
||||||
|
autoSelfClosers: {},
|
||||||
|
implicitlyClosed: {},
|
||||||
|
contextGrabbers: {},
|
||||||
|
doNotIndent: {},
|
||||||
|
allowUnquoted: false,
|
||||||
|
allowMissing: false,
|
||||||
|
allowMissingTagName: false,
|
||||||
|
caseFold: false
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.defineMode("xml", function(editorConf, config_) {
|
||||||
|
var indentUnit = editorConf.indentUnit
|
||||||
|
var config = {}
|
||||||
|
var defaults = config_.htmlMode ? htmlConfig : xmlConfig
|
||||||
|
for (var prop in defaults) config[prop] = defaults[prop]
|
||||||
|
for (var prop in config_) config[prop] = config_[prop]
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inText.isInText = true;
|
||||||
|
|
||||||
|
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 (config.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 (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
|
||||||
|
!config.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 if (config.allowMissingTagName && type == "endTag") {
|
||||||
|
setStyle = "tag bracket";
|
||||||
|
return attrState(type, stream, state);
|
||||||
|
} else {
|
||||||
|
setStyle = "error";
|
||||||
|
return tagNameState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function closeTagNameState(type, stream, state) {
|
||||||
|
if (type == "word") {
|
||||||
|
var tagName = stream.current();
|
||||||
|
if (state.context && state.context.tagName != tagName &&
|
||||||
|
config.implicitlyClosed.hasOwnProperty(state.context.tagName))
|
||||||
|
popContext(state);
|
||||||
|
if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {
|
||||||
|
setStyle = "tag";
|
||||||
|
return closeState;
|
||||||
|
} else {
|
||||||
|
setStyle = "tag error";
|
||||||
|
return closeStateErr;
|
||||||
|
}
|
||||||
|
} else if (config.allowMissingTagName && type == "endTag") {
|
||||||
|
setStyle = "tag bracket";
|
||||||
|
return closeState(type, stream, state);
|
||||||
|
} 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" ||
|
||||||
|
config.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 (!config.allowMissing) setStyle = "error";
|
||||||
|
return attrState(type, stream, state);
|
||||||
|
}
|
||||||
|
function attrValueState(type, stream, state) {
|
||||||
|
if (type == "string") return attrContinuedState;
|
||||||
|
if (type == "word" && config.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(baseIndent) {
|
||||||
|
var state = {tokenize: inText,
|
||||||
|
state: baseState,
|
||||||
|
indented: baseIndent || 0,
|
||||||
|
tagName: null, tagStart: null,
|
||||||
|
context: null}
|
||||||
|
if (baseIndent != null) state.baseIndent = baseIndent
|
||||||
|
return state
|
||||||
|
},
|
||||||
|
|
||||||
|
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 (config.multilineTagIndentPastTag !== false)
|
||||||
|
return state.tagStart + state.tagName.length + 2;
|
||||||
|
else
|
||||||
|
return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
|
||||||
|
}
|
||||||
|
if (config.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 (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
|
||||||
|
context = context.prev;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (tagAfter) { // Opening tag spotted
|
||||||
|
while (context) {
|
||||||
|
var grabbers = config.contextGrabbers[context.tagName];
|
||||||
|
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
|
||||||
|
context = context.prev;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (context && context.prev && !context.startOfLine)
|
||||||
|
context = context.prev;
|
||||||
|
if (context) return context.indent + indentUnit;
|
||||||
|
else return state.baseIndent || 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
electricInput: /<\/[\s\w:]+>$/,
|
||||||
|
blockCommentStart: "<!--",
|
||||||
|
blockCommentEnd: "-->",
|
||||||
|
|
||||||
|
configuration: config.htmlMode ? "html" : "xml",
|
||||||
|
helperType: config.htmlMode ? "html" : "xml",
|
||||||
|
|
||||||
|
skipAttribute: function(state) {
|
||||||
|
if (state.state == attrValueState)
|
||||||
|
state.state = attrState
|
||||||
|
},
|
||||||
|
|
||||||
|
xmlCurrentTag: function(state) {
|
||||||
|
return state.tagName ? {name: state.tagName, close: state.type == "closeTag"} : null
|
||||||
|
},
|
||||||
|
|
||||||
|
xmlCurrentContext: function(state) {
|
||||||
|
var context = []
|
||||||
|
for (var cx = state.context; cx; cx = cx.prev)
|
||||||
|
if (cx.tagName) context.push(cx.tagName)
|
||||||
|
return context.reverse()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.defineMIME("text/xml", "xml");
|
||||||
|
CodeMirror.defineMIME("application/xml", "xml");
|
||||||
|
if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
|
||||||
|
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
||||||
|
|
||||||
|
});
|
@ -16,6 +16,10 @@
|
|||||||
<script src="codemirror/mode/javascript/javascript.js"></script>
|
<script src="codemirror/mode/javascript/javascript.js"></script>
|
||||||
<script src="codemirror/mode/ruby/ruby.js"></script>
|
<script src="codemirror/mode/ruby/ruby.js"></script>
|
||||||
<script src="codemirror/mode/php/php.js"></script>
|
<script src="codemirror/mode/php/php.js"></script>
|
||||||
|
<script src="codemirror/mode/clike/clike.js"></script>
|
||||||
|
<script src="codemirror/mode/xml/xml.js"></script>
|
||||||
|
<script src="codemirror/mode/css/css.js"></script>
|
||||||
|
<script src="codemirror/mode/htmlmixed/htmlmixed.js"></script>
|
||||||
<script src="codemirror/mode/perl/perl.js"></script>
|
<script src="codemirror/mode/perl/perl.js"></script>
|
||||||
<script src="codemirror/mode/lua/lua.js"></script>
|
<script src="codemirror/mode/lua/lua.js"></script>
|
||||||
<script src="assets/checkUpdate.js"></script>
|
<script src="assets/checkUpdate.js"></script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user