github.com/elliott5/community@v0.14.1-0.20160709191136-823126fb026a/app/public/codemirror/mode/mscgen/mscgen.js (about) 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 // Distributed under an MIT license: http://codemirror.net/LICENSE 3 4 // mode(s) for the sequence chart dsl's mscgen, xù and msgenny 5 // For more information on mscgen, see the site of the original author: 6 // http://www.mcternan.me.uk/mscgen 7 // 8 // This mode for mscgen and the two derivative languages were 9 // originally made for use in the mscgen_js interpreter 10 // (https://sverweij.github.io/mscgen_js) 11 12 (function(mod) { 13 if ( typeof exports == "object" && typeof module == "object")// CommonJS 14 mod(require("../../lib/codemirror")); 15 else if ( typeof define == "function" && define.amd)// AMD 16 define(["../../lib/codemirror"], mod); 17 else// Plain browser env 18 mod(CodeMirror); 19 })(function(CodeMirror) { 20 "use strict"; 21 22 var languages = { 23 mscgen: { 24 "keywords" : ["msc"], 25 "options" : ["hscale", "width", "arcgradient", "wordwraparcs"], 26 "attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip"], 27 "brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists 28 "arcsWords" : ["note", "abox", "rbox", "box"], 29 "arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"], 30 "singlecomment" : ["//", "#"], 31 "operators" : ["="] 32 }, 33 xu: { 34 "keywords" : ["msc"], 35 "options" : ["hscale", "width", "arcgradient", "wordwraparcs", "watermark"], 36 "attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip"], 37 "brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists 38 "arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"], 39 "arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"], 40 "singlecomment" : ["//", "#"], 41 "operators" : ["="] 42 }, 43 msgenny: { 44 "keywords" : null, 45 "options" : ["hscale", "width", "arcgradient", "wordwraparcs", "watermark"], 46 "attributes" : null, 47 "brackets" : ["\\{", "\\}"], 48 "arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"], 49 "arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"], 50 "singlecomment" : ["//", "#"], 51 "operators" : ["="] 52 } 53 } 54 55 CodeMirror.defineMode("mscgen", function(_, modeConfig) { 56 var language = languages[modeConfig && modeConfig.language || "mscgen"] 57 return { 58 startState: startStateFn, 59 copyState: copyStateFn, 60 token: produceTokenFunction(language), 61 lineComment : "#", 62 blockCommentStart : "/*", 63 blockCommentEnd : "*/" 64 }; 65 }); 66 67 CodeMirror.defineMIME("text/x-mscgen", "mscgen"); 68 CodeMirror.defineMIME("text/x-xu", {name: "mscgen", language: "xu"}); 69 CodeMirror.defineMIME("text/x-msgenny", {name: "mscgen", language: "msgenny"}); 70 71 function wordRegexpBoundary(pWords) { 72 return new RegExp("\\b(" + pWords.join("|") + ")\\b", "i"); 73 } 74 75 function wordRegexp(pWords) { 76 return new RegExp("(" + pWords.join("|") + ")", "i"); 77 } 78 79 function startStateFn() { 80 return { 81 inComment : false, 82 inString : false, 83 inAttributeList : false, 84 inScript : false 85 }; 86 } 87 88 function copyStateFn(pState) { 89 return { 90 inComment : pState.inComment, 91 inString : pState.inString, 92 inAttributeList : pState.inAttributeList, 93 inScript : pState.inScript 94 }; 95 } 96 97 function produceTokenFunction(pConfig) { 98 99 return function(pStream, pState) { 100 if (pStream.match(wordRegexp(pConfig.brackets), true, true)) { 101 return "bracket"; 102 } 103 /* comments */ 104 if (!pState.inComment) { 105 if (pStream.match(/\/\*[^\*\/]*/, true, true)) { 106 pState.inComment = true; 107 return "comment"; 108 } 109 if (pStream.match(wordRegexp(pConfig.singlecomment), true, true)) { 110 pStream.skipToEnd(); 111 return "comment"; 112 } 113 } 114 if (pState.inComment) { 115 if (pStream.match(/[^\*\/]*\*\//, true, true)) 116 pState.inComment = false; 117 else 118 pStream.skipToEnd(); 119 return "comment"; 120 } 121 /* strings */ 122 if (!pState.inString && pStream.match(/\"(\\\"|[^\"])*/, true, true)) { 123 pState.inString = true; 124 return "string"; 125 } 126 if (pState.inString) { 127 if (pStream.match(/[^\"]*\"/, true, true)) 128 pState.inString = false; 129 else 130 pStream.skipToEnd(); 131 return "string"; 132 } 133 /* keywords & operators */ 134 if (!!pConfig.keywords && pStream.match(wordRegexpBoundary(pConfig.keywords), true, true)) 135 return "keyword"; 136 137 if (pStream.match(wordRegexpBoundary(pConfig.options), true, true)) 138 return "keyword"; 139 140 if (pStream.match(wordRegexpBoundary(pConfig.arcsWords), true, true)) 141 return "keyword"; 142 143 if (pStream.match(wordRegexp(pConfig.arcsOthers), true, true)) 144 return "keyword"; 145 146 if (!!pConfig.operators && pStream.match(wordRegexp(pConfig.operators), true, true)) 147 return "operator"; 148 149 /* attribute lists */ 150 if (!pConfig.inAttributeList && !!pConfig.attributes && pStream.match(/\[/, true, true)) { 151 pConfig.inAttributeList = true; 152 return "bracket"; 153 } 154 if (pConfig.inAttributeList) { 155 if (pConfig.attributes !== null && pStream.match(wordRegexpBoundary(pConfig.attributes), true, true)) { 156 return "attribute"; 157 } 158 if (pStream.match(/]/, true, true)) { 159 pConfig.inAttributeList = false; 160 return "bracket"; 161 } 162 } 163 164 pStream.next(); 165 return "base"; 166 }; 167 } 168 169 });