a71e1b82ed2113ceff8f7218f3e64b7f3ddeea1d
[racktables] / wwwroot / js / codemirror / rackcode.js
1 (function(mod) {
2 if (typeof exports == "object" && typeof module == "object") // CommonJS
3 mod(require("../../lib/codemirror"));
4 else if (typeof define == "function" && define.amd) // AMD
5 define(["../../lib/codemirror"], mod);
6 else // Plain browser env
7 mod(CodeMirror);
8 })(function(CodeMirror) {
9 "use strict";
10 CodeMirror.defineMode('rackcode', function() {
11 var allowkeywords = /^(allow)\b/i;
12 var denykeywords = /^(deny)\b/i;
13 var contextkeywords = /^(context|clear|insert|remove|on)\b/i;
14 var operatorkeywords = /^(define|and|or|not|true|false)\b/i;
15
16 return {
17 token: function(stream, state) {
18
19 if (stream.eatSpace())
20 return null;
21
22 var w;
23
24 if (stream.eatWhile(/\w/)) {
25 w = stream.current();
26
27
28 if (allowkeywords.test(w)) {
29 return 'positive';
30 } else if (denykeywords.test(w)) {
31 return 'negative';
32 } else if (operatorkeywords.test(w)) {
33 return 'operator';
34 } else if (contextkeywords.test(w)) {
35 return 'keyword';
36 }
37
38 } else if (stream.eat('#')) {
39 stream.skipToEnd();
40 return 'comment';
41 } else if (stream.eat('{')) {
42 while (w = stream.next()) {
43 if (w == '}')
44 break;
45
46 if (w == '\\')
47 stream.next();
48 }
49 return 'tag';
50 } else {
51 stream.next();
52 }
53 return null;
54 }
55 };
56 });
57
58 CodeMirror.defineMIME("text/x-rackcode", "rackcode");
59 });