Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/commonlisp/commonlisp.js
1293 views
CodeMirror.defineMode("commonlisp", function (config) {1var assumeBody = /^with|^def|^do|^prog|case$|^cond$|bind$|when$|unless$/;2var numLiteral = /^(?:[+\-]?(?:\d+|\d*\.\d+)(?:[efd][+\-]?\d+)?|[+\-]?\d+(?:\/[+\-]?\d+)?|#b[+\-]?[01]+|#o[+\-]?[0-7]+|#x[+\-]?[\da-f]+)/;3var symbol = /[^\s'`,@()\[\]";]/;4var type;56function readSym(stream) {7var ch;8while (ch = stream.next()) {9if (ch == "\\") stream.next();10else if (!symbol.test(ch)) { stream.backUp(1); break; }11}12return stream.current();13}1415function base(stream, state) {16if (stream.eatSpace()) {type = "ws"; return null;}17if (stream.match(numLiteral)) return "number";18var ch = stream.next();19if (ch == "\\") ch = stream.next();2021if (ch == '"') return (state.tokenize = inString)(stream, state);22else if (ch == "(") { type = "open"; return "bracket"; }23else if (ch == ")" || ch == "]") { type = "close"; return "bracket"; }24else if (ch == ";") { stream.skipToEnd(); type = "ws"; return "comment"; }25else if (/['`,@]/.test(ch)) return null;26else if (ch == "|") {27if (stream.skipTo("|")) { stream.next(); return "symbol"; }28else { stream.skipToEnd(); return "error"; }29} else if (ch == "#") {30var ch = stream.next();31if (ch == "[") { type = "open"; return "bracket"; }32else if (/[+\-=\.']/.test(ch)) return null;33else if (/\d/.test(ch) && stream.match(/^\d*#/)) return null;34else if (ch == "|") return (state.tokenize = inComment)(stream, state);35else if (ch == ":") { readSym(stream); return "meta"; }36else return "error";37} else {38var name = readSym(stream);39if (name == ".") return null;40type = "symbol";41if (name == "nil" || name == "t") return "atom";42if (name.charAt(0) == ":") return "keyword";43if (name.charAt(0) == "&") return "variable-2";44return "variable";45}46}4748function inString(stream, state) {49var escaped = false, next;50while (next = stream.next()) {51if (next == '"' && !escaped) { state.tokenize = base; break; }52escaped = !escaped && next == "\\";53}54return "string";55}5657function inComment(stream, state) {58var next, last;59while (next = stream.next()) {60if (next == "#" && last == "|") { state.tokenize = base; break; }61last = next;62}63type = "ws";64return "comment";65}6667return {68startState: function () {69return {ctx: {prev: null, start: 0, indentTo: 0}, tokenize: base};70},7172token: function (stream, state) {73if (stream.sol() && typeof state.ctx.indentTo != "number")74state.ctx.indentTo = state.ctx.start + 1;7576type = null;77var style = state.tokenize(stream, state);78if (type != "ws") {79if (state.ctx.indentTo == null) {80if (type == "symbol" && assumeBody.test(stream.current()))81state.ctx.indentTo = state.ctx.start + config.indentUnit;82else83state.ctx.indentTo = "next";84} else if (state.ctx.indentTo == "next") {85state.ctx.indentTo = stream.column();86}87}88if (type == "open") state.ctx = {prev: state.ctx, start: stream.column(), indentTo: null};89else if (type == "close") state.ctx = state.ctx.prev || state.ctx;90return style;91},9293indent: function (state, _textAfter) {94var i = state.ctx.indentTo;95return typeof i == "number" ? i : state.ctx.start + 1;96},9798lineComment: ";;",99blockCommentStart: "#|",100blockCommentEnd: "|#"101};102});103104CodeMirror.defineMIME("text/x-common-lisp", "commonlisp");105106107