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

@@ -9,7 +9,7 @@
<script src="scheme.js"></script>
<style>.CodeMirror {background: #f8f8f8;}</style>
<div id=nav>
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<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>

View File

@@ -1,8 +1,9 @@
// 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
/**
* Author: Koh Zi Han, based on implementation by Koh Zi Chun
* Improved by: Jakub T. Jankiewicz
*/
(function(mod) {
@@ -17,7 +18,7 @@
CodeMirror.defineMode("scheme", function () {
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
SYMBOL = "symbol", ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
var INDENT_WORD_SKIP = 2;
function makeKeywords(str) {
@@ -26,8 +27,8 @@ CodeMirror.defineMode("scheme", function () {
return obj;
}
var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
var indentKeys = makeKeywords("define let letrec let* lambda");
var keywords = makeKeywords("λ case-lambda call/cc class cond-expand define-class define-values exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax define-macro defmacro delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
var indentKeys = makeKeywords("define let letrec let* lambda define-macro defmacro let-syntax letrec-syntax let-values let*-values define-syntax syntax-rules define-values when unless");
function stateStack(indent, type, prev) { // represents a state stack object
this.indent = indent;
@@ -67,13 +68,26 @@ CodeMirror.defineMode("scheme", function () {
return stream.match(hexMatcher);
}
function processEscapedSequence(stream, options) {
var next, escaped = false;
while ((next = stream.next()) != null) {
if (next == options.token && !escaped) {
options.state.mode = false;
break;
}
escaped = !escaped && next == "\\";
}
}
return {
startState: function () {
return {
indentStack: null,
indentation: 0,
mode: false,
sExprComment: false
sExprComment: false,
sExprQuote: false
};
},
@@ -91,17 +105,19 @@ CodeMirror.defineMode("scheme", function () {
switch(state.mode){
case "string": // multi-line string parsing mode
var next, escaped = false;
while ((next = stream.next()) != null) {
if (next == "\"" && !escaped) {
state.mode = false;
break;
}
escaped = !escaped && next == "\\";
}
processEscapedSequence(stream, {
token: "\"",
state: state
});
returnType = STRING; // continue on in scheme-string mode
break;
case "symbol": // escape symbol
processEscapedSequence(stream, {
token: "|",
state: state
});
returnType = SYMBOL; // continue on in scheme-symbol mode
break;
case "comment": // comment parsing mode
var next, maybeEnd = false;
while ((next = stream.next()) != null) {
@@ -121,7 +137,7 @@ CodeMirror.defineMode("scheme", function () {
state.sExprComment = 0;
}else{
// if not we just comment the entire of the next token
stream.eatWhile(/[^/s]/); // eat non spaces
stream.eatWhile(/[^\s\(\)\[\]]/); // eat symbol atom
returnType = COMMENT;
break;
}
@@ -133,7 +149,18 @@ CodeMirror.defineMode("scheme", function () {
returnType = STRING;
} else if (ch == "'") {
returnType = ATOM;
if (stream.peek() == "(" || stream.peek() == "["){
if (typeof state.sExprQuote != "number") {
state.sExprQuote = 0;
} // else already in a quoted expression
returnType = ATOM;
} else {
stream.eatWhile(/[\w_\-!$%&*+\.\/:<=>?@\^~]/);
returnType = ATOM;
}
} else if (ch == '|') {
state.mode = "symbol";
returnType = SYMBOL;
} else if (ch == '#') {
if (stream.eat("|")) { // Multi-line comment
state.mode = "comment"; // toggle to comment mode
@@ -161,7 +188,7 @@ CodeMirror.defineMode("scheme", function () {
} else if (stream.match(/^[-+0-9.]/, false)) {
hasRadix = false;
numTest = isDecimalNumber;
// re-consume the intial # if all matches failed
// re-consume the initial # if all matches failed
} else if (!hasExactness) {
stream.eat('#');
}
@@ -209,6 +236,7 @@ CodeMirror.defineMode("scheme", function () {
stream.backUp(stream.current().length - 1); // undo all the eating
if(typeof state.sExprComment == "number") state.sExprComment++;
if(typeof state.sExprQuote == "number") state.sExprQuote++;
returnType = BRACKET;
} else if (ch == ")" || ch == "]") {
@@ -222,16 +250,22 @@ CodeMirror.defineMode("scheme", function () {
state.sExprComment = false; // turn off s-expr commenting mode
}
}
if(typeof state.sExprQuote == "number"){
if(--state.sExprQuote == 0){
returnType = ATOM; // final closing bracket
state.sExprQuote = false; // turn off s-expr quote mode
}
}
}
} else {
stream.eatWhile(/[\w\$_\-!$%&*+\.\/:<=>?@\^~]/);
stream.eatWhile(/[\w_\-!$%&*+\.\/:<=>?@\^~]/);
if (keywords && keywords.propertyIsEnumerable(stream.current())) {
returnType = BUILTIN;
} else returnType = "variable";
}
}
return (typeof state.sExprComment == "number") ? COMMENT : returnType;
return (typeof state.sExprComment == "number") ? COMMENT : ((typeof state.sExprQuote == "number") ? ATOM : returnType);
},
indent: function (state) {
@@ -239,6 +273,8 @@ CodeMirror.defineMode("scheme", function () {
return state.indentStack.indent;
},
fold: "brace-paren",
closeBrackets: {pairs: "()[]{}\"\""},
lineComment: ";;"
};
});