mode-drools.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. ace.define("ace/mode/doc_comment_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",[], 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. token : keywordMapper,
  121. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  122. }, {
  123. token : "keyword.operator",
  124. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  125. }, {
  126. token : "lparen",
  127. regex : "[[({]"
  128. }, {
  129. token : "rparen",
  130. regex : "[\\])}]"
  131. }, {
  132. token : "text",
  133. regex : "\\s+"
  134. }
  135. ],
  136. "comment" : [
  137. {
  138. token : "comment", // closing comment
  139. regex : "\\*\\/",
  140. next : "start"
  141. }, {
  142. defaultToken : "comment"
  143. }
  144. ]
  145. };
  146. this.embedRules(DocCommentHighlightRules, "doc-",
  147. [ DocCommentHighlightRules.getEndRule("start") ]);
  148. };
  149. oop.inherits(JavaHighlightRules, TextHighlightRules);
  150. exports.JavaHighlightRules = JavaHighlightRules;
  151. });
  152. ace.define("ace/mode/drools_highlight_rules",[], function(require, exports, module) {
  153. "use strict";
  154. var oop = require("../lib/oop");
  155. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  156. var JavaHighlightRules = require("./java_highlight_rules").JavaHighlightRules;
  157. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  158. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*";
  159. var packageIdentifierRe = "[a-zA-Z\\$_\u00a1-\uffff][\\.a-zA-Z\\d\\$_\u00a1-\uffff]*";
  160. var DroolsHighlightRules = function() {
  161. var keywords = ("date|effective|expires|lock|on|active|no|loop|auto|focus" +
  162. "|activation|group|agenda|ruleflow|duration|timer|calendars|refract|direct" +
  163. "|dialect|salience|enabled|attributes|extends|template" +
  164. "|function|contains|matches|eval|excludes|soundslike" +
  165. "|memberof|not|in|or|and|exists|forall|over|from|entry|point|accumulate|acc|collect" +
  166. "|action|reverse|result|end|init|instanceof|extends|super|boolean|char|byte|short" +
  167. "|int|long|float|double|this|void|class|new|case|final|if|else|for|while|do" +
  168. "|default|try|catch|finally|switch|synchronized|return|throw|break|continue|assert" +
  169. "|modify|static|public|protected|private|abstract|native|transient|volatile" +
  170. "|strictfp|throws|interface|enum|implements|type|window|trait|no-loop|str"
  171. );
  172. var langClasses = (
  173. "AbstractMethodError|AssertionError|ClassCircularityError|"+
  174. "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+
  175. "ExceptionInInitializerError|IllegalAccessError|"+
  176. "IllegalThreadStateException|InstantiationError|InternalError|"+
  177. "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+
  178. "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+
  179. "SuppressWarnings|TypeNotPresentException|UnknownError|"+
  180. "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+
  181. "InstantiationException|IndexOutOfBoundsException|"+
  182. "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+
  183. "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+
  184. "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+
  185. "InterruptedException|NoSuchMethodException|IllegalAccessException|"+
  186. "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+
  187. "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+
  188. "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+
  189. "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+
  190. "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+
  191. "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+
  192. "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+
  193. "ArrayStoreException|ClassCastException|LinkageError|"+
  194. "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+
  195. "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+
  196. "Cloneable|Class|CharSequence|Comparable|String|Object"
  197. );
  198. var keywordMapper = this.createKeywordMapper({
  199. "variable.language": "this",
  200. "keyword": keywords,
  201. "constant.language": "null",
  202. "support.class" : langClasses,
  203. "support.function" : "retract|update|modify|insert"
  204. }, "identifier");
  205. var stringRules = function() {
  206. return [{
  207. token : "string", // single line
  208. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  209. }, {
  210. token : "string", // single line
  211. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  212. }];
  213. };
  214. var basicPreRules = function(blockCommentRules) {
  215. return [{
  216. token : "comment",
  217. regex : "\\/\\/.*$"
  218. },
  219. DocCommentHighlightRules.getStartRule("doc-start"),
  220. {
  221. token : "comment", // multi line comment
  222. regex : "\\/\\*",
  223. next : blockCommentRules
  224. }, {
  225. token : "constant.numeric", // hex
  226. regex : "0[xX][0-9a-fA-F]+\\b"
  227. }, {
  228. token : "constant.numeric", // float
  229. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  230. }, {
  231. token : "constant.language.boolean",
  232. regex : "(?:true|false)\\b"
  233. }];
  234. };
  235. var blockCommentRules = function(returnRule) {
  236. return [
  237. {
  238. token : "comment.block", // closing comment
  239. regex : "\\*\\/",
  240. next : returnRule
  241. }, {
  242. defaultToken : "comment.block"
  243. }
  244. ];
  245. };
  246. var basicPostRules = function() {
  247. return [{
  248. token : keywordMapper,
  249. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  250. }, {
  251. token : "keyword.operator",
  252. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  253. }, {
  254. token : "lparen",
  255. regex : "[[({]"
  256. }, {
  257. token : "rparen",
  258. regex : "[\\])}]"
  259. }, {
  260. token : "text",
  261. regex : "\\s+"
  262. }];
  263. };
  264. this.$rules = {
  265. "start" : [].concat(basicPreRules("block.comment"), [
  266. {
  267. token : "entity.name.type",
  268. regex : "@[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  269. }, {
  270. token : ["keyword","text","entity.name.type"],
  271. regex : "(package)(\\s+)(" + packageIdentifierRe +")"
  272. }, {
  273. token : ["keyword","text","keyword","text","entity.name.type"],
  274. regex : "(import)(\\s+)(function)(\\s+)(" + packageIdentifierRe +")"
  275. }, {
  276. token : ["keyword","text","entity.name.type"],
  277. regex : "(import)(\\s+)(" + packageIdentifierRe +")"
  278. }, {
  279. token : ["keyword","text","entity.name.type","text","variable"],
  280. regex : "(global)(\\s+)(" + packageIdentifierRe +")(\\s+)(" + identifierRe +")"
  281. }, {
  282. token : ["keyword","text","keyword","text","entity.name.type"],
  283. regex : "(declare)(\\s+)(trait)(\\s+)(" + identifierRe +")"
  284. }, {
  285. token : ["keyword","text","entity.name.type"],
  286. regex : "(declare)(\\s+)(" + identifierRe +")"
  287. }, {
  288. token : ["keyword","text","entity.name.type"],
  289. regex : "(extends)(\\s+)(" + packageIdentifierRe +")"
  290. }, {
  291. token : ["keyword","text"],
  292. regex : "(rule)(\\s+)",
  293. next : "asset.name"
  294. }],
  295. stringRules(),
  296. [{
  297. token : ["variable.other","text","text"],
  298. regex : "(" + identifierRe + ")(\\s*)(:)"
  299. }, {
  300. token : ["keyword","text"],
  301. regex : "(query)(\\s+)",
  302. next : "asset.name"
  303. }, {
  304. token : ["keyword","text"],
  305. regex : "(when)(\\s*)"
  306. }, {
  307. token : ["keyword","text"],
  308. regex : "(then)(\\s*)",
  309. next : "java-start"
  310. }, {
  311. token : "paren.lparen",
  312. regex : /[\[({]/
  313. }, {
  314. token : "paren.rparen",
  315. regex : /[\])}]/
  316. }], basicPostRules()),
  317. "block.comment" : blockCommentRules("start"),
  318. "asset.name" : [
  319. {
  320. token : "entity.name",
  321. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  322. }, {
  323. token : "entity.name",
  324. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  325. }, {
  326. token : "entity.name",
  327. regex : identifierRe
  328. }, {
  329. regex: "",
  330. token: "empty",
  331. next: "start"
  332. }]
  333. };
  334. this.embedRules(DocCommentHighlightRules, "doc-",
  335. [ DocCommentHighlightRules.getEndRule("start") ]);
  336. this.embedRules(JavaHighlightRules, "java-", [
  337. {
  338. token : "support.function",
  339. regex: "\\b(insert|modify|retract|update)\\b"
  340. }, {
  341. token : "keyword",
  342. regex: "\\bend\\b",
  343. next : "start"
  344. }]);
  345. };
  346. oop.inherits(DroolsHighlightRules, TextHighlightRules);
  347. exports.DroolsHighlightRules = DroolsHighlightRules;
  348. });
  349. ace.define("ace/mode/folding/drools",[], function(require, exports, module) {
  350. "use strict";
  351. var oop = require("../../lib/oop");
  352. var Range = require("../../range").Range;
  353. var BaseFoldMode = require("./fold_mode").FoldMode;
  354. var TokenIterator = require("../../token_iterator").TokenIterator;
  355. var FoldMode = exports.FoldMode = function() {};
  356. oop.inherits(FoldMode, BaseFoldMode);
  357. (function() {
  358. this.foldingStartMarker = /\b(rule|declare|query|when|then)\b/;
  359. this.foldingStopMarker = /\bend\b/;
  360. this.getFoldWidgetRange = function(session, foldStyle, row) {
  361. var line = session.getLine(row);
  362. var match = line.match(this.foldingStartMarker);
  363. if (match) {
  364. var i = match.index;
  365. if (match[1]) {
  366. var position = {row: row, column: line.length};
  367. var iterator = new TokenIterator(session, position.row, position.column);
  368. var seek = "end";
  369. var token = iterator.getCurrentToken();
  370. if (token.value == "when") {
  371. seek = "then";
  372. }
  373. while (token) {
  374. if (token.value == seek) {
  375. return Range.fromPoints(position ,{
  376. row: iterator.getCurrentTokenRow(),
  377. column: iterator.getCurrentTokenColumn()
  378. });
  379. }
  380. token = iterator.stepForward();
  381. }
  382. }
  383. }
  384. };
  385. }).call(FoldMode.prototype);
  386. });
  387. ace.define("ace/mode/drools",[], function(require, exports, module) {
  388. "use strict";
  389. var oop = require("../lib/oop");
  390. var TextMode = require("./text").Mode;
  391. var DroolsHighlightRules = require("./drools_highlight_rules").DroolsHighlightRules;
  392. var DroolsFoldMode = require("./folding/drools").FoldMode;
  393. var Mode = function() {
  394. this.HighlightRules = DroolsHighlightRules;
  395. this.foldingRules = new DroolsFoldMode();
  396. this.$behaviour = this.$defaultBehaviour;
  397. };
  398. oop.inherits(Mode, TextMode);
  399. (function() {
  400. this.lineCommentStart = "//";
  401. this.$id = "ace/mode/drools";
  402. }).call(Mode.prototype);
  403. exports.Mode = Mode;
  404. });
  405. (function() {
  406. ace.require(["ace/mode/drools"], function(m) {
  407. if (typeof module == "object" && typeof exports == "object" && module) {
  408. module.exports = m;
  409. }
  410. });
  411. })();