all repos — NoPaste @ 3e3c433f026c49e04d0efa0f0f39fc688ed32bb1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/mirc/mirc.js (view raw)

  1// CodeMirror, copyright (c) by Marijn Haverbeke and others
  2// Distributed under an MIT license: https://codemirror.net/LICENSE
  3
  4//mIRC mode by Ford_Lawnmower :: Based on Velocity mode by Steve O'Hara
  5
  6(function(mod) {
  7  if (typeof exports == "object" && typeof module == "object") // CommonJS
  8    mod(require("../../lib/codemirror"));
  9  else if (typeof define == "function" && define.amd) // AMD
 10    define(["../../lib/codemirror"], mod);
 11  else // Plain browser env
 12    mod(CodeMirror);
 13})(function(CodeMirror) {
 14"use strict";
 15
 16CodeMirror.defineMIME("text/mirc", "mirc");
 17CodeMirror.defineMode("mirc", function() {
 18  function parseWords(str) {
 19    var obj = {}, words = str.split(" ");
 20    for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
 21    return obj;
 22  }
 23  var specials = parseWords("$! $$ $& $? $+ $abook $abs $active $activecid " +
 24                            "$activewid $address $addtok $agent $agentname $agentstat $agentver " +
 25                            "$alias $and $anick $ansi2mirc $aop $appactive $appstate $asc $asctime " +
 26                            "$asin $atan $avoice $away $awaymsg $awaytime $banmask $base $bfind " +
 27                            "$binoff $biton $bnick $bvar $bytes $calc $cb $cd $ceil $chan $chanmodes " +
 28                            "$chantypes $chat $chr $cid $clevel $click $cmdbox $cmdline $cnick $color " +
 29                            "$com $comcall $comchan $comerr $compact $compress $comval $cos $count " +
 30                            "$cr $crc $creq $crlf $ctime $ctimer $ctrlenter $date $day $daylight " +
 31                            "$dbuh $dbuw $dccignore $dccport $dde $ddename $debug $decode $decompress " +
 32                            "$deltok $devent $dialog $did $didreg $didtok $didwm $disk $dlevel $dll " +
 33                            "$dllcall $dname $dns $duration $ebeeps $editbox $emailaddr $encode $error " +
 34                            "$eval $event $exist $feof $ferr $fgetc $file $filename $filtered $finddir " +
 35                            "$finddirn $findfile $findfilen $findtok $fline $floor $fopen $fread $fserve " +
 36                            "$fulladdress $fulldate $fullname $fullscreen $get $getdir $getdot $gettok $gmt " +
 37                            "$group $halted $hash $height $hfind $hget $highlight $hnick $hotline " +
 38                            "$hotlinepos $ial $ialchan $ibl $idle $iel $ifmatch $ignore $iif $iil " +
 39                            "$inelipse $ini $inmidi $inpaste $inpoly $input $inrect $inroundrect " +
 40                            "$insong $instok $int $inwave $ip $isalias $isbit $isdde $isdir $isfile " +
 41                            "$isid $islower $istok $isupper $keychar $keyrpt $keyval $knick $lactive " +
 42                            "$lactivecid $lactivewid $left $len $level $lf $line $lines $link $lock " +
 43                            "$lock $locked $log $logstamp $logstampfmt $longfn $longip $lower $ltimer " +
 44                            "$maddress $mask $matchkey $matchtok $md5 $me $menu $menubar $menucontext " +
 45                            "$menutype $mid $middir $mircdir $mircexe $mircini $mklogfn $mnick $mode " +
 46                            "$modefirst $modelast $modespl $mouse $msfile $network $newnick $nick $nofile " +
 47                            "$nopath $noqt $not $notags $notify $null $numeric $numok $oline $onpoly " +
 48                            "$opnick $or $ord $os $passivedcc $pic $play $pnick $port $portable $portfree " +
 49                            "$pos $prefix $prop $protect $puttok $qt $query $rand $r $rawmsg $read $readomo " +
 50                            "$readn $regex $regml $regsub $regsubex $remove $remtok $replace $replacex " +
 51                            "$reptok $result $rgb $right $round $scid $scon $script $scriptdir $scriptline " +
 52                            "$sdir $send $server $serverip $sfile $sha1 $shortfn $show $signal $sin " +
 53                            "$site $sline $snick $snicks $snotify $sock $sockbr $sockerr $sockname " +
 54                            "$sorttok $sound $sqrt $ssl $sreq $sslready $status $strip $str $stripped " +
 55                            "$syle $submenu $switchbar $tan $target $ticks $time $timer $timestamp " +
 56                            "$timestampfmt $timezone $tip $titlebar $toolbar $treebar $trust $ulevel " +
 57                            "$ulist $upper $uptime $url $usermode $v1 $v2 $var $vcmd $vcmdstat $vcmdver " +
 58                            "$version $vnick $vol $wid $width $wildsite $wildtok $window $wrap $xor");
 59  var keywords = parseWords("abook ajinvite alias aline ame amsg anick aop auser autojoin avoice " +
 60                            "away background ban bcopy beep bread break breplace bset btrunc bunset bwrite " +
 61                            "channel clear clearall cline clipboard close cnick color comclose comopen " +
 62                            "comreg continue copy creq ctcpreply ctcps dcc dccserver dde ddeserver " +
 63                            "debug dec describe dialog did didtok disable disconnect dlevel dline dll " +
 64                            "dns dqwindow drawcopy drawdot drawfill drawline drawpic drawrect drawreplace " +
 65                            "drawrot drawsave drawscroll drawtext ebeeps echo editbox emailaddr enable " +
 66                            "events exit fclose filter findtext finger firewall flash flist flood flush " +
 67                            "flushini font fopen fseek fsend fserve fullname fwrite ghide gload gmove " +
 68                            "gopts goto gplay gpoint gqreq groups gshow gsize gstop gtalk gunload hadd " +
 69                            "halt haltdef hdec hdel help hfree hinc hload hmake hop hsave ial ialclear " +
 70                            "ialmark identd if ignore iline inc invite iuser join kick linesep links list " +
 71                            "load loadbuf localinfo log mdi me menubar mkdir mnick mode msg nick noop notice " +
 72                            "notify omsg onotice part partall pdcc perform play playctrl pop protect pvoice " +
 73                            "qme qmsg query queryn quit raw reload remini remote remove rename renwin " +
 74                            "reseterror resetidle return rlevel rline rmdir run ruser save savebuf saveini " +
 75                            "say scid scon server set showmirc signam sline sockaccept sockclose socklist " +
 76                            "socklisten sockmark sockopen sockpause sockread sockrename sockudp sockwrite " +
 77                            "sound speak splay sreq strip switchbar timer timestamp titlebar tnick tokenize " +
 78                            "toolbar topic tray treebar ulist unload unset unsetall updatenl url uwho " +
 79                            "var vcadd vcmd vcrem vol while whois window winhelp write writeint if isalnum " +
 80                            "isalpha isaop isavoice isban ischan ishop isignore isin isincs isletter islower " +
 81                            "isnotify isnum ison isop isprotect isreg isupper isvoice iswm iswmcs " +
 82                            "elseif else goto menu nicklist status title icon size option text edit " +
 83                            "button check radio box scroll list combo link tab item");
 84  var functions = parseWords("if elseif else and not or eq ne in ni for foreach while switch");
 85  var isOperatorChar = /[+\-*&%=<>!?^\/\|]/;
 86  function chain(stream, state, f) {
 87    state.tokenize = f;
 88    return f(stream, state);
 89  }
 90  function tokenBase(stream, state) {
 91    var beforeParams = state.beforeParams;
 92    state.beforeParams = false;
 93    var ch = stream.next();
 94    if (/[\[\]{}\(\),\.]/.test(ch)) {
 95      if (ch == "(" && beforeParams) state.inParams = true;
 96      else if (ch == ")") state.inParams = false;
 97      return null;
 98    }
 99    else if (/\d/.test(ch)) {
100      stream.eatWhile(/[\w\.]/);
101      return "number";
102    }
103    else if (ch == "\\") {
104      stream.eat("\\");
105      stream.eat(/./);
106      return "number";
107    }
108    else if (ch == "/" && stream.eat("*")) {
109      return chain(stream, state, tokenComment);
110    }
111    else if (ch == ";" && stream.match(/ *\( *\(/)) {
112      return chain(stream, state, tokenUnparsed);
113    }
114    else if (ch == ";" && !state.inParams) {
115      stream.skipToEnd();
116      return "comment";
117    }
118    else if (ch == '"') {
119      stream.eat(/"/);
120      return "keyword";
121    }
122    else if (ch == "$") {
123      stream.eatWhile(/[$_a-z0-9A-Z\.:]/);
124      if (specials && specials.propertyIsEnumerable(stream.current().toLowerCase())) {
125        return "keyword";
126      }
127      else {
128        state.beforeParams = true;
129        return "builtin";
130      }
131    }
132    else if (ch == "%") {
133      stream.eatWhile(/[^,\s()]/);
134      state.beforeParams = true;
135      return "string";
136    }
137    else if (isOperatorChar.test(ch)) {
138      stream.eatWhile(isOperatorChar);
139      return "operator";
140    }
141    else {
142      stream.eatWhile(/[\w\$_{}]/);
143      var word = stream.current().toLowerCase();
144      if (keywords && keywords.propertyIsEnumerable(word))
145        return "keyword";
146      if (functions && functions.propertyIsEnumerable(word)) {
147        state.beforeParams = true;
148        return "keyword";
149      }
150      return null;
151    }
152  }
153  function tokenComment(stream, state) {
154    var maybeEnd = false, ch;
155    while (ch = stream.next()) {
156      if (ch == "/" && maybeEnd) {
157        state.tokenize = tokenBase;
158        break;
159      }
160      maybeEnd = (ch == "*");
161    }
162    return "comment";
163  }
164  function tokenUnparsed(stream, state) {
165    var maybeEnd = 0, ch;
166    while (ch = stream.next()) {
167      if (ch == ";" && maybeEnd == 2) {
168        state.tokenize = tokenBase;
169        break;
170      }
171      if (ch == ")")
172        maybeEnd++;
173      else if (ch != " ")
174        maybeEnd = 0;
175    }
176    return "meta";
177  }
178  return {
179    startState: function() {
180      return {
181        tokenize: tokenBase,
182        beforeParams: false,
183        inParams: false
184      };
185    },
186    token: function(stream, state) {
187      if (stream.eatSpace()) return null;
188      return state.tokenize(stream, state);
189    }
190  };
191});
192
193});