LaravelTest
220 строк · 7.9 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://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: 08/05/2019 AstLinux Project: Support block-comments
13*
14* Author: Stas Kobzar (stas@modulis.ca),
15* Company: Modulis.ca Inc.
16*
17* =====================================================================================
18*/
19
20(function(mod) {21if (typeof exports == "object" && typeof module == "object") // CommonJS22mod(require("../../lib/codemirror"));23else if (typeof define == "function" && define.amd) // AMD24define(["../../lib/codemirror"], mod);25else // Plain browser env26mod(CodeMirror);27})(function(CodeMirror) {28"use strict";29
30CodeMirror.defineMode("asterisk", function() {31var atoms = ["exten", "same", "include","ignorepat","switch"],32dpcmd = ["#include","#exec"],33apps = [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
66function basicToken(stream,state){67var cur = '';68var ch = stream.next();69// comment70if (state.blockComment) {71if (ch == "-" && stream.match("-;", true)) {72state.blockComment = false;73} else if (stream.skipTo("--;")) {74stream.next();75stream.next();76stream.next();77state.blockComment = false;78} else {79stream.skipToEnd();80}81return "comment";82}83if(ch == ";") {84if (stream.match("--", true)) {85if (!stream.match("-", false)) { // Except ;--- is not a block comment86state.blockComment = true;87return "comment";88}89}90stream.skipToEnd();91return "comment";92}93// context94if(ch == '[') {95stream.skipTo(']');96stream.eat(']');97return "header";98}99// string100if(ch == '"') {101stream.skipTo('"');102return "string";103}104if(ch == "'") {105stream.skipTo("'");106return "string-2";107}108// dialplan commands109if(ch == '#') {110stream.eatWhile(/\w/);111cur = stream.current();112if(dpcmd.indexOf(cur) !== -1) {113stream.skipToEnd();114return "strong";115}116}117// application args118if(ch == '$'){119var ch1 = stream.peek();120if(ch1 == '{'){121stream.skipTo('}');122stream.eat('}');123return "variable-3";124}125}126// extension127stream.eatWhile(/\w/);128cur = stream.current();129if(atoms.indexOf(cur) !== -1) {130state.extenStart = true;131switch(cur) {132case 'same': state.extenSame = true; break;133case 'include':134case 'switch':135case 'ignorepat':136state.extenInclude = true;break;137default:break;138}139return "atom";140}141}142
143return {144startState: function() {145return {146blockComment: false,147extenStart: false,148extenSame: false,149extenInclude: false,150extenExten: false,151extenPriority: false,152extenApplication: false153};154},155token: function(stream, state) {156
157var cur = '';158if(stream.eatSpace()) return null;159// extension started160if(state.extenStart){161stream.eatWhile(/[^\s]/);162cur = stream.current();163if(/^=>?$/.test(cur)){164state.extenExten = true;165state.extenStart = false;166return "strong";167} else {168state.extenStart = false;169stream.skipToEnd();170return "error";171}172} else if(state.extenExten) {173// set exten and priority174state.extenExten = false;175state.extenPriority = true;176stream.eatWhile(/[^,]/);177if(state.extenInclude) {178stream.skipToEnd();179state.extenPriority = false;180state.extenInclude = false;181}182if(state.extenSame) {183state.extenPriority = false;184state.extenSame = false;185state.extenApplication = true;186}187return "tag";188} else if(state.extenPriority) {189state.extenPriority = false;190state.extenApplication = true;191stream.next(); // get comma192if(state.extenSame) return null;193stream.eatWhile(/[^,]/);194return "number";195} else if(state.extenApplication) {196stream.eatWhile(/,/);197cur = stream.current();198if(cur === ',') return null;199stream.eatWhile(/\w/);200cur = stream.current().toLowerCase();201state.extenApplication = false;202if(apps.indexOf(cur) !== -1){203return "def strong";204}205} else{206return basicToken(stream,state);207}208
209return null;210},211
212blockCommentStart: ";--",213blockCommentEnd: "--;",214lineComment: ";"215};216});217
218CodeMirror.defineMIME("text/x-asterisk", "asterisk");219
220});221