mirc.js 9.4 KB

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