File modules/editor/codemirror/mode/asterisk/asterisk.js
Last commit: Sun Dec 17 01:14:09 2017 +0100 Jan Dankert Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 // Distributed under an MIT license: http://codemirror.net/LICENSE 3 4 /* 5 * ===================================================================================== 6 * 7 * Filename: mode/asterisk/asterisk.js 8 * 9 * Description: CodeMirror mode for Asterisk dialplan 10 * 11 * Created: 05/17/2012 09:20:25 PM 12 * Revision: none 13 * 14 * Author: Stas Kobzar (stas@modulis.ca), 15 * Company: Modulis.ca Inc. 16 * 17 * ===================================================================================== 18 */ 19 20 (function(mod) { 21 if (typeof exports == "object" && typeof module == "object") // CommonJS 22 mod(require("../../lib/codemirror")); 23 else if (typeof define == "function" && define.amd) // AMD 24 define(["../../lib/codemirror"], mod); 25 else // Plain browser env 26 mod(CodeMirror); 27 })(function(CodeMirror) { 28 "use strict"; 29 30 CodeMirror.defineMode("asterisk", function() { 31 var atoms = ["exten", "same", "include","ignorepat","switch"], 32 dpcmd = ["#include","#exec"], 33 apps = [ 34 "addqueuemember","adsiprog","aelsub","agentlogin","agentmonitoroutgoing","agi", 35 "alarmreceiver","amd","answer","authenticate","background","backgrounddetect", 36 "bridge","busy","callcompletioncancel","callcompletionrequest","celgenuserevent", 37 "changemonitor","chanisavail","channelredirect","chanspy","clearhash","confbridge", 38 "congestion","continuewhile","controlplayback","dahdiacceptr2call","dahdibarge", 39 "dahdiras","dahdiscan","dahdisendcallreroutingfacility","dahdisendkeypadfacility", 40 "datetime","dbdel","dbdeltree","deadagi","dial","dictate","directory","disa", 41 "dumpchan","eagi","echo","endwhile","exec","execif","execiftime","exitwhile","extenspy", 42 "externalivr","festival","flash","followme","forkcdr","getcpeid","gosub","gosubif", 43 "goto","gotoif","gotoiftime","hangup","iax2provision","ices","importvar","incomplete", 44 "ivrdemo","jabberjoin","jabberleave","jabbersend","jabbersendgroup","jabberstatus", 45 "jack","log","macro","macroexclusive","macroexit","macroif","mailboxexists","meetme", 46 "meetmeadmin","meetmechanneladmin","meetmecount","milliwatt","minivmaccmess","minivmdelete", 47 "minivmgreet","minivmmwi","minivmnotify","minivmrecord","mixmonitor","monitor","morsecode", 48 "mp3player","mset","musiconhold","nbscat","nocdr","noop","odbc","odbc","odbcfinish", 49 "originate","ospauth","ospfinish","osplookup","ospnext","page","park","parkandannounce", 50 "parkedcall","pausemonitor","pausequeuemember","pickup","pickupchan","playback","playtones", 51 "privacymanager","proceeding","progress","queue","queuelog","raiseexception","read","readexten", 52 "readfile","receivefax","receivefax","receivefax","record","removequeuemember", 53 "resetcdr","retrydial","return","ringing","sayalpha","saycountedadj","saycountednoun", 54 "saycountpl","saydigits","saynumber","sayphonetic","sayunixtime","senddtmf","sendfax", 55 "sendfax","sendfax","sendimage","sendtext","sendurl","set","setamaflags", 56 "setcallerpres","setmusiconhold","sipaddheader","sipdtmfmode","sipremoveheader","skel", 57 "slastation","slatrunk","sms","softhangup","speechactivategrammar","speechbackground", 58 "speechcreate","speechdeactivategrammar","speechdestroy","speechloadgrammar","speechprocessingsound", 59 "speechstart","speechunloadgrammar","stackpop","startmusiconhold","stopmixmonitor","stopmonitor", 60 "stopmusiconhold","stopplaytones","system","testclient","testserver","transfer","tryexec", 61 "trysystem","unpausemonitor","unpausequeuemember","userevent","verbose","vmauthenticate", 62 "vmsayname","voicemail","voicemailmain","wait","waitexten","waitfornoise","waitforring", 63 "waitforsilence","waitmusiconhold","waituntil","while","zapateller" 64 ]; 65 66 function basicToken(stream,state){ 67 var cur = ''; 68 var ch = stream.next(); 69 // comment 70 if(ch == ";") { 71 stream.skipToEnd(); 72 return "comment"; 73 } 74 // context 75 if(ch == '[') { 76 stream.skipTo(']'); 77 stream.eat(']'); 78 return "header"; 79 } 80 // string 81 if(ch == '"') { 82 stream.skipTo('"'); 83 return "string"; 84 } 85 if(ch == "'") { 86 stream.skipTo("'"); 87 return "string-2"; 88 } 89 // dialplan commands 90 if(ch == '#') { 91 stream.eatWhile(/\w/); 92 cur = stream.current(); 93 if(dpcmd.indexOf(cur) !== -1) { 94 stream.skipToEnd(); 95 return "strong"; 96 } 97 } 98 // application args 99 if(ch == '$'){ 100 var ch1 = stream.peek(); 101 if(ch1 == '{'){ 102 stream.skipTo('}'); 103 stream.eat('}'); 104 return "variable-3"; 105 } 106 } 107 // extension 108 stream.eatWhile(/\w/); 109 cur = stream.current(); 110 if(atoms.indexOf(cur) !== -1) { 111 state.extenStart = true; 112 switch(cur) { 113 case 'same': state.extenSame = true; break; 114 case 'include': 115 case 'switch': 116 case 'ignorepat': 117 state.extenInclude = true;break; 118 default:break; 119 } 120 return "atom"; 121 } 122 } 123 124 return { 125 startState: function() { 126 return { 127 extenStart: false, 128 extenSame: false, 129 extenInclude: false, 130 extenExten: false, 131 extenPriority: false, 132 extenApplication: false 133 }; 134 }, 135 token: function(stream, state) { 136 137 var cur = ''; 138 if(stream.eatSpace()) return null; 139 // extension started 140 if(state.extenStart){ 141 stream.eatWhile(/[^\s]/); 142 cur = stream.current(); 143 if(/^=>?$/.test(cur)){ 144 state.extenExten = true; 145 state.extenStart = false; 146 return "strong"; 147 } else { 148 state.extenStart = false; 149 stream.skipToEnd(); 150 return "error"; 151 } 152 } else if(state.extenExten) { 153 // set exten and priority 154 state.extenExten = false; 155 state.extenPriority = true; 156 stream.eatWhile(/[^,]/); 157 if(state.extenInclude) { 158 stream.skipToEnd(); 159 state.extenPriority = false; 160 state.extenInclude = false; 161 } 162 if(state.extenSame) { 163 state.extenPriority = false; 164 state.extenSame = false; 165 state.extenApplication = true; 166 } 167 return "tag"; 168 } else if(state.extenPriority) { 169 state.extenPriority = false; 170 state.extenApplication = true; 171 stream.next(); // get comma 172 if(state.extenSame) return null; 173 stream.eatWhile(/[^,]/); 174 return "number"; 175 } else if(state.extenApplication) { 176 stream.eatWhile(/,/); 177 cur = stream.current(); 178 if(cur === ',') return null; 179 stream.eatWhile(/\w/); 180 cur = stream.current().toLowerCase(); 181 state.extenApplication = false; 182 if(apps.indexOf(cur) !== -1){ 183 return "def strong"; 184 } 185 } else{ 186 return basicToken(stream,state); 187 } 188 189 return null; 190 } 191 }; 192 }); 193 194 CodeMirror.defineMIME("text/x-asterisk", "asterisk"); 195 196 });
Downloadmodules/editor/codemirror/mode/asterisk/asterisk.js
History Sun, 17 Dec 2017 01:14:09 +0100 Jan Dankert Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.