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);
11
})(function(CodeMirror) {
14
function wordRegexp(words) {
15
return new RegExp("^((" + words.join(")|(") + "))\\b");
24
"Global", "PrimaryGlobal",
26
"LegacyUnenumerableNamedProperties",
35
"TreatNonObjectAsNull",
41
var builtins = wordRegexp(builtinArray);
44
"unsigned", "short", "long",
45
"unrestricted", "float", "double",
46
"boolean", "byte", "octet",
48
"ArrayBuffer", "DataView", "Int8Array", "Int16Array", "Int32Array",
49
"Uint8Array", "Uint16Array", "Uint32Array", "Uint8ClampedArray",
50
"Float32Array", "Float64Array",
51
"ByteString", "DOMString", "USVString", "sequence", "object", "RegExp",
52
"Error", "DOMException", "FrozenArray",
56
var types = wordRegexp(typeArray);
59
"attribute", "callback", "const", "deleter", "dictionary", "enum", "getter",
60
"implements", "inherit", "interface", "iterable", "legacycaller", "maplike",
61
"partial", "required", "serializer", "setlike", "setter", "static",
62
"stringifier", "typedef",
64
"optional", "readonly", "or"
66
var keywords = wordRegexp(keywordArray);
73
var atoms = wordRegexp(atomArray);
75
CodeMirror.registerHelper("hintWords", "webidl",
76
builtinArray.concat(typeArray).concat(keywordArray).concat(atomArray));
78
var startDefArray = ["callback", "dictionary", "enum", "interface"];
79
var startDefs = wordRegexp(startDefArray);
81
var endDefArray = ["typedef"];
82
var endDefs = wordRegexp(endDefArray);
84
var singleOperators = /^[:<=>?]/;
85
var integers = /^-?([1-9][0-9]*|0[Xx][0-9A-Fa-f]+|0[0-7]*)/;
86
var floats = /^-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+)/;
87
var identifiers = /^_?[A-Za-z][0-9A-Z_a-z-]*/;
88
var identifiersEnd = /^_?[A-Za-z][0-9A-Z_a-z-]*(?=\s*;)/;
89
var strings = /^"[^"]*"/;
90
var multilineComments = /^\/\*.*?\*\//;
91
var multilineCommentsStart = /^\/\*.*/;
92
var multilineCommentsEnd = /^.*?\*\//;
94
function readToken(stream, state) {
96
if (stream.eatSpace()) return null;
99
if (state.inComment) {
100
if (stream.match(multilineCommentsEnd)) {
101
state.inComment = false;
107
if (stream.match("//")) {
111
if (stream.match(multilineComments)) return "comment";
112
if (stream.match(multilineCommentsStart)) {
113
state.inComment = true;
118
if (stream.match(/^-?[0-9\.]/, false)) {
119
if (stream.match(integers) || stream.match(floats)) return "number";
123
if (stream.match(strings)) return "string";
126
if (state.startDef && stream.match(identifiers)) return "def";
128
if (state.endDef && stream.match(identifiersEnd)) {
129
state.endDef = false;
133
if (stream.match(keywords)) return "keyword";
135
if (stream.match(types)) {
136
var lastToken = state.lastToken;
137
var nextToken = (stream.match(/^\s*(.+?)\b/, false) || [])[1];
139
if (lastToken === ":" || lastToken === "implements" ||
140
nextToken === "implements" || nextToken === "=") {
149
if (stream.match(builtins)) return "builtin";
150
if (stream.match(atoms)) return "atom";
151
if (stream.match(identifiers)) return "variable";
154
if (stream.match(singleOperators)) return "operator";
161
CodeMirror.defineMode("webidl", function() {
163
startState: function() {
175
token: function(stream, state) {
176
var style = readToken(stream, state);
179
var cur = stream.current();
180
state.lastToken = cur;
181
if (style === "keyword") {
182
state.startDef = startDefs.test(cur);
183
state.endDef = state.endDef || endDefs.test(cur);
185
state.startDef = false;
194
CodeMirror.defineMIME("text/x-webidl", "webidl");