|
| 1 | +(function(mod) { |
| 2 | + if (typeof exports == "object" && typeof module == "object") // CommonJS |
| 3 | + mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); |
| 4 | + else if (typeof define == "function" && define.amd) // AMD |
| 5 | + define(["../../lib/codemirror", "../../addon/mode/simple"], mod); |
| 6 | + else // Plain browser env |
| 7 | + mod(CodeMirror); |
| 8 | +})(function(CodeMirror) { |
| 9 | + // Modify from https://github.com/Stephanvs/vscode-graphviz/blob/master/dot/syntaxes/dot.tmLanguage |
| 10 | + // and https://github.com/PhE/jupyterlab_graphviz/blob/master/src/mode.ts |
| 11 | + |
| 12 | + |
| 13 | + var TYPES = { |
| 14 | + 'application/vnd.graphviz': { |
| 15 | + name: 'dot', |
| 16 | + extensions: ['.gv', '.dot'], |
| 17 | + engine: 'dot' |
| 18 | + }, |
| 19 | + 'application/vnd.graphviz.neato': { |
| 20 | + name: 'neato', |
| 21 | + extensions: ['.neato'], |
| 22 | + engine: 'neato' |
| 23 | + } |
| 24 | + }; |
| 25 | + |
| 26 | + var MODE_NAME = 'graphviz'; |
| 27 | + |
| 28 | + |
| 29 | + var STATES = { |
| 30 | + start: [ |
| 31 | + {regex: /'.*?'|".*?"/, token: "string"}, |
| 32 | + {regex: /-+>?|=|:/, token: "operator"}, |
| 33 | + {regex: /[;,]/, token: "comment"}, |
| 34 | + {regex: /[{}[\]]/, token: "bracket"}, |
| 35 | + |
| 36 | + // storage type |
| 37 | + {regex: /(graph|digraph|strict|node|edge|subgraph)\b/i, token: "atom"}, |
| 38 | + |
| 39 | + // node attribute |
| 40 | + {regex: /\b(bottomlabel|color|comment|distortion|fillcolor|fixedsize|fontcolor|fontname|fontsize|group|height|label|layer|orientation|peripheries|regular|shape|shapefile|sides|skew|style|toplabel|URL|width|z)\b/, token: "property"}, |
| 41 | + |
| 42 | + // edge attribute |
| 43 | + {regex: /\b(arrowhead|arrowsize|arrowtail|color|comment|constraint|decorate|dir|fontcolor|fontname|fontsize|headlabel|headport|headURL|label|labelangle|labeldistance|labelfloat|labelcolor|labelfontname|labelfontsize|layer|lhead|ltail|minlen|samehead|sametail|splines|style|taillabel|tailport|tailURL|weight)\b/, token: "variable-3"}, |
| 44 | + |
| 45 | + // graph attribute |
| 46 | + {regex: /\b(bgcolor|center|clusterrank|color|comment|compound|concentrate|fillcolor|fontname|fontpath|fontsize|label|labeljust|labelloc|layers|margin|mclimit|nodesep|nslimit|nslimit1|ordering|orientation|page|pagedir|quantum|rank|rankdir|ranksep|ratio|remincross|rotate|samplepoints|searchsize|size|style|URL)\b/, token: "variable-3"}, |
| 47 | + |
| 48 | + // other attribute |
| 49 | + {regex: /\b(box|polygon|ellipse|oval|circle|point|egg|triangle|plaintext|plain|diamond|trapezium|parallelogram|house|pentagon|hexagon|septagon|octagon|doublecircle|doubleoctagon|tripleoctagon|invtriangle|invtrapezium|invhouse|Mdiamond|Msquare|Mcircle|rect|rectangle|square|star|none|underline|cylinder|note|tab|folder|box3d|component|promoter|cds|terminator|utr|primersite|restrictionsite|fivepoverhang|threepoverhang|noverhang|assembly|signature|insulator|ribosite|rnastab|proteasesite|proteinstab|rpromoter|rarrow|larrow|lpromoter)\b/, token: "variable-3"}, |
| 50 | + |
| 51 | + {regex: /</, token: "meta", mode: {spec: "xml", end: />>/}}, |
| 52 | + {regex: /#.*/, token: "comment"}, |
| 53 | + {regex: /[a-z][a-z\d_]*/i, token: "variable-2"}, |
| 54 | + {regex: /0x[a-f\d]+|[-+]?(?:\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/i, |
| 55 | + token: "number"}, |
| 56 | + {regex: /\/\/.*/, token: "comment"}, |
| 57 | + {regex: /\/\*/, token: "comment", next: "comment"}, |
| 58 | + ], |
| 59 | + // The multi-line comment state. |
| 60 | + comment: [ |
| 61 | + {regex: /.*?\*\//, token: "comment", next: "start"}, |
| 62 | + {regex: /.*/, token: "comment"} |
| 63 | + ], |
| 64 | + meta: { |
| 65 | + dontIndentStates: ["comment"], |
| 66 | + lineComment: "//" |
| 67 | + } |
| 68 | + }; |
| 69 | + |
| 70 | + |
| 71 | + CodeMirror.defineSimpleMode(MODE_NAME, STATES); |
| 72 | + |
| 73 | + for(var t in TYPES) { |
| 74 | + CodeMirror.defineMIME(t, MODE_NAME); |
| 75 | + CodeMirror.modeInfo.push({ |
| 76 | + // codemirror extensions don't expect the leading dot |
| 77 | + ext: TYPES[t].extensions.map(function(e) { return e.replace(/^\./, '') }), |
| 78 | + mime: t, |
| 79 | + mode: MODE_NAME, |
| 80 | + name: MODE_NAME + ' (' + TYPES[t].name + ')', |
| 81 | + }); |
| 82 | + } |
| 83 | +}) |
0 commit comments