improve CodeMirror integration
[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 {
12 return {
13 token: function (stream)
14 {
15 const WORDS =
16 {
17 'allow': 'keyword positive',
18 'deny': 'keyword negative',
19 'define': 'keyword',
20 'context': 'keyword',
21 'clear': 'keyword',
22 'insert': 'keyword',
23 'remove': 'keyword',
24 'on': 'keyword',
25 'true': 'atom',
26 'false': 'atom',
27 'and': 'operator',
28 'or': 'operator',
29 'not': 'operator',
30 };
31 return stream.eatSpace() ? null :
32 stream.eat ('(') ? 'bracket' :
33 stream.eat (')') ? 'bracket' :
34 stream.match (/^#.*$/) ? 'comment' :
35 stream.match (/^{[^{}]+}/) ? 'variable' : // a tag
36 stream.match (/^\[[^\[\]]+\]/) ? 'def' : // a predicate
37 stream.eatWhile (/\S/) ? WORDS[stream.current()] :
38 null;
39 }
40 };
41 });
42
43 CodeMirror.defineMIME("text/x-rackcode", "rackcode");
44 });