Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/pascal/pascal.js
1294 views
CodeMirror.defineMode("pascal", function() {1function words(str) {2var obj = {}, words = str.split(" ");3for (var i = 0; i < words.length; ++i) obj[words[i]] = true;4return obj;5}6var keywords = words("and array begin case const div do downto else end file for forward integer " +7"boolean char function goto if in label mod nil not of or packed procedure " +8"program record repeat set string then to type until var while with");9var atoms = {"null": true};1011var isOperatorChar = /[+\-*&%=<>!?|\/]/;1213function tokenBase(stream, state) {14var ch = stream.next();15if (ch == "#" && state.startOfLine) {16stream.skipToEnd();17return "meta";18}19if (ch == '"' || ch == "'") {20state.tokenize = tokenString(ch);21return state.tokenize(stream, state);22}23if (ch == "(" && stream.eat("*")) {24state.tokenize = tokenComment;25return tokenComment(stream, state);26}27if (/[\[\]{}\(\),;\:\.]/.test(ch)) {28return null;29}30if (/\d/.test(ch)) {31stream.eatWhile(/[\w\.]/);32return "number";33}34if (ch == "/") {35if (stream.eat("/")) {36stream.skipToEnd();37return "comment";38}39}40if (isOperatorChar.test(ch)) {41stream.eatWhile(isOperatorChar);42return "operator";43}44stream.eatWhile(/[\w\$_]/);45var cur = stream.current();46if (keywords.propertyIsEnumerable(cur)) return "keyword";47if (atoms.propertyIsEnumerable(cur)) return "atom";48return "variable";49}5051function tokenString(quote) {52return function(stream, state) {53var escaped = false, next, end = false;54while ((next = stream.next()) != null) {55if (next == quote && !escaped) {end = true; break;}56escaped = !escaped && next == "\\";57}58if (end || !escaped) state.tokenize = null;59return "string";60};61}6263function tokenComment(stream, state) {64var maybeEnd = false, ch;65while (ch = stream.next()) {66if (ch == ")" && maybeEnd) {67state.tokenize = null;68break;69}70maybeEnd = (ch == "*");71}72return "comment";73}7475// Interface7677return {78startState: function() {79return {tokenize: null};80},8182token: function(stream, state) {83if (stream.eatSpace()) return null;84var style = (state.tokenize || tokenBase)(stream, state);85if (style == "comment" || style == "meta") return style;86return style;87},8889electricChars: "{}"90};91});9293CodeMirror.defineMIME("text/x-pascal", "pascal");949596