summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/scheme
diff options
context:
space:
mode:
Diffstat (limited to 'public/vendor/codemirror/mode/scheme')
-rwxr-xr-xpublic/vendor/codemirror/mode/scheme/index.html77
-rwxr-xr-xpublic/vendor/codemirror/mode/scheme/scheme.js249
2 files changed, 326 insertions, 0 deletions
diff --git a/public/vendor/codemirror/mode/scheme/index.html b/public/vendor/codemirror/mode/scheme/index.html
new file mode 100755
index 00000000..04d5c6a2
--- /dev/null
+++ b/public/vendor/codemirror/mode/scheme/index.html
@@ -0,0 +1,77 @@
+<!doctype html>
+
+<title>CodeMirror: Scheme 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="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>
+
+ <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="#">Scheme</a>
+ </ul>
+</div>
+
+<article>
+<h2>Scheme mode</h2>
+<form><textarea id="code" name="code">
+; See if the input starts with a given symbol.
+(define (match-symbol input pattern)
+ (cond ((null? (remain input)) #f)
+ ((eqv? (car (remain input)) pattern) (r-cdr input))
+ (else #f)))
+
+; Allow the input to start with one of a list of patterns.
+(define (match-or input pattern)
+ (cond ((null? pattern) #f)
+ ((match-pattern input (car pattern)))
+ (else (match-or input (cdr pattern)))))
+
+; Allow a sequence of patterns.
+(define (match-seq input pattern)
+ (if (null? pattern)
+ input
+ (let ((match (match-pattern input (car pattern))))
+ (if match (match-seq match (cdr pattern)) #f))))
+
+; Match with the pattern but no problem if it does not match.
+(define (match-opt input pattern)
+ (let ((match (match-pattern input (car pattern))))
+ (if match match input)))
+
+; Match anything (other than '()), until pattern is found. The rather
+; clumsy form of requiring an ending pattern is needed to decide where
+; the end of the match is. If none is given, this will match the rest
+; of the sentence.
+(define (match-any input pattern)
+ (cond ((null? (remain input)) #f)
+ ((null? pattern) (f-cons (remain input) (clear-remain input)))
+ (else
+ (let ((accum-any (collector)))
+ (define (match-pattern-any input pattern)
+ (cond ((null? (remain input)) #f)
+ (else (accum-any (car (remain input)))
+ (cond ((match-pattern (r-cdr input) pattern))
+ (else (match-pattern-any (r-cdr input) pattern))))))
+ (let ((retval (match-pattern-any input (car pattern))))
+ (if retval
+ (f-cons (accum-any) retval)
+ #f))))))
+</textarea></form>
+ <script>
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
+ </script>
+
+ <p><strong>MIME types defined:</strong> <code>text/x-scheme</code>.</p>
+
+ </article>
diff --git a/public/vendor/codemirror/mode/scheme/scheme.js b/public/vendor/codemirror/mode/scheme/scheme.js
new file mode 100755
index 00000000..22346459
--- /dev/null
+++ b/public/vendor/codemirror/mode/scheme/scheme.js
@@ -0,0 +1,249 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+/**
+ * Author: Koh Zi Han, based on implementation by Koh Zi Chun
+ */
+
+(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("scheme", function () {
+ var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
+ ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
+ var INDENT_WORD_SKIP = 2;
+
+ function makeKeywords(str) {
+ var obj = {}, words = str.split(" ");
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
+ 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");
+
+ function stateStack(indent, type, prev) { // represents a state stack object
+ this.indent = indent;
+ this.type = type;
+ this.prev = prev;
+ }
+
+ function pushStack(state, indent, type) {
+ state.indentStack = new stateStack(indent, type, state.indentStack);
+ }
+
+ function popStack(state) {
+ state.indentStack = state.indentStack.prev;
+ }
+
+ var binaryMatcher = new RegExp(/^(?:[-+]i|[-+][01]+#*(?:\/[01]+#*)?i|[-+]?[01]+#*(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(?:(?:\d+#+\.?#*|\d+\.\d*#*|\.\d+#*|\d+)(?:[esfdl][-+]?\d+)?)|\d+#*\/\d+#*))(?=[()\s;"]|$)/i);
+
+ function isBinaryNumber (stream) {
+ return stream.match(binaryMatcher);
+ }
+
+ function isOctalNumber (stream) {
+ return stream.match(octalMatcher);
+ }
+
+ function isDecimalNumber (stream, backup) {
+ if (backup === true) {
+ stream.backUp(1);
+ }
+ return stream.match(decimalMatcher);
+ }
+
+ function isHexNumber (stream) {
+ return stream.match(hexMatcher);
+ }
+
+ return {
+ startState: function () {
+ return {
+ indentStack: null,
+ indentation: 0,
+ mode: false,
+ sExprComment: false
+ };
+ },
+
+ token: function (stream, state) {
+ if (state.indentStack == null && stream.sol()) {
+ // update indentation, but only if indentStack is empty
+ state.indentation = stream.indentation();
+ }
+
+ // skip spaces
+ if (stream.eatSpace()) {
+ return null;
+ }
+ var returnType = null;
+
+ 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 == "\\";
+ }
+ returnType = STRING; // continue on in scheme-string mode
+ break;
+ case "comment": // comment parsing mode
+ var next, maybeEnd = false;
+ while ((next = stream.next()) != null) {
+ if (next == "#" && maybeEnd) {
+
+ state.mode = false;
+ break;
+ }
+ maybeEnd = (next == "|");
+ }
+ returnType = COMMENT;
+ break;
+ case "s-expr-comment": // s-expr commenting mode
+ state.mode = false;
+ if(stream.peek() == "(" || stream.peek() == "["){
+ // actually start scheme s-expr commenting mode
+ state.sExprComment = 0;
+ }else{
+ // if not we just comment the entire of the next token
+ stream.eatWhile(/[^/s]/); // eat non spaces
+ returnType = COMMENT;
+ break;
+ }
+ default: // default parsing mode
+ var ch = stream.next();
+
+ if (ch == "\"") {
+ state.mode = "string";
+ returnType = STRING;
+
+ } else if (ch == "'") {
+ returnType = ATOM;
+ } else if (ch == '#') {
+ if (stream.eat("|")) { // Multi-line comment
+ state.mode = "comment"; // toggle to comment mode
+ returnType = COMMENT;
+ } else if (stream.eat(/[tf]/i)) { // #t/#f (atom)
+ returnType = ATOM;
+ } else if (stream.eat(';')) { // S-Expr comment
+ state.mode = "s-expr-comment";
+ returnType = COMMENT;
+ } else {
+ var numTest = null, hasExactness = false, hasRadix = true;
+ if (stream.eat(/[ei]/i)) {
+ hasExactness = true;
+ } else {
+ stream.backUp(1); // must be radix specifier
+ }
+ if (stream.match(/^#b/i)) {
+ numTest = isBinaryNumber;
+ } else if (stream.match(/^#o/i)) {
+ numTest = isOctalNumber;
+ } else if (stream.match(/^#x/i)) {
+ numTest = isHexNumber;
+ } else if (stream.match(/^#d/i)) {
+ numTest = isDecimalNumber;
+ } else if (stream.match(/^[-+0-9.]/, false)) {
+ hasRadix = false;
+ numTest = isDecimalNumber;
+ // re-consume the intial # if all matches failed
+ } else if (!hasExactness) {
+ stream.eat('#');
+ }
+ if (numTest != null) {
+ if (hasRadix && !hasExactness) {
+ // consume optional exactness after radix
+ stream.match(/^#[ei]/i);
+ }
+ if (numTest(stream))
+ returnType = NUMBER;
+ }
+ }
+ } else if (/^[-+0-9.]/.test(ch) && isDecimalNumber(stream, true)) { // match non-prefixed number, must be decimal
+ returnType = NUMBER;
+ } else if (ch == ";") { // comment
+ stream.skipToEnd(); // rest of the line is a comment
+ returnType = COMMENT;
+ } else if (ch == "(" || ch == "[") {
+ var keyWord = ''; var indentTemp = stream.column(), letter;
+ /**
+ Either
+ (indent-word ..
+ (non-indent-word ..
+ (;something else, bracket, etc.
+ */
+
+ while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) {
+ keyWord += letter;
+ }
+
+ if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
+
+ pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
+ } else { // non-indent word
+ // we continue eating the spaces
+ stream.eatSpace();
+ if (stream.eol() || stream.peek() == ";") {
+ // nothing significant after
+ // we restart indentation 1 space after
+ pushStack(state, indentTemp + 1, ch);
+ } else {
+ pushStack(state, indentTemp + stream.current().length, ch); // else we match
+ }
+ }
+ stream.backUp(stream.current().length - 1); // undo all the eating
+
+ if(typeof state.sExprComment == "number") state.sExprComment++;
+
+ returnType = BRACKET;
+ } else if (ch == ")" || ch == "]") {
+ returnType = BRACKET;
+ if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
+ popStack(state);
+
+ if(typeof state.sExprComment == "number"){
+ if(--state.sExprComment == 0){
+ returnType = COMMENT; // final closing bracket
+ state.sExprComment = false; // turn off s-expr commenting mode
+ }
+ }
+ }
+ } else {
+ stream.eatWhile(/[\w\$_\-!$%&*+\.\/:<=>?@\^~]/);
+
+ if (keywords && keywords.propertyIsEnumerable(stream.current())) {
+ returnType = BUILTIN;
+ } else returnType = "variable";
+ }
+ }
+ return (typeof state.sExprComment == "number") ? COMMENT : returnType;
+ },
+
+ indent: function (state) {
+ if (state.indentStack == null) return state.indentation;
+ return state.indentStack.indent;
+ },
+
+ closeBrackets: {pairs: "()[]{}\"\""},
+ lineComment: ";;"
+ };
+});
+
+CodeMirror.defineMIME("text/x-scheme", "scheme");
+
+});