mode-drools.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. );
  59. var buildinConstants = ("null|Infinity|NaN|undefined");
  60. var langClasses = (
  61. "AbstractMethodError|AssertionError|ClassCircularityError|"+
  62. "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+
  63. "ExceptionInInitializerError|IllegalAccessError|"+
  64. "IllegalThreadStateException|InstantiationError|InternalError|"+
  65. "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+
  66. "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+
  67. "SuppressWarnings|TypeNotPresentException|UnknownError|"+
  68. "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+
  69. "InstantiationException|IndexOutOfBoundsException|"+
  70. "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+
  71. "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+
  72. "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+
  73. "InterruptedException|NoSuchMethodException|IllegalAccessException|"+
  74. "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+
  75. "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+
  76. "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+
  77. "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+
  78. "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+
  79. "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+
  80. "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+
  81. "ArrayStoreException|ClassCastException|LinkageError|"+
  82. "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+
  83. "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+
  84. "Cloneable|Class|CharSequence|Comparable|String|Object"
  85. );
  86. var keywordMapper = this.createKeywordMapper({
  87. "variable.language": "this",
  88. "keyword": keywords,
  89. "constant.language": buildinConstants,
  90. "support.function": langClasses
  91. }, "identifier");
  92. this.$rules = {
  93. "start" : [
  94. {
  95. token : "comment",
  96. regex : "\\/\\/.*$"
  97. },
  98. DocCommentHighlightRules.getStartRule("doc-start"),
  99. {
  100. token : "comment", // multi line comment
  101. regex : "\\/\\*",
  102. next : "comment"
  103. }, {
  104. token : "string", // single line
  105. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  106. }, {
  107. token : "string", // single line
  108. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  109. }, {
  110. token : "constant.numeric", // hex
  111. regex : /0(?:[xX][0-9a-fA-F][0-9a-fA-F_]*|[bB][01][01_]*)[LlSsDdFfYy]?\b/
  112. }, {
  113. token : "constant.numeric", // float
  114. regex : /[+-]?\d[\d_]*(?:(?:\.[\d_]*)?(?:[eE][+-]?[\d_]+)?)?[LlSsDdFfYy]?\b/
  115. }, {
  116. token : "constant.language.boolean",
  117. regex : "(?:true|false)\\b"
  118. }, {
  119. token : keywordMapper,
  120. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  121. }, {
  122. token : "keyword.operator",
  123. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  124. }, {
  125. token : "lparen",
  126. regex : "[[({]"
  127. }, {
  128. token : "rparen",
  129. regex : "[\\])}]"
  130. }, {
  131. token : "text",
  132. regex : "\\s+"
  133. }
  134. ],
  135. "comment" : [
  136. {
  137. token : "comment", // closing comment
  138. regex : ".*?\\*\\/",
  139. next : "start"
  140. }, {
  141. token : "comment", // comment spanning whole line
  142. regex : ".+"
  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",["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) {
  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. token : "comment.block", // comment spanning whole line
  243. regex : ".+"
  244. }
  245. ];
  246. }
  247. var basicPostRules = function() {
  248. return [{
  249. token : keywordMapper,
  250. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  251. }, {
  252. token : "keyword.operator",
  253. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  254. }, {
  255. token : "lparen",
  256. regex : "[[({]"
  257. }, {
  258. token : "rparen",
  259. regex : "[\\])}]"
  260. }, {
  261. token : "text",
  262. regex : "\\s+"
  263. }];
  264. };
  265. this.$rules = {
  266. "start" : [].concat(basicPreRules("block.comment"), [
  267. {
  268. token : "entity.name.type",
  269. regex : "@[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  270. }, {
  271. token : ["keyword","text","entity.name.type"],
  272. regex : "(package)(\\s+)(" + packageIdentifierRe +")"
  273. }, {
  274. token : ["keyword","text","keyword","text","entity.name.type"],
  275. regex : "(import)(\\s+)(function)(\\s+)(" + packageIdentifierRe +")"
  276. }, {
  277. token : ["keyword","text","entity.name.type"],
  278. regex : "(import)(\\s+)(" + packageIdentifierRe +")"
  279. }, {
  280. token : ["keyword","text","entity.name.type","text","variable"],
  281. regex : "(global)(\\s+)(" + packageIdentifierRe +")(\\s+)(" + identifierRe +")"
  282. }, {
  283. token : ["keyword","text","keyword","text","entity.name.type"],
  284. regex : "(declare)(\\s+)(trait)(\\s+)(" + identifierRe +")"
  285. }, {
  286. token : ["keyword","text","entity.name.type"],
  287. regex : "(declare)(\\s+)(" + identifierRe +")"
  288. }, {
  289. token : ["keyword","text","entity.name.type"],
  290. regex : "(extends)(\\s+)(" + packageIdentifierRe +")"
  291. }, {
  292. token : ["keyword","text"],
  293. regex : "(rule)(\\s+)",
  294. next : "asset.name"
  295. }],
  296. stringRules(),
  297. [{
  298. token : ["variable.other","text","text"],
  299. regex : "(" + identifierRe + ")(\\s*)(:)"
  300. }, {
  301. token : ["keyword","text"],
  302. regex : "(query)(\\s+)",
  303. next : "asset.name"
  304. }, {
  305. token : ["keyword","text"],
  306. regex : "(when)(\\s*)"
  307. }, {
  308. token : ["keyword","text"],
  309. regex : "(then)(\\s*)",
  310. next : "java-start"
  311. }, {
  312. token : "paren.lparen",
  313. regex : /[\[({]/
  314. }, {
  315. token : "paren.rparen",
  316. regex : /[\])}]/
  317. }], basicPostRules()),
  318. "block.comment" : blockCommentRules("start"),
  319. "asset.name" : [
  320. {
  321. token : "entity.name",
  322. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  323. }, {
  324. token : "entity.name",
  325. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  326. }, {
  327. token : "entity.name",
  328. regex : identifierRe
  329. }, {
  330. regex: "",
  331. token: "empty",
  332. next: "start"
  333. }]
  334. };
  335. this.embedRules(DocCommentHighlightRules, "doc-",
  336. [ DocCommentHighlightRules.getEndRule("start") ]);
  337. this.embedRules(JavaHighlightRules, "java-", [
  338. {
  339. token : "support.function",
  340. regex: "\\b(insert|modify|retract|update)\\b"
  341. }, {
  342. token : "keyword",
  343. regex: "\\bend\\b",
  344. next : "start"
  345. }]);
  346. };
  347. oop.inherits(DroolsHighlightRules, TextHighlightRules);
  348. exports.DroolsHighlightRules = DroolsHighlightRules;
  349. });
  350. 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) {
  351. "use strict";
  352. var oop = require("../../lib/oop");
  353. var Range = require("../../range").Range;
  354. var BaseFoldMode = require("./fold_mode").FoldMode;
  355. var TokenIterator = require("../../token_iterator").TokenIterator;
  356. var FoldMode = exports.FoldMode = function() {};
  357. oop.inherits(FoldMode, BaseFoldMode);
  358. (function() {
  359. this.foldingStartMarker = /\b(rule|declare|query|when|then)\b/;
  360. this.foldingStopMarker = /\bend\b/;
  361. this.getFoldWidgetRange = function(session, foldStyle, row) {
  362. var line = session.getLine(row);
  363. var match = line.match(this.foldingStartMarker);
  364. if (match) {
  365. var i = match.index;
  366. if (match[1]) {
  367. var position = {row: row, column: line.length};
  368. var iterator = new TokenIterator(session, position.row, position.column);
  369. var seek = "end";
  370. var token = iterator.getCurrentToken();
  371. if (token.value == "when") {
  372. seek = "then";
  373. }
  374. while (token) {
  375. if (token.value == seek) {
  376. return Range.fromPoints(position ,{
  377. row: iterator.getCurrentTokenRow(),
  378. column: iterator.getCurrentTokenColumn()
  379. });
  380. }
  381. token = iterator.stepForward();
  382. }
  383. }
  384. }
  385. }
  386. }).call(FoldMode.prototype);
  387. });
  388. 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) {
  389. "use strict";
  390. var oop = require("../lib/oop");
  391. var TextMode = require("./text").Mode;
  392. var DroolsHighlightRules = require("./drools_highlight_rules").DroolsHighlightRules;
  393. var DroolsFoldMode = require("./folding/drools").FoldMode;
  394. var Mode = function() {
  395. this.HighlightRules = DroolsHighlightRules;
  396. this.foldingRules = new DroolsFoldMode();
  397. this.$behaviour = this.$defaultBehaviour;
  398. };
  399. oop.inherits(Mode, TextMode);
  400. (function() {
  401. this.lineCommentStart = "//";
  402. this.$id = "ace/mode/drools";
  403. }).call(Mode.prototype);
  404. exports.Mode = Mode;
  405. });