|
| 1 | +/* |
| 2 | + * PlantUML Mode for CodeMirror |
| 3 | + * @author keisuke kimura https://github.com/kkeisuke |
| 4 | + * @link https://github.com/kkeisuke/plantuml-editor/blob/master/src/lib/codemirror/mode/plantuml/plantuml.js |
| 5 | + */ |
| 6 | +(function(mod) { |
| 7 | + if (typeof exports == "object" && typeof module == "object") // CommonJS |
| 8 | + mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); |
| 9 | + else if (typeof define == "function" && define.amd) // AMD |
| 10 | + define(["../../lib/codemirror", "../../addon/mode/simple"], mod); |
| 11 | + else // Plain browser env |
| 12 | + mod(CodeMirror); |
| 13 | +})(function(CodeMirror) { |
| 14 | + CodeMirror.defineSimpleMode('plantuml', { |
| 15 | + start: [ |
| 16 | + // シングルライン コメント |
| 17 | + // TODO ^ が効かない |
| 18 | + { |
| 19 | + regex: /^'.*/, |
| 20 | + token: 'comment' |
| 21 | + }, |
| 22 | + // ダブルコーテーション付の文字列 |
| 23 | + { |
| 24 | + regex: /"(?:[^\\]|\\.)*?(?:"|$)/, |
| 25 | + token: 'string' |
| 26 | + }, |
| 27 | + // { |
| 28 | + // regex: /@enduml|@startuml/, |
| 29 | + // token: 'keyword' |
| 30 | + // }, |
| 31 | + { |
| 32 | + regex: /\b(abstract|actor|agent|class|component|database|enum|interface|node|note|object|participant|partition|rectangle|state|static|storage|usecase)\b/, |
| 33 | + token: 'keyword' |
| 34 | + }, |
| 35 | + { |
| 36 | + regex: /\b(true|false)\b/, |
| 37 | + token: 'keyword' |
| 38 | + }, |
| 39 | + { |
| 40 | + regex: /\b(activate|again|allow_mixing|also|alt|as|autonumber|bottom|box|break|caption|center|create|critical|deactivate|destroy|direction|down|else|end|endfooter|endheader|endif|endlegend|endwhile|entity|footbox|footer|fork|group)\b/, |
| 41 | + token: 'atom' |
| 42 | + }, |
| 43 | + { |
| 44 | + regex: /\b(header|hide|if|is|left|legend|link|loop|namespace|newpage|of|on|opt|over|package|page|par|ref|repeat|return|right|rotate|scale|show|skin|skinparam|start|stop|title|then|top|up|while)\b/, |
| 45 | + token: 'atom' |
| 46 | + }, |
| 47 | + { |
| 48 | + regex: /!define/, |
| 49 | + token: 'atom' |
| 50 | + }, |
| 51 | + { |
| 52 | + regex: /(AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGreen|DarkGrey|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkSlateGrey|DarkTurquoise|DarkViolet|Darkorange|DeepPink|DeepSkyBlue|DimGray|DimGrey|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gray|Green|GreenYellow|Grey|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGreen|LightGrey|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSlateGrey|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|SlateGrey|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)/, |
| 53 | + token: 'variable-3' |
| 54 | + }, |
| 55 | + // 単語 |
| 56 | + { |
| 57 | + regex: /[a-zA-Z$][\w$]*/, |
| 58 | + token: 'variable' |
| 59 | + }, |
| 60 | + // --> |
| 61 | + // TODO 旧アクティビティ図対応のため、\s を先頭に付けていない。 |
| 62 | + { |
| 63 | + regex: /-+(up|right|down|left)*-*[|]?[>*o]*\s/, |
| 64 | + token: 'variable-2' |
| 65 | + }, |
| 66 | + // ..> |
| 67 | + { |
| 68 | + regex: /\s\.+(up|right|down|left)*\.*[|]?[>*o]*\s/, |
| 69 | + token: 'variable-2' |
| 70 | + }, |
| 71 | + // <-- |
| 72 | + { |
| 73 | + regex: /\s[<*o]*[|]?-+(up|right|down|left)*-*\s/, |
| 74 | + token: 'variable-2' |
| 75 | + }, |
| 76 | + // <.. |
| 77 | + { |
| 78 | + regex: /\s[<*o]*[|]?\.+(up|right|down|left)*\.*\s/, |
| 79 | + token: 'variable-2' |
| 80 | + }, |
| 81 | + // 記号 |
| 82 | + { |
| 83 | + regex: /(<<|>>|:|;|\\n)/, |
| 84 | + token: 'variable-2' |
| 85 | + }, |
| 86 | + // Public メソッド |
| 87 | + { |
| 88 | + regex: /\+[^(]+\(\)/, |
| 89 | + token: 'variable-2' |
| 90 | + }, |
| 91 | + // Private メソッド |
| 92 | + { |
| 93 | + regex: /-[^(]+\(\)/, |
| 94 | + token: 'variable-2' |
| 95 | + }, |
| 96 | + // Protected メソッド |
| 97 | + { |
| 98 | + regex: /#[^(]+\(\)/, |
| 99 | + token: 'variable-2' |
| 100 | + }, |
| 101 | + // Activity β タイトル |
| 102 | + // TODO ER図と重複してしまう |
| 103 | + // { |
| 104 | + // regex: /\|[^|#]+\|/, |
| 105 | + // token: 'variable-2' |
| 106 | + // }, |
| 107 | + // {} 内のインデントを揃える |
| 108 | + { |
| 109 | + regex: /[{[(]/, |
| 110 | + indent: true |
| 111 | + }, |
| 112 | + { |
| 113 | + regex: /[}\])]/, |
| 114 | + dedent: true |
| 115 | + }, |
| 116 | + // 複数行のコメント |
| 117 | + { |
| 118 | + regex: /\/'/, |
| 119 | + token: 'comment', |
| 120 | + next: 'comment' |
| 121 | + } |
| 122 | + ], |
| 123 | + // 複数行のコメント |
| 124 | + comment: [ |
| 125 | + { |
| 126 | + regex: /.*?'\//, |
| 127 | + token: 'comment', |
| 128 | + next: 'start' |
| 129 | + }, |
| 130 | + { |
| 131 | + regex: /.*/, |
| 132 | + token: 'comment' |
| 133 | + } |
| 134 | + ] |
| 135 | + }) |
| 136 | +}) |
0 commit comments