LaravelTest
175 строк · 6.8 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://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) {13if ( typeof exports == "object" && typeof module == "object")// CommonJS14mod(require("../../lib/codemirror"));15else if ( typeof define == "function" && define.amd)// AMD16define(["../../lib/codemirror"], mod);17else// Plain browser env18mod(CodeMirror);19})(function(CodeMirror) {20"use strict";21
22var languages = {23mscgen: {24"keywords" : ["msc"],25"options" : ["hscale", "width", "arcgradient", "wordwraparcs"],26"constants" : ["true", "false", "on", "off"],27"attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip"],28"brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists29"arcsWords" : ["note", "abox", "rbox", "box"],30"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"],31"singlecomment" : ["//", "#"],32"operators" : ["="]33},34xu: {35"keywords" : ["msc", "xu"],36"options" : ["hscale", "width", "arcgradient", "wordwraparcs", "wordwrapentities", "watermark"],37"constants" : ["true", "false", "on", "off", "auto"],38"attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip", "title", "deactivate", "activate", "activation"],39"brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists40"arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"],41"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"],42"singlecomment" : ["//", "#"],43"operators" : ["="]44},45msgenny: {46"keywords" : null,47"options" : ["hscale", "width", "arcgradient", "wordwraparcs", "wordwrapentities", "watermark"],48"constants" : ["true", "false", "on", "off", "auto"],49"attributes" : null,50"brackets" : ["\\{", "\\}"],51"arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"],52"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"],53"singlecomment" : ["//", "#"],54"operators" : ["="]55}56}57
58CodeMirror.defineMode("mscgen", function(_, modeConfig) {59var language = languages[modeConfig && modeConfig.language || "mscgen"]60return {61startState: startStateFn,62copyState: copyStateFn,63token: produceTokenFunction(language),64lineComment : "#",65blockCommentStart : "/*",66blockCommentEnd : "*/"67};68});69
70CodeMirror.defineMIME("text/x-mscgen", "mscgen");71CodeMirror.defineMIME("text/x-xu", {name: "mscgen", language: "xu"});72CodeMirror.defineMIME("text/x-msgenny", {name: "mscgen", language: "msgenny"});73
74function wordRegexpBoundary(pWords) {75return new RegExp("^\\b(?:" + pWords.join("|") + ")\\b", "i");76}77
78function wordRegexp(pWords) {79return new RegExp("^(?:" + pWords.join("|") + ")", "i");80}81
82function startStateFn() {83return {84inComment : false,85inString : false,86inAttributeList : false,87inScript : false88};89}90
91function copyStateFn(pState) {92return {93inComment : pState.inComment,94inString : pState.inString,95inAttributeList : pState.inAttributeList,96inScript : pState.inScript97};98}99
100function produceTokenFunction(pConfig) {101
102return function(pStream, pState) {103if (pStream.match(wordRegexp(pConfig.brackets), true, true)) {104return "bracket";105}106/* comments */107if (!pState.inComment) {108if (pStream.match(/\/\*[^\*\/]*/, true, true)) {109pState.inComment = true;110return "comment";111}112if (pStream.match(wordRegexp(pConfig.singlecomment), true, true)) {113pStream.skipToEnd();114return "comment";115}116}117if (pState.inComment) {118if (pStream.match(/[^\*\/]*\*\//, true, true))119pState.inComment = false;120else121pStream.skipToEnd();122return "comment";123}124/* strings */125if (!pState.inString && pStream.match(/\"(\\\"|[^\"])*/, true, true)) {126pState.inString = true;127return "string";128}129if (pState.inString) {130if (pStream.match(/[^\"]*\"/, true, true))131pState.inString = false;132else133pStream.skipToEnd();134return "string";135}136/* keywords & operators */137if (!!pConfig.keywords && pStream.match(wordRegexpBoundary(pConfig.keywords), true, true))138return "keyword";139
140if (pStream.match(wordRegexpBoundary(pConfig.options), true, true))141return "keyword";142
143if (pStream.match(wordRegexpBoundary(pConfig.arcsWords), true, true))144return "keyword";145
146if (pStream.match(wordRegexp(pConfig.arcsOthers), true, true))147return "keyword";148
149if (!!pConfig.operators && pStream.match(wordRegexp(pConfig.operators), true, true))150return "operator";151
152if (!!pConfig.constants && pStream.match(wordRegexp(pConfig.constants), true, true))153return "variable";154
155/* attribute lists */156if (!pConfig.inAttributeList && !!pConfig.attributes && pStream.match('[', true, true)) {157pConfig.inAttributeList = true;158return "bracket";159}160if (pConfig.inAttributeList) {161if (pConfig.attributes !== null && pStream.match(wordRegexpBoundary(pConfig.attributes), true, true)) {162return "attribute";163}164if (pStream.match(']', true, true)) {165pConfig.inAttributeList = false;166return "bracket";167}168}169
170pStream.next();171return "base";172};173}174
175});176