mode-zeek.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. ace.define("ace/mode/zeek_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var ZeekHighlightRules = function() {
  6. this.$rules = {
  7. "start": [
  8. {
  9. token: "comment.line",
  10. regex: "#.*$"
  11. },
  12. {
  13. token: "string.double",
  14. regex: /"/,
  15. next: "string-state"
  16. },
  17. {
  18. token: "string.regexp",
  19. regex: "(/)(?=.*/)",
  20. next: "pattern-state"
  21. },
  22. {
  23. token: ["keyword.other", "meta.preprocessor"],
  24. regex: /(@(?:load-plugin|load-sigs|load|unload))(.*$)/
  25. },
  26. {
  27. token: "keyword.other",
  28. regex: /@(?:DEBUG|DIR|FILENAME|deprecated|if|ifdef|ifndef|else|endif)/
  29. },
  30. {
  31. token: [
  32. "keyword.other",
  33. "meta.preprocessor",
  34. "keyword.operator",
  35. "meta.preprocessor"
  36. ],
  37. regex: /(@prefixes)(\s*)(\+?=)(.*$)/
  38. },
  39. {
  40. token: "storage.modifier.attribute",
  41. regex: /\&\b(?:redef|priority|log|optional|default|add_func|delete_func|expire_func|read_expire|write_expire|create_expire|synchronized|persistent|rotate_interval|rotate_size|encrypt|raw_output|mergeable|error_handler|type_column|deprecated)\b/
  42. },
  43. {
  44. token: "constant.language",
  45. regex: /\b(?:T|F)\b/
  46. },
  47. {
  48. token: "constant.numeric.port",
  49. regex: /\b\d{1,5}\/(?:udp|tcp|icmp|unknown)\b/
  50. },
  51. {
  52. token: "constant.numeric.addr",
  53. regex: /\b(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\b/,
  54. comment: "IPv4 address"
  55. },
  56. {
  57. token: "constant.numeric.addr",
  58. regex: /\[(?:[0-9a-fA-F]{0,4}:){2,7}(?:[0-9a-fA-F]{0,4})?(?:(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2}))?\]/,
  59. comment: "IPv6 address"
  60. },
  61. {
  62. token: "constant.numeric.float.decimal.interval",
  63. regex: /(?:(?:\d*\.\d*(?:[eE][+-]?\d+)?|\d*[eE][+-]?\d+|\d*\.\d*)|\d+)\s*(?:day|hr|min|msec|usec|sec)s?/
  64. },
  65. {
  66. token: "constant.numeric.float.decimal",
  67. regex: /\d*\.\d*(?:[eE][+-]?\d+)?|\d*[eE][+-]?\d+|\d*\.\d*/
  68. },
  69. {
  70. token: "constant.numeric.hostname",
  71. regex: /\b[A-Za-z0-9][A-Za-z0-9\-]*(?:\.[A-Za-z0-9][A-Za-z0-9\-]*)+\b/
  72. },
  73. {
  74. token: "constant.numeric.integer.hexadecimal",
  75. regex: /\b0x[0-9a-fA-F]+\b/
  76. },
  77. {
  78. token: "constant.numeric.integer.decimal",
  79. regex: /\b\d+\b/
  80. },
  81. {
  82. token: "keyword.operator",
  83. regex: /==|!=|<=|<|>=|>/
  84. },
  85. {
  86. token: "keyword.operator",
  87. regex: /(&&)|(\|\|)|(!)/
  88. },
  89. {
  90. token: "keyword.operator",
  91. regex: /=|\+=|-=/
  92. },
  93. {
  94. token: "keyword.operator",
  95. regex: /\+\+|\+|--|-|\*|\/|%/
  96. },
  97. {
  98. token: "keyword.operator",
  99. regex: /&|\||\^|~/
  100. },
  101. {
  102. token: "keyword.operator",
  103. regex: /\b(?:in|as|is)\b/
  104. },
  105. {
  106. token: "punctuation.terminator",
  107. regex: /;/
  108. },
  109. {
  110. token: "punctuation.accessor",
  111. regex: /\??\$/
  112. },
  113. {
  114. token: "punctuation.accessor",
  115. regex: /::/
  116. },
  117. {
  118. token: "keyword.operator",
  119. regex: /\?/
  120. },
  121. {
  122. token: "punctuation.separator",
  123. regex: /:/
  124. },
  125. {
  126. token: "punctuation.separator",
  127. regex: /,/
  128. },
  129. {
  130. token: [
  131. "keyword.other",
  132. "meta.namespace",
  133. "entity.name.namespace"
  134. ],
  135. regex: /(module)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)/
  136. },
  137. {
  138. token: "keyword.other",
  139. regex: /\bexport\b/
  140. },
  141. {
  142. token: "keyword.control.conditional",
  143. regex: /\b(?:if|else)\b/
  144. },
  145. {
  146. token: "keyword.control",
  147. regex: /\b(?:for|while)\b/
  148. },
  149. {
  150. token: "keyword.control",
  151. regex: /\b(?:return|break|next|continue|fallthrough)\b/
  152. },
  153. {
  154. token: "keyword.control",
  155. regex: /\b(?:switch|default|case)\b/
  156. },
  157. {
  158. token: "keyword.other",
  159. regex: /\b(?:add|delete)\b/
  160. },
  161. {
  162. token: "keyword.other",
  163. regex: /\bprint\b/
  164. },
  165. {
  166. token: "keyword.control",
  167. regex: /\b(?:when|timeout|schedule)\b/
  168. },
  169. {
  170. token: [
  171. "keyword.other",
  172. "meta.struct.record",
  173. "entity.name.struct.record",
  174. "meta.struct.record",
  175. "punctuation.separator",
  176. "meta.struct.record",
  177. "storage.type.struct.record"
  178. ],
  179. regex: /\b(type)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)(\s*)(:)(\s*\b)(record)\b/
  180. },
  181. {
  182. token: [
  183. "keyword.other",
  184. "meta.enum",
  185. "entity.name.enum",
  186. "meta.enum",
  187. "punctuation.separator",
  188. "meta.enum",
  189. "storage.type.enum"
  190. ],
  191. regex: /\b(type)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)(\s*)(:)(\s*\b)(enum)\b/
  192. },
  193. {
  194. token: [
  195. "keyword.other",
  196. "meta.type",
  197. "entity.name.type",
  198. "meta.type",
  199. "punctuation.separator"
  200. ],
  201. regex: /\b(type)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)(\s*)(:)/
  202. },
  203. {
  204. token: [
  205. "keyword.other",
  206. "meta.struct.record",
  207. "storage.type.struct.record",
  208. "meta.struct.record",
  209. "entity.name.struct.record"
  210. ],
  211. regex: /\b(redef)(\s+)(record)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)\b/
  212. },
  213. {
  214. token: [
  215. "keyword.other",
  216. "meta.enum",
  217. "storage.type.enum",
  218. "meta.enum",
  219. "entity.name.enum"
  220. ],
  221. regex: /\b(redef)(\s+)(enum)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)\b/
  222. },
  223. {
  224. token: [
  225. "storage.type",
  226. "text",
  227. "entity.name.function.event"
  228. ],
  229. regex: /\b(event)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)(?=s*\()/
  230. },
  231. {
  232. token: [
  233. "storage.type",
  234. "text",
  235. "entity.name.function.hook"
  236. ],
  237. regex: /\b(hook)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)(?=s*\()/
  238. },
  239. {
  240. token: [
  241. "storage.type",
  242. "text",
  243. "entity.name.function"
  244. ],
  245. regex: /\b(function)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)(?=s*\()/
  246. },
  247. {
  248. token: "keyword.other",
  249. regex: /\bredef\b/
  250. },
  251. {
  252. token: "storage.type",
  253. regex: /\bany\b/
  254. },
  255. {
  256. token: "storage.type",
  257. regex: /\b(?:enum|record|set|table|vector)\b/
  258. },
  259. {
  260. token: [
  261. "storage.type",
  262. "text",
  263. "keyword.operator",
  264. "text",
  265. "storage.type"
  266. ],
  267. regex: /\b(opaque)(\s+)(of)(\s+)([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)\b/
  268. },
  269. {
  270. token: "keyword.operator",
  271. regex: /\bof\b/
  272. },
  273. {
  274. token: "storage.type",
  275. regex: /\b(?:addr|bool|count|double|file|int|interval|pattern|port|string|subnet|time)\b/
  276. },
  277. {
  278. token: "storage.type",
  279. regex: /\b(?:function|hook|event)\b/
  280. },
  281. {
  282. token: "storage.modifier",
  283. regex: /\b(?:global|local|const|option)\b/
  284. },
  285. {
  286. token: "entity.name.function.call",
  287. regex: /\b[A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*(?=s*\()/
  288. },
  289. {
  290. token: "punctuation.section.block.begin",
  291. regex: /\{/
  292. },
  293. {
  294. token: "punctuation.section.block.end",
  295. regex: /\}/
  296. },
  297. {
  298. token: "punctuation.section.brackets.begin",
  299. regex: /\[/
  300. },
  301. {
  302. token: "punctuation.section.brackets.end",
  303. regex: /\]/
  304. },
  305. {
  306. token: "punctuation.section.parens.begin",
  307. regex: /\(/
  308. },
  309. {
  310. token: "punctuation.section.parens.end",
  311. regex: /\)/
  312. }
  313. ], // state: start
  314. "string-state": [
  315. {
  316. token: "constant.character.escape",
  317. regex: /\\./
  318. },
  319. {
  320. token: "string.double",
  321. regex: /"/,
  322. next: "start"
  323. },
  324. {
  325. token: "constant.other.placeholder",
  326. regex: /%-?[0-9]*(\.[0-9]+)?[DTdxsefg]/
  327. },
  328. {
  329. token: "string.double",
  330. regex: "."
  331. }
  332. ], // state: string-state
  333. "pattern-state": [
  334. {
  335. token: "constant.character.escape",
  336. regex: /\\./
  337. },
  338. {
  339. token: "string.regexp",
  340. regex: "/",
  341. next: "start"
  342. },
  343. {
  344. token: "string.regexp",
  345. regex: "."
  346. }
  347. ] // state: pattern-state
  348. };
  349. this.normalizeRules();
  350. };
  351. ZeekHighlightRules.metaData = {
  352. fileTypes: ["bro", "zeek"],
  353. name: "Zeek",
  354. scopeName: "source.zeek"
  355. };
  356. oop.inherits(ZeekHighlightRules, TextHighlightRules);
  357. exports.ZeekHighlightRules = ZeekHighlightRules;
  358. });
  359. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  360. "use strict";
  361. var oop = require("../../lib/oop");
  362. var Range = require("../../range").Range;
  363. var BaseFoldMode = require("./fold_mode").FoldMode;
  364. var FoldMode = exports.FoldMode = function(commentRegex) {
  365. if (commentRegex) {
  366. this.foldingStartMarker = new RegExp(
  367. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  368. );
  369. this.foldingStopMarker = new RegExp(
  370. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  371. );
  372. }
  373. };
  374. oop.inherits(FoldMode, BaseFoldMode);
  375. (function() {
  376. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  377. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  378. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  379. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  380. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  381. this._getFoldWidgetBase = this.getFoldWidget;
  382. this.getFoldWidget = function(session, foldStyle, row) {
  383. var line = session.getLine(row);
  384. if (this.singleLineBlockCommentRe.test(line)) {
  385. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  386. return "";
  387. }
  388. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  389. if (!fw && this.startRegionRe.test(line))
  390. return "start"; // lineCommentRegionStart
  391. return fw;
  392. };
  393. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  394. var line = session.getLine(row);
  395. if (this.startRegionRe.test(line))
  396. return this.getCommentRegionBlock(session, line, row);
  397. var match = line.match(this.foldingStartMarker);
  398. if (match) {
  399. var i = match.index;
  400. if (match[1])
  401. return this.openingBracketBlock(session, match[1], row, i);
  402. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  403. if (range && !range.isMultiLine()) {
  404. if (forceMultiline) {
  405. range = this.getSectionRange(session, row);
  406. } else if (foldStyle != "all")
  407. range = null;
  408. }
  409. return range;
  410. }
  411. if (foldStyle === "markbegin")
  412. return;
  413. var match = line.match(this.foldingStopMarker);
  414. if (match) {
  415. var i = match.index + match[0].length;
  416. if (match[1])
  417. return this.closingBracketBlock(session, match[1], row, i);
  418. return session.getCommentFoldRange(row, i, -1);
  419. }
  420. };
  421. this.getSectionRange = function(session, row) {
  422. var line = session.getLine(row);
  423. var startIndent = line.search(/\S/);
  424. var startRow = row;
  425. var startColumn = line.length;
  426. row = row + 1;
  427. var endRow = row;
  428. var maxRow = session.getLength();
  429. while (++row < maxRow) {
  430. line = session.getLine(row);
  431. var indent = line.search(/\S/);
  432. if (indent === -1)
  433. continue;
  434. if (startIndent > indent)
  435. break;
  436. var subRange = this.getFoldWidgetRange(session, "all", row);
  437. if (subRange) {
  438. if (subRange.start.row <= startRow) {
  439. break;
  440. } else if (subRange.isMultiLine()) {
  441. row = subRange.end.row;
  442. } else if (startIndent == indent) {
  443. break;
  444. }
  445. }
  446. endRow = row;
  447. }
  448. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  449. };
  450. this.getCommentRegionBlock = function(session, line, row) {
  451. var startColumn = line.search(/\s*$/);
  452. var maxRow = session.getLength();
  453. var startRow = row;
  454. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  455. var depth = 1;
  456. while (++row < maxRow) {
  457. line = session.getLine(row);
  458. var m = re.exec(line);
  459. if (!m) continue;
  460. if (m[1]) depth--;
  461. else depth++;
  462. if (!depth) break;
  463. }
  464. var endRow = row;
  465. if (endRow > startRow) {
  466. return new Range(startRow, startColumn, endRow, line.length);
  467. }
  468. };
  469. }).call(FoldMode.prototype);
  470. });
  471. ace.define("ace/mode/zeek",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/zeek_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  472. "use strict";
  473. var oop = require("../lib/oop");
  474. var TextMode = require("./text").Mode;
  475. var ZeekHighlightRules = require("./zeek_highlight_rules").ZeekHighlightRules;
  476. var FoldMode = require("./folding/cstyle").FoldMode;
  477. var Mode = function() {
  478. this.HighlightRules = ZeekHighlightRules;
  479. this.foldingRules = new FoldMode();
  480. };
  481. oop.inherits(Mode, TextMode);
  482. (function() {
  483. this.lineCommentStart = "#";
  484. this.$id = "ace/mode/zeek";
  485. }).call(Mode.prototype);
  486. exports.Mode = Mode;
  487. }); (function() {
  488. ace.require(["ace/mode/zeek"], function(m) {
  489. if (typeof module == "object" && typeof exports == "object" && module) {
  490. module.exports = m;
  491. }
  492. });
  493. })();