openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

troff.js (2392B)


      1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
      2 // Distributed under an MIT license: http://codemirror.net/LICENSE
      3 
      4 (function(mod) {
      5   if (typeof exports == "object" && typeof module == "object")
      6     mod(require("../../lib/codemirror"));
      7   else if (typeof define == "function" && define.amd)
      8     define(["../../lib/codemirror"], mod);
      9   else
     10     mod(CodeMirror);
     11 })(function(CodeMirror) {
     12 "use strict";
     13 
     14 CodeMirror.defineMode('troff', function() {
     15 
     16   var words = {};
     17 
     18   function tokenBase(stream) {
     19     if (stream.eatSpace()) return null;
     20 
     21     var sol = stream.sol();
     22     var ch = stream.next();
     23 
     24     if (ch === '\\') {
     25       if (stream.match('fB') || stream.match('fR') || stream.match('fI') ||
     26           stream.match('u')  || stream.match('d')  ||
     27           stream.match('%')  || stream.match('&')) {
     28         return 'string';
     29       }
     30       if (stream.match('m[')) {
     31         stream.skipTo(']');
     32         stream.next();
     33         return 'string';
     34       }
     35       if (stream.match('s+') || stream.match('s-')) {
     36         stream.eatWhile(/[\d-]/);
     37         return 'string';
     38       }
     39       if (stream.match('\(') || stream.match('*\(')) {
     40         stream.eatWhile(/[\w-]/);
     41         return 'string';
     42       }
     43       return 'string';
     44     }
     45     if (sol && (ch === '.' || ch === '\'')) {
     46       if (stream.eat('\\') && stream.eat('\"')) {
     47         stream.skipToEnd();
     48         return 'comment';
     49       }
     50     }
     51     if (sol && ch === '.') {
     52       if (stream.match('B ') || stream.match('I ') || stream.match('R ')) {
     53         return 'attribute';
     54       }
     55       if (stream.match('TH ') || stream.match('SH ') || stream.match('SS ') || stream.match('HP ')) {
     56         stream.skipToEnd();
     57         return 'quote';
     58       }
     59       if ((stream.match(/[A-Z]/) && stream.match(/[A-Z]/)) || (stream.match(/[a-z]/) && stream.match(/[a-z]/))) {
     60         return 'attribute';
     61       }
     62     }
     63     stream.eatWhile(/[\w-]/);
     64     var cur = stream.current();
     65     return words.hasOwnProperty(cur) ? words[cur] : null;
     66   }
     67 
     68   function tokenize(stream, state) {
     69     return (state.tokens[0] || tokenBase) (stream, state);
     70   };
     71 
     72   return {
     73     startState: function() {return {tokens:[]};},
     74     token: function(stream, state) {
     75       return tokenize(stream, state);
     76     }
     77   };
     78 });
     79 
     80 CodeMirror.defineMIME('text/troff', 'troff');
     81 CodeMirror.defineMIME('text/x-troff', 'troff');
     82 CodeMirror.defineMIME('application/x-troff', 'troff');
     83 
     84 });