mode-bro.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. ace.define("ace/mode/bro_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 BroHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. token: "punctuation.definition.comment.bro",
  9. regex: /#/,
  10. push: [{
  11. token: "comment.line.number-sign.bro",
  12. regex: /$/,
  13. next: "pop"
  14. }, {
  15. defaultToken: "comment.line.number-sign.bro"
  16. }]
  17. }, {
  18. token: "keyword.control.bro",
  19. regex: /\b(?:break|case|continue|else|for|if|return|switch|next|when|timeout|schedule)\b/
  20. }, {
  21. token: [
  22. "meta.function.bro",
  23. "meta.function.bro",
  24. "storage.type.bro",
  25. "meta.function.bro",
  26. "entity.name.function.bro",
  27. "meta.function.bro"
  28. ],
  29. regex: /^(\s*)(?:function|hook|event)(\s*)(.*)(\s*\()(.*)(\).*$)/
  30. }, {
  31. token: "storage.type.bro",
  32. regex: /\b(?:bool|enum|double|int|count|port|addr|subnet|any|file|interval|time|string|table|vector|set|record|pattern|hook)\b/
  33. }, {
  34. token: "storage.modifier.bro",
  35. regex: /\b(?:global|const|redef|local|&(?:optional|rotate_interval|rotate_size|add_func|del_func|expire_func|expire_create|expire_read|expire_write|persistent|synchronized|encrypt|mergeable|priority|group|type_column|log|error_handler))\b/
  36. }, {
  37. token: "keyword.operator.bro",
  38. regex: /\s*(?:\||&&|(?:>|<|!)=?|==)\s*|\b!?in\b/
  39. }, {
  40. token: "constant.language.bro",
  41. regex: /\b(?:T|F)\b/
  42. }, {
  43. token: "constant.numeric.bro",
  44. regex: /\b(?:0(?:x|X)[0-9a-fA-F]*|(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:(?:e|E)(?:\+|-)?[0-9]+)?)(?:\/(?:tcp|udp|icmp)|\s*(?:u?sec|min|hr|day)s?)?\b/
  45. }, {
  46. token: "punctuation.definition.string.begin.bro",
  47. regex: /"/,
  48. push: [{
  49. token: "punctuation.definition.string.end.bro",
  50. regex: /"/,
  51. next: "pop"
  52. }, {
  53. include: "#string_escaped_char"
  54. }, {
  55. include: "#string_placeholder"
  56. }, {
  57. defaultToken: "string.quoted.double.bro"
  58. }]
  59. }, {
  60. token: "punctuation.definition.string.begin.bro",
  61. regex: /\//,
  62. push: [{
  63. token: "punctuation.definition.string.end.bro",
  64. regex: /\//,
  65. next: "pop"
  66. }, {
  67. include: "#string_escaped_char"
  68. }, {
  69. include: "#string_placeholder"
  70. }, {
  71. defaultToken: "string.quoted.regex.bro"
  72. }]
  73. }, {
  74. token: [
  75. "meta.preprocessor.bro.load",
  76. "keyword.other.special-method.bro"
  77. ],
  78. regex: /^(\s*)(\@load(?:-sigs)?)\b/,
  79. push: [{
  80. token: [],
  81. regex: /(?=\#)|$/,
  82. next: "pop"
  83. }, {
  84. defaultToken: "meta.preprocessor.bro.load"
  85. }]
  86. }, {
  87. token: [
  88. "meta.preprocessor.bro.if",
  89. "keyword.other.special-method.bro",
  90. "meta.preprocessor.bro.if"
  91. ],
  92. regex: /^(\s*)(\@endif|\@if(?:n?def)?)(.*$)/,
  93. push: [{
  94. token: [],
  95. regex: /$/,
  96. next: "pop"
  97. }, {
  98. defaultToken: "meta.preprocessor.bro.if"
  99. }]
  100. }],
  101. "#disabled": [{
  102. token: "text",
  103. regex: /^\s*\@if(?:n?def)?\b.*$/,
  104. push: [{
  105. token: "text",
  106. regex: /^\s*\@endif\b.*$/,
  107. next: "pop"
  108. }, {
  109. include: "#disabled"
  110. }, {
  111. include: "#pragma-mark"
  112. }],
  113. comment: "eat nested preprocessor ifdefs"
  114. }],
  115. "#preprocessor-rule-other": [{
  116. token: [
  117. "text",
  118. "meta.preprocessor.bro",
  119. "meta.preprocessor.bro",
  120. "text"
  121. ],
  122. regex: /^(\s*)(@if)((?:n?def)?)\b(.*?)(?:(?=)|$)/,
  123. push: [{
  124. token: ["text", "meta.preprocessor.bro", "text"],
  125. regex: /^(\s*)(@endif)\b(.*$)/,
  126. next: "pop"
  127. }, {
  128. include: "$base"
  129. }]
  130. }],
  131. "#string_escaped_char": [{
  132. token: "constant.character.escape.bro",
  133. regex: /\\(?:\\|[abefnprtv'"?]|[0-3]\d{,2}|[4-7]\d?|x[a-fA-F0-9]{,2})/
  134. }, {
  135. token: "invalid.illegal.unknown-escape.bro",
  136. regex: /\\./
  137. }],
  138. "#string_placeholder": [{
  139. token: "constant.other.placeholder.bro",
  140. regex: /%(?:\d+\$)?[#0\- +']*[,;:_]?(?:-?\d+|\*(?:-?\d+\$)?)?(?:\.(?:-?\d+|\*(?:-?\d+\$)?)?)?(?:hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)?[diouxXDOUeEfFgGaACcSspn%]/
  141. }, {
  142. token: "invalid.illegal.placeholder.bro",
  143. regex: /%/
  144. }]
  145. }
  146. this.normalizeRules();
  147. };
  148. BroHighlightRules.metaData = {
  149. fileTypes: ["bro"],
  150. foldingStartMarker: "^(\\@if(n?def)?)",
  151. foldingStopMarker: "^\\@endif",
  152. keyEquivalent: "@B",
  153. name: "Bro",
  154. scopeName: "source.bro"
  155. }
  156. oop.inherits(BroHighlightRules, TextHighlightRules);
  157. exports.BroHighlightRules = BroHighlightRules;
  158. });
  159. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  160. "use strict";
  161. var oop = require("../../lib/oop");
  162. var Range = require("../../range").Range;
  163. var BaseFoldMode = require("./fold_mode").FoldMode;
  164. var FoldMode = exports.FoldMode = function(commentRegex) {
  165. if (commentRegex) {
  166. this.foldingStartMarker = new RegExp(
  167. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  168. );
  169. this.foldingStopMarker = new RegExp(
  170. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  171. );
  172. }
  173. };
  174. oop.inherits(FoldMode, BaseFoldMode);
  175. (function() {
  176. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  177. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  178. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  179. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  180. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  181. this._getFoldWidgetBase = this.getFoldWidget;
  182. this.getFoldWidget = function(session, foldStyle, row) {
  183. var line = session.getLine(row);
  184. if (this.singleLineBlockCommentRe.test(line)) {
  185. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  186. return "";
  187. }
  188. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  189. if (!fw && this.startRegionRe.test(line))
  190. return "start"; // lineCommentRegionStart
  191. return fw;
  192. };
  193. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  194. var line = session.getLine(row);
  195. if (this.startRegionRe.test(line))
  196. return this.getCommentRegionBlock(session, line, row);
  197. var match = line.match(this.foldingStartMarker);
  198. if (match) {
  199. var i = match.index;
  200. if (match[1])
  201. return this.openingBracketBlock(session, match[1], row, i);
  202. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  203. if (range && !range.isMultiLine()) {
  204. if (forceMultiline) {
  205. range = this.getSectionRange(session, row);
  206. } else if (foldStyle != "all")
  207. range = null;
  208. }
  209. return range;
  210. }
  211. if (foldStyle === "markbegin")
  212. return;
  213. var match = line.match(this.foldingStopMarker);
  214. if (match) {
  215. var i = match.index + match[0].length;
  216. if (match[1])
  217. return this.closingBracketBlock(session, match[1], row, i);
  218. return session.getCommentFoldRange(row, i, -1);
  219. }
  220. };
  221. this.getSectionRange = function(session, row) {
  222. var line = session.getLine(row);
  223. var startIndent = line.search(/\S/);
  224. var startRow = row;
  225. var startColumn = line.length;
  226. row = row + 1;
  227. var endRow = row;
  228. var maxRow = session.getLength();
  229. while (++row < maxRow) {
  230. line = session.getLine(row);
  231. var indent = line.search(/\S/);
  232. if (indent === -1)
  233. continue;
  234. if (startIndent > indent)
  235. break;
  236. var subRange = this.getFoldWidgetRange(session, "all", row);
  237. if (subRange) {
  238. if (subRange.start.row <= startRow) {
  239. break;
  240. } else if (subRange.isMultiLine()) {
  241. row = subRange.end.row;
  242. } else if (startIndent == indent) {
  243. break;
  244. }
  245. }
  246. endRow = row;
  247. }
  248. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  249. };
  250. this.getCommentRegionBlock = function(session, line, row) {
  251. var startColumn = line.search(/\s*$/);
  252. var maxRow = session.getLength();
  253. var startRow = row;
  254. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  255. var depth = 1;
  256. while (++row < maxRow) {
  257. line = session.getLine(row);
  258. var m = re.exec(line);
  259. if (!m) continue;
  260. if (m[1]) depth--;
  261. else depth++;
  262. if (!depth) break;
  263. }
  264. var endRow = row;
  265. if (endRow > startRow) {
  266. return new Range(startRow, startColumn, endRow, line.length);
  267. }
  268. };
  269. }).call(FoldMode.prototype);
  270. });
  271. ace.define("ace/mode/bro",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/bro_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  272. "use strict";
  273. var oop = require("../lib/oop");
  274. var TextMode = require("./text").Mode;
  275. var BroHighlightRules = require("./bro_highlight_rules").BroHighlightRules;
  276. var FoldMode = require("./folding/cstyle").FoldMode;
  277. var Mode = function() {
  278. this.HighlightRules = BroHighlightRules;
  279. this.foldingRules = new FoldMode();
  280. };
  281. oop.inherits(Mode, TextMode);
  282. (function() {
  283. this.$id = "ace/mode/bro"
  284. }).call(Mode.prototype);
  285. exports.Mode = Mode;
  286. });