Blame | Letzte Änderung | Log anzeigen | RSS feed
// CodeMirror, copyright (c) by Marijn Haverbeke and others// Distributed under an MIT license: http://codemirror.net/LICENSE(function(mod) {if (typeof exports == "object" && typeof module == "object") // CommonJSmod(require("../../lib/codemirror"));else if (typeof define == "function" && define.amd) // AMDdefine(["../../lib/codemirror"], mod);else // Plain browser envmod(CodeMirror);})(function(CodeMirror) {"use strict";CodeMirror.defineMode("dylan", function(_config) {// Wordsvar words = {// Words that introduce unnamed definitions like "define interface"unnamedDefinition: ["interface"],// Words that introduce simple named definitions like "define library"namedDefinition: ["module", "library", "macro","C-struct", "C-union","C-function", "C-callable-wrapper"],// Words that introduce type definitions like "define class".// These are also parameterized like "define method" and are// appended to otherParameterizedDefinitionWordstypeParameterizedDefinition: ["class", "C-subtype", "C-mapped-subtype"],// Words that introduce trickier definitions like "define method".// These require special definitions to be added to startExpressionsotherParameterizedDefinition: ["method", "function","C-variable", "C-address"],// Words that introduce module constant definitions.// These must also be simple definitions and are// appended to otherSimpleDefinitionWordsconstantSimpleDefinition: ["constant"],// Words that introduce module variable definitions.// These must also be simple definitions and are// appended to otherSimpleDefinitionWordsvariableSimpleDefinition: ["variable"],// Other words that introduce simple definitions// (without implicit bodies).otherSimpleDefinition: ["generic", "domain","C-pointer-type","table"],// Words that begin statements with implicit bodies.statement: ["if", "block", "begin", "method", "case","for", "select", "when", "unless", "until","while", "iterate", "profiling", "dynamic-bind"],// Patterns that act as separators in compound statements.// This may include any general pattern that must be indented// specially.separator: ["finally", "exception", "cleanup", "else","elseif", "afterwards"],// Keywords that do not require special indentation handling,// but which should be highlightedother: ["above", "below", "by", "from", "handler", "in","instance", "let", "local", "otherwise", "slot","subclass", "then", "to", "keyed-by", "virtual"],// Condition signaling function callssignalingCalls: ["signal", "error", "cerror","break", "check-type", "abort"]};words["otherDefinition"] =words["unnamedDefinition"].concat(words["namedDefinition"]).concat(words["otherParameterizedDefinition"]);words["definition"] =words["typeParameterizedDefinition"].concat(words["otherDefinition"]);words["parameterizedDefinition"] =words["typeParameterizedDefinition"].concat(words["otherParameterizedDefinition"]);words["simpleDefinition"] =words["constantSimpleDefinition"].concat(words["variableSimpleDefinition"]).concat(words["otherSimpleDefinition"]);words["keyword"] =words["statement"].concat(words["separator"]).concat(words["other"]);// Patternsvar symbolPattern = "[-_a-zA-Z?!*@<>$%]+";var symbol = new RegExp("^" + symbolPattern);var patterns = {// Symbols with special syntaxsymbolKeyword: symbolPattern + ":",symbolClass: "<" + symbolPattern + ">",symbolGlobal: "\\*" + symbolPattern + "\\*",symbolConstant: "\\$" + symbolPattern};var patternStyles = {symbolKeyword: "atom",symbolClass: "tag",symbolGlobal: "variable-2",symbolConstant: "variable-3"};// Compile all patterns to regular expressionsfor (var patternName in patterns)if (patterns.hasOwnProperty(patternName))patterns[patternName] = new RegExp("^" + patterns[patternName]);// Names beginning "with-" and "without-" are commonly// used as statement macropatterns["keyword"] = [/^with(?:out)?-[-_a-zA-Z?!*@<>$%]+/];var styles = {};styles["keyword"] = "keyword";styles["definition"] = "def";styles["simpleDefinition"] = "def";styles["signalingCalls"] = "builtin";// protected words lookup tablevar wordLookup = {};var styleLookup = {};["keyword","definition","simpleDefinition","signalingCalls"].forEach(function(type) {words[type].forEach(function(word) {wordLookup[word] = type;styleLookup[word] = styles[type];});});function chain(stream, state, f) {state.tokenize = f;return f(stream, state);}function tokenBase(stream, state) {// Stringvar ch = stream.peek();if (ch == "'" || ch == '"') {stream.next();return chain(stream, state, tokenString(ch, "string"));}// Commentelse if (ch == "/") {stream.next();if (stream.eat("*")) {return chain(stream, state, tokenComment);} else if (stream.eat("/")) {stream.skipToEnd();return "comment";} else {stream.skipTo(" ");return "operator";}}// Decimalelse if (/\d/.test(ch)) {stream.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);return "number";}// Hashelse if (ch == "#") {stream.next();// Symbol with string syntaxch = stream.peek();if (ch == '"') {stream.next();return chain(stream, state, tokenString('"', "string-2"));}// Binary numberelse if (ch == "b") {stream.next();stream.eatWhile(/[01]/);return "number";}// Hex numberelse if (ch == "x") {stream.next();stream.eatWhile(/[\da-f]/i);return "number";}// Octal numberelse if (ch == "o") {stream.next();stream.eatWhile(/[0-7]/);return "number";}// Hash symbolelse {stream.eatWhile(/[-a-zA-Z]/);return "keyword";}} else if (stream.match("end")) {return "keyword";}for (var name in patterns) {if (patterns.hasOwnProperty(name)) {var pattern = patterns[name];if ((pattern instanceof Array && pattern.some(function(p) {return stream.match(p);})) || stream.match(pattern))return patternStyles[name];}}if (stream.match("define")) {return "def";} else {stream.eatWhile(/[\w\-]/);// Keywordif (wordLookup[stream.current()]) {return styleLookup[stream.current()];} else if (stream.current().match(symbol)) {return "variable";} else {stream.next();return "variable-2";}}}function tokenComment(stream, state) {var maybeEnd = false,ch;while ((ch = stream.next())) {if (ch == "/" && maybeEnd) {state.tokenize = tokenBase;break;}maybeEnd = (ch == "*");}return "comment";}function tokenString(quote, style) {return function(stream, state) {var next, end = false;while ((next = stream.next()) != null) {if (next == quote) {end = true;break;}}if (end)state.tokenize = tokenBase;return style;};}// Interfacereturn {startState: function() {return {tokenize: tokenBase,currentIndent: 0};},token: function(stream, state) {if (stream.eatSpace())return null;var style = state.tokenize(stream, state);return style;},blockCommentStart: "/*",blockCommentEnd: "*/"};});CodeMirror.defineMIME("text/x-dylan", "dylan");});