| 1 |
var atoms = ["exten", "same", "include","ignorepat","switch"], |
| 2 |
dpcmd = ["#include","#exec"], |
| 3 |
apps = [ |
| 4 |
"addqueuemember","adsiprog","aelsub","agentlogin","agentmonitoroutgoing","agi", |
| 5 |
"alarmreceiver","amd","answer","authenticate","background","backgrounddetect", |
| 6 |
"bridge","busy","callcompletioncancel","callcompletionrequest","celgenuserevent", |
| 7 |
"changemonitor","chanisavail","channelredirect","chanspy","clearhash","confbridge", |
| 8 |
"congestion","continuewhile","controlplayback","dahdiacceptr2call","dahdibarge", |
| 9 |
"dahdiras","dahdiscan","dahdisendcallreroutingfacility","dahdisendkeypadfacility", |
| 10 |
"datetime","dbdel","dbdeltree","deadagi","dial","dictate","directory","disa", |
| 11 |
"dumpchan","eagi","echo","endwhile","exec","execif","execiftime","exitwhile","extenspy", |
| 12 |
"externalivr","festival","flash","followme","forkcdr","getcpeid","gosub","gosubif", |
| 13 |
"goto","gotoif","gotoiftime","hangup","iax2provision","ices","importvar","incomplete", |
| 14 |
"ivrdemo","jabberjoin","jabberleave","jabbersend","jabbersendgroup","jabberstatus", |
| 15 |
"jack","log","macro","macroexclusive","macroexit","macroif","mailboxexists","meetme", |
| 16 |
"meetmeadmin","meetmechanneladmin","meetmecount","milliwatt","minivmaccmess","minivmdelete", |
| 17 |
"minivmgreet","minivmmwi","minivmnotify","minivmrecord","mixmonitor","monitor","morsecode", |
| 18 |
"mp3player","mset","musiconhold","nbscat","nocdr","noop","odbc","odbc","odbcfinish", |
| 19 |
"originate","ospauth","ospfinish","osplookup","ospnext","page","park","parkandannounce", |
| 20 |
"parkedcall","pausemonitor","pausequeuemember","pickup","pickupchan","playback","playtones", |
| 21 |
"privacymanager","proceeding","progress","queue","queuelog","raiseexception","read","readexten", |
| 22 |
"readfile","receivefax","receivefax","receivefax","record","removequeuemember", |
| 23 |
"resetcdr","retrydial","return","ringing","sayalpha","saycountedadj","saycountednoun", |
| 24 |
"saycountpl","saydigits","saynumber","sayphonetic","sayunixtime","senddtmf","sendfax", |
| 25 |
"sendfax","sendfax","sendimage","sendtext","sendurl","set","setamaflags", |
| 26 |
"setcallerpres","setmusiconhold","sipaddheader","sipdtmfmode","sipremoveheader","skel", |
| 27 |
"slastation","slatrunk","sms","softhangup","speechactivategrammar","speechbackground", |
| 28 |
"speechcreate","speechdeactivategrammar","speechdestroy","speechloadgrammar","speechprocessingsound", |
| 29 |
"speechstart","speechunloadgrammar","stackpop","startmusiconhold","stopmixmonitor","stopmonitor", |
| 30 |
"stopmusiconhold","stopplaytones","system","testclient","testserver","transfer","tryexec", |
| 31 |
"trysystem","unpausemonitor","unpausequeuemember","userevent","verbose","vmauthenticate", |
| 32 |
"vmsayname","voicemail","voicemailmain","wait","waitexten","waitfornoise","waitforring", |
| 33 |
"waitforsilence","waitmusiconhold","waituntil","while","zapateller" |
| 34 |
]; |
| 35 |
|
| 36 |
function basicToken(stream,state){ |
| 37 |
var cur = ''; |
| 38 |
var ch = stream.next(); |
| 39 |
// comment |
| 40 |
if (state.blockComment) { |
| 41 |
if (ch == "-" && stream.match("-;", true)) { |
| 42 |
state.blockComment = false; |
| 43 |
} else if (stream.skipTo("--;")) { |
| 44 |
stream.next(); |
| 45 |
stream.next(); |
| 46 |
stream.next(); |
| 47 |
state.blockComment = false; |
| 48 |
} else { |
| 49 |
stream.skipToEnd(); |
| 50 |
} |
| 51 |
return "comment"; |
| 52 |
} |
| 53 |
if(ch == ";") { |
| 54 |
if (stream.match("--", true)) { |
| 55 |
if (!stream.match("-", false)) { // Except ;--- is not a block comment |
| 56 |
state.blockComment = true; |
| 57 |
return "comment"; |
| 58 |
} |
| 59 |
} |
| 60 |
stream.skipToEnd(); |
| 61 |
return "comment"; |
| 62 |
} |
| 63 |
// context |
| 64 |
if(ch == '[') { |
| 65 |
stream.skipTo(']'); |
| 66 |
stream.eat(']'); |
| 67 |
return "header"; |
| 68 |
} |
| 69 |
// string |
| 70 |
if(ch == '"') { |
| 71 |
stream.skipTo('"'); |
| 72 |
return "string"; |
| 73 |
} |
| 74 |
if(ch == "'") { |
| 75 |
stream.skipTo("'"); |
| 76 |
return "string.special"; |
| 77 |
} |
| 78 |
// dialplan commands |
| 79 |
if(ch == '#') { |
| 80 |
stream.eatWhile(/\w/); |
| 81 |
cur = stream.current(); |
| 82 |
if(dpcmd.indexOf(cur) !== -1) { |
| 83 |
stream.skipToEnd(); |
| 84 |
return "strong"; |
| 85 |
} |
| 86 |
} |
| 87 |
// application args |
| 88 |
if(ch == '$'){ |
| 89 |
var ch1 = stream.peek(); |
| 90 |
if(ch1 == '{'){ |
| 91 |
stream.skipTo('}'); |
| 92 |
stream.eat('}'); |
| 93 |
return "variableName.special"; |
| 94 |
} |
| 95 |
} |
| 96 |
// extension |
| 97 |
stream.eatWhile(/\w/); |
| 98 |
cur = stream.current(); |
| 99 |
if(atoms.indexOf(cur) !== -1) { |
| 100 |
state.extenStart = true; |
| 101 |
switch(cur) { |
| 102 |
case 'same': state.extenSame = true; break; |
| 103 |
case 'include': |
| 104 |
case 'switch': |
| 105 |
case 'ignorepat': |
| 106 |
state.extenInclude = true;break; |
| 107 |
default:break; |
| 108 |
} |
| 109 |
return "atom"; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
export const asterisk = { |
| 114 |
name: "asterisk", |
| 115 |
startState: function() { |
| 116 |
return { |
| 117 |
blockComment: false, |
| 118 |
extenStart: false, |
| 119 |
extenSame: false, |
| 120 |
extenInclude: false, |
| 121 |
extenExten: false, |
| 122 |
extenPriority: false, |
| 123 |
extenApplication: false |
| 124 |
}; |
| 125 |
}, |
| 126 |
token: function(stream, state) { |
| 127 |
|
| 128 |
var cur = ''; |
| 129 |
if(stream.eatSpace()) return null; |
| 130 |
// extension started |
| 131 |
if(state.extenStart){ |
| 132 |
stream.eatWhile(/[^\s]/); |
| 133 |
cur = stream.current(); |
| 134 |
if(/^=>?$/.test(cur)){ |
| 135 |
state.extenExten = true; |
| 136 |
state.extenStart = false; |
| 137 |
return "strong"; |
| 138 |
} else { |
| 139 |
state.extenStart = false; |
| 140 |
stream.skipToEnd(); |
| 141 |
return "error"; |
| 142 |
} |
| 143 |
} else if(state.extenExten) { |
| 144 |
// set exten and priority |
| 145 |
state.extenExten = false; |
| 146 |
state.extenPriority = true; |
| 147 |
stream.eatWhile(/[^,]/); |
| 148 |
if(state.extenInclude) { |
| 149 |
stream.skipToEnd(); |
| 150 |
state.extenPriority = false; |
| 151 |
state.extenInclude = false; |
| 152 |
} |
| 153 |
if(state.extenSame) { |
| 154 |
state.extenPriority = false; |
| 155 |
state.extenSame = false; |
| 156 |
state.extenApplication = true; |
| 157 |
} |
| 158 |
return "tag"; |
| 159 |
} else if(state.extenPriority) { |
| 160 |
state.extenPriority = false; |
| 161 |
state.extenApplication = true; |
| 162 |
stream.next(); // get comma |
| 163 |
if(state.extenSame) return null; |
| 164 |
stream.eatWhile(/[^,]/); |
| 165 |
return "number"; |
| 166 |
} else if(state.extenApplication) { |
| 167 |
stream.eatWhile(/,/); |
| 168 |
cur = stream.current(); |
| 169 |
if(cur === ',') return null; |
| 170 |
stream.eatWhile(/\w/); |
| 171 |
cur = stream.current().toLowerCase(); |
| 172 |
state.extenApplication = false; |
| 173 |
if(apps.indexOf(cur) !== -1){ |
| 174 |
return "def"; |
| 175 |
} |
| 176 |
} else{ |
| 177 |
return basicToken(stream,state); |
| 178 |
} |
| 179 |
|
| 180 |
return null; |
| 181 |
}, |
| 182 |
|
| 183 |
languageData: { |
| 184 |
commentTokens: {line: ";", block: {open: ";--", close: "--;"}} |
| 185 |
} |
| 186 |
}; |