mirc.js 9.8 KB

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