mode-drools.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. ace.define("ace/mode/doc_comment_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 DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. };
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. ace.define("ace/mode/java_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
  42. "use strict";
  43. var oop = require("../lib/oop");
  44. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  46. var JavaHighlightRules = function() {
  47. var keywords = (
  48. "abstract|continue|for|new|switch|" +
  49. "assert|default|goto|package|synchronized|" +
  50. "boolean|do|if|private|this|" +
  51. "break|double|implements|protected|throw|" +
  52. "byte|else|import|public|throws|" +
  53. "case|enum|instanceof|return|transient|" +
  54. "catch|extends|int|short|try|" +
  55. "char|final|interface|static|void|" +
  56. "class|finally|long|strictfp|volatile|" +
  57. "const|float|native|super|while|" +
  58. "var"
  59. );
  60. var buildinConstants = ("null|Infinity|NaN|undefined");
  61. var langClasses = (
  62. "AbstractMethodError|AssertionError|ClassCircularityError|"+
  63. "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+
  64. "ExceptionInInitializerError|IllegalAccessError|"+
  65. "IllegalThreadStateException|InstantiationError|InternalError|"+
  66. "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+
  67. "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+
  68. "SuppressWarnings|TypeNotPresentException|UnknownError|"+
  69. "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+
  70. "InstantiationException|IndexOutOfBoundsException|"+
  71. "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+
  72. "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+
  73. "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+
  74. "InterruptedException|NoSuchMethodException|IllegalAccessException|"+
  75. "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+
  76. "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+
  77. "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+
  78. "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+
  79. "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+
  80. "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+
  81. "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+
  82. "ArrayStoreException|ClassCastException|LinkageError|"+
  83. "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+
  84. "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+
  85. "Cloneable|Class|CharSequence|Comparable|String|Object"
  86. );
  87. var keywordMapper = this.createKeywordMapper({
  88. "variable.language": "this",
  89. "keyword": keywords,
  90. "constant.language": buildinConstants,
  91. "support.function": langClasses
  92. }, "identifier");
  93. this.$rules = {
  94. "start" : [
  95. {
  96. token : "comment",
  97. regex : "\\/\\/.*$"
  98. },
  99. DocCommentHighlightRules.getStartRule("doc-start"),
  100. {
  101. token : "comment", // multi line comment
  102. regex : "\\/\\*",
  103. next : "comment"
  104. }, {
  105. token : "string", // single line
  106. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  107. }, {
  108. token : "string", // single line
  109. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  110. }, {
  111. token : "constant.numeric", // hex
  112. regex : /0(?:[xX][0-9a-fA-F][0-9a-fA-F_]*|[bB][01][01_]*)[LlSsDdFfYy]?\b/
  113. }, {
  114. token : "constant.numeric", // float
  115. regex : /[+-]?\d[\d_]*(?:(?:\.[\d_]*)?(?:[eE][+-]?[\d_]+)?)?[LlSsDdFfYy]?\b/
  116. }, {
  117. token : "constant.language.boolean",
  118. regex : "(?:true|false)\\b"
  119. }, {
  120. regex: "(open(?:\\s+))?module(?=\\s*\\w)",
  121. token: "keyword",
  122. next: [{
  123. regex: "{",
  124. token: "paren.lparen",
  125. next: [{
  126. regex: "}",
  127. token: "paren.rparen",
  128. next: "start"
  129. }, {
  130. regex: "\\b(requires|transitive|exports|opens|to|uses|provides|with)\\b",
  131. token: "keyword"
  132. }]
  133. }, {
  134. token : "text",
  135. regex : "\\s+"
  136. }, {
  137. token : "identifier",
  138. regex : "\\w+"
  139. }, {
  140. token : "punctuation.operator",
  141. regex : "."
  142. }, {
  143. token : "text",
  144. regex : "\\s+"
  145. }, {
  146. regex: "", // exit if there is anything else
  147. next: "start"
  148. }]
  149. }, {
  150. token : keywordMapper,
  151. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  152. }, {
  153. token : "keyword.operator",
  154. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  155. }, {
  156. token : "lparen",
  157. regex : "[[({]"
  158. }, {
  159. token : "rparen",
  160. regex : "[\\])}]"
  161. }, {
  162. token : "text",
  163. regex : "\\s+"
  164. }
  165. ],
  166. "comment" : [
  167. {
  168. token : "comment", // closing comment
  169. regex : "\\*\\/",
  170. next : "start"
  171. }, {
  172. defaultToken : "comment"
  173. }
  174. ]
  175. };
  176. this.embedRules(DocCommentHighlightRules, "doc-",
  177. [ DocCommentHighlightRules.getEndRule("start") ]);
  178. this.normalizeRules();
  179. };
  180. oop.inherits(JavaHighlightRules, TextHighlightRules);
  181. exports.JavaHighlightRules = JavaHighlightRules;
  182. });
  183. ace.define("ace/mode/drools_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules","ace/mode/java_highlight_rules","ace/mode/doc_comment_highlight_rules"], function(require, exports, module) {
  184. "use strict";
  185. var oop = require("../lib/oop");
  186. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  187. var JavaHighlightRules = require("./java_highlight_rules").JavaHighlightRules;
  188. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  189. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*";
  190. var packageIdentifierRe = "[a-zA-Z\\$_\u00a1-\uffff][\\.a-zA-Z\\d\\$_\u00a1-\uffff]*";
  191. var DroolsHighlightRules = function() {
  192. var keywords = ("date|effective|expires|lock|on|active|no|loop|auto|focus" +
  193. "|activation|group|agenda|ruleflow|duration|timer|calendars|refract|direct" +
  194. "|dialect|salience|enabled|attributes|extends|template" +
  195. "|function|contains|matches|eval|excludes|soundslike" +
  196. "|memberof|not|in|or|and|exists|forall|over|from|entry|point|accumulate|acc|collect" +
  197. "|action|reverse|result|end|init|instanceof|extends|super|boolean|char|byte|short" +
  198. "|int|long|float|double|this|void|class|new|case|final|if|else|for|while|do" +
  199. "|default|try|catch|finally|switch|synchronized|return|throw|break|continue|assert" +
  200. "|modify|static|public|protected|private|abstract|native|transient|volatile" +
  201. "|strictfp|throws|interface|enum|implements|type|window|trait|no-loop|str"
  202. );
  203. var langClasses = (
  204. "AbstractMethodError|AssertionError|ClassCircularityError|"+
  205. "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+
  206. "ExceptionInInitializerError|IllegalAccessError|"+
  207. "IllegalThreadStateException|InstantiationError|InternalError|"+
  208. "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+
  209. "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+
  210. "SuppressWarnings|TypeNotPresentException|UnknownError|"+
  211. "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+
  212. "InstantiationException|IndexOutOfBoundsException|"+
  213. "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+
  214. "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+
  215. "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+
  216. "InterruptedException|NoSuchMethodException|IllegalAccessException|"+
  217. "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+
  218. "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+
  219. "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+
  220. "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+
  221. "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+
  222. "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+
  223. "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+
  224. "ArrayStoreException|ClassCastException|LinkageError|"+
  225. "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+
  226. "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+
  227. "Cloneable|Class|CharSequence|Comparable|String|Object"
  228. );
  229. var keywordMapper = this.createKeywordMapper({
  230. "variable.language": "this",
  231. "keyword": keywords,
  232. "constant.language": "null",
  233. "support.class" : langClasses,
  234. "support.function" : "retract|update|modify|insert"
  235. }, "identifier");
  236. var stringRules = function() {
  237. return [{
  238. token : "string", // single line
  239. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  240. }, {
  241. token : "string", // single line
  242. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  243. }];
  244. };
  245. var basicPreRules = function(blockCommentRules) {
  246. return [{
  247. token : "comment",
  248. regex : "\\/\\/.*$"
  249. },
  250. DocCommentHighlightRules.getStartRule("doc-start"),
  251. {
  252. token : "comment", // multi line comment
  253. regex : "\\/\\*",
  254. next : blockCommentRules
  255. }, {
  256. token : "constant.numeric", // hex
  257. regex : "0[xX][0-9a-fA-F]+\\b"
  258. }, {
  259. token : "constant.numeric", // float
  260. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  261. }, {
  262. token : "constant.language.boolean",
  263. regex : "(?:true|false)\\b"
  264. }];
  265. };
  266. var blockCommentRules = function(returnRule) {
  267. return [
  268. {
  269. token : "comment.block", // closing comment
  270. regex : "\\*\\/",
  271. next : returnRule
  272. }, {
  273. defaultToken : "comment.block"
  274. }
  275. ];
  276. };
  277. var basicPostRules = function() {
  278. return [{
  279. token : keywordMapper,
  280. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  281. }, {
  282. token : "keyword.operator",
  283. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  284. }, {
  285. token : "lparen",
  286. regex : "[[({]"
  287. }, {
  288. token : "rparen",
  289. regex : "[\\])}]"
  290. }, {
  291. token : "text",
  292. regex : "\\s+"
  293. }];
  294. };
  295. this.$rules = {
  296. "start" : [].concat(basicPreRules("block.comment"), [
  297. {
  298. token : "entity.name.type",
  299. regex : "@[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  300. }, {
  301. token : ["keyword","text","entity.name.type"],
  302. regex : "(package)(\\s+)(" + packageIdentifierRe +")"
  303. }, {
  304. token : ["keyword","text","keyword","text","entity.name.type"],
  305. regex : "(import)(\\s+)(function)(\\s+)(" + packageIdentifierRe +")"
  306. }, {
  307. token : ["keyword","text","entity.name.type"],
  308. regex : "(import)(\\s+)(" + packageIdentifierRe +")"
  309. }, {
  310. token : ["keyword","text","entity.name.type","text","variable"],
  311. regex : "(global)(\\s+)(" + packageIdentifierRe +")(\\s+)(" + identifierRe +")"
  312. }, {
  313. token : ["keyword","text","keyword","text","entity.name.type"],
  314. regex : "(declare)(\\s+)(trait)(\\s+)(" + identifierRe +")"
  315. }, {
  316. token : ["keyword","text","entity.name.type"],
  317. regex : "(declare)(\\s+)(" + identifierRe +")"
  318. }, {
  319. token : ["keyword","text","entity.name.type"],
  320. regex : "(extends)(\\s+)(" + packageIdentifierRe +")"
  321. }, {
  322. token : ["keyword","text"],
  323. regex : "(rule)(\\s+)",
  324. next : "asset.name"
  325. }],
  326. stringRules(),
  327. [{
  328. token : ["variable.other","text","text"],
  329. regex : "(" + identifierRe + ")(\\s*)(:)"
  330. }, {
  331. token : ["keyword","text"],
  332. regex : "(query)(\\s+)",
  333. next : "asset.name"
  334. }, {
  335. token : ["keyword","text"],
  336. regex : "(when)(\\s*)"
  337. }, {
  338. token : ["keyword","text"],
  339. regex : "(then)(\\s*)",
  340. next : "java-start"
  341. }, {
  342. token : "paren.lparen",
  343. regex : /[\[({]/
  344. }, {
  345. token : "paren.rparen",
  346. regex : /[\])}]/
  347. }], basicPostRules()),
  348. "block.comment" : blockCommentRules("start"),
  349. "asset.name" : [
  350. {
  351. token : "entity.name",
  352. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  353. }, {
  354. token : "entity.name",
  355. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  356. }, {
  357. token : "entity.name",
  358. regex : identifierRe
  359. }, {
  360. regex: "",
  361. token: "empty",
  362. next: "start"
  363. }]
  364. };
  365. this.embedRules(DocCommentHighlightRules, "doc-",
  366. [ DocCommentHighlightRules.getEndRule("start") ]);
  367. this.embedRules(JavaHighlightRules, "java-", [
  368. {
  369. token : "support.function",
  370. regex: "\\b(insert|modify|retract|update)\\b"
  371. }, {
  372. token : "keyword",
  373. regex: "\\bend\\b",
  374. next : "start"
  375. }]);
  376. };
  377. oop.inherits(DroolsHighlightRules, TextHighlightRules);
  378. exports.DroolsHighlightRules = DroolsHighlightRules;
  379. });
  380. ace.define("ace/mode/folding/drools",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode","ace/token_iterator"], function(require, exports, module) {
  381. "use strict";
  382. var oop = require("../../lib/oop");
  383. var Range = require("../../range").Range;
  384. var BaseFoldMode = require("./fold_mode").FoldMode;
  385. var TokenIterator = require("../../token_iterator").TokenIterator;
  386. var FoldMode = exports.FoldMode = function() {};
  387. oop.inherits(FoldMode, BaseFoldMode);
  388. (function() {
  389. this.foldingStartMarker = /\b(rule|declare|query|when|then)\b/;
  390. this.foldingStopMarker = /\bend\b/;
  391. this.getFoldWidgetRange = function(session, foldStyle, row) {
  392. var line = session.getLine(row);
  393. var match = line.match(this.foldingStartMarker);
  394. if (match) {
  395. var i = match.index;
  396. if (match[1]) {
  397. var position = {row: row, column: line.length};
  398. var iterator = new TokenIterator(session, position.row, position.column);
  399. var seek = "end";
  400. var token = iterator.getCurrentToken();
  401. if (token.value == "when") {
  402. seek = "then";
  403. }
  404. while (token) {
  405. if (token.value == seek) {
  406. return Range.fromPoints(position ,{
  407. row: iterator.getCurrentTokenRow(),
  408. column: iterator.getCurrentTokenColumn()
  409. });
  410. }
  411. token = iterator.stepForward();
  412. }
  413. }
  414. }
  415. };
  416. }).call(FoldMode.prototype);
  417. });
  418. ace.define("ace/mode/drools",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/drools_highlight_rules","ace/mode/folding/drools"], function(require, exports, module) {
  419. "use strict";
  420. var oop = require("../lib/oop");
  421. var TextMode = require("./text").Mode;
  422. var DroolsHighlightRules = require("./drools_highlight_rules").DroolsHighlightRules;
  423. var DroolsFoldMode = require("./folding/drools").FoldMode;
  424. var Mode = function() {
  425. this.HighlightRules = DroolsHighlightRules;
  426. this.foldingRules = new DroolsFoldMode();
  427. this.$behaviour = this.$defaultBehaviour;
  428. };
  429. oop.inherits(Mode, TextMode);
  430. (function() {
  431. this.lineCommentStart = "//";
  432. this.$id = "ace/mode/drools";
  433. this.snippetFileId = "ace/snippets/drools";
  434. }).call(Mode.prototype);
  435. exports.Mode = Mode;
  436. }); (function() {
  437. ace.require(["ace/mode/drools"], function(m) {
  438. if (typeof module == "object" && typeof exports == "object" && module) {
  439. module.exports = m;
  440. }
  441. });
  442. })();