upgrade editor.md(many bug exists)

This commit is contained in:
gsw945
2024-03-27 16:26:01 +08:00
parent 93441cad0e
commit 8c2c69e433
448 changed files with 43080 additions and 16808 deletions

View File

@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Distributed under an MIT license: https://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
@@ -11,6 +11,14 @@
})(function(CodeMirror) {
"use strict";
function forEach(arr, f) {
for (var i = 0; i < arr.length; i++) f(arr[i], i)
}
function some(arr, f) {
for (var i = 0; i < arr.length; i++) if (f(arr[i], i)) return true
return false
}
CodeMirror.defineMode("dylan", function(_config) {
// Words
var words = {
@@ -136,13 +144,13 @@ CodeMirror.defineMode("dylan", function(_config) {
var wordLookup = {};
var styleLookup = {};
[
forEach([
"keyword",
"definition",
"simpleDefinition",
"signalingCalls"
].forEach(function(type) {
words[type].forEach(function(word) {
], function(type) {
forEach(words[type], function(word) {
wordLookup[word] = type;
styleLookup[word] = styles[type];
});
@@ -154,20 +162,12 @@ CodeMirror.defineMode("dylan", function(_config) {
return f(stream, state);
}
var type, content;
function ret(_type, style, _content) {
type = _type;
content = _content;
return style;
}
function tokenBase(stream, state) {
// String
var ch = stream.peek();
if (ch == "'" || ch == '"') {
stream.next();
return chain(stream, state, tokenString(ch, "string", "string"));
return chain(stream, state, tokenString(ch, "string"));
}
// Comment
else if (ch == "/") {
@@ -176,16 +176,17 @@ CodeMirror.defineMode("dylan", function(_config) {
return chain(stream, state, tokenComment);
} else if (stream.eat("/")) {
stream.skipToEnd();
return ret("comment", "comment");
} else {
stream.skipTo(" ");
return ret("operator", "operator");
return "comment";
}
stream.backUp(1);
}
// Decimal
else if (/\d/.test(ch)) {
stream.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);
return ret("number", "number");
else if (/[+\-\d\.]/.test(ch)) {
if (stream.match(/^[+-]?[0-9]*\.[0-9]*([esdx][+-]?[0-9]+)?/i) ||
stream.match(/^[+-]?[0-9]+([esdx][+-]?[0-9]+)/i) ||
stream.match(/^[+-]?\d+/)) {
return "number";
}
}
// Hash
else if (ch == "#") {
@@ -194,84 +195,136 @@ CodeMirror.defineMode("dylan", function(_config) {
ch = stream.peek();
if (ch == '"') {
stream.next();
return chain(stream, state, tokenString('"', "symbol", "string-2"));
return chain(stream, state, tokenString('"', "string"));
}
// Binary number
else if (ch == "b") {
stream.next();
stream.eatWhile(/[01]/);
return ret("number", "number");
return "number";
}
// Hex number
else if (ch == "x") {
stream.next();
stream.eatWhile(/[\da-f]/i);
return ret("number", "number");
return "number";
}
// Octal number
else if (ch == "o") {
stream.next();
stream.eatWhile(/[0-7]/);
return ret("number", "number");
return "number";
}
// Token concatenation in macros
else if (ch == '#') {
stream.next();
return "punctuation";
}
// Sequence literals
else if ((ch == '[') || (ch == '(')) {
stream.next();
return "bracket";
// Hash symbol
else {
} else if (stream.match(/f|t|all-keys|include|key|next|rest/i)) {
return "atom";
} else {
stream.eatWhile(/[-a-zA-Z]/);
return ret("hash", "keyword");
return "error";
}
} else if (ch == "~") {
stream.next();
ch = stream.peek();
if (ch == "=") {
stream.next();
ch = stream.peek();
if (ch == "=") {
stream.next();
return "operator";
}
return "operator";
}
return "operator";
} else if (ch == ":") {
stream.next();
ch = stream.peek();
if (ch == "=") {
stream.next();
return "operator";
} else if (ch == ":") {
stream.next();
return "punctuation";
}
} else if ("[](){}".indexOf(ch) != -1) {
stream.next();
return "bracket";
} else if (".,".indexOf(ch) != -1) {
stream.next();
return "punctuation";
} else if (stream.match("end")) {
return ret("end", "keyword");
return "keyword";
}
for (var name in patterns) {
if (patterns.hasOwnProperty(name)) {
var pattern = patterns[name];
if ((pattern instanceof Array && pattern.some(function(p) {
if ((pattern instanceof Array && some(pattern, function(p) {
return stream.match(p);
})) || stream.match(pattern))
return ret(name, patternStyles[name], stream.current());
return patternStyles[name];
}
}
if (/[+\-*\/^=<>&|]/.test(ch)) {
stream.next();
return "operator";
}
if (stream.match("define")) {
return ret("definition", "def");
return "def";
} else {
stream.eatWhile(/[\w\-]/);
// Keyword
if (wordLookup[stream.current()]) {
return ret(wordLookup[stream.current()], styleLookup[stream.current()], stream.current());
if (wordLookup.hasOwnProperty(stream.current())) {
return styleLookup[stream.current()];
} else if (stream.current().match(symbol)) {
return ret("variable", "variable");
return "variable";
} else {
stream.next();
return ret("other", "variable-2");
return "variable-2";
}
}
}
function tokenComment(stream, state) {
var maybeEnd = false,
ch;
var maybeEnd = false, maybeNested = false, nestedCount = 0, ch;
while ((ch = stream.next())) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
break;
if (nestedCount > 0) {
nestedCount--;
} else {
state.tokenize = tokenBase;
break;
}
} else if (ch == "*" && maybeNested) {
nestedCount++;
}
maybeEnd = (ch == "*");
maybeNested = (ch == "/");
}
return ret("comment", "comment");
return "comment";
}
function tokenString(quote, type, style) {
function tokenString(quote, style) {
return function(stream, state) {
var next, end = false;
var escaped = false, next, end = false;
while ((next = stream.next()) != null) {
if (next == quote) {
if (next == quote && !escaped) {
end = true;
break;
}
escaped = !escaped && next == "\\";
}
if (end)
if (end || !escaped) {
state.tokenize = tokenBase;
return ret(type, style);
}
return style;
};
}