// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// mode(s) for the sequence chart dsl's mscgen, xù and msgenny
// For more information on mscgen, see the site of the original author:
// http://www.mcternan.me.uk/mscgen
// This mode for mscgen and the two derivative languages were
// originally made for use in the mscgen_js interpreter
// (https://sverweij.github.io/mscgen_js)
if ( typeof exports == "object" && typeof module == "object")// CommonJS
mod(require("../../lib/codemirror"));
else if ( typeof define == "function" && define.amd)// AMD
define(["../../lib/codemirror"], mod);
})(function(CodeMirror) {
"options" : ["hscale", "width", "arcgradient", "wordwraparcs"],
"attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip"],
"brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists
"arcsWords" : ["note", "abox", "rbox", "box"],
"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"],
"singlecomment" : ["//", "#"],
"options" : ["hscale", "width", "arcgradient", "wordwraparcs", "watermark"],
"attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip"],
"brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists
"arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"],
"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"],
"singlecomment" : ["//", "#"],
"options" : ["hscale", "width", "arcgradient", "wordwraparcs", "watermark"],
"brackets" : ["\\{", "\\}"],
"arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"],
"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"],
"singlecomment" : ["//", "#"],
CodeMirror.defineMode("mscgen", function(_, modeConfig) {
var language = languages[modeConfig && modeConfig.language || "mscgen"]
startState: startStateFn,
token: produceTokenFunction(language),
blockCommentStart : "/*",
CodeMirror.defineMIME("text/x-mscgen", "mscgen");
CodeMirror.defineMIME("text/x-xu", {name: "mscgen", language: "xu"});
CodeMirror.defineMIME("text/x-msgenny", {name: "mscgen", language: "msgenny"});
function wordRegexpBoundary(pWords) {
return new RegExp("\\b(" + pWords.join("|") + ")\\b", "i");
function wordRegexp(pWords) {
return new RegExp("(" + pWords.join("|") + ")", "i");
function startStateFn() {
function copyStateFn(pState) {
inComment : pState.inComment,
inString : pState.inString,
inAttributeList : pState.inAttributeList,
inScript : pState.inScript
function produceTokenFunction(pConfig) {
return function(pStream, pState) {
if (pStream.match(wordRegexp(pConfig.brackets), true, true)) {
if (pStream.match(/\/\*[^\*\/]*/, true, true)) {
if (pStream.match(wordRegexp(pConfig.singlecomment), true, true)) {
if (pStream.match(/[^\*\/]*\*\//, true, true))
pState.inComment = false;
if (!pState.inString && pStream.match(/\"(\\\"|[^\"])*/, true, true)) {
if (pStream.match(/[^\"]*\"/, true, true))
/* keywords & operators */
if (!!pConfig.keywords && pStream.match(wordRegexpBoundary(pConfig.keywords), true, true))
if (pStream.match(wordRegexpBoundary(pConfig.options), true, true))
if (pStream.match(wordRegexpBoundary(pConfig.arcsWords), true, true))
if (pStream.match(wordRegexp(pConfig.arcsOthers), true, true))
if (!!pConfig.operators && pStream.match(wordRegexp(pConfig.operators), true, true))
if (!pConfig.inAttributeList && !!pConfig.attributes && pStream.match(/\[/, true, true)) {
pConfig.inAttributeList = true;
if (pConfig.inAttributeList) {
if (pConfig.attributes !== null && pStream.match(wordRegexpBoundary(pConfig.attributes), true, true)) {
if (pStream.match(/]/, true, true)) {
pConfig.inAttributeList = false;