all repos — NoPaste @ 4d5201f1a9fd36bf5ab4e04de97fc70c12081b9a

Resurrected - The PussTheCat.org fork of NoPaste

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

  1// CodeMirror, copyright (c) by Marijn Haverbeke and others
  2// Distributed under an MIT license: https://codemirror.net/LICENSE
  3
  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
 14CodeMirror.defineMode("eiffel", function() {
 15  function wordObj(words) {
 16    var o = {};
 17    for (var i = 0, e = words.length; i < e; ++i) o[words[i]] = true;
 18    return o;
 19  }
 20  var keywords = wordObj([
 21    'note',
 22    'across',
 23    'when',
 24    'variant',
 25    'until',
 26    'unique',
 27    'undefine',
 28    'then',
 29    'strip',
 30    'select',
 31    'retry',
 32    'rescue',
 33    'require',
 34    'rename',
 35    'reference',
 36    'redefine',
 37    'prefix',
 38    'once',
 39    'old',
 40    'obsolete',
 41    'loop',
 42    'local',
 43    'like',
 44    'is',
 45    'inspect',
 46    'infix',
 47    'include',
 48    'if',
 49    'frozen',
 50    'from',
 51    'external',
 52    'export',
 53    'ensure',
 54    'end',
 55    'elseif',
 56    'else',
 57    'do',
 58    'creation',
 59    'create',
 60    'check',
 61    'alias',
 62    'agent',
 63    'separate',
 64    'invariant',
 65    'inherit',
 66    'indexing',
 67    'feature',
 68    'expanded',
 69    'deferred',
 70    'class',
 71    'Void',
 72    'True',
 73    'Result',
 74    'Precursor',
 75    'False',
 76    'Current',
 77    'create',
 78    'attached',
 79    'detachable',
 80    'as',
 81    'and',
 82    'implies',
 83    'not',
 84    'or'
 85  ]);
 86  var operators = wordObj([":=", "and then","and", "or","<<",">>"]);
 87
 88  function chain(newtok, stream, state) {
 89    state.tokenize.push(newtok);
 90    return newtok(stream, state);
 91  }
 92
 93  function tokenBase(stream, state) {
 94    if (stream.eatSpace()) return null;
 95    var ch = stream.next();
 96    if (ch == '"'||ch == "'") {
 97      return chain(readQuoted(ch, "string"), stream, state);
 98    } else if (ch == "-"&&stream.eat("-")) {
 99      stream.skipToEnd();
100      return "comment";
101    } else if (ch == ":"&&stream.eat("=")) {
102      return "operator";
103    } else if (/[0-9]/.test(ch)) {
104      stream.eatWhile(/[xXbBCc0-9\.]/);
105      stream.eat(/[\?\!]/);
106      return "ident";
107    } else if (/[a-zA-Z_0-9]/.test(ch)) {
108      stream.eatWhile(/[a-zA-Z_0-9]/);
109      stream.eat(/[\?\!]/);
110      return "ident";
111    } else if (/[=+\-\/*^%<>~]/.test(ch)) {
112      stream.eatWhile(/[=+\-\/*^%<>~]/);
113      return "operator";
114    } else {
115      return null;
116    }
117  }
118
119  function readQuoted(quote, style,  unescaped) {
120    return function(stream, state) {
121      var escaped = false, ch;
122      while ((ch = stream.next()) != null) {
123        if (ch == quote && (unescaped || !escaped)) {
124          state.tokenize.pop();
125          break;
126        }
127        escaped = !escaped && ch == "%";
128      }
129      return style;
130    };
131  }
132
133  return {
134    startState: function() {
135      return {tokenize: [tokenBase]};
136    },
137
138    token: function(stream, state) {
139      var style = state.tokenize[state.tokenize.length-1](stream, state);
140      if (style == "ident") {
141        var word = stream.current();
142        style = keywords.propertyIsEnumerable(stream.current()) ? "keyword"
143          : operators.propertyIsEnumerable(stream.current()) ? "operator"
144          : /^[A-Z][A-Z_0-9]*$/g.test(word) ? "tag"
145          : /^0[bB][0-1]+$/g.test(word) ? "number"
146          : /^0[cC][0-7]+$/g.test(word) ? "number"
147          : /^0[xX][a-fA-F0-9]+$/g.test(word) ? "number"
148          : /^([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)$/g.test(word) ? "number"
149          : /^[0-9]+$/g.test(word) ? "number"
150          : "variable";
151      }
152      return style;
153    },
154    lineComment: "--"
155  };
156});
157
158CodeMirror.defineMIME("text/x-eiffel", "eiffel");
159
160});