mode-apex.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. define("ace/mode/doc_comment_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  2. "use strict";
  3. var oop = ace_require("../lib/oop");
  4. var TextHighlightRules = ace_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. define("ace/mode/apex_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules","ace/mode/doc_comment_highlight_rules"], function(ace_require, exports, module) {
  42. "use strict";
  43. var oop = ace_require("../lib/oop");
  44. var TextHighlightRules = ace_require("../mode/text_highlight_rules").TextHighlightRules;
  45. var DocCommentHighlightRules = ace_require("../mode/doc_comment_highlight_rules").DocCommentHighlightRules;
  46. var ApexHighlightRules = function() {
  47. var mainKeywordMapper = this.createKeywordMapper({
  48. "variable.language": "activate|any|autonomous|begin|bigdecimal|byte|cast|char|collect|const"
  49. + "|end|exit|export|float|goto|group|having|hint|import|inner|into|join|loop|number|object|of|outer"
  50. + "|parallel|pragma|retrieve|returning|search|short|stat|synchronized|then|this_month"
  51. + "|transaction|type|when",
  52. "keyword": "private|protected|public|native|synchronized|abstract|threadsafe|transient|static|final"
  53. + "|and|array|as|asc|break|bulk|by|catch|class|commit|continue|convertcurrency"
  54. + "|delete|desc|do|else|enum|extends|false|final|finally|for|from|future|global"
  55. + "|if|implements|in|insert|instanceof|interface|last_90_days|last_month"
  56. + "|last_n_days|last_week|like|limit|list|map|merge|new|next_90_days|next_month|next_n_days"
  57. + "|next_week|not|null|nulls|on|or|override|package|return"
  58. + "|rollback|savepoint|select|set|sort|super|testmethod|this|this_week|throw|today"
  59. + "|tolabel|tomorrow|trigger|true|try|undelete|update|upsert|using|virtual|webservice"
  60. + "|where|while|yesterday|switch|case|default",
  61. "storage.type":
  62. "def|boolean|byte|char|short|int|float|pblob|date|datetime|decimal|double|id|integer|long|string|time|void|blob|Object",
  63. "constant.language":
  64. "true|false|null|after|before|count|excludes|first|includes|last|order|sharing|with",
  65. "support.function":
  66. "system|apex|label|apexpages|userinfo|schema"
  67. }, "identifier", true);
  68. function keywordMapper(value) {
  69. if (value.slice(-3) == "__c") return "support.function";
  70. return mainKeywordMapper(value);
  71. }
  72. function string(start, options) {
  73. return {
  74. regex: start + (options.multiline ? "" : "(?=.)"),
  75. token: "string.start",
  76. next: [{
  77. regex: options.escape,
  78. token: "character.escape"
  79. }, {
  80. regex: options.error,
  81. token: "error.invalid"
  82. }, {
  83. regex: start + (options.multiline ? "" : "|$"),
  84. token: "string.end",
  85. next: options.next || "start"
  86. }, {
  87. defaultToken: "string"
  88. }]
  89. };
  90. }
  91. function comments() {
  92. return [{
  93. token : "comment",
  94. regex : "\\/\\/(?=.)",
  95. next : [
  96. DocCommentHighlightRules.getTagRule(),
  97. {token : "comment", regex : "$|^", next : "start"},
  98. {defaultToken : "comment", caseInsensitive: true}
  99. ]
  100. },
  101. DocCommentHighlightRules.getStartRule("doc-start"),
  102. {
  103. token : "comment", // multi line comment
  104. regex : /\/\*/,
  105. next : [
  106. DocCommentHighlightRules.getTagRule(),
  107. {token : "comment", regex : "\\*\\/", next : "start"},
  108. {defaultToken : "comment", caseInsensitive: true}
  109. ]
  110. }
  111. ];
  112. }
  113. this.$rules = {
  114. start: [
  115. string("'", {
  116. escape: /\\[nb'"\\]/,
  117. error: /\\./,
  118. multiline: false
  119. }),
  120. comments("c"),
  121. {
  122. type: "decoration",
  123. token: [
  124. "meta.package.apex",
  125. "keyword.other.package.apex",
  126. "meta.package.apex",
  127. "storage.modifier.package.apex",
  128. "meta.package.apex",
  129. "punctuation.terminator.apex"
  130. ],
  131. regex: /^(\s*)(package)\b(?:(\s*)([^ ;$]+)(\s*)((?:;)?))?/
  132. }, {
  133. regex: /@[a-zA-Z_$][a-zA-Z_$\d\u0080-\ufffe]*/,
  134. token: "constant.language"
  135. },
  136. {
  137. regex: /[a-zA-Z_$][a-zA-Z_$\d\u0080-\ufffe]*/,
  138. token: keywordMapper
  139. },
  140. {
  141. regex: "`#%",
  142. token: "error.invalid"
  143. }, {
  144. token : "constant.numeric", // float
  145. regex : /[+-]?\d+(?:(?:\.\d*)?(?:[LlDdEe][+-]?\d+)?)\b|\.\d+[LlDdEe]/
  146. }, {
  147. token : "keyword.operator",
  148. regex : /--|\+\+|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|[!$%&*+\-~\/^]=?/,
  149. next : "start"
  150. }, {
  151. token : "punctuation.operator",
  152. regex : /[?:,;.]/,
  153. next : "start"
  154. }, {
  155. token : "paren.lparen",
  156. regex : /[\[]/,
  157. next : "maybe_soql",
  158. merge : false
  159. }, {
  160. token : "paren.lparen",
  161. regex : /[\[({]/,
  162. next : "start",
  163. merge : false
  164. }, {
  165. token : "paren.rparen",
  166. regex : /[\])}]/,
  167. merge : false
  168. }
  169. ],
  170. maybe_soql: [{
  171. regex: /\s+/,
  172. token: "text"
  173. }, {
  174. regex: /(SELECT|FIND)\b/,
  175. token: "keyword",
  176. caseInsensitive: true,
  177. next: "soql"
  178. }, {
  179. regex: "",
  180. token: "none",
  181. next: "start"
  182. }],
  183. soql: [{
  184. regex: "(:?ASC|BY|CATEGORY|CUBE|DATA|DESC|END|FIND|FIRST|FOR|FROM|GROUP|HAVING|IN|LAST"
  185. + "|LIMIT|NETWORK|NULLS|OFFSET|ORDER|REFERENCE|RETURNING|ROLLUP|SCOPE|SELECT"
  186. + "|SNIPPET|TRACKING|TYPEOF|UPDATE|USING|VIEW|VIEWSTAT|WHERE|WITH|AND|OR)\\b",
  187. token: "keyword",
  188. caseInsensitive: true
  189. }, {
  190. regex: "(:?target_length|toLabel|convertCurrency|count|Contact|Account|User|FIELDS)\\b",
  191. token: "support.function",
  192. caseInsensitive: true
  193. }, {
  194. token : "paren.rparen",
  195. regex : /[\]]/,
  196. next : "start",
  197. merge : false
  198. },
  199. string("'", {
  200. escape: /\\[nb'"\\]/,
  201. error: /\\./,
  202. multiline: false,
  203. next: "soql"
  204. }),
  205. string('"', {
  206. escape: /\\[nb'"\\]/,
  207. error: /\\./,
  208. multiline: false,
  209. next: "soql"
  210. }),
  211. {
  212. regex: /\\./,
  213. token: "character.escape"
  214. },
  215. {
  216. regex : /[\?\&\|\!\{\}\[\]\(\)\^\~\*\:\"\'\+\-\,\.=\\\/]/,
  217. token : "keyword.operator"
  218. }],
  219. "log-start" : [ {
  220. token : "timestamp.invisible",
  221. regex : /^[\d:.() ]+\|/,
  222. next: "log-header"
  223. }, {
  224. token : "timestamp.invisible",
  225. regex : /^ (Number of|Maximum)[^:]*:/,
  226. next: "log-comment"
  227. }, {
  228. token : "invisible",
  229. regex : /^Execute Anonymous:/,
  230. next: "log-comment"
  231. }, {
  232. defaultToken: "text"
  233. }],
  234. "log-comment": [{
  235. token : "log-comment",
  236. regex : /.*$/,
  237. next: "log-start"
  238. }],
  239. "log-header": [{
  240. token : "timestamp.invisible",
  241. regex : /((USER_DEBUG|\[\d+\]|DEBUG)\|)+/
  242. },
  243. {
  244. token : "keyword",
  245. regex: "(?:EXECUTION_FINISHED|EXECUTION_STARTED|CODE_UNIT_STARTED"
  246. + "|CUMULATIVE_LIMIT_USAGE|LIMIT_USAGE_FOR_NS"
  247. + "|CUMULATIVE_LIMIT_USAGE_END|CODE_UNIT_FINISHED)"
  248. }, {
  249. regex: "",
  250. next: "log-start"
  251. }]
  252. };
  253. this.embedRules(DocCommentHighlightRules, "doc-",
  254. [ DocCommentHighlightRules.getEndRule("start") ]);
  255. this.normalizeRules();
  256. };
  257. oop.inherits(ApexHighlightRules, TextHighlightRules);
  258. exports.ApexHighlightRules = ApexHighlightRules;
  259. });
  260. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  261. "use strict";
  262. var oop = ace_require("../../lib/oop");
  263. var Range = ace_require("../../range").Range;
  264. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  265. var FoldMode = exports.FoldMode = function(commentRegex) {
  266. if (commentRegex) {
  267. this.foldingStartMarker = new RegExp(
  268. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  269. );
  270. this.foldingStopMarker = new RegExp(
  271. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  272. );
  273. }
  274. };
  275. oop.inherits(FoldMode, BaseFoldMode);
  276. (function() {
  277. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  278. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  279. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  280. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  281. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  282. this._getFoldWidgetBase = this.getFoldWidget;
  283. this.getFoldWidget = function(session, foldStyle, row) {
  284. var line = session.getLine(row);
  285. if (this.singleLineBlockCommentRe.test(line)) {
  286. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  287. return "";
  288. }
  289. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  290. if (!fw && this.startRegionRe.test(line))
  291. return "start"; // lineCommentRegionStart
  292. return fw;
  293. };
  294. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  295. var line = session.getLine(row);
  296. if (this.startRegionRe.test(line))
  297. return this.getCommentRegionBlock(session, line, row);
  298. var match = line.match(this.foldingStartMarker);
  299. if (match) {
  300. var i = match.index;
  301. if (match[1])
  302. return this.openingBracketBlock(session, match[1], row, i);
  303. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  304. if (range && !range.isMultiLine()) {
  305. if (forceMultiline) {
  306. range = this.getSectionRange(session, row);
  307. } else if (foldStyle != "all")
  308. range = null;
  309. }
  310. return range;
  311. }
  312. if (foldStyle === "markbegin")
  313. return;
  314. var match = line.match(this.foldingStopMarker);
  315. if (match) {
  316. var i = match.index + match[0].length;
  317. if (match[1])
  318. return this.closingBracketBlock(session, match[1], row, i);
  319. return session.getCommentFoldRange(row, i, -1);
  320. }
  321. };
  322. this.getSectionRange = function(session, row) {
  323. var line = session.getLine(row);
  324. var startIndent = line.search(/\S/);
  325. var startRow = row;
  326. var startColumn = line.length;
  327. row = row + 1;
  328. var endRow = row;
  329. var maxRow = session.getLength();
  330. while (++row < maxRow) {
  331. line = session.getLine(row);
  332. var indent = line.search(/\S/);
  333. if (indent === -1)
  334. continue;
  335. if (startIndent > indent)
  336. break;
  337. var subRange = this.getFoldWidgetRange(session, "all", row);
  338. if (subRange) {
  339. if (subRange.start.row <= startRow) {
  340. break;
  341. } else if (subRange.isMultiLine()) {
  342. row = subRange.end.row;
  343. } else if (startIndent == indent) {
  344. break;
  345. }
  346. }
  347. endRow = row;
  348. }
  349. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  350. };
  351. this.getCommentRegionBlock = function(session, line, row) {
  352. var startColumn = line.search(/\s*$/);
  353. var maxRow = session.getLength();
  354. var startRow = row;
  355. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  356. var depth = 1;
  357. while (++row < maxRow) {
  358. line = session.getLine(row);
  359. var m = re.exec(line);
  360. if (!m) continue;
  361. if (m[1]) depth--;
  362. else depth++;
  363. if (!depth) break;
  364. }
  365. var endRow = row;
  366. if (endRow > startRow) {
  367. return new Range(startRow, startColumn, endRow, line.length);
  368. }
  369. };
  370. }).call(FoldMode.prototype);
  371. });
  372. define("ace/mode/apex",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/apex_highlight_rules","ace/mode/folding/cstyle","ace/mode/behaviour/cstyle"], function(ace_require, exports, module) {
  373. "use strict";
  374. var oop = ace_require("../lib/oop");
  375. var TextMode = ace_require("../mode/text").Mode;
  376. var ApexHighlightRules = ace_require("./apex_highlight_rules").ApexHighlightRules;
  377. var FoldMode = ace_require("../mode/folding/cstyle").FoldMode;
  378. var CstyleBehaviour = ace_require("../mode/behaviour/cstyle").CstyleBehaviour;
  379. function ApexMode() {
  380. TextMode.call(this);
  381. this.HighlightRules = ApexHighlightRules;
  382. this.foldingRules = new FoldMode();
  383. this.$behaviour = new CstyleBehaviour();
  384. }
  385. oop.inherits(ApexMode, TextMode);
  386. ApexMode.prototype.lineCommentStart = "//";
  387. ApexMode.prototype.blockComment = {
  388. start: "/*",
  389. end: "*/"
  390. };
  391. exports.Mode = ApexMode;
  392. }); (function() {
  393. window.ace_require(["ace/mode/apex"], function(m) {
  394. if (typeof module == "object" && typeof exports == "object" && module) {
  395. module.exports = m;
  396. }
  397. });
  398. })();